From f943764a292837cbf262a4f29dc0021d808852d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Sun, 24 Nov 2019 10:44:55 +0100 Subject: [PATCH] Fix `iced_native` widget examples --- native/src/widget/checkbox.rs | 2 +- native/src/widget/image.rs | 19 ++++++++----------- native/src/widget/radio.rs | 2 +- native/src/widget/text.rs | 3 ++- native/src/widget/text_input.rs | 3 ++- wgpu/src/renderer/widget/image.rs | 6 +++--- 6 files changed, 17 insertions(+), 18 deletions(-) diff --git a/native/src/widget/checkbox.rs b/native/src/widget/checkbox.rs index 655fd0ae..9251d9a0 100644 --- a/native/src/widget/checkbox.rs +++ b/native/src/widget/checkbox.rs @@ -14,7 +14,7 @@ use crate::{ /// /// ``` /// # use iced_native::Checkbox; -/// +/// # /// pub enum Message { /// CheckboxToggled(bool), /// } diff --git a/native/src/widget/image.rs b/native/src/widget/image.rs index c64f07b1..4c588c9d 100644 --- a/native/src/widget/image.rs +++ b/native/src/widget/image.rs @@ -10,19 +10,16 @@ use std::hash::Hash; /// /// ``` /// # use iced_native::Image; -/// +/// # /// let image = Image::new("resources/ferris.png"); /// ``` +/// +/// #[derive(Debug)] pub struct Image { - /// The image path - pub path: String, - - /// The width of the image - pub width: Length, - - /// The height of the image - pub height: Length, + path: String, + width: Length, + height: Length, } impl Image { @@ -99,7 +96,7 @@ where layout: Layout<'_>, _cursor_position: Point, ) -> Renderer::Output { - renderer.draw(&self, layout) + renderer.draw(&self.path, layout) } fn hash_layout(&self, state: &mut Hasher) { @@ -124,7 +121,7 @@ pub trait Renderer: crate::Renderer { /// Draws an [`Image`]. /// /// [`Image`]: struct.Image.html - fn draw(&mut self, image: &Image, layout: Layout<'_>) -> Self::Output; + fn draw(&mut self, path: &str, layout: Layout<'_>) -> Self::Output; } impl<'a, Message, Renderer> From for Element<'a, Message, Renderer> diff --git a/native/src/widget/radio.rs b/native/src/widget/radio.rs index cc642d1c..04d7fb3c 100644 --- a/native/src/widget/radio.rs +++ b/native/src/widget/radio.rs @@ -13,7 +13,7 @@ use std::hash::Hash; /// # Example /// ``` /// # use iced_native::Radio; -/// +/// # /// #[derive(Debug, Clone, Copy, PartialEq, Eq)] /// pub enum Choice { /// A, diff --git a/native/src/widget/text.rs b/native/src/widget/text.rs index cf0701b9..01ffe8fd 100644 --- a/native/src/widget/text.rs +++ b/native/src/widget/text.rs @@ -12,8 +12,9 @@ use std::hash::Hash; /// /// ``` /// # use iced_native::Text; -/// +/// # /// Text::new("I <3 iced!") +/// .color([0.0, 0.0, 1.0]) /// .size(40); /// ``` #[derive(Debug, Clone)] diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index fbf144e3..6e0857ae 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -28,7 +28,8 @@ use crate::{ /// "This is the placeholder...", /// value, /// Message::TextInputChanged, -/// ); +/// ) +/// .padding(10); /// ``` #[allow(missing_debug_implementations)] pub struct TextInput<'a, Message> { diff --git a/wgpu/src/renderer/widget/image.rs b/wgpu/src/renderer/widget/image.rs index fe594365..0006dde1 100644 --- a/wgpu/src/renderer/widget/image.rs +++ b/wgpu/src/renderer/widget/image.rs @@ -1,15 +1,15 @@ use crate::{Primitive, Renderer}; -use iced_native::{image, Image, Layout, MouseCursor}; +use iced_native::{image, Layout, MouseCursor}; impl image::Renderer for Renderer { fn dimensions(&self, path: &str) -> (u32, u32) { self.image_pipeline.dimensions(path) } - fn draw(&mut self, image: &Image, layout: Layout<'_>) -> Self::Output { + fn draw(&mut self, path: &str, layout: Layout<'_>) -> Self::Output { ( Primitive::Image { - path: image.path.clone(), + path: String::from(path), bounds: layout.bounds(), }, MouseCursor::OutOfBounds,