use iced::widget::{button, column, container}; use iced::{Alignment, Element, Length, Sandbox, Settings}; pub fn main() -> iced::Result { Exit::run(Settings::default()) } #[derive(Default)] struct Exit { show_confirm: bool, exit: bool, } #[derive(Debug, Clone, Copy)] enum Message { Confirm, Exit, } impl Sandbox for Exit { type Message = Message; fn new() -> Self { Self::default() } fn title(&self) -> String { String::from("Exit - Iced") } fn should_exit(&self) -> bool { self.exit } fn update(&mut self, message: Message) { match message { Message::Confirm => { self.exit = true; } Message::Exit => { self.show_confirm = true; } } } fn view(&self) -> Element { let content = if self.show_confirm { column![ "Are you sure you want to exit?", button("Yes, exit now") .padding([10, 20]) .on_press(Message::Confirm), ] } else { column![ "Click the button to exit", button("Exit").padding([10, 20]).on_press(Message::Exit), ] } .spacing(10) .align_items(Alignment::Center); container(content) .width(Length::Fill) .height(Length::Fill) .padding(20) .center_x() .center_y() .into() } }