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:
@@ -31,7 +31,9 @@ use winit::{
|
||||
keyboard::{KeyCode, PhysicalKey},
|
||||
};
|
||||
|
||||
use crate::testbed::{testbed_dashboard::TestbedDashboard, testbed_generic::TestbedGeneric};
|
||||
use crate::testbed::{
|
||||
TestbedUpdateParams, testbed_dashboard::TestbedDashboard, testbed_generic::TestbedGeneric,
|
||||
};
|
||||
|
||||
mod assets;
|
||||
mod profiler;
|
||||
@@ -124,6 +126,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
} => match delta {
|
||||
MouseScrollDelta::LineDelta(x, y) => testbed
|
||||
.layout()
|
||||
.borrow_mut()
|
||||
.push_event(
|
||||
&mut listeners,
|
||||
&wgui::event::Event::MouseWheel(MouseWheelEvent {
|
||||
@@ -136,6 +139,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.unwrap(),
|
||||
MouseScrollDelta::PixelDelta(pos) => testbed
|
||||
.layout()
|
||||
.borrow_mut()
|
||||
.push_event(
|
||||
&mut listeners,
|
||||
&wgui::event::Event::MouseWheel(MouseWheelEvent {
|
||||
@@ -155,6 +159,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
if matches!(state, winit::event::ElementState::Pressed) {
|
||||
testbed
|
||||
.layout()
|
||||
.borrow_mut()
|
||||
.push_event(
|
||||
&mut listeners,
|
||||
&wgui::event::Event::MouseDown(MouseDownEvent {
|
||||
@@ -168,6 +173,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
} else {
|
||||
testbed
|
||||
.layout()
|
||||
.borrow_mut()
|
||||
.push_event(
|
||||
&mut listeners,
|
||||
&wgui::event::Event::MouseUp(MouseUpEvent {
|
||||
@@ -188,6 +194,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
mouse = vec2(position.x as _, position.y as _);
|
||||
testbed
|
||||
.layout()
|
||||
.borrow_mut()
|
||||
.push_event(
|
||||
&mut listeners,
|
||||
&wgui::event::Event::MouseMotion(MouseMotionEvent {
|
||||
@@ -261,18 +268,19 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}
|
||||
|
||||
while timestep.on_tick() {
|
||||
testbed.layout().tick().unwrap();
|
||||
testbed.layout().borrow_mut().tick().unwrap();
|
||||
}
|
||||
|
||||
testbed
|
||||
.update(
|
||||
(swapchain_size[0] as f32 / scale) as _,
|
||||
(swapchain_size[1] as f32 / scale) as _,
|
||||
timestep.alpha,
|
||||
)
|
||||
.update(TestbedUpdateParams {
|
||||
listeners: &mut listeners,
|
||||
width: (swapchain_size[0] as f32 / scale) as _,
|
||||
height: (swapchain_size[1] as f32 / scale) as _,
|
||||
timestep_alpha: timestep.alpha,
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
if !render_context.dirty && !testbed.layout().check_toggle_needs_redraw() {
|
||||
if !render_context.dirty && !testbed.layout().borrow_mut().check_toggle_needs_redraw() {
|
||||
// no need to redraw
|
||||
std::thread::sleep(std::time::Duration::from_millis(5)); // dirty fix to prevent cpu burning precious cycles doing a busy loop
|
||||
return;
|
||||
@@ -301,7 +309,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.unwrap();
|
||||
cmd_buf.begin_rendering(tgt).unwrap();
|
||||
|
||||
let primitives = wgui::drawing::draw(testbed.layout()).unwrap();
|
||||
let primitives = wgui::drawing::draw(&testbed.layout().borrow_mut()).unwrap();
|
||||
render_context
|
||||
.draw(&mut shared_context, &mut cmd_buf, &primitives)
|
||||
.unwrap();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user