dash-frontend: tabs, other fixes (desc)

- set rustfmt line width to 120 columns by default for wgui
- dashboard tabs
- wgui: `remove_children`
This commit is contained in:
Aleksander
2025-09-15 20:37:55 +02:00
parent f115d2d2cf
commit 54767d75da
30 changed files with 624 additions and 191 deletions

View File

@@ -1,10 +1,17 @@
use wgui::layout::Layout;
use wgui::{event::EventListenerCollection, layout::RcLayout};
pub mod testbed_any;
pub mod testbed_dashboard;
pub mod testbed_generic;
pub trait Testbed {
fn update(&mut self, width: f32, height: f32, timestep_alpha: f32) -> anyhow::Result<()>;
fn layout(&mut self) -> &mut Layout;
pub struct TestbedUpdateParams<'a> {
pub listeners: &'a mut EventListenerCollection<(), ()>,
pub width: f32,
pub height: f32,
pub timestep_alpha: f32,
}
pub trait Testbed {
fn update(&mut self, params: TestbedUpdateParams) -> anyhow::Result<()>;
fn layout(&self) -> &RcLayout;
}

View File

@@ -1,14 +1,17 @@
use crate::{assets, testbed::Testbed};
use crate::{
assets,
testbed::{Testbed, TestbedUpdateParams},
};
use glam::Vec2;
use wgui::{
event::EventListenerCollection,
globals::WguiGlobals,
layout::{Layout, LayoutParams},
layout::{LayoutParams, RcLayout},
parser::{ParseDocumentParams, ParserState},
};
pub struct TestbedAny {
pub layout: Layout,
pub layout: RcLayout,
#[allow(dead_code)]
state: ParserState,
@@ -29,19 +32,23 @@ impl TestbedAny {
},
&LayoutParams::default(),
)?;
Ok(Self { layout, state })
Ok(Self {
layout: layout.as_rc(),
state,
})
}
}
impl Testbed for TestbedAny {
fn update(&mut self, width: f32, height: f32, timestep_alpha: f32) -> anyhow::Result<()> {
self
.layout
.update(Vec2::new(width, height), timestep_alpha)?;
fn update(&mut self, params: TestbedUpdateParams) -> anyhow::Result<()> {
self.layout.borrow_mut().update(
Vec2::new(params.width, params.height),
params.timestep_alpha,
)?;
Ok(())
}
fn layout(&mut self) -> &mut Layout {
&mut self.layout
fn layout(&self) -> &RcLayout {
&self.layout
}
}

View File

@@ -1,25 +1,32 @@
use crate::testbed::Testbed;
use wgui::{event::EventListenerCollection, layout::Layout};
use crate::testbed::{Testbed, TestbedUpdateParams};
use dash_frontend::Frontend;
use wgui::{event::EventListenerCollection, layout::RcLayout};
pub struct TestbedDashboard {
frontend: dash_frontend::Frontend,
layout: RcLayout,
frontend: dash_frontend::RcFrontend,
}
impl TestbedDashboard {
pub fn new(listeners: &mut EventListenerCollection<(), ()>) -> anyhow::Result<Self> {
Ok(Self {
frontend: dash_frontend::Frontend::new(dash_frontend::FrontendParams { listeners })?,
})
let (frontend, layout) =
dash_frontend::Frontend::new(dash_frontend::FrontendParams { listeners })?;
Ok(Self { frontend, layout })
}
}
impl Testbed for TestbedDashboard {
fn update(&mut self, width: f32, height: f32, timestep_alpha: f32) -> anyhow::Result<()> {
self.frontend.update(width, height, timestep_alpha)?;
Ok(())
fn update(&mut self, params: TestbedUpdateParams) -> anyhow::Result<()> {
Frontend::update(
&self.frontend,
params.listeners,
params.width,
params.height,
params.timestep_alpha,
)
}
fn layout(&mut self) -> &mut Layout {
self.frontend.get_layout()
fn layout(&self) -> &RcLayout {
&self.layout
}
}

View File

@@ -1,6 +1,9 @@
use std::rc::Rc;
use crate::{assets, testbed::Testbed};
use crate::{
assets,
testbed::{Testbed, TestbedUpdateParams},
};
use glam::Vec2;
use wgui::{
components::{
@@ -12,13 +15,13 @@ use wgui::{
event::EventListenerCollection,
globals::WguiGlobals,
i18n::Translation,
layout::{Layout, LayoutParams, Widget},
layout::{LayoutParams, RcLayout, Widget},
parser::{ParseDocumentExtra, ParseDocumentParams, ParserState},
widget::{label::WidgetLabel, rectangle::WidgetRectangle},
};
pub struct TestbedGeneric {
pub layout: Layout,
pub layout: RcLayout,
#[allow(dead_code)]
state: ParserState,
@@ -103,12 +106,16 @@ impl TestbedGeneric {
let button_aqua = state.fetch_component_as::<ComponentButton>("button_aqua")?;
let button_yellow = state.fetch_component_as::<ComponentButton>("button_yellow")?;
handle_button_click(button_red, label_cur_option.clone(), "Clicked red");
handle_button_click(button_aqua, label_cur_option.clone(), "Clicked aqua");
handle_button_click(button_yellow, label_cur_option.clone(), "Clicked yellow");
handle_button_click(button_red, label_cur_option.widget.clone(), "Clicked red");
handle_button_click(button_aqua, label_cur_option.widget.clone(), "Clicked aqua");
handle_button_click(
button_yellow,
label_cur_option.widget.clone(),
"Clicked yellow",
);
let cb_first = state.fetch_component_as::<ComponentCheckbox>("cb_first")?;
let label = label_cur_option.clone();
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(
@@ -118,19 +125,23 @@ impl TestbedGeneric {
Ok(())
}));
Ok(Self { layout, state })
Ok(Self {
layout: layout.as_rc(),
state,
})
}
}
impl Testbed for TestbedGeneric {
fn update(&mut self, width: f32, height: f32, timestep_alpha: f32) -> anyhow::Result<()> {
self
.layout
.update(Vec2::new(width, height), timestep_alpha)?;
fn update(&mut self, params: TestbedUpdateParams) -> anyhow::Result<()> {
self.layout.borrow_mut().update(
Vec2::new(params.width, params.height),
params.timestep_alpha,
)?;
Ok(())
}
fn layout(&mut self) -> &mut Layout {
&mut self.layout
fn layout(&self) -> &RcLayout {
&self.layout
}
}