summaryrefslogtreecommitdiffstats
path: root/src/widget.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/widget.rs')
-rw-r--r--src/widget.rs57
1 files changed, 32 insertions, 25 deletions
diff --git a/src/widget.rs b/src/widget.rs
index 17ff50b6..b8ecb409 100644
--- a/src/widget.rs
+++ b/src/widget.rs
@@ -1,16 +1,25 @@
-//! Use the built-in widgets in your user interface.
+//! Use the built-in widgets or create your own.
//!
-//! # Customization
-//! Every drawable widget has its own module with a `Renderer` trait that must
-//! be implemented by a custom renderer before being able to use the
-//! widget.
+//! # Built-in widgets
+//! Every built-in drawable widget has its own module with a `Renderer` trait
+//! that must be implemented by a [renderer] before being able to use it as
+//! a [`Widget`].
//!
-//! The built-in [`Renderer`] supports all the widgets in this module!
+//! # 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.
//!
-//! [`ui` module]: ../index.html
-//! [`Row`]: struct.Row.html
-//! [`Column`]: struct.Column.html
-//! [`Renderer`]: ../struct.Renderer.html
+//! # Re-exports
+//! For convenience, the contents of this module are available at the root
+//! module. Therefore, you can directly type:
+//!
+//! ```
+//! use iced::{button, Button, Widget};
+//! ```
+//!
+//! [`Widget`]: trait.Widget.html
+//! [renderer]: ../renderer/index.html
mod column;
mod row;
@@ -34,24 +43,22 @@ pub use text::Text;
use crate::{Event, Hasher, Layout, MouseCursor, Node, Point};
-/// A component that displays information or allows interaction.
+/// A component that displays information and allows interaction.
///
-/// If you want to build a custom widget, you will need to implement this trait.
-/// Additionally, remember to also provide [`Into<Element>`] so your users can
-/// easily turn your [`Widget`] into a generic [`Element`]
+/// If you want to build your own widgets, you will need to implement this
+/// trait.
///
-/// [`Into<Element>`]: struct.Element.html
/// [`Widget`]: trait.Widget.html
-/// [`Element`]: struct.Element.html
+/// [`Element`]: ../struct.Element.html
pub trait Widget<Message, Renderer>: std::fmt::Debug {
/// Returns the [`Node`] of the [`Widget`].
///
/// This [`Node`] is used by the runtime to compute the [`Layout`] of the
/// user interface.
///
- /// [`Node`]: struct.Node.html
+ /// [`Node`]: ../struct.Node.html
/// [`Widget`]: trait.Widget.html
- /// [`Layout`]: struct.Layout.html
+ /// [`Layout`]: ../struct.Layout.html
fn node(&self, renderer: &Renderer) -> Node;
/// Draws the [`Widget`] using the associated `Renderer`.
@@ -59,7 +66,7 @@ pub trait Widget<Message, Renderer>: std::fmt::Debug {
/// It must return the [`MouseCursor`] state for the [`Widget`].
///
/// [`Widget`]: trait.Widget.html
- /// [`MouseCursor`]: enum.MouseCursor.html
+ /// [`MouseCursor`]: ../enum.MouseCursor.html
fn draw(
&self,
renderer: &mut Renderer,
@@ -78,9 +85,9 @@ pub trait Widget<Message, Renderer>: std::fmt::Debug {
/// its value cannot affect the overall [`Layout`] of the user interface.
///
/// [`Widget`]: trait.Widget.html
- /// [`Layout`]: struct.Layout.html
- /// [`Text`]: ../widget/text/struct.Text.html
- fn hash(&self, state: &mut Hasher);
+ /// [`Layout`]: ../struct.Layout.html
+ /// [`Text`]: text/struct.Text.html
+ fn hash_layout(&self, state: &mut Hasher);
/// Processes a runtime [`Event`].
///
@@ -88,14 +95,14 @@ pub trait Widget<Message, Renderer>: std::fmt::Debug {
/// * an [`Event`] describing user interaction
/// * the computed [`Layout`] of the [`Widget`]
/// * the current cursor position
- /// * a mutable `Message` vector, allowing the [`Widget`] to produce
+ /// * a mutable `Message` list, allowing the [`Widget`] to produce
/// new messages based on user interaction.
///
/// By default, it does nothing.
///
- /// [`Event`]: enum.Event.html
+ /// [`Event`]: ../enum.Event.html
/// [`Widget`]: trait.Widget.html
- /// [`Layout`]: struct.Layout.html
+ /// [`Layout`]: ../struct.Layout.html
fn on_event(
&mut self,
_event: Event,