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 {
|
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;
|
impl ApplicationState {
|
||||||
type Message = ();
|
fn title(&self) -> String {
|
||||||
type Flags = ();
|
"YOLO SWAGG 関ヶ原の乱 ჩემი სიტყვებში".to_string()
|
||||||
|
}
|
||||||
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()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
Loading…
Reference in New Issue
Block a user