From 3a327e08e96d9588d145c32afe4f04f37a8f0f0f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 30 Dec 2019 21:32:21 +0100 Subject: Rename `Empty` widget to `Space` --- native/src/widget.rs | 6 +-- native/src/widget/empty.rs | 103 -------------------------------------------- native/src/widget/space.rs | 104 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+), 106 deletions(-) delete mode 100644 native/src/widget/empty.rs create mode 100644 native/src/widget/space.rs (limited to 'native') diff --git a/native/src/widget.rs b/native/src/widget.rs index b73f229e..dcc99645 100644 --- a/native/src/widget.rs +++ b/native/src/widget.rs @@ -24,12 +24,12 @@ pub mod button; pub mod checkbox; pub mod column; pub mod container; -pub mod empty; pub mod image; pub mod radio; pub mod row; pub mod scrollable; pub mod slider; +pub mod space; pub mod svg; pub mod text; pub mod text_input; @@ -43,8 +43,6 @@ pub use column::Column; #[doc(no_inline)] pub use container::Container; #[doc(no_inline)] -pub use empty::Empty; -#[doc(no_inline)] pub use image::Image; #[doc(no_inline)] pub use radio::Radio; @@ -55,6 +53,8 @@ pub use scrollable::Scrollable; #[doc(no_inline)] pub use slider::Slider; #[doc(no_inline)] +pub use space::Space; +#[doc(no_inline)] pub use svg::Svg; #[doc(no_inline)] pub use text::Text; diff --git a/native/src/widget/empty.rs b/native/src/widget/empty.rs deleted file mode 100644 index f670048f..00000000 --- a/native/src/widget/empty.rs +++ /dev/null @@ -1,103 +0,0 @@ -//! Distribute content vertically. -use std::hash::Hash; - -use crate::{ - layout, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget, -}; - -/// An amount of empty space. -/// -/// It can be useful if you want to fill some space with nothing. -/// -/// [`Empty`]: struct.Empty.html -#[derive(Debug)] -pub struct Empty { - width: Length, - height: Length, -} - -impl Empty { - /// Creates an amount of [`Empty`] space. - /// - /// [`Empty`]: struct.Empty.html - pub fn new() -> Self { - Empty { - width: Length::Shrink, - height: Length::Shrink, - } - } - - /// Sets the width of the [`Empty`] space. - /// - /// [`Empty`]: struct..html - pub fn width(mut self, width: Length) -> Self { - self.width = width; - self - } - - /// Sets the height of the [`Empty`] space. - /// - /// [`Empty`]: struct.Column.html - pub fn height(mut self, height: Length) -> Self { - self.height = height; - self - } -} - -impl<'a, Message, Renderer> Widget for Empty -where - Renderer: self::Renderer, -{ - fn width(&self) -> Length { - self.width - } - - fn height(&self) -> Length { - self.height - } - - fn layout( - &self, - _renderer: &Renderer, - limits: &layout::Limits, - ) -> layout::Node { - let limits = limits.width(self.width).height(self.height); - - layout::Node::new(limits.resolve(Size::ZERO)) - } - - fn draw( - &self, - renderer: &mut Renderer, - layout: Layout<'_>, - _cursor_position: Point, - ) -> Renderer::Output { - renderer.draw(layout.bounds()) - } - - fn hash_layout(&self, state: &mut Hasher) { - std::any::TypeId::of::().hash(state); - self.width.hash(state); - self.height.hash(state); - } -} - -/// The renderer of an amount of [`Empty`] space. -/// -/// [`Empty`]: struct.Empty.html -pub trait Renderer: crate::Renderer { - /// Draws an amount of [`Empty`] space. - /// - /// You should most likely return an empty primitive here. - fn draw(&mut self, bounds: Rectangle) -> Self::Output; -} - -impl<'a, Message, Renderer> From for Element<'a, Message, Renderer> -where - Renderer: self::Renderer, - Message: 'static, -{ - fn from(empty: Empty) -> Element<'a, Message, Renderer> { - Element::new(empty) - } -} diff --git a/native/src/widget/space.rs b/native/src/widget/space.rs new file mode 100644 index 00000000..2029c52f --- /dev/null +++ b/native/src/widget/space.rs @@ -0,0 +1,104 @@ +//! Distribute content vertically. +use std::hash::Hash; + +use crate::{ + layout, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget, +}; + +/// An amount of empty space. +/// +/// It can be useful if you want to fill some space with nothing. +#[derive(Debug)] +pub struct Space { + width: Length, + height: Length, +} + +impl Space { + /// Creates an amount of empty [`Space`] with the given width and height. + /// + /// [`Space`]: struct.Space.html + pub fn new(width: Length, height: Length) -> Self { + Space { width, height } + } + + /// Creates an amount of horizontal [`Space`]. + /// + /// [`Space`]: struct.Space.html + pub fn with_width(width: Length) -> Self { + Space { + width, + height: Length::Shrink, + } + } + + /// Creates an amount of vertical [`Space`]. + /// + /// [`Space`]: struct.Space.html + pub fn with_height(height: Length) -> Self { + Space { + width: Length::Shrink, + height, + } + } +} + +impl<'a, Message, Renderer> Widget for Space +where + Renderer: self::Renderer, +{ + fn width(&self) -> Length { + self.width + } + + fn height(&self) -> Length { + self.height + } + + fn layout( + &self, + _renderer: &Renderer, + limits: &layout::Limits, + ) -> layout::Node { + let limits = limits.width(self.width).height(self.height); + + layout::Node::new(limits.resolve(Size::ZERO)) + } + + fn draw( + &self, + renderer: &mut Renderer, + layout: Layout<'_>, + _cursor_position: Point, + ) -> Renderer::Output { + renderer.draw(layout.bounds()) + } + + fn hash_layout(&self, state: &mut Hasher) { + std::any::TypeId::of::().hash(state); + self.width.hash(state); + self.height.hash(state); + } +} + +/// The renderer of an amount of [`Space`]. +/// +/// [`Space`]: struct.Space.html +pub trait Renderer: crate::Renderer { + /// Draws an amount of empty [`Space`]. + /// + /// You should most likely return an empty primitive here. + /// + /// [`Space`]: struct.Space.html + fn draw(&mut self, bounds: Rectangle) -> Self::Output; +} + +impl<'a, Message, Renderer> From for Element<'a, Message, Renderer> +where + Renderer: self::Renderer, + Message: 'static, +{ + fn from(space: Space) -> Element<'a, Message, Renderer> { + Element::new(space) + } +} -- cgit