From 611f89fc5956d51b54253a989ff023e56a936311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Wed, 17 Sep 2025 23:49:01 +0200 Subject: [PATCH] Rename `space_{x,y}` to `space::{horizontal,vertical}` --- devtools/src/lib.rs | 8 ++--- examples/bezier_tool/src/main.rs | 4 +-- examples/combo_box/src/main.rs | 4 +-- examples/editor/src/main.rs | 6 ++-- examples/gallery/src/civitai.rs | 2 +- examples/gallery/src/main.rs | 47 ++++++++++++++--------------- examples/gradient/src/main.rs | 4 +-- examples/layout/src/main.rs | 32 +++++++++++--------- examples/lazy/src/main.rs | 4 +-- examples/markdown/src/main.rs | 4 +-- examples/modal/src/main.rs | 14 ++++++--- examples/multi_window/src/main.rs | 6 ++-- examples/pick_list/src/main.rs | 6 ++-- examples/scrollable/src/main.rs | 22 +++++++------- examples/styling/src/main.rs | 4 +-- examples/toast/src/main.rs | 4 +-- examples/tour/src/main.rs | 8 ++--- examples/vectorial_text/src/main.rs | 4 +-- examples/visible_bounds/src/main.rs | 12 ++++---- tester/src/lib.rs | 8 ++--- widget/src/helpers.rs | 22 +++++--------- widget/src/lib.rs | 2 +- widget/src/responsive.rs | 4 +-- widget/src/scrollable.rs | 8 ++--- widget/src/space.rs | 46 ++++++++++++++++------------ 25 files changed, 143 insertions(+), 142 deletions(-) diff --git a/devtools/src/lib.rs b/devtools/src/lib.rs index ca0f739d..c806912d 100644 --- a/devtools/src/lib.rs +++ b/devtools/src/lib.rs @@ -24,7 +24,7 @@ use crate::runtime::task::{self, Task}; use crate::time_machine::TimeMachine; use crate::widget::{ bottom_right, button, center, column, container, opaque, row, scrollable, - space_x, stack, text, themer, + space, stack, text, themer, }; use std::fmt; @@ -447,7 +447,7 @@ where .width(100) .on_press(Message::CancelSetup) .style(button::danger), - space_x(), + space::horizontal(), button( text(match goal { Goal::Installation => "Install", @@ -497,13 +497,13 @@ where let comparison = column![ row![ "Installed revision:", - space_x(), + space::horizontal(), inline_code(revision.as_deref().unwrap_or("Unknown")) ] .align_y(Center), row![ "Compatible revision:", - space_x(), + space::horizontal(), inline_code(comet::COMPATIBLE_REVISION), ] .align_y(Center) diff --git a/examples/bezier_tool/src/main.rs b/examples/bezier_tool/src/main.rs index 0f006821..2523924a 100644 --- a/examples/bezier_tool/src/main.rs +++ b/examples/bezier_tool/src/main.rs @@ -1,5 +1,5 @@ //! This example showcases an interactive `Canvas` for drawing Bézier curves. -use iced::widget::{button, container, hover, right, space_x}; +use iced::widget::{button, container, hover, right, space}; use iced::{Element, Theme}; pub fn main() -> iced::Result { @@ -38,7 +38,7 @@ impl Example { container(hover( self.bezier.view(&self.curves).map(Message::AddCurve), if self.curves.is_empty() { - container(space_x()) + container(space::horizontal()) } else { right( button("Clear") diff --git a/examples/combo_box/src/main.rs b/examples/combo_box/src/main.rs index cc0e7fc0..fc16d88b 100644 --- a/examples/combo_box/src/main.rs +++ b/examples/combo_box/src/main.rs @@ -1,4 +1,4 @@ -use iced::widget::{center, column, combo_box, scrollable, space_y, text}; +use iced::widget::{center, column, combo_box, scrollable, space, text}; use iced::{Center, Element, Fill}; pub fn main() -> iced::Result { @@ -60,7 +60,7 @@ impl Example { text(&self.text), "What is your language?", combo_box, - space_y().height(150), + space().height(150), ] .width(Fill) .align_x(Center) diff --git a/examples/editor/src/main.rs b/examples/editor/src/main.rs index 6a987030..b854275f 100644 --- a/examples/editor/src/main.rs +++ b/examples/editor/src/main.rs @@ -1,7 +1,7 @@ use iced::highlighter; use iced::keyboard; use iced::widget::{ - button, center_x, column, container, operation, pick_list, row, space_x, + button, center_x, column, container, operation, pick_list, row, space, text, text_editor, toggler, tooltip, }; use iced::{Center, Element, Fill, Font, Task, Theme}; @@ -157,7 +157,7 @@ impl Editor { "Save file", self.is_dirty.then_some(Message::SaveFile) ), - space_x(), + space::horizontal(), toggler(self.word_wrap) .label("Word Wrap") .on_toggle(Message::WordWrapToggled), @@ -184,7 +184,7 @@ impl Editor { } else { String::from("New file") }), - space_x(), + space::horizontal(), text({ let (line, column) = self.content.cursor_position(); diff --git a/examples/gallery/src/civitai.rs b/examples/gallery/src/civitai.rs index b24b1031..97f0ad89 100644 --- a/examples/gallery/src/civitai.rs +++ b/examples/gallery/src/civitai.rs @@ -15,7 +15,7 @@ pub struct Image { } impl Image { - pub const LIMIT: usize = 99; + pub const LIMIT: usize = 96; pub async fn list() -> Result, Error> { let client = reqwest::Client::new(); diff --git a/examples/gallery/src/main.rs b/examples/gallery/src/main.rs index 529c04d4..182fd606 100644 --- a/examples/gallery/src/main.rs +++ b/examples/gallery/src/main.rs @@ -10,7 +10,7 @@ use iced::animation; use iced::time::{Instant, milliseconds}; use iced::widget::{ button, container, float, grid, image, mouse_area, opaque, scrollable, - sensor, space_x, stack, + sensor, space, stack, }; use iced::window; use iced::{ @@ -227,7 +227,7 @@ fn card<'a>( }) .into() } else { - space_x().into() + space::horizontal().into() }; if let Some(blurhash) = preview.blurhash(now) { @@ -241,7 +241,7 @@ fn card<'a>( thumbnail } } else { - space_x().into() + space::horizontal().into() }; let card = mouse_area(container(image).style(container::dark)) @@ -264,7 +264,7 @@ fn card<'a>( } fn placeholder<'a>() -> Element<'a, Message> { - container(space_x()).style(container::dark).into() + container(space()).style(container::dark).into() } enum Preview { @@ -415,35 +415,32 @@ impl Viewer { || self.image_fade_in.is_animating(now) } - fn view(&self, now: Instant) -> Element<'_, Message> { + fn view(&self, now: Instant) -> Option> { let opacity = self.background_fade_in.interpolate(0.0, 0.8, now); - let image: Element<'_, _> = if let Some(handle) = &self.image { + if opacity <= 0.0 { + return None; + } + + let image = self.image.as_ref().map(|handle| { image(handle) .width(Fill) .height(Fill) .opacity(self.image_fade_in.interpolate(0.0, 1.0, now)) .scale(self.image_fade_in.interpolate(1.5, 1.0, now)) - .into() - } else { - space_x().into() - }; + }); - if opacity > 0.0 { - opaque( - mouse_area( - container(image) - .center(Fill) - .style(move |_theme| { - container::Style::default() - .background(color!(0x000000, opacity)) - }) - .padding(20), - ) - .on_press(Message::Close), + Some(opaque( + mouse_area( + container(image) + .center(Fill) + .style(move |_theme| { + container::Style::default() + .background(color!(0x000000, opacity)) + }) + .padding(20), ) - } else { - space_x().into() - } + .on_press(Message::Close), + )) } } diff --git a/examples/gradient/src/main.rs b/examples/gradient/src/main.rs index d927cd23..05505f35 100644 --- a/examples/gradient/src/main.rs +++ b/examples/gradient/src/main.rs @@ -1,6 +1,6 @@ use iced::gradient; use iced::theme; -use iced::widget::{checkbox, column, container, row, slider, space_x, text}; +use iced::widget::{checkbox, column, container, row, slider, space, text}; use iced::{Center, Color, Element, Fill, Radians, Theme, color}; pub fn main() -> iced::Result { @@ -57,7 +57,7 @@ impl Gradient { transparent, } = *self; - let gradient_box = container(space_x()) + let gradient_box = container(space()) .style(move |_theme| { let gradient = gradient::Linear::new(angle) .add_stop(0.0, start) diff --git a/examples/layout/src/main.rs b/examples/layout/src/main.rs index dc311d75..210f745d 100644 --- a/examples/layout/src/main.rs +++ b/examples/layout/src/main.rs @@ -3,7 +3,7 @@ use iced::keyboard; use iced::mouse; use iced::widget::{ button, canvas, center, center_y, checkbox, column, container, pick_list, - pin, row, rule, scrollable, space_x, stack, text, + pin, row, rule, scrollable, space, stack, text, }; use iced::{ Center, Element, Fill, Font, Length, Point, Rectangle, Renderer, Shrink, @@ -70,7 +70,7 @@ impl Layout { fn view(&self) -> Element<'_, Message> { let header = row![ text(self.example.title).size(20).font(Font::MONOSPACE), - space_x(), + space::horizontal(), checkbox("Explain", self.explain) .on_toggle(Message::ExplainToggled), pick_list(Theme::ALL, self.theme.as_ref(), Message::ThemeSelected) @@ -92,23 +92,19 @@ impl Layout { }) .padding(4); - let controls = row([ + let controls = row![ (!self.example.is_first()).then_some( button(text("← Previous")) .padding([5, 10]) .on_press(Message::Previous) - .into(), ), - Some(space_x().into()), + space::horizontal(), (!self.example.is_last()).then_some( button(text("Next →")) .padding([5, 10]) .on_press(Message::Next) - .into(), ), - ] - .into_iter() - .flatten()); + ]; column![header, example, controls] .spacing(10) @@ -143,7 +139,7 @@ impl Example { }, Self { title: "Space", - view: space, + view: space_, }, Self { title: "Application", @@ -237,15 +233,21 @@ fn row_<'a>() -> Element<'a, Message> { .into() } -fn space<'a>() -> Element<'a, Message> { - row!["Left!", space_x(), "Right!"].into() +fn space_<'a>() -> Element<'a, Message> { + row!["Left!", space::horizontal(), "Right!"].into() } fn application<'a>() -> Element<'a, Message> { let header = container( - row![square(40), space_x(), "Header!", space_x(), square(40),] - .padding(10) - .align_y(Center), + row![ + square(40), + space::horizontal(), + "Header!", + space::horizontal(), + square(40), + ] + .padding(10) + .align_y(Center), ) .style(|theme| { let palette = theme.extended_palette(); diff --git a/examples/lazy/src/main.rs b/examples/lazy/src/main.rs index 99348da7..6a48b655 100644 --- a/examples/lazy/src/main.rs +++ b/examples/lazy/src/main.rs @@ -1,5 +1,5 @@ use iced::widget::{ - button, column, lazy, pick_list, row, scrollable, space_x, text, text_input, + button, column, lazy, pick_list, row, scrollable, space, text, text_input, }; use iced::{Element, Fill}; @@ -173,7 +173,7 @@ impl App { row![ text(item.name.clone()).color(item.color), - space_x(), + space::horizontal(), pick_list(Color::ALL, Some(item.color), move |color| { Message::ItemColorChanged(item.clone(), color) }), diff --git a/examples/markdown/src/main.rs b/examples/markdown/src/main.rs index c6df9a0c..6e2a79b9 100644 --- a/examples/markdown/src/main.rs +++ b/examples/markdown/src/main.rs @@ -6,7 +6,7 @@ use iced::highlighter; use iced::time::{self, Instant, milliseconds}; use iced::widget::{ button, center_x, container, hover, image, markdown, operation, right, row, - scrollable, sensor, space_x, text_editor, toggler, + scrollable, sensor, space, text_editor, toggler, }; use iced::window; use iced::{ @@ -264,7 +264,7 @@ impl<'a> markdown::Viewer<'a, Message> for CustomViewer<'a> { ) .into() } else { - sensor(space_x()) + sensor(space()) .key_ref(url.as_str()) .delay(milliseconds(500)) .on_show(|_size| Message::ImageShown(url.clone())) diff --git a/examples/modal/src/main.rs b/examples/modal/src/main.rs index 82596130..daf288e0 100644 --- a/examples/modal/src/main.rs +++ b/examples/modal/src/main.rs @@ -3,7 +3,7 @@ use iced::keyboard; use iced::keyboard::key; use iced::widget::{ button, center, column, container, mouse_area, opaque, operation, - pick_list, row, space_x, stack, text, text_input, + pick_list, row, space, stack, text, text_input, }; use iced::{Bottom, Color, Element, Fill, Subscription, Task}; @@ -95,12 +95,16 @@ impl App { fn view(&self) -> Element<'_, Message> { let content = container( column![ - row![text("Top Left"), space_x(), text("Top Right")] + row![text("Top Left"), space::horizontal(), text("Top Right")] .height(Fill), center(button(text("Show Modal")).on_press(Message::ShowModal)), - row![text("Bottom Left"), space_x(), text("Bottom Right")] - .align_y(Bottom) - .height(Fill), + row![ + text("Bottom Left"), + space::horizontal(), + text("Bottom Right") + ] + .align_y(Bottom) + .height(Fill), ] .height(Fill), ) diff --git a/examples/multi_window/src/main.rs b/examples/multi_window/src/main.rs index a8076617..a834a617 100644 --- a/examples/multi_window/src/main.rs +++ b/examples/multi_window/src/main.rs @@ -1,6 +1,6 @@ use iced::widget::{ - button, center, center_x, column, container, operation, scrollable, - space_x, text, text_input, + button, center, center_x, column, container, operation, scrollable, space, + text, text_input, }; use iced::window; use iced::{ @@ -134,7 +134,7 @@ impl Example { if let Some(window) = self.windows.get(&window_id) { center(window.view(window_id)).into() } else { - space_x().into() + space().into() } } diff --git a/examples/pick_list/src/main.rs b/examples/pick_list/src/main.rs index a1e44ae8..f67e3a6c 100644 --- a/examples/pick_list/src/main.rs +++ b/examples/pick_list/src/main.rs @@ -1,4 +1,4 @@ -use iced::widget::{column, pick_list, scrollable, space_y}; +use iced::widget::{column, pick_list, scrollable, space}; use iced::{Center, Element, Fill}; pub fn main() -> iced::Result { @@ -33,10 +33,10 @@ impl Example { .placeholder("Choose a language..."); let content = column![ - space_y().height(600), + space().height(600), "Which is your favorite language?", pick_list, - space_y().height(600), + space().height(600), ] .width(Fill) .align_x(Center) diff --git a/examples/scrollable/src/main.rs b/examples/scrollable/src/main.rs index 9c6bfa1c..17b1fad2 100644 --- a/examples/scrollable/src/main.rs +++ b/examples/scrollable/src/main.rs @@ -1,6 +1,6 @@ use iced::widget::{ button, column, container, operation, progress_bar, radio, row, scrollable, - slider, space_x, space_y, text, + slider, space, text, }; use iced::{Border, Center, Color, Element, Fill, Task, Theme}; @@ -190,9 +190,9 @@ impl ScrollableDemo { column![ scroll_to_end_button(), text("Beginning!"), - space_y().height(1200), + space().height(1200), text("Middle!"), - space_y().height(1200), + space().height(1200), text("End!"), scroll_to_beginning_button(), ] @@ -215,9 +215,9 @@ impl ScrollableDemo { row![ scroll_to_end_button(), text("Beginning!"), - space_x().width(1200), + space().width(1200), text("Middle!"), - space_x().width(1200), + space().width(1200), text("End!"), scroll_to_beginning_button(), ] @@ -242,25 +242,25 @@ impl ScrollableDemo { row![ column![ text("Let's do some scrolling!"), - space_y().height(2400) + space().height(2400) ], scroll_to_end_button(), text("Horizontal - Beginning!"), - space_x().width(1200), + space().width(1200), //vertical content column![ text("Horizontal - Middle!"), scroll_to_end_button(), text("Vertical - Beginning!"), - space_y().height(1200), + space().height(1200), text("Vertical - Middle!"), - space_y().height(1200), + space().height(1200), text("Vertical - End!"), scroll_to_beginning_button(), - space_y().height(40), + space().height(40), ] .spacing(40), - space_x().width(1200), + space().width(1200), text("Horizontal - End!"), scroll_to_beginning_button(), ] diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index 996f80ce..56e5bb27 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -1,7 +1,7 @@ use iced::keyboard; use iced::widget::{ button, center_x, center_y, checkbox, column, container, pick_list, - progress_bar, row, rule, scrollable, slider, space_y, text, text_input, + progress_bar, row, rule, scrollable, slider, space, text, text_input, toggler, }; use iced::{Center, Element, Fill, Shrink, Subscription, Theme}; @@ -127,7 +127,7 @@ impl Styling { let scroll_me = scrollable(column![ "Scroll me!", - space_y().height(800), + space().height(800), "You did it!" ]) .width(Fill) diff --git a/examples/toast/src/main.rs b/examples/toast/src/main.rs index 8f91c9a5..b3f09dd6 100644 --- a/examples/toast/src/main.rs +++ b/examples/toast/src/main.rs @@ -171,7 +171,7 @@ mod toast { use iced::mouse; use iced::theme; use iced::time::{self, Duration, Instant}; - use iced::widget::{button, column, container, row, rule, space_x, text}; + use iced::widget::{button, column, container, row, rule, space, text}; use iced::window; use iced::{ Alignment, Center, Element, Event, Fill, Length, Point, Rectangle, @@ -237,7 +237,7 @@ mod toast { container( row![ text(toast.title.as_str()), - space_x(), + space::horizontal(), button("X") .on_press((on_close)(index)) .padding(3), diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index 33ae3cca..fbefa6ad 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -1,7 +1,7 @@ use iced::widget::{Button, Column, Container, Slider}; use iced::widget::{ button, center_x, center_y, checkbox, column, image, radio, rich_text, row, - scrollable, slider, space_x, space_y, span, text, text_input, toggler, + scrollable, slider, space, span, text, text_input, toggler, }; use iced::{Center, Color, Element, Fill, Font, Pixels, color}; @@ -146,7 +146,7 @@ impl Tour { .on_press(Message::BackPressed) .style(button::secondary) }), - space_x(), + space::horizontal(), self.can_continue().then(|| { padded_button("Next").on_press(Message::NextPressed) }) @@ -405,14 +405,14 @@ impl Tour { text("Tip: You can use the scrollbar to scroll down faster!") .size(16), ) - .push(space_y().height(4096)) + .push(space().height(4096)) .push( text("You are halfway there!") .width(Fill) .size(30) .align_x(Center), ) - .push(space_y().height(4096)) + .push(space().height(4096)) .push(ferris(300, image::FilterMethod::Linear)) .push(text("You made it!").width(Fill).size(50).align_x(Center)) } diff --git a/examples/vectorial_text/src/main.rs b/examples/vectorial_text/src/main.rs index 12d190a3..bf0fd657 100644 --- a/examples/vectorial_text/src/main.rs +++ b/examples/vectorial_text/src/main.rs @@ -1,6 +1,6 @@ use iced::alignment; use iced::mouse; -use iced::widget::{canvas, checkbox, column, row, slider, space_x, text}; +use iced::widget::{canvas, checkbox, column, row, slider, space, text}; use iced::{Center, Element, Fill, Point, Rectangle, Renderer, Theme, Vector}; pub fn main() -> iced::Result { @@ -49,7 +49,7 @@ impl VectorialText { fn view(&self) -> Element<'_, Message> { let slider_with_label = |label, range, value, message: fn(f32) -> _| { column![ - row![text(label), space_x(), text!("{:.2}", value)], + row![text(label), space::horizontal(), text!("{:.2}", value)], slider(range, value, message).step(0.01) ] .spacing(2) diff --git a/examples/visible_bounds/src/main.rs b/examples/visible_bounds/src/main.rs index 4025dcf4..4a900bf7 100644 --- a/examples/visible_bounds/src/main.rs +++ b/examples/visible_bounds/src/main.rs @@ -1,7 +1,7 @@ use iced::event::{self, Event}; use iced::mouse; use iced::widget::{ - self, column, container, row, scrollable, selector, space_x, space_y, text, + self, column, container, row, scrollable, selector, space, text, }; use iced::window; use iced::{ @@ -63,7 +63,7 @@ impl Example { let data_row = |label, value, color| { row![ text(label), - space_x(), + space::horizontal(), text(value) .font(Font::MONOSPACE) .size(14) @@ -111,21 +111,21 @@ impl Example { scrollable( column![ text("Scroll me!"), - space_y().height(400), + space().height(400), container(text("I am the outer container!")) .id(OUTER_CONTAINER) .padding(40) .style(container::rounded_box), - space_y().height(400), + space().height(400), scrollable( column![ text("Scroll me!"), - space_y().height(400), + space().height(400), container(text("I am the inner container!")) .id(INNER_CONTAINER) .padding(40) .style(container::rounded_box), - space_y().height(400), + space().height(400), ] .padding(20) ) diff --git a/tester/src/lib.rs b/tester/src/lib.rs index 16450b4e..5ac77968 100644 --- a/tester/src/lib.rs +++ b/tester/src/lib.rs @@ -28,7 +28,7 @@ use crate::test::instruction; use crate::test::{Emulator, Ice, Instruction}; use crate::widget::{ button, center, column, combo_box, container, pick_list, row, rule, - scrollable, space_x, text, text_editor, text_input, themer, + scrollable, space, text, text_editor, text_input, themer, }; /// Attaches a [`Tester`] to the given [`Program`]. @@ -564,7 +564,7 @@ impl Tester

{ let viewport = container( scrollable( container(match &self.state { - State::Empty => Element::from(space_x()), + State::Empty => Element::from(space()), State::Idle { state } => { let theme = program.theme(state, window); @@ -795,7 +795,7 @@ impl Tester

{ }; let edit = if self.is_busy() { - Element::from(space_x()) + Element::from(space::horizontal()) } else if self.edit.is_none() { button(icon::pencil().size(14)) .padding(0) @@ -849,7 +849,7 @@ where column![ row![ text(fragment).size(14).font(Font::MONOSPACE), - space_x(), + space::horizontal(), control.into() ] .spacing(5) diff --git a/widget/src/helpers.rs b/widget/src/helpers.rs index a5d20222..4afb8cee 100644 --- a/widget/src/helpers.rs +++ b/widget/src/helpers.rs @@ -1017,7 +1017,7 @@ where /// # mod iced { pub mod widget { pub use iced_widget::*; } } /// # pub type State = (); /// # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>; -/// use iced::widget::{column, scrollable, space_y}; +/// use iced::widget::{column, scrollable, space}; /// /// enum Message { /// // ... @@ -1026,7 +1026,7 @@ where /// fn view(state: &State) -> Element<'_, Message> { /// scrollable(column![ /// "Scroll me!", -/// space_y().height(3000), +/// space().height(3000), /// "You did it!", /// ]).into() /// } @@ -1729,20 +1729,12 @@ where ComboBox::new(state, placeholder, selection, on_selected) } -/// Creates a new [`Space`] widget that fills the available -/// horizontal space. +/// Creates some empty [`Space`] with no size. /// -/// This can be useful to separate widgets in a [`Row`]. -pub fn space_x() -> Space { - Space::with_width(Length::Fill) -} - -/// Creates a new [`Space`] widget that fills the available -/// vertical space. -/// -/// This can be useful to separate widgets in a [`Column`]. -pub fn space_y() -> Space { - Space::with_height(Length::Fill) +/// This is considered the "identity" widget. It will take +/// no space and do nothing. +pub fn space() -> Space { + Space::new() } /// Creates a horizontal [`Rule`] with the given height. diff --git a/widget/src/lib.rs b/widget/src/lib.rs index c58220a8..73f1ed22 100644 --- a/widget/src/lib.rs +++ b/widget/src/lib.rs @@ -14,7 +14,6 @@ mod column; mod mouse_area; mod pin; mod responsive; -mod space; mod stack; mod themer; @@ -35,6 +34,7 @@ pub mod rule; pub mod scrollable; pub mod sensor; pub mod slider; +pub mod space; pub mod table; pub mod text; pub mod text_editor; diff --git a/widget/src/responsive.rs b/widget/src/responsive.rs index 06757fbd..76e9c62c 100644 --- a/widget/src/responsive.rs +++ b/widget/src/responsive.rs @@ -8,7 +8,7 @@ use crate::core::{ self, Clipboard, Element, Event, Length, Rectangle, Shell, Size, Vector, Widget, }; -use crate::space_x; +use crate::space; /// A widget that is aware of its dimensions. /// @@ -43,7 +43,7 @@ where view: Box::new(view), width: Length::Fill, height: Length::Fill, - content: Element::new(space_x().width(0)), + content: Element::new(space()), } } diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs index 2535ecb8..75fd249c 100644 --- a/widget/src/scrollable.rs +++ b/widget/src/scrollable.rs @@ -5,7 +5,7 @@ //! # mod iced { pub mod widget { pub use iced_widget::*; } } //! # pub type State = (); //! # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>; -//! use iced::widget::{column, scrollable, space_y}; +//! use iced::widget::{column, scrollable, space}; //! //! enum Message { //! // ... @@ -14,7 +14,7 @@ //! fn view(state: &State) -> Element<'_, Message> { //! scrollable(column![ //! "Scroll me!", -//! space_y().height(3000), +//! space().height(3000), //! "You did it!", //! ]).into() //! } @@ -48,7 +48,7 @@ pub use operation::scrollable::{AbsoluteOffset, RelativeOffset}; /// # mod iced { pub mod widget { pub use iced_widget::*; } } /// # pub type State = (); /// # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>; -/// use iced::widget::{column, scrollable, space_y}; +/// use iced::widget::{column, scrollable, space}; /// /// enum Message { /// // ... @@ -57,7 +57,7 @@ pub use operation::scrollable::{AbsoluteOffset, RelativeOffset}; /// fn view(state: &State) -> Element<'_, Message> { /// scrollable(column![ /// "Scroll me!", -/// space_y().height(3000), +/// space().height(3000), /// "You did it!", /// ]).into() /// } diff --git a/widget/src/space.rs b/widget/src/space.rs index 949ea3ce..231d4704 100644 --- a/widget/src/space.rs +++ b/widget/src/space.rs @@ -1,4 +1,4 @@ -//! Distribute content vertically. +//! Add some explicit spacing between elements. use crate::core; use crate::core::layout; use crate::core::mouse; @@ -6,6 +6,22 @@ use crate::core::renderer; use crate::core::widget::Tree; use crate::core::{Element, Layout, Length, Rectangle, Size, Widget}; +/// Creates a new [`Space`] widget that fills the available +/// horizontal space. +/// +/// This can be useful to separate widgets in a [`Row`](crate::Row). +pub fn horizontal() -> Space { + Space::new().width(Length::Fill) +} + +/// Creates a new [`Space`] widget that fills the available +/// vertical space. +/// +/// This can be useful to separate widgets in a [`Column`](crate::Column). +pub fn vertical() -> Space { + Space::new().height(Length::Fill) +} + /// An amount of empty space. /// /// It can be useful if you want to fill some space with nothing. @@ -16,27 +32,11 @@ pub struct Space { } impl Space { - /// Creates an amount of empty [`Space`] with the given width and height. - pub fn new(width: impl Into, height: impl Into) -> Self { - Space { - width: width.into(), - height: height.into(), - } - } - - /// Creates an amount of horizontal [`Space`]. - pub fn with_width(width: impl Into) -> Self { - Space { - width: width.into(), - height: Length::Shrink, - } - } - - /// Creates an amount of vertical [`Space`]. - pub fn with_height(height: impl Into) -> Self { + /// Creates some empty [`Space`] with no size. + pub fn new() -> Self { Space { width: Length::Shrink, - height: height.into(), + height: Length::Shrink, } } @@ -53,6 +53,12 @@ impl Space { } } +impl Default for Space { + fn default() -> Self { + Space::new() + } +} + impl Widget for Space where Renderer: core::Renderer,