dash-frontend: clock, wgui: refactoring, non-panicking casts

This commit is contained in:
Aleksander
2025-09-16 20:09:13 +02:00
parent 129785daa7
commit 0fdc0e3828
20 changed files with 287 additions and 165 deletions

View File

@@ -1,5 +1,4 @@
use crate::testbed::{Testbed, TestbedUpdateParams};
use dash_frontend::Frontend;
use wgui::{event::EventListenerCollection, layout::RcLayout};
pub struct TestbedDashboard {
@@ -17,7 +16,8 @@ impl TestbedDashboard {
impl Testbed for TestbedDashboard {
fn update(&mut self, params: TestbedUpdateParams) -> anyhow::Result<()> {
Frontend::update(
let mut frontend = self.frontend.borrow_mut();
frontend.update(
&self.frontend,
params.listeners,
params.width,

View File

@@ -32,15 +32,14 @@ fn button_click_callback(
label: Widget,
text: &'static str,
) -> ButtonClickCallback {
Box::new(move |e| {
label.get_as_mut::<WidgetLabel>().set_text(
&mut e.state.globals.i18n(),
Translation::from_raw_text(text),
);
Box::new(move |mut e| {
label
.get_as_mut::<WidgetLabel>()
.unwrap()
.set_text(&mut e.as_common(), Translation::from_raw_text(text));
button.try_cast::<ComponentButton>()?.set_text(
e.state,
e.alterables,
&mut e.as_common(),
Translation::from_raw_text("this button has been clicked"),
);
@@ -93,12 +92,8 @@ impl TestbedGeneric {
let button_click_me = state.fetch_component_as::<ComponentButton>("button_click_me")?;
let button = button_click_me.clone();
button_click_me.on_click(Box::new(move |e| {
button.set_text(
e.state,
e.alterables,
Translation::from_raw_text("congrats!"),
);
button_click_me.on_click(Box::new(move |mut e| {
button.set_text(&mut e.as_common(), Translation::from_raw_text("congrats!"));
Ok(())
}));
@@ -116,12 +111,10 @@ impl TestbedGeneric {
let cb_first = state.fetch_component_as::<ComponentCheckbox>("cb_first")?;
let label = label_cur_option.widget.clone();
cb_first.on_toggle(Box::new(move |e| {
let mut widget = label.get_as_mut::<WidgetLabel>();
widget.set_text(
&mut e.state.globals.i18n(),
Translation::from_raw_text(&format!("checkbox toggle: {}", e.checked)),
);
cb_first.on_toggle(Box::new(move |mut e| {
let mut widget = label.get_as_mut::<WidgetLabel>().unwrap();
let text = format!("checkbox toggle: {}", e.checked);
widget.set_text(&mut e.as_common(), Translation::from_raw_text(&text));
Ok(())
}));