Write more documentation

This commit is contained in:
Héctor Ramón Jiménez 2019-08-28 06:45:39 +02:00
parent 5dbcf211ef
commit 8758dd446f
7 changed files with 32 additions and 23 deletions

View file

@ -4,7 +4,8 @@
[![Crates.io](https://img.shields.io/crates/v/iced.svg)](https://crates.io/crates/iced) [![Crates.io](https://img.shields.io/crates/v/iced.svg)](https://crates.io/crates/iced)
[![License](https://img.shields.io/crates/l/iced.svg)](https://github.com/hecrj/iced/blob/master/LICENSE) [![License](https://img.shields.io/crates/l/iced.svg)](https://github.com/hecrj/iced/blob/master/LICENSE)
A simple GUI runtime for Rust, heavily inspired by [Elm]. A renderer-agnostic GUI library for Rust focused on simplicity and type-safety.
Inspired by [Elm].
__Iced is in a very early stage of development.__ Many [basic features are still __Iced is in a very early stage of development.__ Many [basic features are still
missing] and there are probably _many_ bugs. [Feel free to contribute!] missing] and there are probably _many_ bugs. [Feel free to contribute!]
@ -18,12 +19,11 @@ missing] and there are probably _many_ bugs. [Feel free to contribute!]
[gui_gfycat]: https://gfycat.com/gloomyweakhammerheadshark [gui_gfycat]: https://gfycat.com/gloomyweakhammerheadshark
## Features ## Features
* Simple, easy-to-use API * Simple, easy-to-use, renderer-agnostic API
* Responsive, flexbox-based layouting * Responsive, flexbox-based layouting
* Type-safe, reactive programming model * Type-safe, reactive programming model
* Built-in widgets * Built-in widgets
* Custom widget support * Custom widget support
* Renderer-agnostic runtime
## Installation ## Installation
Add `iced` as a dependency in your `Cargo.toml`: Add `iced` as a dependency in your `Cargo.toml`:
@ -67,8 +67,8 @@ struct Counter {
} }
``` ```
Now that we have state, what are the user interactions we care about? The Now that we have state... When will it change? When either button is pressed!
button presses! These are our __messages__: These user interactions are our __messages__:
```rust ```rust
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
@ -108,7 +108,7 @@ impl Counter {
} }
``` ```
Finally, we need to be able to react to the __messages__ and mutate our Finally, we need to be able to react to the __messages__ and change our
__state__ accordingly in our __update logic__: __state__ accordingly in our __update logic__:
```rust ```rust
@ -131,7 +131,7 @@ impl Counter {
And that's everything! We just wrote a whole user interface. Iced is now able And that's everything! We just wrote a whole user interface. Iced is now able
to: to:
1. Take the result of our __view logic__ and build a user interface. 1. Take the result of our __view logic__ and layout its widgets.
1. Process events from our system and produce __messages__ for our 1. Process events from our system and produce __messages__ for our
__update logic__. __update logic__.
1. Draw the resulting user interface using our chosen __renderer__. 1. Draw the resulting user interface using our chosen __renderer__.

View file

@ -1,12 +1,12 @@
//! Iced is a simple GUI runtime for Rust, heavily inspired by [Elm]. //! Iced is a renderer-agnostic GUI library for Rust focused on simplicity and
//! type-safety. Inspired by [Elm].
//! //!
//! # Features //! # Features
//! * Simple, easy-to-use API //! * Simple, easy-to-use, renderer-agnostic API
//! * Responsive, flexbox-based layouting //! * Responsive, flexbox-based layouting
//! * Type-safe, reactive programming model //! * Type-safe, reactive programming model
//! * Many built-in widgets //! * Built-in widgets
//! * Custom widget support //! * Custom widget support
//! * Renderer-agnostic runtime
//! //!
//! Check out the [repository] and the [examples] for more details! //! Check out the [repository] and the [examples] for more details!
//! //!
@ -43,8 +43,8 @@
//! } //! }
//! ``` //! ```
//! //!
//! Now that we have state, what are the user interactions we care about? The //! Now that we have state... When will it change? When either button is pressed!
//! button presses! These are our __messages__: //! These user interactions are our __messages__:
//! //!
//! ``` //! ```
//! #[derive(Debug, Clone, Copy)] //! #[derive(Debug, Clone, Copy)]
@ -139,7 +139,7 @@
//! } //! }
//! ``` //! ```
//! //!
//! Finally, we need to be able to react to the __messages__ and mutate our //! Finally, we need to be able to react to the __messages__ and change our
//! __state__ accordingly in our __update logic__: //! __state__ accordingly in our __update logic__:
//! //!
//! ``` //! ```

View file

@ -1 +1,2 @@
/// A 2D point.
pub type Point = nalgebra::Point2<f32>; pub type Point = nalgebra::Point2<f32>;

View file

@ -3,6 +3,7 @@ use crate::{input::mouse, Column, Element, Event, Layout, MouseCursor, Point};
use std::hash::Hasher; use std::hash::Hasher;
use stretch::result; use stretch::result;
/// A set of interactive graphical elements with a specific layout.
pub struct UserInterface<'a, Message, Renderer> { pub struct UserInterface<'a, Message, Renderer> {
hash: u64, hash: u64,
root: Element<'a, Message, Renderer>, root: Element<'a, Message, Renderer>,

View file

@ -1,8 +1,14 @@
//! Use the built-in widgets or create your own! //! Use the built-in widgets or create your own!
//! //!
//! # Customization //! # Built-in widgets
//! Every drawable widget has its own module with a `Renderer` trait that must //! Every built-in drawable widget has its own module with a `Renderer` trait
//! be implemented by a renderer before being able to use it as a [`Widget`]. //! that must be implemented by an [`iced::Renderer`] before being able to use
//! it as a [`Widget`].
//!
//! # Custom widgets
//! If you want to implement a custom widget, you simply need to implement the
//! [`Widget`] trait. You can use the API of the built-in widgets as a guide or
//! source of inspiration.
//! //!
//! # Re-exports //! # Re-exports
//! For convenience, the contents of this module are available at the root //! For convenience, the contents of this module are available at the root
@ -13,6 +19,7 @@
//! ``` //! ```
//! //!
//! [`Widget`]: trait.Widget.html //! [`Widget`]: trait.Widget.html
//! [`iced::Renderer`]: ../trait.Renderer.html
mod column; mod column;
mod row; mod row;
@ -78,8 +85,8 @@ pub trait Widget<Message, Renderer>: std::fmt::Debug {
/// its value cannot affect the overall [`Layout`] of the user interface. /// its value cannot affect the overall [`Layout`] of the user interface.
/// ///
/// [`Widget`]: trait.Widget.html /// [`Widget`]: trait.Widget.html
/// [`Layout`]: struct.Layout.html /// [`Layout`]: ../struct.Layout.html
/// [`Text`]: ../widget/text/struct.Text.html /// [`Text`]: text/struct.Text.html
fn hash(&self, state: &mut Hasher); fn hash(&self, state: &mut Hasher);
/// Processes a runtime [`Event`]. /// Processes a runtime [`Event`].
@ -93,9 +100,9 @@ pub trait Widget<Message, Renderer>: std::fmt::Debug {
/// ///
/// By default, it does nothing. /// By default, it does nothing.
/// ///
/// [`Event`]: enum.Event.html /// [`Event`]: ../enum.Event.html
/// [`Widget`]: trait.Widget.html /// [`Widget`]: trait.Widget.html
/// [`Layout`]: struct.Layout.html /// [`Layout`]: ../struct.Layout.html
fn on_event( fn on_event(
&mut self, &mut self,
_event: Event, _event: Event,

View file

@ -5,7 +5,7 @@ use crate::{
Style, Widget, Style, Widget,
}; };
/// A container that places its contents vertically. /// A container that distributes its contents vertically.
/// ///
/// A [`Column`] will try to fill the horizontal space of its container. /// A [`Column`] will try to fill the horizontal space of its container.
/// ///

View file

@ -5,7 +5,7 @@ use crate::{
Style, Widget, Style, Widget,
}; };
/// A container that places its contents horizontally. /// A container that distributes its contents horizontally.
/// ///
/// A [`Row`] will try to fill the horizontal space of its container. /// A [`Row`] will try to fill the horizontal space of its container.
/// ///