Fix `iced_native` widget examples

This commit is contained in:
Héctor Ramón Jiménez 2019-11-24 10:44:55 +01:00
parent 7a8a79cd37
commit f943764a29
6 changed files with 17 additions and 18 deletions

View File

@ -14,7 +14,7 @@ use crate::{
/// ///
/// ``` /// ```
/// # use iced_native::Checkbox; /// # use iced_native::Checkbox;
/// /// #
/// pub enum Message { /// pub enum Message {
/// CheckboxToggled(bool), /// CheckboxToggled(bool),
/// } /// }

View File

@ -10,19 +10,16 @@ use std::hash::Hash;
/// ///
/// ``` /// ```
/// # use iced_native::Image; /// # use iced_native::Image;
/// /// #
/// let image = Image::new("resources/ferris.png"); /// let image = Image::new("resources/ferris.png");
/// ``` /// ```
///
/// <img src="https://github.com/hecrj/iced/blob/9712b319bb7a32848001b96bd84977430f14b623/examples/resources/ferris.png?raw=true" width="300">
#[derive(Debug)] #[derive(Debug)]
pub struct Image { pub struct Image {
/// The image path path: String,
pub path: String, width: Length,
height: Length,
/// The width of the image
pub width: Length,
/// The height of the image
pub height: Length,
} }
impl Image { impl Image {
@ -99,7 +96,7 @@ where
layout: Layout<'_>, layout: Layout<'_>,
_cursor_position: Point, _cursor_position: Point,
) -> Renderer::Output { ) -> Renderer::Output {
renderer.draw(&self, layout) renderer.draw(&self.path, layout)
} }
fn hash_layout(&self, state: &mut Hasher) { fn hash_layout(&self, state: &mut Hasher) {
@ -124,7 +121,7 @@ pub trait Renderer: crate::Renderer {
/// Draws an [`Image`]. /// Draws an [`Image`].
/// ///
/// [`Image`]: struct.Image.html /// [`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<Image> for Element<'a, Message, Renderer> impl<'a, Message, Renderer> From<Image> for Element<'a, Message, Renderer>

View File

@ -13,7 +13,7 @@ use std::hash::Hash;
/// # Example /// # Example
/// ``` /// ```
/// # use iced_native::Radio; /// # use iced_native::Radio;
/// /// #
/// #[derive(Debug, Clone, Copy, PartialEq, Eq)] /// #[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// pub enum Choice { /// pub enum Choice {
/// A, /// A,

View File

@ -12,8 +12,9 @@ use std::hash::Hash;
/// ///
/// ``` /// ```
/// # use iced_native::Text; /// # use iced_native::Text;
/// /// #
/// Text::new("I <3 iced!") /// Text::new("I <3 iced!")
/// .color([0.0, 0.0, 1.0])
/// .size(40); /// .size(40);
/// ``` /// ```
#[derive(Debug, Clone)] #[derive(Debug, Clone)]

View File

@ -28,7 +28,8 @@ use crate::{
/// "This is the placeholder...", /// "This is the placeholder...",
/// value, /// value,
/// Message::TextInputChanged, /// Message::TextInputChanged,
/// ); /// )
/// .padding(10);
/// ``` /// ```
#[allow(missing_debug_implementations)] #[allow(missing_debug_implementations)]
pub struct TextInput<'a, Message> { pub struct TextInput<'a, Message> {

View File

@ -1,15 +1,15 @@
use crate::{Primitive, Renderer}; use crate::{Primitive, Renderer};
use iced_native::{image, Image, Layout, MouseCursor}; use iced_native::{image, Layout, MouseCursor};
impl image::Renderer for Renderer { impl image::Renderer for Renderer {
fn dimensions(&self, path: &str) -> (u32, u32) { fn dimensions(&self, path: &str) -> (u32, u32) {
self.image_pipeline.dimensions(path) 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 { Primitive::Image {
path: image.path.clone(), path: String::from(path),
bounds: layout.bounds(), bounds: layout.bounds(),
}, },
MouseCursor::OutOfBounds, MouseCursor::OutOfBounds,