Skip to content

Commit ba4fe53

Browse files
authored
Merge pull request #16 from kas-gui/work
Update to KAS 0.14.2
2 parents 3e21f9f + a1c0978 commit ba4fe53

File tree

5 files changed

+42
-54
lines changed

5 files changed

+42
-54
lines changed

Cargo.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@ resolver = "2"
77
publish = false
88

99
[dependencies]
10-
kas = { version = "0.14.0-alpha" }
10+
kas = { version = "0.14.2" }
1111
chrono = "0.4"
1212
env_logger = "0.8"
1313
pest = "2.1"
1414
pest_derive = "2.1"
15-
16-
[patch.crates-io.kas]
17-
git = "https://github.com/kas-gui/kas.git"
18-
rev = "90b19d6847ba1d4185de4605218b05db2b30024e"

src/flight_booker.rs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,8 @@ pub fn window() -> Window<()> {
142142
EditBox::new(Guard::new(false)),
143143
EditBox::new(Guard::new(true)),
144144
Text::new(|_, data: &Data| format!("{}", data.error)),
145-
Button::new_msg(label_any("Book"), ActionBook).on_update(
146-
|cx, button, data: &Data| cx.set_disabled(button.id(), !data.error.is_none())
147-
),
145+
Button::new_msg(label_any("Book"), ActionBook)
146+
.on_update(|cx, _, data: &Data| cx.set_disabled(!data.error.is_none())),
148147
];
149148

150149
let ui = Adapt::new(ui, data)
@@ -161,27 +160,24 @@ pub fn window() -> Window<()> {
161160

162161
data.update_error();
163162
})
164-
.on_messages(|cx, _, data| {
165-
if cx.try_pop::<ActionBook>().is_some() {
166-
let msg = if !data.error.is_none() {
167-
// should be impossible since the button is disabled
168-
format!("{}", data.error)
169-
} else {
170-
match data.flight {
171-
Flight::OneWay => format!(
172-
"You have booked a one-way flight on {}",
173-
data.out.unwrap().format("%Y-%m-%d")
174-
),
175-
Flight::Return => format!(
176-
"You have booked an out-bound flight on {} and a return flight on {}",
177-
data.out.unwrap().format("%Y-%m-%d"),
178-
data.ret.unwrap().format("%Y-%m-%d"),
179-
),
180-
}
181-
};
182-
cx.add_window::<()>(MessageBox::new(msg).into_window("Booker result"));
183-
}
184-
false
163+
.on_message(|cx, data, ActionBook| {
164+
let msg = if !data.error.is_none() {
165+
// should be impossible since the button is disabled
166+
format!("{}", data.error)
167+
} else {
168+
match data.flight {
169+
Flight::OneWay => format!(
170+
"You have booked a one-way flight on {}",
171+
data.out.unwrap().format("%Y-%m-%d")
172+
),
173+
Flight::Return => format!(
174+
"You have booked an out-bound flight on {} and a return flight on {}",
175+
data.out.unwrap().format("%Y-%m-%d"),
176+
data.ret.unwrap().format("%Y-%m-%d"),
177+
),
178+
}
179+
};
180+
cx.add_window::<()>(MessageBox::new(msg).into_window("Booker result"));
185181
});
186182

187183
Window::new(ui, "Flight Booker")

src/main.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ enum X {
2727
Cells,
2828
}
2929

30-
fn main() -> Result<(), kas::shell::Error> {
30+
fn main() -> Result<(), kas::app::Error> {
3131
env_logger::init();
3232

3333
let ui = impl_anon! {
@@ -66,7 +66,8 @@ fn main() -> Result<(), kas::shell::Error> {
6666
let window = Window::new(ui, "7GUIs Launcher");
6767

6868
let theme = kas::theme::FlatTheme::new();
69-
let mut shell = kas::shell::Default::with_theme(theme).build(())?;
70-
shell.add(window);
71-
shell.run()
69+
kas::app::Default::with_theme(theme)
70+
.build(())?
71+
.with(window)
72+
.run()
7273
}

src/temp_conv.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ impl_scope! {
4040

4141
pub fn window() -> Window<()> {
4242
let ui = kas::row![
43-
EditBox::parser(|temp: &Temperature| temp.celsius, Message::FromCelsius),
43+
EditBox::instant_parser(|temp: &Temperature| temp.celsius, Message::FromCelsius),
4444
"Celsius =",
45-
EditBox::parser(
45+
EditBox::instant_parser(
4646
|temp: &Temperature| temp.fahrenheit,
4747
Message::FromFahrenheit
4848
),

src/timer.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub fn window() -> Window<()> {
5050
data.start = Some(Instant::now());
5151
cx.request_timer(TIMER_ID, TIMER_SLEEP);
5252
})
53-
.on_timer(TIMER_ID, |cx, _, data| {
53+
.on_timer(TIMER_ID, |cx, data, _| {
5454
if let Some(start) = data.start {
5555
data.elapsed = data.duration.min(Instant::now() - start);
5656
if data.elapsed < data.duration {
@@ -63,26 +63,21 @@ pub fn window() -> Window<()> {
6363
false
6464
}
6565
})
66-
.on_messages(|cx, _, data| {
67-
if let Some(dur) = cx.try_pop() {
68-
data.duration = dur;
69-
if let Some(start) = data.start {
70-
data.elapsed = data.duration.min(Instant::now() - start);
71-
if data.elapsed >= data.duration {
72-
data.start = None;
73-
}
74-
} else if data.elapsed < data.duration {
75-
data.start = Some(Instant::now() - data.elapsed);
76-
cx.request_timer(TIMER_ID, Duration::ZERO);
66+
.on_message(|cx, data, dur| {
67+
data.duration = dur;
68+
if let Some(start) = data.start {
69+
data.elapsed = data.duration.min(Instant::now() - start);
70+
if data.elapsed >= data.duration {
71+
data.start = None;
7772
}
78-
true
79-
} else if let Some(ActionReset) = cx.try_pop() {
80-
data.start = Some(Instant::now());
81-
cx.request_timer(TIMER_ID, TIMER_SLEEP);
82-
true
83-
} else {
84-
false
73+
} else if data.elapsed < data.duration {
74+
data.start = Some(Instant::now() - data.elapsed);
75+
cx.request_timer(TIMER_ID, Duration::ZERO);
8576
}
77+
})
78+
.on_message(|cx, data, ActionReset| {
79+
data.start = Some(Instant::now());
80+
cx.request_timer(TIMER_ID, TIMER_SLEEP);
8681
});
8782

8883
Window::new(ui, "Timer")

0 commit comments

Comments
 (0)