diff --git a/Cargo.toml b/Cargo.toml index e904890..3c341a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,12 +7,8 @@ resolver = "2" publish = false [dependencies] -kas = { version = "0.14.0-alpha" } +kas = { version = "0.14.2" } chrono = "0.4" env_logger = "0.8" pest = "2.1" pest_derive = "2.1" - -[patch.crates-io.kas] -git = "https://github.com/kas-gui/kas.git" -rev = "90b19d6847ba1d4185de4605218b05db2b30024e" diff --git a/src/flight_booker.rs b/src/flight_booker.rs index f5f17fc..ddff88b 100644 --- a/src/flight_booker.rs +++ b/src/flight_booker.rs @@ -142,9 +142,8 @@ pub fn window() -> Window<()> { EditBox::new(Guard::new(false)), EditBox::new(Guard::new(true)), Text::new(|_, data: &Data| format!("{}", data.error)), - Button::new_msg(label_any("Book"), ActionBook).on_update( - |cx, button, data: &Data| cx.set_disabled(button.id(), !data.error.is_none()) - ), + Button::new_msg(label_any("Book"), ActionBook) + .on_update(|cx, _, data: &Data| cx.set_disabled(!data.error.is_none())), ]; let ui = Adapt::new(ui, data) @@ -161,27 +160,24 @@ pub fn window() -> Window<()> { data.update_error(); }) - .on_messages(|cx, _, data| { - if cx.try_pop::().is_some() { - let msg = if !data.error.is_none() { - // should be impossible since the button is disabled - format!("{}", data.error) - } else { - match data.flight { - Flight::OneWay => format!( - "You have booked a one-way flight on {}", - data.out.unwrap().format("%Y-%m-%d") - ), - Flight::Return => format!( - "You have booked an out-bound flight on {} and a return flight on {}", - data.out.unwrap().format("%Y-%m-%d"), - data.ret.unwrap().format("%Y-%m-%d"), - ), - } - }; - cx.add_window::<()>(MessageBox::new(msg).into_window("Booker result")); - } - false + .on_message(|cx, data, ActionBook| { + let msg = if !data.error.is_none() { + // should be impossible since the button is disabled + format!("{}", data.error) + } else { + match data.flight { + Flight::OneWay => format!( + "You have booked a one-way flight on {}", + data.out.unwrap().format("%Y-%m-%d") + ), + Flight::Return => format!( + "You have booked an out-bound flight on {} and a return flight on {}", + data.out.unwrap().format("%Y-%m-%d"), + data.ret.unwrap().format("%Y-%m-%d"), + ), + } + }; + cx.add_window::<()>(MessageBox::new(msg).into_window("Booker result")); }); Window::new(ui, "Flight Booker") diff --git a/src/main.rs b/src/main.rs index b96eb1a..0eca634 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,7 @@ enum X { Cells, } -fn main() -> Result<(), kas::shell::Error> { +fn main() -> Result<(), kas::app::Error> { env_logger::init(); let ui = impl_anon! { @@ -66,7 +66,8 @@ fn main() -> Result<(), kas::shell::Error> { let window = Window::new(ui, "7GUIs Launcher"); let theme = kas::theme::FlatTheme::new(); - let mut shell = kas::shell::Default::with_theme(theme).build(())?; - shell.add(window); - shell.run() + kas::app::Default::with_theme(theme) + .build(())? + .with(window) + .run() } diff --git a/src/temp_conv.rs b/src/temp_conv.rs index 9b0fccd..be82e57 100644 --- a/src/temp_conv.rs +++ b/src/temp_conv.rs @@ -40,9 +40,9 @@ impl_scope! { pub fn window() -> Window<()> { let ui = kas::row![ - EditBox::parser(|temp: &Temperature| temp.celsius, Message::FromCelsius), + EditBox::instant_parser(|temp: &Temperature| temp.celsius, Message::FromCelsius), "Celsius =", - EditBox::parser( + EditBox::instant_parser( |temp: &Temperature| temp.fahrenheit, Message::FromFahrenheit ), diff --git a/src/timer.rs b/src/timer.rs index 8edbf84..2242791 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -50,7 +50,7 @@ pub fn window() -> Window<()> { data.start = Some(Instant::now()); cx.request_timer(TIMER_ID, TIMER_SLEEP); }) - .on_timer(TIMER_ID, |cx, _, data| { + .on_timer(TIMER_ID, |cx, data, _| { if let Some(start) = data.start { data.elapsed = data.duration.min(Instant::now() - start); if data.elapsed < data.duration { @@ -63,26 +63,21 @@ pub fn window() -> Window<()> { false } }) - .on_messages(|cx, _, data| { - if let Some(dur) = cx.try_pop() { - data.duration = dur; - if let Some(start) = data.start { - data.elapsed = data.duration.min(Instant::now() - start); - if data.elapsed >= data.duration { - data.start = None; - } - } else if data.elapsed < data.duration { - data.start = Some(Instant::now() - data.elapsed); - cx.request_timer(TIMER_ID, Duration::ZERO); + .on_message(|cx, data, dur| { + data.duration = dur; + if let Some(start) = data.start { + data.elapsed = data.duration.min(Instant::now() - start); + if data.elapsed >= data.duration { + data.start = None; } - true - } else if let Some(ActionReset) = cx.try_pop() { - data.start = Some(Instant::now()); - cx.request_timer(TIMER_ID, TIMER_SLEEP); - true - } else { - false + } else if data.elapsed < data.duration { + data.start = Some(Instant::now() - data.elapsed); + cx.request_timer(TIMER_ID, Duration::ZERO); } + }) + .on_message(|cx, data, ActionReset| { + data.start = Some(Instant::now()); + cx.request_timer(TIMER_ID, TIMER_SLEEP); }); Window::new(ui, "Timer")