summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-02-15 02:08:22 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-02-15 02:08:22 +0100
commite8049af23dbf4988ff24b75b90104295f61098a2 (patch)
tree21840d4799c0645d9572af6d44c58bd7be117a39
parent9dd20ead085ff3b9b4bd441b5e4938cf8e813f35 (diff)
downloadiced-e8049af23dbf4988ff24b75b90104295f61098a2.tar.gz
iced-e8049af23dbf4988ff24b75b90104295f61098a2.tar.bz2
iced-e8049af23dbf4988ff24b75b90104295f61098a2.zip
Make `horizontal_space` and `vertical_space` fill by default
-rw-r--r--examples/combo_box/src/main.rs2
-rw-r--r--examples/editor/src/main.rs4
-rw-r--r--examples/gradient/src/main.rs2
-rw-r--r--examples/layout/src/main.rs10
-rw-r--r--examples/lazy/src/main.rs2
-rw-r--r--examples/modal/src/main.rs12
-rw-r--r--examples/pick_list/src/main.rs4
-rw-r--r--examples/scrollable/src/main.rs20
-rw-r--r--examples/styling/src/main.rs2
-rw-r--r--examples/toast/src/main.rs2
-rw-r--r--examples/tour/src/main.rs6
-rw-r--r--examples/vectorial_text/src/main.rs2
-rw-r--r--examples/visible_bounds/src/main.rs10
-rw-r--r--widget/src/helpers.rs8
-rw-r--r--widget/src/lazy/responsive.rs2
-rw-r--r--widget/src/space.rs12
16 files changed, 54 insertions, 46 deletions
diff --git a/examples/combo_box/src/main.rs b/examples/combo_box/src/main.rs
index 4f347667..fcf5feaa 100644
--- a/examples/combo_box/src/main.rs
+++ b/examples/combo_box/src/main.rs
@@ -68,7 +68,7 @@ impl Sandbox for Example {
text(&self.text),
"What is your language?",
combo_box,
- vertical_space(150),
+ vertical_space().height(150),
]
.width(Length::Fill)
.align_items(Alignment::Center)
diff --git a/examples/editor/src/main.rs b/examples/editor/src/main.rs
index 75b66264..53c9cf7c 100644
--- a/examples/editor/src/main.rs
+++ b/examples/editor/src/main.rs
@@ -155,7 +155,7 @@ impl Application for Editor {
"Save file",
self.is_dirty.then_some(Message::SaveFile)
),
- horizontal_space(Length::Fill),
+ horizontal_space(),
pick_list(
highlighter::Theme::ALL,
Some(self.theme),
@@ -179,7 +179,7 @@ impl Application for Editor {
} else {
String::from("New file")
}),
- horizontal_space(Length::Fill),
+ horizontal_space(),
text({
let (line, column) = self.content.cursor_position();
diff --git a/examples/gradient/src/main.rs b/examples/gradient/src/main.rs
index 32b2e4aa..a021c164 100644
--- a/examples/gradient/src/main.rs
+++ b/examples/gradient/src/main.rs
@@ -71,7 +71,7 @@ impl Sandbox for Gradient {
transparent,
} = *self;
- let gradient_box = container(horizontal_space(Length::Fill))
+ let gradient_box = container(horizontal_space())
.width(Length::Fill)
.height(Length::Fill)
.style(move |_: &_| {
diff --git a/examples/layout/src/main.rs b/examples/layout/src/main.rs
index f41c9986..06a476be 100644
--- a/examples/layout/src/main.rs
+++ b/examples/layout/src/main.rs
@@ -85,7 +85,7 @@ impl Application for Layout {
fn view(&self) -> Element<Message> {
let header = row![
text(self.example.title).size(20).font(Font::MONOSPACE),
- horizontal_space(Length::Fill),
+ horizontal_space(),
checkbox("Explain", self.explain)
.on_toggle(Message::ExplainToggled),
pick_list(Theme::ALL, Some(&self.theme), Message::ThemeSelected),
@@ -117,7 +117,7 @@ impl Application for Layout {
.on_press(Message::Previous)
.into(),
),
- Some(horizontal_space(Length::Fill).into()),
+ Some(horizontal_space().into()),
(!self.example.is_last()).then_some(
button("Next →")
.padding([5, 10])
@@ -251,16 +251,16 @@ fn row_<'a>() -> Element<'a, Message> {
}
fn space<'a>() -> Element<'a, Message> {
- row!["Left!", horizontal_space(Length::Fill), "Right!"].into()
+ row!["Left!", horizontal_space(), "Right!"].into()
}
fn application<'a>() -> Element<'a, Message> {
let header = container(
row![
square(40),
- horizontal_space(Length::Fill),
+ horizontal_space(),
"Header!",
- horizontal_space(Length::Fill),
+ horizontal_space(),
square(40),
]
.padding(10)
diff --git a/examples/lazy/src/main.rs b/examples/lazy/src/main.rs
index 04df0744..9d8c0e35 100644
--- a/examples/lazy/src/main.rs
+++ b/examples/lazy/src/main.rs
@@ -186,7 +186,7 @@ impl Sandbox for App {
row![
text(&item.name)
.style(theme::Text::Color(item.color.into())),
- horizontal_space(Length::Fill),
+ horizontal_space(),
pick_list(Color::ALL, Some(item.color), move |color| {
Message::ItemColorChanged(item.clone(), color)
}),
diff --git a/examples/modal/src/main.rs b/examples/modal/src/main.rs
index 1dac0075..938ce32c 100644
--- a/examples/modal/src/main.rs
+++ b/examples/modal/src/main.rs
@@ -111,13 +111,9 @@ impl Application for App {
fn view(&self) -> Element<Message> {
let content = container(
column![
- row![
- text("Top Left"),
- horizontal_space(Length::Fill),
- text("Top Right")
- ]
- .align_items(Alignment::Start)
- .height(Length::Fill),
+ row![text("Top Left"), horizontal_space(), text("Top Right")]
+ .align_items(Alignment::Start)
+ .height(Length::Fill),
container(
button(text("Show Modal")).on_press(Message::ShowModal)
)
@@ -127,7 +123,7 @@ impl Application for App {
.height(Length::Fill),
row![
text("Bottom Left"),
- horizontal_space(Length::Fill),
+ horizontal_space(),
text("Bottom Right")
]
.align_items(Alignment::End)
diff --git a/examples/pick_list/src/main.rs b/examples/pick_list/src/main.rs
index e4d96dc8..c40493e2 100644
--- a/examples/pick_list/src/main.rs
+++ b/examples/pick_list/src/main.rs
@@ -43,10 +43,10 @@ impl Sandbox for Example {
.placeholder("Choose a language...");
let content = column![
- vertical_space(600),
+ vertical_space().height(600),
"Which is your favorite language?",
pick_list,
- vertical_space(600),
+ vertical_space().height(600),
]
.width(Length::Fill)
.align_items(Alignment::Center)
diff --git a/examples/scrollable/src/main.rs b/examples/scrollable/src/main.rs
index 29c39c36..ac18fd38 100644
--- a/examples/scrollable/src/main.rs
+++ b/examples/scrollable/src/main.rs
@@ -216,9 +216,9 @@ impl Application for ScrollableDemo {
column![
scroll_to_end_button(),
text("Beginning!"),
- vertical_space(1200),
+ vertical_space().height(1200),
text("Middle!"),
- vertical_space(1200),
+ vertical_space().height(1200),
text("End!"),
scroll_to_beginning_button(),
]
@@ -241,9 +241,9 @@ impl Application for ScrollableDemo {
row![
scroll_to_end_button(),
text("Beginning!"),
- horizontal_space(1200),
+ horizontal_space().width(1200),
text("Middle!"),
- horizontal_space(1200),
+ horizontal_space().width(1200),
text("End!"),
scroll_to_beginning_button(),
]
@@ -268,25 +268,25 @@ impl Application for ScrollableDemo {
row![
column![
text("Let's do some scrolling!"),
- vertical_space(2400)
+ vertical_space().height(2400)
],
scroll_to_end_button(),
text("Horizontal - Beginning!"),
- horizontal_space(1200),
+ horizontal_space().width(1200),
//vertical content
column![
text("Horizontal - Middle!"),
scroll_to_end_button(),
text("Vertical - Beginning!"),
- vertical_space(1200),
+ vertical_space().height(1200),
text("Vertical - Middle!"),
- vertical_space(1200),
+ vertical_space().height(1200),
text("Vertical - End!"),
scroll_to_beginning_button(),
- vertical_space(40),
+ vertical_space().height(40),
]
.spacing(40),
- horizontal_space(1200),
+ horizontal_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 c26215b6..befdfc1b 100644
--- a/examples/styling/src/main.rs
+++ b/examples/styling/src/main.rs
@@ -76,7 +76,7 @@ impl Sandbox for Styling {
let scrollable = scrollable(column![
"Scroll me!",
- vertical_space(800),
+ vertical_space().height(800),
"You did it!"
])
.width(Length::Fill)
diff --git a/examples/toast/src/main.rs b/examples/toast/src/main.rs
index 7f067e2f..ae947acb 100644
--- a/examples/toast/src/main.rs
+++ b/examples/toast/src/main.rs
@@ -274,7 +274,7 @@ mod toast {
container(
row![
text(toast.title.as_str()),
- horizontal_space(Length::Fill),
+ horizontal_space(),
button("X")
.on_press((on_close)(index))
.padding(3),
diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs
index 15d37896..509f46e7 100644
--- a/examples/tour/src/main.rs
+++ b/examples/tour/src/main.rs
@@ -66,7 +66,7 @@ impl Sandbox for Tour {
);
}
- controls = controls.push(horizontal_space(Length::Fill));
+ controls = controls.push(horizontal_space());
if steps.can_continue() {
controls =
@@ -574,14 +574,14 @@ impl<'a> Step {
text("Tip: You can use the scrollbar to scroll down faster!")
.size(16),
)
- .push(vertical_space(4096))
+ .push(vertical_space().height(4096))
.push(
text("You are halfway there!")
.width(Length::Fill)
.size(30)
.horizontal_alignment(alignment::Horizontal::Center),
)
- .push(vertical_space(4096))
+ .push(vertical_space().height(4096))
.push(ferris(300, image::FilterMethod::Linear))
.push(
text("You made it!")
diff --git a/examples/vectorial_text/src/main.rs b/examples/vectorial_text/src/main.rs
index c2212b22..0b9ea938 100644
--- a/examples/vectorial_text/src/main.rs
+++ b/examples/vectorial_text/src/main.rs
@@ -64,7 +64,7 @@ impl Sandbox for VectorialText {
column![
row![
text(label),
- horizontal_space(Length::Fill),
+ horizontal_space(),
text(format!("{:.2}", value))
],
slider(range, value, message).step(0.01)
diff --git a/examples/visible_bounds/src/main.rs b/examples/visible_bounds/src/main.rs
index 33d76da8..bef5d296 100644
--- a/examples/visible_bounds/src/main.rs
+++ b/examples/visible_bounds/src/main.rs
@@ -81,7 +81,7 @@ impl Application for Example {
let data_row = |label, value, color| {
row![
text(label),
- horizontal_space(Length::Fill),
+ horizontal_space(),
text(value).font(Font::MONOSPACE).size(14).style(color),
]
.height(40)
@@ -127,21 +127,21 @@ impl Application for Example {
scrollable(
column![
text("Scroll me!"),
- vertical_space(400),
+ vertical_space().height(400),
container(text("I am the outer container!"))
.id(OUTER_CONTAINER.clone())
.padding(40)
.style(theme::Container::Box),
- vertical_space(400),
+ vertical_space().height(400),
scrollable(
column![
text("Scroll me!"),
- vertical_space(400),
+ vertical_space().height(400),
container(text("I am the inner container!"))
.id(INNER_CONTAINER.clone())
.padding(40)
.style(theme::Container::Box),
- vertical_space(400)
+ vertical_space().height(400),
]
.padding(20)
)
diff --git a/widget/src/helpers.rs b/widget/src/helpers.rs
index e9898d67..400fced5 100644
--- a/widget/src/helpers.rs
+++ b/widget/src/helpers.rs
@@ -305,15 +305,15 @@ where
/// Creates a new horizontal [`Space`] with the given [`Length`].
///
/// [`Space`]: crate::Space
-pub fn horizontal_space(width: impl Into<Length>) -> Space {
- Space::with_width(width)
+pub fn horizontal_space() -> Space {
+ Space::with_width(Length::Fill)
}
/// Creates a new vertical [`Space`] with the given [`Length`].
///
/// [`Space`]: crate::Space
-pub fn vertical_space(height: impl Into<Length>) -> Space {
- Space::with_height(height)
+pub fn vertical_space() -> Space {
+ Space::with_height(Length::Fill)
}
/// Creates a horizontal [`Rule`] with the given height.
diff --git a/widget/src/lazy/responsive.rs b/widget/src/lazy/responsive.rs
index 44312a21..313e1edb 100644
--- a/widget/src/lazy/responsive.rs
+++ b/widget/src/lazy/responsive.rs
@@ -50,7 +50,7 @@ where
content: RefCell::new(Content {
size: Size::ZERO,
layout: None,
- element: Element::new(horizontal_space(0)),
+ element: Element::new(horizontal_space().width(0)),
}),
}
}
diff --git a/widget/src/space.rs b/widget/src/space.rs
index aeec91f9..35bb30c4 100644
--- a/widget/src/space.rs
+++ b/widget/src/space.rs
@@ -39,6 +39,18 @@ impl Space {
height: height.into(),
}
}
+
+ /// Sets the width of the [`Space`].
+ pub fn width(mut self, width: impl Into<Length>) -> Self {
+ self.width = width.into();
+ self
+ }
+
+ /// Sets the height of the [`Space`].
+ pub fn height(mut self, height: impl Into<Length>) -> Self {
+ self.height = height.into();
+ self
+ }
}
impl<Message, Theme, Renderer> Widget<Message, Theme, Renderer> for Space