From c7afe6f9930c168c7ea2f6a557af7c6bc171ce65 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Wed, 2 Oct 2024 02:58:28 -0700 Subject: [PATCH] Basic application state --- src/iced.rs | 44 ++++++++++++++------------------------------ 1 file changed, 14 insertions(+), 30 deletions(-) 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() + } } -*/