diff options
author | 2019-11-22 22:14:04 +0100 | |
---|---|---|
committer | 2019-11-22 22:14:04 +0100 | |
commit | fa227255b02adbbfa99801a7baaa4d6d387f7302 (patch) | |
tree | 1b9b4c97a6b6a054ff73cd69ac9b1493f50392c3 /web/src/widget | |
parent | 048909b45dfecef73bfacf3b5aa67462470ccca2 (diff) | |
download | iced-fa227255b02adbbfa99801a7baaa4d6d387f7302.tar.gz iced-fa227255b02adbbfa99801a7baaa4d6d387f7302.tar.bz2 iced-fa227255b02adbbfa99801a7baaa4d6d387f7302.zip |
Write docs for `iced_web`
Diffstat (limited to '')
-rw-r--r-- | web/src/widget.rs | 27 | ||||
-rw-r--r-- | web/src/widget/button.rs | 21 | ||||
-rw-r--r-- | web/src/widget/checkbox.rs | 1 | ||||
-rw-r--r-- | web/src/widget/column.rs | 1 | ||||
-rw-r--r-- | web/src/widget/radio.rs | 1 | ||||
-rw-r--r-- | web/src/widget/row.rs | 2 | ||||
-rw-r--r-- | web/src/widget/slider.rs | 36 |
7 files changed, 86 insertions, 3 deletions
diff --git a/web/src/widget.rs b/web/src/widget.rs index 88b2efc9..30ac8eeb 100644 --- a/web/src/widget.rs +++ b/web/src/widget.rs @@ -1,15 +1,31 @@ +//! Use the built-in widgets or create your own. +//! +//! # 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 +//! For convenience, the contents of this module are available at the root +//! module. Therefore, you can directly type: +//! +//! ``` +//! use iced_web::{button, Button, Widget}; +//! ``` +//! +//! [`Widget`]: trait.Widget.html use crate::Bus; use dodrio::bumpalo; pub mod button; pub mod slider; -pub mod text; mod checkbox; mod column; mod image; mod radio; mod row; +mod text; #[doc(no_inline)] pub use button::Button; @@ -26,7 +42,16 @@ pub use image::Image; pub use radio::Radio; pub use row::Row; +/// A component that displays information and allows interaction. +/// +/// If you want to build your own widgets, you will need to implement this +/// trait. +/// +/// [`Widget`]: trait.Widget.html pub trait Widget<Message> { + /// Produces a VDOM node for the [`Widget`]. + /// + /// [`Widget`]: trait.Widget.html fn node<'b>( &self, bump: &'b bumpalo::Bump, diff --git a/web/src/widget/button.rs b/web/src/widget/button.rs index ddf67743..1c13f34d 100644 --- a/web/src/widget/button.rs +++ b/web/src/widget/button.rs @@ -1,8 +1,27 @@ +//! Allow your users to perform actions by pressing a button. +//! +//! A [`Button`] has some local [`State`]. +//! +//! [`Button`]: struct.Button.html +//! [`State`]: struct.State.html use crate::{Background, Bus, Element, Length, Widget}; use dodrio::bumpalo; -/// A generic widget that produces a message when clicked. +/// A generic widget that produces a message when pressed. +/// +/// ``` +/// # use iced_web::{button, Button, Text}; +/// # +/// enum Message { +/// ButtonPressed, +/// } +/// +/// let mut state = button::State::new(); +/// let button = Button::new(&mut state, Text::new("Press me!")) +/// .on_press(Message::ButtonPressed); +/// ``` +#[allow(missing_debug_implementations)] pub struct Button<'a, Message> { content: Element<'a, Message>, on_press: Option<Message>, diff --git a/web/src/widget/checkbox.rs b/web/src/widget/checkbox.rs index 8bcef816..94b42554 100644 --- a/web/src/widget/checkbox.rs +++ b/web/src/widget/checkbox.rs @@ -19,6 +19,7 @@ use dodrio::bumpalo; /// ``` /// ///  +#[allow(missing_debug_implementations)] pub struct Checkbox<Message> { is_checked: bool, on_toggle: Box<dyn Fn(bool) -> Message>, diff --git a/web/src/widget/column.rs b/web/src/widget/column.rs index cea50f6d..ee8c14fa 100644 --- a/web/src/widget/column.rs +++ b/web/src/widget/column.rs @@ -8,6 +8,7 @@ use std::u32; /// A [`Column`] will try to fill the horizontal space of its container. /// /// [`Column`]: struct.Column.html +#[allow(missing_debug_implementations)] pub struct Column<'a, Message> { spacing: u16, padding: u16, diff --git a/web/src/widget/radio.rs b/web/src/widget/radio.rs index a0b8fc43..32532ebe 100644 --- a/web/src/widget/radio.rs +++ b/web/src/widget/radio.rs @@ -27,6 +27,7 @@ use dodrio::bumpalo; /// ``` /// ///  +#[allow(missing_debug_implementations)] pub struct Radio<Message> { is_selected: bool, on_click: Message, diff --git a/web/src/widget/row.rs b/web/src/widget/row.rs index 44cacd50..b980d9b4 100644 --- a/web/src/widget/row.rs +++ b/web/src/widget/row.rs @@ -8,7 +8,7 @@ use std::u32; /// A [`Row`] will try to fill the horizontal space of its container. /// /// [`Row`]: struct.Row.html -#[allow(missing_docs)] +#[allow(missing_debug_implementations)] pub struct Row<'a, Message> { spacing: u16, padding: u16, diff --git a/web/src/widget/slider.rs b/web/src/widget/slider.rs index acdef0a1..16e20b82 100644 --- a/web/src/widget/slider.rs +++ b/web/src/widget/slider.rs @@ -1,8 +1,37 @@ +//! Display an interactive selector of a single value from a range of values. +//! +//! A [`Slider`] has some local [`State`]. +//! +//! [`Slider`]: struct.Slider.html +//! [`State`]: struct.State.html use crate::{Bus, Element, Length, Widget}; use dodrio::bumpalo; use std::{ops::RangeInclusive, rc::Rc}; +/// An horizontal bar and a handle that selects a single value from a range of +/// values. +/// +/// A [`Slider`] will try to fill the horizontal space of its container. +/// +/// [`Slider`]: struct.Slider.html +/// +/// # Example +/// ``` +/// # use iced_web::{slider, Slider}; +/// # +/// pub enum Message { +/// SliderChanged(f32), +/// } +/// +/// let state = &mut slider::State::new(); +/// let value = 50.0; +/// +/// Slider::new(state, 0.0..=100.0, value, Message::SliderChanged); +/// ``` +/// +///  +#[allow(missing_debug_implementations)] pub struct Slider<'a, Message> { _state: &'a mut State, range: RangeInclusive<f32>, @@ -108,9 +137,16 @@ where } } +/// The local state of a [`Slider`]. +/// +/// [`Slider`]: struct.Slider.html +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] pub struct State; impl State { + /// Creates a new [`State`]. + /// + /// [`State`]: struct.State.html pub fn new() -> Self { Self } |