Make Row
, Column
, and Checkbox
shrink by default
This commit is contained in:
parent
74d01a6957
commit
2ff0e48142
@ -124,10 +124,7 @@ impl Sandbox for Example {
|
|||||||
.max_width(500)
|
.max_width(500)
|
||||||
.align_items(Align::Center)
|
.align_items(Align::Center)
|
||||||
.push(Circle::new(self.radius))
|
.push(Circle::new(self.radius))
|
||||||
.push(
|
.push(Text::new(format!("Radius: {}", self.radius.to_string())))
|
||||||
Text::new(format!("Radius: {}", self.radius.to_string()))
|
|
||||||
.width(Length::Shrink),
|
|
||||||
)
|
|
||||||
.push(Slider::new(
|
.push(Slider::new(
|
||||||
&mut self.slider,
|
&mut self.slider,
|
||||||
1.0..=100.0,
|
1.0..=100.0,
|
||||||
|
@ -57,13 +57,9 @@ impl Application for Events {
|
|||||||
|
|
||||||
fn view(&mut self) -> Element<Message> {
|
fn view(&mut self) -> Element<Message> {
|
||||||
let events = self.last.iter().fold(
|
let events = self.last.iter().fold(
|
||||||
Column::new().width(Length::Shrink).spacing(10),
|
Column::new().spacing(10),
|
||||||
|column, event| {
|
|column, event| {
|
||||||
column.push(
|
column.push(Text::new(format!("{:?}", event)).size(40))
|
||||||
Text::new(format!("{:?}", event))
|
|
||||||
.size(40)
|
|
||||||
.width(Length::Shrink),
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -71,11 +67,9 @@ impl Application for Events {
|
|||||||
self.enabled,
|
self.enabled,
|
||||||
"Listen to runtime events",
|
"Listen to runtime events",
|
||||||
Message::Toggled,
|
Message::Toggled,
|
||||||
)
|
);
|
||||||
.width(Length::Shrink);
|
|
||||||
|
|
||||||
let content = Column::new()
|
let content = Column::new()
|
||||||
.width(Length::Shrink)
|
|
||||||
.align_items(Align::Center)
|
.align_items(Align::Center)
|
||||||
.spacing(20)
|
.spacing(20)
|
||||||
.push(events)
|
.push(events)
|
||||||
|
@ -77,11 +77,8 @@ impl Application for Pokedex {
|
|||||||
|
|
||||||
fn view(&mut self) -> Element<Message> {
|
fn view(&mut self) -> Element<Message> {
|
||||||
let content = match self {
|
let content = match self {
|
||||||
Pokedex::Loading => Column::new().width(Length::Shrink).push(
|
Pokedex::Loading => Column::new()
|
||||||
Text::new("Searching for Pokémon...")
|
.push(Text::new("Searching for Pokémon...").size(40)),
|
||||||
.width(Length::Shrink)
|
|
||||||
.size(40),
|
|
||||||
),
|
|
||||||
Pokedex::Loaded { pokemon, search } => Column::new()
|
Pokedex::Loaded { pokemon, search } => Column::new()
|
||||||
.max_width(500)
|
.max_width(500)
|
||||||
.spacing(20)
|
.spacing(20)
|
||||||
@ -91,14 +88,9 @@ impl Application for Pokedex {
|
|||||||
button(search, "Keep searching!").on_press(Message::Search),
|
button(search, "Keep searching!").on_press(Message::Search),
|
||||||
),
|
),
|
||||||
Pokedex::Errored { try_again, .. } => Column::new()
|
Pokedex::Errored { try_again, .. } => Column::new()
|
||||||
.width(Length::Shrink)
|
|
||||||
.spacing(20)
|
.spacing(20)
|
||||||
.align_items(Align::End)
|
.align_items(Align::End)
|
||||||
.push(
|
.push(Text::new("Whoops! Something went wrong...").size(40))
|
||||||
Text::new("Whoops! Something went wrong...")
|
|
||||||
.width(Length::Shrink)
|
|
||||||
.size(40),
|
|
||||||
)
|
|
||||||
.push(button(try_again, "Try again").on_press(Message::Search)),
|
.push(button(try_again, "Try again").on_press(Message::Search)),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -134,10 +126,13 @@ impl Pokemon {
|
|||||||
Row::new()
|
Row::new()
|
||||||
.align_items(Align::Center)
|
.align_items(Align::Center)
|
||||||
.spacing(20)
|
.spacing(20)
|
||||||
.push(Text::new(&self.name).size(30))
|
.push(
|
||||||
|
Text::new(&self.name)
|
||||||
|
.size(30)
|
||||||
|
.width(Length::Fill),
|
||||||
|
)
|
||||||
.push(
|
.push(
|
||||||
Text::new(format!("#{}", self.number))
|
Text::new(format!("#{}", self.number))
|
||||||
.width(Length::Shrink)
|
|
||||||
.size(20)
|
.size(20)
|
||||||
.color([0.5, 0.5, 0.5]),
|
.color([0.5, 0.5, 0.5]),
|
||||||
),
|
),
|
||||||
|
@ -96,7 +96,6 @@ impl Application for Stopwatch {
|
|||||||
seconds % MINUTE,
|
seconds % MINUTE,
|
||||||
self.duration.subsec_millis() / 10,
|
self.duration.subsec_millis() / 10,
|
||||||
))
|
))
|
||||||
.width(Length::Shrink)
|
|
||||||
.size(40);
|
.size(40);
|
||||||
|
|
||||||
let button = |state, label, color: [f32; 3]| {
|
let button = |state, label, color: [f32; 3]| {
|
||||||
@ -125,13 +124,11 @@ impl Application for Stopwatch {
|
|||||||
.on_press(Message::Reset);
|
.on_press(Message::Reset);
|
||||||
|
|
||||||
let controls = Row::new()
|
let controls = Row::new()
|
||||||
.width(Length::Shrink)
|
|
||||||
.spacing(20)
|
.spacing(20)
|
||||||
.push(toggle_button)
|
.push(toggle_button)
|
||||||
.push(reset_button);
|
.push(reset_button);
|
||||||
|
|
||||||
let content = Column::new()
|
let content = Column::new()
|
||||||
.width(Length::Shrink)
|
|
||||||
.align_items(Align::Center)
|
.align_items(Align::Center)
|
||||||
.spacing(20)
|
.spacing(20)
|
||||||
.push(duration)
|
.push(duration)
|
||||||
|
@ -25,13 +25,14 @@ impl Sandbox for Tiger {
|
|||||||
let content = {
|
let content = {
|
||||||
use iced::{Column, Svg};
|
use iced::{Column, Svg};
|
||||||
|
|
||||||
Column::new()
|
Column::new().padding(20).push(
|
||||||
.width(Length::Shrink)
|
Svg::new(format!(
|
||||||
.padding(20)
|
|
||||||
.push(Svg::new(format!(
|
|
||||||
"{}/examples/resources/tiger.svg",
|
"{}/examples/resources/tiger.svg",
|
||||||
env!("CARGO_MANIFEST_DIR")
|
env!("CARGO_MANIFEST_DIR")
|
||||||
)))
|
))
|
||||||
|
.width(Length::Fill)
|
||||||
|
.height(Length::Fill),
|
||||||
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(not(feature = "svg"))]
|
#[cfg(not(feature = "svg"))]
|
||||||
@ -39,7 +40,6 @@ impl Sandbox for Tiger {
|
|||||||
use iced::{HorizontalAlignment, Text};
|
use iced::{HorizontalAlignment, Text};
|
||||||
|
|
||||||
Text::new("You need to enable the `svg` feature!")
|
Text::new("You need to enable the `svg` feature!")
|
||||||
.width(Length::Shrink)
|
|
||||||
.horizontal_alignment(HorizontalAlignment::Center)
|
.horizontal_alignment(HorizontalAlignment::Center)
|
||||||
.size(30)
|
.size(30)
|
||||||
};
|
};
|
||||||
|
@ -146,6 +146,7 @@ impl Application for Todos {
|
|||||||
..
|
..
|
||||||
}) => {
|
}) => {
|
||||||
let title = Text::new("todos")
|
let title = Text::new("todos")
|
||||||
|
.width(Length::Fill)
|
||||||
.size(100)
|
.size(100)
|
||||||
.color([0.5, 0.5, 0.5])
|
.color([0.5, 0.5, 0.5])
|
||||||
.horizontal_alignment(HorizontalAlignment::Center);
|
.horizontal_alignment(HorizontalAlignment::Center);
|
||||||
@ -284,7 +285,8 @@ impl Task {
|
|||||||
self.completed,
|
self.completed,
|
||||||
&self.description,
|
&self.description,
|
||||||
TaskMessage::Completed,
|
TaskMessage::Completed,
|
||||||
);
|
)
|
||||||
|
.width(Length::Fill);
|
||||||
|
|
||||||
Row::new()
|
Row::new()
|
||||||
.spacing(20)
|
.spacing(20)
|
||||||
@ -323,11 +325,7 @@ impl Task {
|
|||||||
Row::new()
|
Row::new()
|
||||||
.spacing(10)
|
.spacing(10)
|
||||||
.push(delete_icon().color(Color::WHITE))
|
.push(delete_icon().color(Color::WHITE))
|
||||||
.push(
|
.push(Text::new("Delete").color(Color::WHITE)),
|
||||||
Text::new("Delete")
|
|
||||||
.width(Length::Shrink)
|
|
||||||
.color(Color::WHITE),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.on_press(TaskMessage::Delete)
|
.on_press(TaskMessage::Delete)
|
||||||
.padding(10)
|
.padding(10)
|
||||||
@ -358,7 +356,7 @@ impl Controls {
|
|||||||
let tasks_left = tasks.iter().filter(|task| !task.completed).count();
|
let tasks_left = tasks.iter().filter(|task| !task.completed).count();
|
||||||
|
|
||||||
let filter_button = |state, label, filter, current_filter| {
|
let filter_button = |state, label, filter, current_filter| {
|
||||||
let label = Text::new(label).size(16).width(Length::Shrink);
|
let label = Text::new(label).size(16);
|
||||||
let button = if filter == current_filter {
|
let button = if filter == current_filter {
|
||||||
Button::new(state, label.color(Color::WHITE))
|
Button::new(state, label.color(Color::WHITE))
|
||||||
.background(Color::from_rgb(0.2, 0.2, 0.7))
|
.background(Color::from_rgb(0.2, 0.2, 0.7))
|
||||||
@ -381,11 +379,11 @@ impl Controls {
|
|||||||
tasks_left,
|
tasks_left,
|
||||||
if tasks_left == 1 { "task" } else { "tasks" }
|
if tasks_left == 1 { "task" } else { "tasks" }
|
||||||
))
|
))
|
||||||
|
.width(Length::Fill)
|
||||||
.size(16),
|
.size(16),
|
||||||
)
|
)
|
||||||
.push(
|
.push(
|
||||||
Row::new()
|
Row::new()
|
||||||
.width(Length::Shrink)
|
|
||||||
.spacing(10)
|
.spacing(10)
|
||||||
.push(filter_button(
|
.push(filter_button(
|
||||||
all_button,
|
all_button,
|
||||||
|
@ -67,7 +67,7 @@ impl Sandbox for Tour {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
controls = controls.push(Column::new());
|
controls = controls.push(Column::new().width(Length::Fill));
|
||||||
|
|
||||||
if steps.can_continue() {
|
if steps.can_continue() {
|
||||||
controls = controls.push(
|
controls = controls.push(
|
||||||
@ -401,6 +401,7 @@ impl<'a> Step {
|
|||||||
))
|
))
|
||||||
.push(
|
.push(
|
||||||
Text::new(&value.to_string())
|
Text::new(&value.to_string())
|
||||||
|
.width(Length::Fill)
|
||||||
.horizontal_alignment(HorizontalAlignment::Center),
|
.horizontal_alignment(HorizontalAlignment::Center),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -447,6 +448,7 @@ impl<'a> Step {
|
|||||||
))
|
))
|
||||||
.push(
|
.push(
|
||||||
Text::new(&format!("{} px", spacing))
|
Text::new(&format!("{} px", spacing))
|
||||||
|
.width(Length::Fill)
|
||||||
.horizontal_alignment(HorizontalAlignment::Center),
|
.horizontal_alignment(HorizontalAlignment::Center),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -561,6 +563,7 @@ impl<'a> Step {
|
|||||||
))
|
))
|
||||||
.push(
|
.push(
|
||||||
Text::new(&format!("Width: {} px", width.to_string()))
|
Text::new(&format!("Width: {} px", width.to_string()))
|
||||||
|
.width(Length::Fill)
|
||||||
.horizontal_alignment(HorizontalAlignment::Center),
|
.horizontal_alignment(HorizontalAlignment::Center),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -580,6 +583,7 @@ impl<'a> Step {
|
|||||||
.push(Column::new().height(Length::Units(4096)))
|
.push(Column::new().height(Length::Units(4096)))
|
||||||
.push(
|
.push(
|
||||||
Text::new("You are halfway there!")
|
Text::new("You are halfway there!")
|
||||||
|
.width(Length::Fill)
|
||||||
.size(30)
|
.size(30)
|
||||||
.horizontal_alignment(HorizontalAlignment::Center),
|
.horizontal_alignment(HorizontalAlignment::Center),
|
||||||
)
|
)
|
||||||
@ -587,6 +591,7 @@ impl<'a> Step {
|
|||||||
.push(ferris(300))
|
.push(ferris(300))
|
||||||
.push(
|
.push(
|
||||||
Text::new("You made it!")
|
Text::new("You made it!")
|
||||||
|
.width(Length::Fill)
|
||||||
.size(50)
|
.size(50)
|
||||||
.horizontal_alignment(HorizontalAlignment::Center),
|
.horizontal_alignment(HorizontalAlignment::Center),
|
||||||
)
|
)
|
||||||
@ -629,6 +634,7 @@ impl<'a> Step {
|
|||||||
} else {
|
} else {
|
||||||
value
|
value
|
||||||
})
|
})
|
||||||
|
.width(Length::Fill)
|
||||||
.horizontal_alignment(HorizontalAlignment::Center),
|
.horizontal_alignment(HorizontalAlignment::Center),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ impl<Message> Checkbox<Message> {
|
|||||||
on_toggle: Box::new(f),
|
on_toggle: Box::new(f),
|
||||||
label: String::from(label),
|
label: String::from(label),
|
||||||
label_color: None,
|
label_color: None,
|
||||||
width: Length::Fill,
|
width: Length::Shrink,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> {
|
|||||||
Column {
|
Column {
|
||||||
spacing: 0,
|
spacing: 0,
|
||||||
padding: 0,
|
padding: 0,
|
||||||
width: Length::Fill,
|
width: Length::Shrink,
|
||||||
height: Length::Shrink,
|
height: Length::Shrink,
|
||||||
max_width: u32::MAX,
|
max_width: u32::MAX,
|
||||||
max_height: u32::MAX,
|
max_height: u32::MAX,
|
||||||
|
@ -95,6 +95,7 @@ where
|
|||||||
let size = self::Renderer::default_size(renderer);
|
let size = self::Renderer::default_size(renderer);
|
||||||
|
|
||||||
Row::<(), Renderer>::new()
|
Row::<(), Renderer>::new()
|
||||||
|
.width(Length::Fill)
|
||||||
.spacing(15)
|
.spacing(15)
|
||||||
.align_items(Align::Center)
|
.align_items(Align::Center)
|
||||||
.push(
|
.push(
|
||||||
|
@ -33,7 +33,7 @@ impl<'a, Message, Renderer> Row<'a, Message, Renderer> {
|
|||||||
Row {
|
Row {
|
||||||
spacing: 0,
|
spacing: 0,
|
||||||
padding: 0,
|
padding: 0,
|
||||||
width: Length::Fill,
|
width: Length::Shrink,
|
||||||
height: Length::Shrink,
|
height: Length::Shrink,
|
||||||
max_width: u32::MAX,
|
max_width: u32::MAX,
|
||||||
max_height: u32::MAX,
|
max_height: u32::MAX,
|
||||||
|
@ -30,7 +30,7 @@ impl Svg {
|
|||||||
Svg {
|
Svg {
|
||||||
handle: handle.into(),
|
handle: handle.into(),
|
||||||
width: Length::Fill,
|
width: Length::Fill,
|
||||||
height: Length::Fill,
|
height: Length::Shrink,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ impl Text {
|
|||||||
size: None,
|
size: None,
|
||||||
color: None,
|
color: None,
|
||||||
font: Font::Default,
|
font: Font::Default,
|
||||||
width: Length::Fill,
|
width: Length::Shrink,
|
||||||
height: Length::Shrink,
|
height: Length::Shrink,
|
||||||
horizontal_alignment: HorizontalAlignment::Left,
|
horizontal_alignment: HorizontalAlignment::Left,
|
||||||
vertical_alignment: VerticalAlignment::Top,
|
vertical_alignment: VerticalAlignment::Top,
|
||||||
|
@ -64,11 +64,11 @@ impl<'a, Message> TextInput<'a, Message> {
|
|||||||
placeholder: &str,
|
placeholder: &str,
|
||||||
value: &str,
|
value: &str,
|
||||||
on_change: F,
|
on_change: F,
|
||||||
) -> Self
|
) -> TextInput<'a, Message>
|
||||||
where
|
where
|
||||||
F: 'static + Fn(String) -> Message,
|
F: 'static + Fn(String) -> Message,
|
||||||
{
|
{
|
||||||
Self {
|
TextInput {
|
||||||
state,
|
state,
|
||||||
placeholder: String::from(placeholder),
|
placeholder: String::from(placeholder),
|
||||||
value: Value::new(value),
|
value: Value::new(value),
|
||||||
|
@ -28,7 +28,7 @@ impl<'a, Message> Column<'a, Message> {
|
|||||||
Column {
|
Column {
|
||||||
spacing: 0,
|
spacing: 0,
|
||||||
padding: 0,
|
padding: 0,
|
||||||
width: Length::Fill,
|
width: Length::Shrink,
|
||||||
height: Length::Shrink,
|
height: Length::Shrink,
|
||||||
max_width: u32::MAX,
|
max_width: u32::MAX,
|
||||||
max_height: u32::MAX,
|
max_height: u32::MAX,
|
||||||
|
@ -28,7 +28,7 @@ impl<'a, Message> Row<'a, Message> {
|
|||||||
Row {
|
Row {
|
||||||
spacing: 0,
|
spacing: 0,
|
||||||
padding: 0,
|
padding: 0,
|
||||||
width: Length::Fill,
|
width: Length::Shrink,
|
||||||
height: Length::Shrink,
|
height: Length::Shrink,
|
||||||
max_width: u32::MAX,
|
max_width: u32::MAX,
|
||||||
max_height: u32::MAX,
|
max_height: u32::MAX,
|
||||||
|
@ -36,7 +36,7 @@ impl Text {
|
|||||||
size: None,
|
size: None,
|
||||||
color: None,
|
color: None,
|
||||||
font: Font::Default,
|
font: Font::Default,
|
||||||
width: Length::Fill,
|
width: Length::Shrink,
|
||||||
height: Length::Shrink,
|
height: Length::Shrink,
|
||||||
horizontal_alignment: HorizontalAlignment::Left,
|
horizontal_alignment: HorizontalAlignment::Left,
|
||||||
vertical_alignment: VerticalAlignment::Top,
|
vertical_alignment: VerticalAlignment::Top,
|
||||||
|
Loading…
Reference in New Issue
Block a user