Basic application state
This commit is contained in:
parent
bbe05f64b8
commit
c7afe6f993
44
src/iced.rs
44
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<Message> {
|
||||
fn view(state: &ApplicationState) -> Element<Message> {
|
||||
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()
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user