Fix details in documentation
This commit is contained in:
parent
ec66e3fc1b
commit
36d18d979f
9 changed files with 40 additions and 32 deletions
|
|
@ -26,10 +26,10 @@ pub fn main() -> ggez::GameResult {
|
||||||
|
|
||||||
struct Game {
|
struct Game {
|
||||||
spritesheet: graphics::Image,
|
spritesheet: graphics::Image,
|
||||||
|
|
||||||
cache: Option<iced::Cache>,
|
|
||||||
events: Vec<iced::Event>,
|
|
||||||
tour: Tour,
|
tour: Tour,
|
||||||
|
|
||||||
|
events: Vec<iced::Event>,
|
||||||
|
cache: Option<iced::Cache>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Game {
|
impl Game {
|
||||||
|
|
@ -38,10 +38,10 @@ impl Game {
|
||||||
|
|
||||||
Ok(Game {
|
Ok(Game {
|
||||||
spritesheet: graphics::Image::new(context, "/ui.png").unwrap(),
|
spritesheet: graphics::Image::new(context, "/ui.png").unwrap(),
|
||||||
|
|
||||||
cache: Some(iced::Cache::default()),
|
|
||||||
events: Vec::new(),
|
|
||||||
tour: Tour::new(),
|
tour: Tour::new(),
|
||||||
|
|
||||||
|
events: Vec::new(),
|
||||||
|
cache: Some(iced::Cache::default()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,10 @@ pub trait Renderer {
|
||||||
/// Explains the [`Layout`] of an [`Element`] for debugging purposes.
|
/// Explains the [`Layout`] of an [`Element`] for debugging purposes.
|
||||||
///
|
///
|
||||||
/// This will be called when [`Element::explain`] has been used. It should
|
/// This will be called when [`Element::explain`] has been used. It should
|
||||||
/// _explain_ the [`Layout`] graphically.
|
/// _explain_ the given [`Layout`] graphically.
|
||||||
|
///
|
||||||
|
/// A common approach consists in recursively rendering the bounds of the
|
||||||
|
/// [`Layout`] and its children.
|
||||||
///
|
///
|
||||||
/// [`Layout`]: struct.Layout.html
|
/// [`Layout`]: struct.Layout.html
|
||||||
/// [`Element`]: struct.Element.html
|
/// [`Element`]: struct.Element.html
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ impl<'a, Message, Renderer> UserInterface<'a, Message, Renderer> {
|
||||||
|
|
||||||
pub fn update(
|
pub fn update(
|
||||||
&mut self,
|
&mut self,
|
||||||
events: std::vec::Drain<'_, Event>,
|
events: impl Iterator<Item = Event>,
|
||||||
) -> Vec<Message> {
|
) -> Vec<Message> {
|
||||||
let mut messages = Vec::new();
|
let mut messages = Vec::new();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,18 @@
|
||||||
//! Use the built-in widgets in your user interface.
|
//! Use the built-in widgets or create your own!
|
||||||
//!
|
//!
|
||||||
//! # Customization
|
//! # Customization
|
||||||
//! Every drawable widget has its own module with a `Renderer` trait that must
|
//! 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
|
//! be implemented by a renderer before being able to use it as a [`Widget`].
|
||||||
//! widget.
|
|
||||||
//!
|
//!
|
||||||
//! The built-in [`Renderer`] supports all the widgets in this module!
|
//! # Re-exports
|
||||||
|
//! For convenience, the contents of this module are available at the root
|
||||||
|
//! module. Therefore, you can directly type:
|
||||||
//!
|
//!
|
||||||
//! [`ui` module]: ../index.html
|
//! ```
|
||||||
//! [`Row`]: struct.Row.html
|
//! use iced::{button, Button, Widget};
|
||||||
//! [`Column`]: struct.Column.html
|
//! ```
|
||||||
//! [`Renderer`]: ../struct.Renderer.html
|
//!
|
||||||
|
//! [`Widget`]: trait.Widget.html
|
||||||
mod column;
|
mod column;
|
||||||
mod row;
|
mod row;
|
||||||
|
|
||||||
|
|
@ -30,24 +32,26 @@ pub use text::Text;
|
||||||
|
|
||||||
use crate::{Event, Hasher, Layout, MouseCursor, Node, Point};
|
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 your own widgets, you will need to implement this
|
||||||
|
/// trait.
|
||||||
///
|
///
|
||||||
/// 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
|
/// Additionally, remember to also provide [`Into<Element>`] so your users can
|
||||||
/// easily turn your [`Widget`] into a generic [`Element`]
|
/// easily turn your [`Widget`] into a generic [`Element`].
|
||||||
///
|
///
|
||||||
/// [`Into<Element>`]: struct.Element.html
|
/// [`Into<Element>`]: ../struct.Element.html
|
||||||
/// [`Widget`]: trait.Widget.html
|
/// [`Widget`]: trait.Widget.html
|
||||||
/// [`Element`]: struct.Element.html
|
/// [`Element`]: ../struct.Element.html
|
||||||
pub trait Widget<Message, Renderer>: std::fmt::Debug {
|
pub trait Widget<Message, Renderer>: std::fmt::Debug {
|
||||||
/// Returns the [`Node`] of the [`Widget`].
|
/// Returns the [`Node`] of the [`Widget`].
|
||||||
///
|
///
|
||||||
/// This [`Node`] is used by the runtime to compute the [`Layout`] of the
|
/// This [`Node`] is used by the runtime to compute the [`Layout`] of the
|
||||||
/// user interface.
|
/// user interface.
|
||||||
///
|
///
|
||||||
/// [`Node`]: struct.Node.html
|
/// [`Node`]: ../struct.Node.html
|
||||||
/// [`Widget`]: trait.Widget.html
|
/// [`Widget`]: trait.Widget.html
|
||||||
/// [`Layout`]: struct.Layout.html
|
/// [`Layout`]: ../struct.Layout.html
|
||||||
fn node(&self, renderer: &Renderer) -> Node;
|
fn node(&self, renderer: &Renderer) -> Node;
|
||||||
|
|
||||||
/// Draws the [`Widget`] using the associated `Renderer`.
|
/// Draws the [`Widget`] using the associated `Renderer`.
|
||||||
|
|
@ -55,7 +59,7 @@ pub trait Widget<Message, Renderer>: std::fmt::Debug {
|
||||||
/// It must return the [`MouseCursor`] state for the [`Widget`].
|
/// It must return the [`MouseCursor`] state for the [`Widget`].
|
||||||
///
|
///
|
||||||
/// [`Widget`]: trait.Widget.html
|
/// [`Widget`]: trait.Widget.html
|
||||||
/// [`MouseCursor`]: enum.MouseCursor.html
|
/// [`MouseCursor`]: ../enum.MouseCursor.html
|
||||||
fn draw(
|
fn draw(
|
||||||
&self,
|
&self,
|
||||||
renderer: &mut Renderer,
|
renderer: &mut Renderer,
|
||||||
|
|
|
||||||
|
|
@ -218,7 +218,7 @@ impl State {
|
||||||
|
|
||||||
/// The type of a [`Button`].
|
/// The type of a [`Button`].
|
||||||
///
|
///
|
||||||
/// 
|
/// 
|
||||||
///
|
///
|
||||||
/// [`Button`]: struct.Button.html
|
/// [`Button`]: struct.Button.html
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> {
|
||||||
|
|
||||||
/// Sets the vertical spacing _between_ elements in pixels.
|
/// Sets the vertical spacing _between_ elements in pixels.
|
||||||
///
|
///
|
||||||
/// Custom margins per element do not exist in Coffee. You should use this
|
/// Custom margins per element do not exist in Iced. You should use this
|
||||||
/// method instead! While less flexible, it helps you keep spacing between
|
/// method instead! While less flexible, it helps you keep spacing between
|
||||||
/// elements consistent.
|
/// elements consistent.
|
||||||
pub fn spacing(mut self, px: u16) -> Self {
|
pub fn spacing(mut self, px: u16) -> Self {
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ use std::hash::Hash;
|
||||||
/// .label_color(Color::Black);
|
/// .label_color(Color::Black);
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// 
|
/// 
|
||||||
pub struct Radio<Color, Message> {
|
pub struct Radio<Color, Message> {
|
||||||
is_selected: bool,
|
is_selected: bool,
|
||||||
on_click: Message,
|
on_click: Message,
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ impl<'a, Message, Renderer> Row<'a, Message, Renderer> {
|
||||||
|
|
||||||
/// Sets the horizontal spacing _between_ elements in pixels.
|
/// Sets the horizontal spacing _between_ elements in pixels.
|
||||||
///
|
///
|
||||||
/// Custom margins per element do not exist in Coffee. You should use this
|
/// Custom margins per element do not exist in Iced. You should use this
|
||||||
/// method instead! While less flexible, it helps you keep spacing between
|
/// method instead! While less flexible, it helps you keep spacing between
|
||||||
/// elements consistent.
|
/// elements consistent.
|
||||||
pub fn spacing(mut self, px: u16) -> Self {
|
pub fn spacing(mut self, px: u16) -> Self {
|
||||||
|
|
|
||||||
|
|
@ -141,13 +141,14 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The renderer of a [`Text`] fragment.
|
/// The renderer of a [`Text`] fragment with a generic `Color`.
|
||||||
///
|
///
|
||||||
/// Your [`core::Renderer`] will need to implement this trait before being
|
/// Your [`Renderer`] will need to implement this trait before being
|
||||||
/// able to use a [`Text`] in your user interface.
|
/// able to use [`Text`] in your [`UserInterface`].
|
||||||
///
|
///
|
||||||
/// [`Text`]: struct.Text.html
|
/// [`Text`]: struct.Text.html
|
||||||
/// [`core::Renderer`]: ../../core/trait.Renderer.html
|
/// [`Renderer`]: ../../trait.Renderer.html
|
||||||
|
/// [`UserInterface`]: ../../struct.UserInterface.html
|
||||||
pub trait Renderer<Color> {
|
pub trait Renderer<Color> {
|
||||||
/// Creates a [`Node`] with the given [`Style`] for the provided [`Text`]
|
/// Creates a [`Node`] with the given [`Style`] for the provided [`Text`]
|
||||||
/// contents and size.
|
/// contents and size.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue