Rename Empty widget to Space

This commit is contained in:
Héctor Ramón Jiménez 2019-12-30 21:32:21 +01:00
parent 8426bf953c
commit 3a327e08e9
8 changed files with 69 additions and 69 deletions

View file

@ -1,7 +1,7 @@
use iced::{ use iced::{
button, scrollable, slider, text_input, Button, Checkbox, Color, Column, button, scrollable, slider, text_input, Button, Checkbox, Color, Column,
Container, Element, Empty, HorizontalAlignment, Image, Length, Radio, Row, Container, Element, HorizontalAlignment, Image, Length, Radio, Row,
Sandbox, Scrollable, Settings, Slider, Text, TextInput, Sandbox, Scrollable, Settings, Slider, Space, Text, TextInput,
}; };
pub fn main() { pub fn main() {
@ -67,7 +67,7 @@ impl Sandbox for Tour {
); );
} }
controls = controls.push(Empty::new().width(Length::Fill)); controls = controls.push(Space::with_width(Length::Fill));
if steps.can_continue() { if steps.can_continue() {
controls = controls.push( controls = controls.push(

View file

@ -24,12 +24,12 @@ pub mod button;
pub mod checkbox; pub mod checkbox;
pub mod column; pub mod column;
pub mod container; pub mod container;
pub mod empty;
pub mod image; pub mod image;
pub mod radio; pub mod radio;
pub mod row; pub mod row;
pub mod scrollable; pub mod scrollable;
pub mod slider; pub mod slider;
pub mod space;
pub mod svg; pub mod svg;
pub mod text; pub mod text;
pub mod text_input; pub mod text_input;
@ -43,8 +43,6 @@ pub use column::Column;
#[doc(no_inline)] #[doc(no_inline)]
pub use container::Container; pub use container::Container;
#[doc(no_inline)] #[doc(no_inline)]
pub use empty::Empty;
#[doc(no_inline)]
pub use image::Image; pub use image::Image;
#[doc(no_inline)] #[doc(no_inline)]
pub use radio::Radio; pub use radio::Radio;
@ -55,6 +53,8 @@ pub use scrollable::Scrollable;
#[doc(no_inline)] #[doc(no_inline)]
pub use slider::Slider; pub use slider::Slider;
#[doc(no_inline)] #[doc(no_inline)]
pub use space::Space;
#[doc(no_inline)]
pub use svg::Svg; pub use svg::Svg;
#[doc(no_inline)] #[doc(no_inline)]
pub use text::Text; pub use text::Text;

View file

@ -8,43 +8,42 @@ use crate::{
/// An amount of empty space. /// An amount of empty space.
/// ///
/// It can be useful if you want to fill some space with nothing. /// It can be useful if you want to fill some space with nothing.
///
/// [`Empty`]: struct.Empty.html
#[derive(Debug)] #[derive(Debug)]
pub struct Empty { pub struct Space {
width: Length, width: Length,
height: Length, height: Length,
} }
impl Empty { impl Space {
/// Creates an amount of [`Empty`] space. /// Creates an amount of empty [`Space`] with the given width and height.
/// ///
/// [`Empty`]: struct.Empty.html /// [`Space`]: struct.Space.html
pub fn new() -> Self { pub fn new(width: Length, height: Length) -> Self {
Empty { Space { width, height }
width: Length::Shrink, }
/// Creates an amount of horizontal [`Space`].
///
/// [`Space`]: struct.Space.html
pub fn with_width(width: Length) -> Self {
Space {
width,
height: Length::Shrink, height: Length::Shrink,
} }
} }
/// Sets the width of the [`Empty`] space. /// Creates an amount of vertical [`Space`].
/// ///
/// [`Empty`]: struct..html /// [`Space`]: struct.Space.html
pub fn width(mut self, width: Length) -> Self { pub fn with_height(height: Length) -> Self {
self.width = width; Space {
self width: Length::Shrink,
} height,
}
/// 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<Message, Renderer> for Empty impl<'a, Message, Renderer> Widget<Message, Renderer> for Space
where where
Renderer: self::Renderer, Renderer: self::Renderer,
{ {
@ -76,28 +75,30 @@ where
} }
fn hash_layout(&self, state: &mut Hasher) { fn hash_layout(&self, state: &mut Hasher) {
std::any::TypeId::of::<Empty>().hash(state); std::any::TypeId::of::<Space>().hash(state);
self.width.hash(state); self.width.hash(state);
self.height.hash(state); self.height.hash(state);
} }
} }
/// The renderer of an amount of [`Empty`] space. /// The renderer of an amount of [`Space`].
/// ///
/// [`Empty`]: struct.Empty.html /// [`Space`]: struct.Space.html
pub trait Renderer: crate::Renderer { pub trait Renderer: crate::Renderer {
/// Draws an amount of [`Empty`] space. /// Draws an amount of empty [`Space`].
/// ///
/// You should most likely return an empty primitive here. /// You should most likely return an empty primitive here.
///
/// [`Space`]: struct.Space.html
fn draw(&mut self, bounds: Rectangle) -> Self::Output; fn draw(&mut self, bounds: Rectangle) -> Self::Output;
} }
impl<'a, Message, Renderer> From<Empty> for Element<'a, Message, Renderer> impl<'a, Message, Renderer> From<Space> for Element<'a, Message, Renderer>
where where
Renderer: self::Renderer, Renderer: self::Renderer,
Message: 'static, Message: 'static,
{ {
fn from(empty: Empty) -> Element<'a, Message, Renderer> { fn from(space: Space) -> Element<'a, Message, Renderer> {
Element::new(empty) Element::new(space)
} }
} }

View file

@ -1,6 +1,6 @@
pub use iced_winit::{ pub use iced_winit::{
Align, Background, Color, Command, Empty, Font, HorizontalAlignment, Align, Background, Color, Command, Font, HorizontalAlignment, Length,
Length, Subscription, VerticalAlignment, Space, Subscription, VerticalAlignment,
}; };
pub mod widget { pub mod widget {

View file

@ -25,10 +25,10 @@ pub mod text_input;
mod checkbox; mod checkbox;
mod column; mod column;
mod container; mod container;
mod empty;
mod image; mod image;
mod radio; mod radio;
mod row; mod row;
mod space;
mod text; mod text;
#[doc(no_inline)] #[doc(no_inline)]
@ -45,10 +45,10 @@ pub use text_input::TextInput;
pub use checkbox::Checkbox; pub use checkbox::Checkbox;
pub use column::Column; pub use column::Column;
pub use container::Container; pub use container::Container;
pub use empty::Empty;
pub use image::Image; pub use image::Image;
pub use radio::Radio; pub use radio::Radio;
pub use row::Row; pub use row::Row;
pub use space::Space;
/// A component that displays information and allows interaction. /// A component that displays information and allows interaction.
/// ///

View file

@ -4,43 +4,42 @@ use dodrio::bumpalo;
/// An amount of empty space. /// An amount of empty space.
/// ///
/// It can be useful if you want to fill some space with nothing. /// It can be useful if you want to fill some space with nothing.
///
/// [`Empty`]: struct.Empty.html
#[derive(Debug)] #[derive(Debug)]
pub struct Empty { pub struct Space {
width: Length, width: Length,
height: Length, height: Length,
} }
impl Empty { impl Space {
/// Creates an amount of [`Empty`] space. /// Creates an amount of empty [`Space`] with the given width and height.
/// ///
/// [`Empty`]: struct.Empty.html /// [`Space`]: struct.Space.html
pub fn new() -> Self { pub fn new(width: Length, height: Length) -> Self {
Empty { Space { width, height }
width: Length::Shrink, }
/// Creates an amount of horizontal [`Space`].
///
/// [`Space`]: struct.Space.html
pub fn with_width(width: Length) -> Self {
Space {
width,
height: Length::Shrink, height: Length::Shrink,
} }
} }
/// Sets the width of the [`Empty`] space. /// Creates an amount of vertical [`Space`].
/// ///
/// [`Empty`]: struct..html /// [`Space`]: struct.Space.html
pub fn width(mut self, width: Length) -> Self { pub fn with_height(height: Length) -> Self {
self.width = width; Space {
self width: Length::Shrink,
} height,
}
/// 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> Widget<Message> for Empty { impl<'a, Message> Widget<Message> for Space {
fn node<'b>( fn node<'b>(
&self, &self,
bump: &'b bumpalo::Bump, bump: &'b bumpalo::Bump,
@ -63,8 +62,8 @@ impl<'a, Message> Widget<Message> for Empty {
} }
} }
impl<'a, Message> From<Empty> for Element<'a, Message> { impl<'a, Message> From<Space> for Element<'a, Message> {
fn from(empty: Empty) -> Element<'a, Message> { fn from(space: Space) -> Element<'a, Message> {
Element::new(empty) Element::new(space)
} }
} }

View file

@ -1,12 +1,12 @@
mod button; mod button;
mod checkbox; mod checkbox;
mod column; mod column;
mod empty;
mod image; mod image;
mod radio; mod radio;
mod row; mod row;
mod scrollable; mod scrollable;
mod slider; mod slider;
mod space;
mod text; mod text;
mod text_input; mod text_input;

View file

@ -1,7 +1,7 @@
use crate::{Primitive, Renderer}; use crate::{Primitive, Renderer};
use iced_native::{empty, MouseCursor, Rectangle}; use iced_native::{space, MouseCursor, Rectangle};
impl empty::Renderer for Renderer { impl space::Renderer for Renderer {
fn draw(&mut self, _bounds: Rectangle) -> Self::Output { fn draw(&mut self, _bounds: Rectangle) -> Self::Output {
(Primitive::None, MouseCursor::OutOfBounds) (Primitive::None, MouseCursor::OutOfBounds)
} }