Skip to content

Commit

Permalink
Update to KAS 0.14.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Dec 12, 2023
1 parent 3e21f9f commit a1c0978
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 54 deletions.
6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
44 changes: 20 additions & 24 deletions src/flight_booker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -161,27 +160,24 @@ pub fn window() -> Window<()> {

data.update_error();
})
.on_messages(|cx, _, data| {
if cx.try_pop::<ActionBook>().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")
Expand Down
9 changes: 5 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand Down Expand Up @@ -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()
}
4 changes: 2 additions & 2 deletions src/temp_conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
),
Expand Down
33 changes: 14 additions & 19 deletions src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
Expand Down

0 comments on commit a1c0978

Please sign in to comment.