From 8b8f7563ad33dafeadf6238e377748cdec17d67a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 10 Sep 2019 19:41:49 +0200 Subject: Switch to workspace layout --- src/widget/image.rs | 178 ---------------------------------------------------- 1 file changed, 178 deletions(-) delete mode 100644 src/widget/image.rs (limited to 'src/widget/image.rs') diff --git a/src/widget/image.rs b/src/widget/image.rs deleted file mode 100644 index d94bfea5..00000000 --- a/src/widget/image.rs +++ /dev/null @@ -1,178 +0,0 @@ -//! Display images in your user interface. - -use crate::{ - Align, Element, Hasher, Layout, MouseCursor, Node, Point, Rectangle, Style, - Widget, -}; - -use std::hash::Hash; - -/// A frame that displays an image while keeping aspect ratio. -/// -/// It implements [`Widget`] when the associated `Renderer` implements the -/// [`image::Renderer`] trait. -/// -/// [`Widget`]: ../../core/trait.Widget.html -/// [`image::Renderer`]: trait.Renderer.html -/// -/// # Example -/// -/// ``` -/// use iced::Image; -/// -/// # let my_handle = String::from("some_handle"); -/// let image = Image::new(my_handle); -/// ``` -pub struct Image { - image: I, - source: Option>, - width: Option, - height: Option, - style: Style, -} - -impl std::fmt::Debug for Image { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("Image") - .field("source", &self.source) - .field("width", &self.width) - .field("height", &self.height) - .field("style", &self.style) - .finish() - } -} - -impl Image { - /// Creates a new [`Image`] with given image handle. - /// - /// [`Image`]: struct.Image.html - pub fn new(image: I) -> Self { - Image { - image, - source: None, - width: None, - height: None, - style: Style::default(), - } - } - - /// Sets the portion of the [`Image`] to draw. - /// - /// [`Image`]: struct.Image.html - pub fn clip(mut self, source: Rectangle) -> Self { - self.source = Some(source); - self - } - - /// Sets the width of the [`Image`] boundaries in pixels. - /// - /// [`Image`]: struct.Image.html - pub fn width(mut self, width: u16) -> Self { - self.width = Some(width); - self - } - - /// Sets the height of the [`Image`] boundaries in pixels. - /// - /// [`Image`]: struct.Image.html - pub fn height(mut self, height: u16) -> Self { - self.height = Some(height); - self - } - - /// Sets the alignment of the [`Image`] itself. - /// - /// This is useful if you want to override the default alignment given by - /// the parent container. - /// - /// [`Image`]: struct.Image.html - pub fn align_self(mut self, align: Align) -> Self { - self.style = self.style.align_self(align); - self - } -} - -impl Widget for Image -where - Renderer: self::Renderer, - I: Clone, -{ - fn node(&self, renderer: &Renderer) -> Node { - renderer.node( - self.style, - &self.image, - self.width, - self.height, - self.source, - ) - } - - fn draw( - &self, - renderer: &mut Renderer, - layout: Layout<'_>, - _cursor_position: Point, - ) -> MouseCursor { - renderer.draw(&self.image, layout.bounds(), self.source); - - MouseCursor::OutOfBounds - } - - fn hash_layout(&self, state: &mut Hasher) { - self.style.hash(state); - self.width.hash(state); - self.height.hash(state); - } -} - -/// The renderer of an [`Image`]. -/// -/// Your [renderer] will need to implement this trait before being able to use -/// an [`Image`] in your user interface. -/// -/// [`Image`]: struct.Image.html -/// [renderer]: ../../renderer/index.html -pub trait Renderer { - /// Creates a [`Node`] with the given [`Style`] for the provided [`Image`] - /// and its size. - /// - /// You should probably keep the original aspect ratio, if possible. - /// - /// [`Node`]: ../../struct.Node.html - /// [`Style`]: ../../struct.Style.html - /// [`Image`]: struct.Image.html - fn node( - &self, - style: Style, - image: &I, - width: Option, - height: Option, - source: Option>, - ) -> Node; - - /// Draws an [`Image`]. - /// - /// It receives: - /// * the bounds of the [`Image`] - /// * the handle of the loaded [`Image`] - /// * the portion of the image to draw. If not specified, the entire image - /// should be drawn. - /// - /// [`Image`]: struct.Image.html - fn draw( - &mut self, - image: &I, - bounds: Rectangle, - source: Option>, - ); -} - -impl<'a, I, Message, Renderer> From> for Element<'a, Message, Renderer> -where - Renderer: self::Renderer, - I: Clone + 'a, -{ - fn from(image: Image) -> Element<'a, Message, Renderer> { - Element::new(image) - } -} -- cgit From a97401aed2a173260a4abfdb65a77975ce6c0f01 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 14 Sep 2019 19:16:06 +0200 Subject: Rethink workspace structure --- src/widget/image.rs | 178 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 src/widget/image.rs (limited to 'src/widget/image.rs') diff --git a/src/widget/image.rs b/src/widget/image.rs new file mode 100644 index 00000000..d94bfea5 --- /dev/null +++ b/src/widget/image.rs @@ -0,0 +1,178 @@ +//! Display images in your user interface. + +use crate::{ + Align, Element, Hasher, Layout, MouseCursor, Node, Point, Rectangle, Style, + Widget, +}; + +use std::hash::Hash; + +/// A frame that displays an image while keeping aspect ratio. +/// +/// It implements [`Widget`] when the associated `Renderer` implements the +/// [`image::Renderer`] trait. +/// +/// [`Widget`]: ../../core/trait.Widget.html +/// [`image::Renderer`]: trait.Renderer.html +/// +/// # Example +/// +/// ``` +/// use iced::Image; +/// +/// # let my_handle = String::from("some_handle"); +/// let image = Image::new(my_handle); +/// ``` +pub struct Image { + image: I, + source: Option>, + width: Option, + height: Option, + style: Style, +} + +impl std::fmt::Debug for Image { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Image") + .field("source", &self.source) + .field("width", &self.width) + .field("height", &self.height) + .field("style", &self.style) + .finish() + } +} + +impl Image { + /// Creates a new [`Image`] with given image handle. + /// + /// [`Image`]: struct.Image.html + pub fn new(image: I) -> Self { + Image { + image, + source: None, + width: None, + height: None, + style: Style::default(), + } + } + + /// Sets the portion of the [`Image`] to draw. + /// + /// [`Image`]: struct.Image.html + pub fn clip(mut self, source: Rectangle) -> Self { + self.source = Some(source); + self + } + + /// Sets the width of the [`Image`] boundaries in pixels. + /// + /// [`Image`]: struct.Image.html + pub fn width(mut self, width: u16) -> Self { + self.width = Some(width); + self + } + + /// Sets the height of the [`Image`] boundaries in pixels. + /// + /// [`Image`]: struct.Image.html + pub fn height(mut self, height: u16) -> Self { + self.height = Some(height); + self + } + + /// Sets the alignment of the [`Image`] itself. + /// + /// This is useful if you want to override the default alignment given by + /// the parent container. + /// + /// [`Image`]: struct.Image.html + pub fn align_self(mut self, align: Align) -> Self { + self.style = self.style.align_self(align); + self + } +} + +impl Widget for Image +where + Renderer: self::Renderer, + I: Clone, +{ + fn node(&self, renderer: &Renderer) -> Node { + renderer.node( + self.style, + &self.image, + self.width, + self.height, + self.source, + ) + } + + fn draw( + &self, + renderer: &mut Renderer, + layout: Layout<'_>, + _cursor_position: Point, + ) -> MouseCursor { + renderer.draw(&self.image, layout.bounds(), self.source); + + MouseCursor::OutOfBounds + } + + fn hash_layout(&self, state: &mut Hasher) { + self.style.hash(state); + self.width.hash(state); + self.height.hash(state); + } +} + +/// The renderer of an [`Image`]. +/// +/// Your [renderer] will need to implement this trait before being able to use +/// an [`Image`] in your user interface. +/// +/// [`Image`]: struct.Image.html +/// [renderer]: ../../renderer/index.html +pub trait Renderer { + /// Creates a [`Node`] with the given [`Style`] for the provided [`Image`] + /// and its size. + /// + /// You should probably keep the original aspect ratio, if possible. + /// + /// [`Node`]: ../../struct.Node.html + /// [`Style`]: ../../struct.Style.html + /// [`Image`]: struct.Image.html + fn node( + &self, + style: Style, + image: &I, + width: Option, + height: Option, + source: Option>, + ) -> Node; + + /// Draws an [`Image`]. + /// + /// It receives: + /// * the bounds of the [`Image`] + /// * the handle of the loaded [`Image`] + /// * the portion of the image to draw. If not specified, the entire image + /// should be drawn. + /// + /// [`Image`]: struct.Image.html + fn draw( + &mut self, + image: &I, + bounds: Rectangle, + source: Option>, + ); +} + +impl<'a, I, Message, Renderer> From> for Element<'a, Message, Renderer> +where + Renderer: self::Renderer, + I: Clone + 'a, +{ + fn from(image: Image) -> Element<'a, Message, Renderer> { + Element::new(image) + } +} -- cgit From 655978f480c32bc696f0d5fe2fff834bfbf238ea Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 15 Sep 2019 18:53:13 +0200 Subject: Draft nodes for missing widgets --- src/widget/image.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/widget/image.rs') diff --git a/src/widget/image.rs b/src/widget/image.rs index d94bfea5..8c869ab8 100644 --- a/src/widget/image.rs +++ b/src/widget/image.rs @@ -24,9 +24,11 @@ use std::hash::Hash; /// let image = Image::new(my_handle); /// ``` pub struct Image { - image: I, + /// The image handle + pub image: I, source: Option>, - width: Option, + /// The width of the image + pub width: Option, height: Option, style: Style, } -- cgit From f9de39ddaa3020a9585b1648afb0ead45dfd7aa9 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 19 Sep 2019 15:01:12 +0200 Subject: Unify `web` and `ggez` tour examples :tada: --- src/widget/image.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/widget/image.rs') diff --git a/src/widget/image.rs b/src/widget/image.rs index 8c869ab8..1601234e 100644 --- a/src/widget/image.rs +++ b/src/widget/image.rs @@ -99,7 +99,7 @@ where Renderer: self::Renderer, I: Clone, { - fn node(&self, renderer: &Renderer) -> Node { + fn node(&self, renderer: &mut Renderer) -> Node { renderer.node( self.style, &self.image, @@ -144,7 +144,7 @@ pub trait Renderer { /// [`Style`]: ../../struct.Style.html /// [`Image`]: struct.Image.html fn node( - &self, + &mut self, style: Style, image: &I, width: Option, -- cgit From b9e0f7494881ad7cdfbcbc16878ecc6ef717753f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 20 Sep 2019 19:15:31 +0200 Subject: Create `iced_core` and `iced_native` --- src/widget/image.rs | 180 ---------------------------------------------------- 1 file changed, 180 deletions(-) delete mode 100644 src/widget/image.rs (limited to 'src/widget/image.rs') diff --git a/src/widget/image.rs b/src/widget/image.rs deleted file mode 100644 index 1601234e..00000000 --- a/src/widget/image.rs +++ /dev/null @@ -1,180 +0,0 @@ -//! Display images in your user interface. - -use crate::{ - Align, Element, Hasher, Layout, MouseCursor, Node, Point, Rectangle, Style, - Widget, -}; - -use std::hash::Hash; - -/// A frame that displays an image while keeping aspect ratio. -/// -/// It implements [`Widget`] when the associated `Renderer` implements the -/// [`image::Renderer`] trait. -/// -/// [`Widget`]: ../../core/trait.Widget.html -/// [`image::Renderer`]: trait.Renderer.html -/// -/// # Example -/// -/// ``` -/// use iced::Image; -/// -/// # let my_handle = String::from("some_handle"); -/// let image = Image::new(my_handle); -/// ``` -pub struct Image { - /// The image handle - pub image: I, - source: Option>, - /// The width of the image - pub width: Option, - height: Option, - style: Style, -} - -impl std::fmt::Debug for Image { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("Image") - .field("source", &self.source) - .field("width", &self.width) - .field("height", &self.height) - .field("style", &self.style) - .finish() - } -} - -impl Image { - /// Creates a new [`Image`] with given image handle. - /// - /// [`Image`]: struct.Image.html - pub fn new(image: I) -> Self { - Image { - image, - source: None, - width: None, - height: None, - style: Style::default(), - } - } - - /// Sets the portion of the [`Image`] to draw. - /// - /// [`Image`]: struct.Image.html - pub fn clip(mut self, source: Rectangle) -> Self { - self.source = Some(source); - self - } - - /// Sets the width of the [`Image`] boundaries in pixels. - /// - /// [`Image`]: struct.Image.html - pub fn width(mut self, width: u16) -> Self { - self.width = Some(width); - self - } - - /// Sets the height of the [`Image`] boundaries in pixels. - /// - /// [`Image`]: struct.Image.html - pub fn height(mut self, height: u16) -> Self { - self.height = Some(height); - self - } - - /// Sets the alignment of the [`Image`] itself. - /// - /// This is useful if you want to override the default alignment given by - /// the parent container. - /// - /// [`Image`]: struct.Image.html - pub fn align_self(mut self, align: Align) -> Self { - self.style = self.style.align_self(align); - self - } -} - -impl Widget for Image -where - Renderer: self::Renderer, - I: Clone, -{ - fn node(&self, renderer: &mut Renderer) -> Node { - renderer.node( - self.style, - &self.image, - self.width, - self.height, - self.source, - ) - } - - fn draw( - &self, - renderer: &mut Renderer, - layout: Layout<'_>, - _cursor_position: Point, - ) -> MouseCursor { - renderer.draw(&self.image, layout.bounds(), self.source); - - MouseCursor::OutOfBounds - } - - fn hash_layout(&self, state: &mut Hasher) { - self.style.hash(state); - self.width.hash(state); - self.height.hash(state); - } -} - -/// The renderer of an [`Image`]. -/// -/// Your [renderer] will need to implement this trait before being able to use -/// an [`Image`] in your user interface. -/// -/// [`Image`]: struct.Image.html -/// [renderer]: ../../renderer/index.html -pub trait Renderer { - /// Creates a [`Node`] with the given [`Style`] for the provided [`Image`] - /// and its size. - /// - /// You should probably keep the original aspect ratio, if possible. - /// - /// [`Node`]: ../../struct.Node.html - /// [`Style`]: ../../struct.Style.html - /// [`Image`]: struct.Image.html - fn node( - &mut self, - style: Style, - image: &I, - width: Option, - height: Option, - source: Option>, - ) -> Node; - - /// Draws an [`Image`]. - /// - /// It receives: - /// * the bounds of the [`Image`] - /// * the handle of the loaded [`Image`] - /// * the portion of the image to draw. If not specified, the entire image - /// should be drawn. - /// - /// [`Image`]: struct.Image.html - fn draw( - &mut self, - image: &I, - bounds: Rectangle, - source: Option>, - ); -} - -impl<'a, I, Message, Renderer> From> for Element<'a, Message, Renderer> -where - Renderer: self::Renderer, - I: Clone + 'a, -{ - fn from(image: Image) -> Element<'a, Message, Renderer> { - Element::new(image) - } -} -- cgit