Basic application state

This commit is contained in:
Greg Shuflin 2024-10-02 02:58:28 -07:00
parent bbe05f64b8
commit c7afe6f993

View File

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