From f4f8f62f55bcaf5b92b7af96544f153f88bab287 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 1 Apr 2020 03:14:49 +0200 Subject: Add example for `Canvas` widget --- wgpu/src/widget/canvas.rs | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'wgpu/src/widget') diff --git a/wgpu/src/widget/canvas.rs b/wgpu/src/widget/canvas.rs index 3a9605c9..5d531a0a 100644 --- a/wgpu/src/widget/canvas.rs +++ b/wgpu/src/widget/canvas.rs @@ -33,11 +33,48 @@ pub use text::Text; /// A widget capable of drawing 2D graphics. /// /// A [`Canvas`] may contain multiple layers. A [`Layer`] is drawn using the -/// painter's algorithm. In other words, layers will be drawn on top of each in -/// the same order they are pushed into the [`Canvas`]. +/// painter's algorithm. In other words, layers will be drawn on top of each +/// other in the same order they are pushed into the [`Canvas`]. /// /// [`Canvas`]: struct.Canvas.html /// [`Layer`]: layer/trait.Layer.html +/// +/// # Example +/// Let's see how we can draw a circle: +/// +/// ``` +/// # mod iced { +/// # pub use iced_wgpu::canvas; +/// # pub use iced_native::Color; +/// # } +/// use iced::canvas::{self, layer, Canvas, Drawable, Fill, Frame, Path}; +/// use iced::Color; +/// +/// // First, we define the data we need for drawing +/// #[derive(Debug)] +/// struct Circle { +/// radius: f32, +/// } +/// +/// // Then, we implement the `Drawable` trait +/// impl Drawable for Circle { +/// fn draw(&self, frame: &mut Frame) { +/// // We create a `Path` representing a simple circle +/// let circle = Path::new(|p| p.circle(frame.center(), self.radius)); +/// +/// // And fill it with some color +/// frame.fill(&circle, Fill::Color(Color::BLACK)); +/// } +/// } +/// +/// // We can use a `Cache` to avoid unnecessary re-tessellation +/// let cache: layer::Cache = layer::Cache::new(); +/// +/// // Finally, we simply provide the data to our `Cache` and push the resulting +/// // layer into a `Canvas` +/// let canvas = Canvas::new() +/// .push(cache.with(&Circle { radius: 50.0 })); +/// ``` #[derive(Debug)] pub struct Canvas<'a> { width: Length, -- cgit From 4c44517556976454c0598c876addb10b88515cda Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 1 Apr 2020 04:34:14 +0200 Subject: Fix minor documentation issues --- wgpu/src/widget/canvas.rs | 2 +- wgpu/src/widget/canvas/layer/cache.rs | 2 +- wgpu/src/widget/canvas/path.rs | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) (limited to 'wgpu/src/widget') diff --git a/wgpu/src/widget/canvas.rs b/wgpu/src/widget/canvas.rs index 5d531a0a..6c9a9e19 100644 --- a/wgpu/src/widget/canvas.rs +++ b/wgpu/src/widget/canvas.rs @@ -42,7 +42,7 @@ pub use text::Text; /// # Example /// Let's see how we can draw a circle: /// -/// ``` +/// ```no_run /// # mod iced { /// # pub use iced_wgpu::canvas; /// # pub use iced_native::Color; diff --git a/wgpu/src/widget/canvas/layer/cache.rs b/wgpu/src/widget/canvas/layer/cache.rs index f7002459..20a095bd 100644 --- a/wgpu/src/widget/canvas/layer/cache.rs +++ b/wgpu/src/widget/canvas/layer/cache.rs @@ -12,7 +12,7 @@ use std::{cell::RefCell, marker::PhantomData, sync::Arc}; /// change or it is explicitly cleared. /// /// [`Layer`]: ../trait.Layer.html -/// [`Cached`]: struct.Cached.html +/// [`Cache`]: struct.Cache.html #[derive(Debug)] pub struct Cache { input: PhantomData, diff --git a/wgpu/src/widget/canvas/path.rs b/wgpu/src/widget/canvas/path.rs index 15c2e853..e7ff47f3 100644 --- a/wgpu/src/widget/canvas/path.rs +++ b/wgpu/src/widget/canvas/path.rs @@ -3,6 +3,7 @@ pub mod arc; mod builder; +#[doc(no_inline)] pub use arc::Arc; pub use builder::Builder; -- cgit From 48b90a752915557f216bcbc808f4163a4d110dac Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 2 Apr 2020 02:51:33 +0200 Subject: Add examples to `Canvas` documentation --- wgpu/src/widget/canvas.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'wgpu/src/widget') diff --git a/wgpu/src/widget/canvas.rs b/wgpu/src/widget/canvas.rs index 6c9a9e19..325f90ce 100644 --- a/wgpu/src/widget/canvas.rs +++ b/wgpu/src/widget/canvas.rs @@ -39,8 +39,21 @@ pub use text::Text; /// [`Canvas`]: struct.Canvas.html /// [`Layer`]: layer/trait.Layer.html /// -/// # Example -/// Let's see how we can draw a circle: +/// # Examples +/// The repository has a couple of [examples] showcasing how to use a +/// [`Canvas`]: +/// +/// - [`clock`], an application that uses the [`Canvas`] widget to draw a clock +/// and its hands to display the current time. +/// - [`solar_system`], an animated solar system drawn using the [`Canvas`] widget +/// and showcasing how to compose different transforms. +/// +/// [examples]: https://github.com/hecrj/iced/tree/0.1/examples +/// [`clock`]: https://github.com/hecrj/iced/tree/0.1/examples/clock +/// [`solar_system`]: https://github.com/hecrj/iced/tree/0.1/examples/solar_system +/// +/// ## Drawing a simple circle +/// If you want to get a quick overview, here's how we can draw a simple circle: /// /// ```no_run /// # mod iced { -- cgit From 703f7657e15234554afb5c62fafed6fd4f8d1d03 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 2 Apr 2020 03:29:46 +0200 Subject: Add example to `pane_grid` module documentation --- wgpu/src/widget/pane_grid.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'wgpu/src/widget') diff --git a/wgpu/src/widget/pane_grid.rs b/wgpu/src/widget/pane_grid.rs index 7bc2f7c5..578e8960 100644 --- a/wgpu/src/widget/pane_grid.rs +++ b/wgpu/src/widget/pane_grid.rs @@ -1,6 +1,13 @@ //! Let your users split regions of your application and organize layout dynamically. //! //! [![Pane grid - Iced](https://thumbs.gfycat.com/MixedFlatJellyfish-small.gif)](https://gfycat.com/mixedflatjellyfish) +//! +//! # Example +//! The [`pane_grid` example] showcases how to use a [`PaneGrid`] with resizing, +//! drag and drop, and hotkey support. +//! +//! [`pane_grid` example]: https://github.com/hecrj/iced/tree/0.1/examples/pane_grid +//! [`PaneGrid`]: type.PaneGrid.html use crate::Renderer; pub use iced_native::pane_grid::{ -- cgit