Skip to content

Commit

Permalink
Center contents with Container in exit example
Browse files Browse the repository at this point in the history
... also add some `padding` to buttons!
  • Loading branch information
hecrj committed Jan 3, 2022
1 parent 8a70d10 commit ecd0997
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions examples/exit/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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 {
Expand Down Expand Up @@ -47,29 +48,37 @@ impl Sandbox for Exit {
}

fn view(&mut self) -> Element<Message> {
if self.show_confirm {
let content = if self.show_confirm {
Column::new()
.padding(20)
.spacing(10)
.align_items(Alignment::Center)
.push(Text::new("Are you sure you want to exit?"))
.push(
Button::new(
&mut self.confirm_button,
Text::new("Yes, exit now"),
)
.padding([10, 20])
.on_press(Message::Confirm),
)
.into()
} else {
Column::new()
.padding(20)
.spacing(10)
.align_items(Alignment::Center)
.push(Text::new("Click the button to exit"))
.push(
Button::new(&mut self.exit_button, Text::new("Exit"))
.padding([10, 20])
.on_press(Message::Exit),
)
.into()
}
};

Container::new(content)
.width(Length::Fill)
.height(Length::Fill)
.padding(20)
.center_x()
.center_y()
.into()
}
}

0 comments on commit ecd0997

Please sign in to comment.