Center contents with Container in exit example
... also add some `padding` to buttons!
This commit is contained in:
parent
8a70d10401
commit
ecd0997576
1 changed files with 16 additions and 7 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
use iced::{
|
use iced::{
|
||||||
button, Alignment, Button, Column, Element, Sandbox, Settings, Text,
|
button, Alignment, Button, Column, Container, Element, Length, Sandbox,
|
||||||
|
Settings, Text,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn main() -> iced::Result {
|
pub fn main() -> iced::Result {
|
||||||
|
|
@ -47,9 +48,9 @@ impl Sandbox for Exit {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view(&mut self) -> Element<Message> {
|
fn view(&mut self) -> Element<Message> {
|
||||||
if self.show_confirm {
|
let content = if self.show_confirm {
|
||||||
Column::new()
|
Column::new()
|
||||||
.padding(20)
|
.spacing(10)
|
||||||
.align_items(Alignment::Center)
|
.align_items(Alignment::Center)
|
||||||
.push(Text::new("Are you sure you want to exit?"))
|
.push(Text::new("Are you sure you want to exit?"))
|
||||||
.push(
|
.push(
|
||||||
|
|
@ -57,19 +58,27 @@ impl Sandbox for Exit {
|
||||||
&mut self.confirm_button,
|
&mut self.confirm_button,
|
||||||
Text::new("Yes, exit now"),
|
Text::new("Yes, exit now"),
|
||||||
)
|
)
|
||||||
|
.padding([10, 20])
|
||||||
.on_press(Message::Confirm),
|
.on_press(Message::Confirm),
|
||||||
)
|
)
|
||||||
.into()
|
|
||||||
} else {
|
} else {
|
||||||
Column::new()
|
Column::new()
|
||||||
.padding(20)
|
.spacing(10)
|
||||||
.align_items(Alignment::Center)
|
.align_items(Alignment::Center)
|
||||||
.push(Text::new("Click the button to exit"))
|
.push(Text::new("Click the button to exit"))
|
||||||
.push(
|
.push(
|
||||||
Button::new(&mut self.exit_button, Text::new("Exit"))
|
Button::new(&mut self.exit_button, Text::new("Exit"))
|
||||||
|
.padding([10, 20])
|
||||||
.on_press(Message::Exit),
|
.on_press(Message::Exit),
|
||||||
)
|
)
|
||||||
.into()
|
};
|
||||||
}
|
|
||||||
|
Container::new(content)
|
||||||
|
.width(Length::Fill)
|
||||||
|
.height(Length::Fill)
|
||||||
|
.padding(20)
|
||||||
|
.center_x()
|
||||||
|
.center_y()
|
||||||
|
.into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue