diff --git a/src/iced.rs b/src/iced.rs index f37e192..66241f9 100644 --- a/src/iced.rs +++ b/src/iced.rs @@ -5,7 +5,7 @@ use iced::{ pub fn iced_main() -> iced::Result { println!("Iced"); - iced::run("A counter", update, view) + iced::application(ApplicationState::title, update, view).run() } #[derive(Debug, Clone)] @@ -13,40 +13,24 @@ enum Message { Increment, } -fn update(counter: &mut u64, message: Message) { +fn update(state: &mut ApplicationState, message: Message) { match message { - Message::Increment => *counter += 1, + Message::Increment => state.counter += 1, } } -fn view(counter: &u64) -> Element { +fn view(state: &ApplicationState) -> Element { + let counter = state.counter; button(text(counter)).on_press(Message::Increment).into() } -/* -struct Gamarjoba; - - -impl Application for Gamarjoba { - type Executor = executor::Default; - type Message = (); - type Flags = (); - - fn new(_flags: (),) -> (Self, Command<()>) { - (Gamarjoba, Command::none()) - } - - fn title(&self) -> String { - "YOLO SWAGG 関ヶ原の乱 ჩემი სიტყვებში".to_owned() - } - - fn update(&mut self, _message: (), _clipboard: &mut Clipboard) -> Command<()> { - Command::none() - } - - fn view(&mut self) -> Element<()> { - Text::new("Gamarjoba, munde!").into() - } - +#[derive(Default)] +struct ApplicationState { + counter: u64, +} + +impl ApplicationState { + fn title(&self) -> String { + "YOLO SWAGG 関ヶ原の乱 ჩემი სიტყვებში".to_string() + } } -*/