remove RcFrontend & RcLayout
[skip ci]
This commit is contained in:
@@ -10,6 +10,7 @@ use wgui::{
|
||||
i18n::Translation,
|
||||
layout::{Layout, LayoutParams, WidgetID},
|
||||
parser::{Fetchable, ParseDocumentParams, ParserState},
|
||||
task::Tasks,
|
||||
widget::{label::WidgetLabel, rectangle::WidgetRectangle},
|
||||
windowing::{WguiWindow, WguiWindowParams, WguiWindowParamsExtra, WguiWindowPlacement},
|
||||
};
|
||||
@@ -18,10 +19,9 @@ use wlx_common::{dash_interface::BoxDashInterface, timestep::Timestep};
|
||||
use crate::{
|
||||
assets, settings,
|
||||
tab::{
|
||||
apps::TabApps, games::TabGames, home::TabHome, monado::TabMonado, processes::TabProcesses, settings::TabSettings,
|
||||
Tab, TabType,
|
||||
Tab, TabType, apps::TabApps, games::TabGames, home::TabHome, monado::TabMonado, processes::TabProcesses,
|
||||
settings::TabSettings,
|
||||
},
|
||||
task::Tasks,
|
||||
util::{
|
||||
popup_manager::{MountPopupParams, PopupManager, PopupManagerParams},
|
||||
toast_manager::ToastManager,
|
||||
@@ -308,37 +308,37 @@ impl Frontend {
|
||||
|
||||
// "Home" side button
|
||||
self.tasks.handle_button(
|
||||
self.state.fetch_component_as::<ComponentButton>("btn_side_home")?,
|
||||
&self.state.fetch_component_as::<ComponentButton>("btn_side_home")?,
|
||||
FrontendTask::SetTab(TabType::Home),
|
||||
);
|
||||
|
||||
// "Apps" side button
|
||||
self.tasks.handle_button(
|
||||
self.state.fetch_component_as::<ComponentButton>("btn_side_apps")?,
|
||||
&self.state.fetch_component_as::<ComponentButton>("btn_side_apps")?,
|
||||
FrontendTask::SetTab(TabType::Apps),
|
||||
);
|
||||
|
||||
// "Games" side button
|
||||
self.tasks.handle_button(
|
||||
self.state.fetch_component_as::<ComponentButton>("btn_side_games")?,
|
||||
&self.state.fetch_component_as::<ComponentButton>("btn_side_games")?,
|
||||
FrontendTask::SetTab(TabType::Games),
|
||||
);
|
||||
|
||||
// "Monado side button"
|
||||
self.tasks.handle_button(
|
||||
self.state.fetch_component_as::<ComponentButton>("btn_side_monado")?,
|
||||
&self.state.fetch_component_as::<ComponentButton>("btn_side_monado")?,
|
||||
FrontendTask::SetTab(TabType::Monado),
|
||||
);
|
||||
|
||||
// "Processes" side button
|
||||
self.tasks.handle_button(
|
||||
self.state.fetch_component_as::<ComponentButton>("btn_side_processes")?,
|
||||
&self.state.fetch_component_as::<ComponentButton>("btn_side_processes")?,
|
||||
FrontendTask::SetTab(TabType::Processes),
|
||||
);
|
||||
|
||||
// "Settings" side button
|
||||
self.tasks.handle_button(
|
||||
self.state.fetch_component_as::<ComponentButton>("btn_side_settings")?,
|
||||
&self.state.fetch_component_as::<ComponentButton>("btn_side_settings")?,
|
||||
FrontendTask::SetTab(TabType::Settings),
|
||||
);
|
||||
|
||||
@@ -348,13 +348,13 @@ impl Frontend {
|
||||
|
||||
// "Audio" bottom bar button
|
||||
self.tasks.handle_button(
|
||||
self.state.fetch_component_as::<ComponentButton>("btn_audio")?,
|
||||
&self.state.fetch_component_as::<ComponentButton>("btn_audio")?,
|
||||
FrontendTask::ShowAudioSettings,
|
||||
);
|
||||
|
||||
// "Recenter playspace" bottom bar button
|
||||
self.tasks.handle_button(
|
||||
self.state.fetch_component_as::<ComponentButton>("btn_recenter")?,
|
||||
&self.state.fetch_component_as::<ComponentButton>("btn_recenter")?,
|
||||
FrontendTask::RecenterPlayspace,
|
||||
);
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ mod assets;
|
||||
pub mod frontend;
|
||||
pub mod settings;
|
||||
mod tab;
|
||||
mod task;
|
||||
mod util;
|
||||
mod various;
|
||||
mod views;
|
||||
|
||||
@@ -7,12 +7,12 @@ use wgui::{
|
||||
i18n::Translation,
|
||||
layout::{WidgetID, WidgetPair},
|
||||
parser::{Fetchable, ParseDocumentParams, ParserState},
|
||||
task::Tasks,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
frontend::{Frontend, FrontendTask, FrontendTasks},
|
||||
tab::{Tab, TabType},
|
||||
task::Tasks,
|
||||
util::{
|
||||
self,
|
||||
desktop_finder::DesktopEntry,
|
||||
|
||||
@@ -67,11 +67,11 @@ impl TabHome {
|
||||
let btn_settings = state.fetch_component_as::<ComponentButton>("btn_settings")?;
|
||||
|
||||
let tasks = &mut frontend.tasks;
|
||||
tasks.handle_button(btn_apps, FrontendTask::SetTab(TabType::Apps));
|
||||
tasks.handle_button(btn_games, FrontendTask::SetTab(TabType::Games));
|
||||
tasks.handle_button(btn_monado, FrontendTask::SetTab(TabType::Monado));
|
||||
tasks.handle_button(btn_processes, FrontendTask::SetTab(TabType::Processes));
|
||||
tasks.handle_button(btn_settings, FrontendTask::SetTab(TabType::Settings));
|
||||
tasks.handle_button(&btn_apps, FrontendTask::SetTab(TabType::Apps));
|
||||
tasks.handle_button(&btn_games, FrontendTask::SetTab(TabType::Games));
|
||||
tasks.handle_button(&btn_monado, FrontendTask::SetTab(TabType::Monado));
|
||||
tasks.handle_button(&btn_processes, FrontendTask::SetTab(TabType::Processes));
|
||||
tasks.handle_button(&btn_settings, FrontendTask::SetTab(TabType::Settings));
|
||||
|
||||
Ok(Self { state })
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ use wgui::{
|
||||
components::checkbox::ComponentCheckbox,
|
||||
layout::WidgetID,
|
||||
parser::{Fetchable, ParseDocumentParams, ParserState},
|
||||
task::Tasks,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
@@ -13,37 +14,71 @@ use crate::{
|
||||
tab::{Tab, TabType},
|
||||
};
|
||||
|
||||
enum Task {
|
||||
ToggleSetting(SettingType, bool),
|
||||
}
|
||||
|
||||
pub struct TabSettings {
|
||||
#[allow(dead_code)]
|
||||
pub state: ParserState,
|
||||
|
||||
tasks: Tasks<Task>,
|
||||
}
|
||||
|
||||
impl Tab for TabSettings {
|
||||
fn get_type(&self) -> TabType {
|
||||
TabType::Settings
|
||||
}
|
||||
|
||||
fn update(&mut self, frontend: &mut Frontend) -> anyhow::Result<()> {
|
||||
for task in self.tasks.drain() {
|
||||
match task {
|
||||
Task::ToggleSetting(setting, n) => self.toggle_setting(frontend, setting, n),
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::enum_variant_names)]
|
||||
#[derive(Clone)]
|
||||
enum SettingType {
|
||||
DashHideUsername,
|
||||
DashAmPmClock,
|
||||
DashOpaqueBackground,
|
||||
DashXwaylandByDefault,
|
||||
}
|
||||
|
||||
impl SettingType {
|
||||
fn get_bool<'a>(&self, settings: &'a mut settings::Settings) -> &'a mut bool {
|
||||
match self {
|
||||
SettingType::DashHideUsername => &mut settings.home_screen.hide_username,
|
||||
SettingType::DashAmPmClock => &mut settings.general.am_pm_clock,
|
||||
SettingType::DashOpaqueBackground => &mut settings.general.opaque_background,
|
||||
SettingType::DashXwaylandByDefault => &mut settings.tweaks.xwayland_by_default,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn init_setting_checkbox(
|
||||
frontend: &mut Frontend,
|
||||
tasks: &Tasks<Task>,
|
||||
checkbox: Rc<ComponentCheckbox>,
|
||||
fetch_callback: fn(&mut settings::Settings) -> &mut bool,
|
||||
change_callback: Option<fn(&mut Frontend, bool)>,
|
||||
setting: SettingType,
|
||||
additional_frontend_task: Option<FrontendTask>,
|
||||
) -> anyhow::Result<()> {
|
||||
let mut c = frontend.layout.start_common();
|
||||
checkbox.set_checked(&mut c.common(), *setting.get_bool(frontend.settings.get_mut()));
|
||||
|
||||
let tasks = tasks.clone();
|
||||
let frontend_tasks = frontend.tasks.clone();
|
||||
|
||||
checkbox.set_checked(&mut c.common(), *fetch_callback(params.settings));
|
||||
let rc_frontend = params.frontend.clone();
|
||||
checkbox.on_toggle(Box::new(move |_common, e| {
|
||||
let mut frontend = rc_frontend.borrow_mut();
|
||||
*fetch_callback(frontend.settings.get_mut()) = e.checked;
|
||||
tasks.push(Task::ToggleSetting(setting.clone(), e.checked));
|
||||
|
||||
if let Some(change_callback) = &change_callback {
|
||||
change_callback(&mut frontend, e.checked);
|
||||
if let Some(task) = &additional_frontend_task {
|
||||
frontend_tasks.push(task.clone());
|
||||
}
|
||||
|
||||
frontend.settings.mark_as_dirty();
|
||||
|
||||
Ok(())
|
||||
}));
|
||||
|
||||
@@ -63,42 +98,56 @@ impl TabSettings {
|
||||
parent_id,
|
||||
)?;
|
||||
|
||||
let tasks = Tasks::new();
|
||||
|
||||
init_setting_checkbox(
|
||||
frontend,
|
||||
&tasks,
|
||||
state.data.fetch_component_as::<ComponentCheckbox>("cb_hide_username")?,
|
||||
|settings| &mut settings.home_screen.hide_username,
|
||||
SettingType::DashHideUsername,
|
||||
None,
|
||||
)?;
|
||||
|
||||
init_setting_checkbox(
|
||||
frontend,
|
||||
&tasks,
|
||||
state.data.fetch_component_as::<ComponentCheckbox>("cb_am_pm_clock")?,
|
||||
|settings| &mut settings.general.am_pm_clock,
|
||||
Some(|frontend, _| {
|
||||
frontend.tasks.push(FrontendTask::RefreshClock);
|
||||
}),
|
||||
SettingType::DashAmPmClock,
|
||||
None,
|
||||
)?;
|
||||
|
||||
init_setting_checkbox(
|
||||
frontend,
|
||||
&tasks,
|
||||
state.data.fetch_component_as::<ComponentCheckbox>("cb_am_pm_clock")?,
|
||||
SettingType::DashAmPmClock,
|
||||
Some(FrontendTask::RefreshClock),
|
||||
)?;
|
||||
|
||||
init_setting_checkbox(
|
||||
frontend,
|
||||
&tasks,
|
||||
state
|
||||
.data
|
||||
.fetch_component_as::<ComponentCheckbox>("cb_opaque_background")?,
|
||||
|settings| &mut settings.general.opaque_background,
|
||||
Some(|frontend, _| {
|
||||
frontend.tasks.push(FrontendTask::RefreshBackground);
|
||||
}),
|
||||
SettingType::DashOpaqueBackground,
|
||||
Some(FrontendTask::RefreshBackground),
|
||||
)?;
|
||||
|
||||
init_setting_checkbox(
|
||||
frontend,
|
||||
&tasks,
|
||||
state
|
||||
.data
|
||||
.fetch_component_as::<ComponentCheckbox>("cb_xwayland_by_default")?,
|
||||
|settings| &mut settings.tweaks.xwayland_by_default,
|
||||
SettingType::DashXwaylandByDefault,
|
||||
None,
|
||||
)?;
|
||||
|
||||
Ok(Self { state })
|
||||
Ok(Self { state, tasks })
|
||||
}
|
||||
|
||||
fn toggle_setting(&mut self, frontend: &mut Frontend, setting: SettingType, state: bool) {
|
||||
*setting.get_bool(frontend.settings.get_mut()) = state;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ use wgui::{
|
||||
i18n::Translation,
|
||||
layout::{Layout, WidgetID},
|
||||
parser::{Fetchable, ParseDocumentParams, ParserState},
|
||||
task::Tasks,
|
||||
widget::label::WidgetLabel,
|
||||
};
|
||||
use wlx_common::dash_interface::BoxDashInterface;
|
||||
@@ -15,7 +16,6 @@ use wlx_common::dash_interface::BoxDashInterface;
|
||||
use crate::{
|
||||
frontend::{FrontendTask, FrontendTasks},
|
||||
settings::SettingsIO,
|
||||
task::Tasks,
|
||||
util::desktop_finder::DesktopEntry,
|
||||
};
|
||||
|
||||
@@ -96,7 +96,7 @@ impl View {
|
||||
|
||||
let tasks = Tasks::new();
|
||||
|
||||
tasks.handle_button(btn_launch, Task::Launch);
|
||||
tasks.handle_button(&btn_launch, Task::Launch);
|
||||
|
||||
let id_icon_parent = state.get_widget_id("icon_parent")?;
|
||||
|
||||
|
||||
@@ -12,12 +12,12 @@ use wgui::{
|
||||
i18n::Translation,
|
||||
layout::{Layout, WidgetID},
|
||||
parser::{Fetchable, ParseDocumentParams, ParserState},
|
||||
task::Tasks,
|
||||
widget::ConstructEssentials,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
frontend::{FrontendTask, FrontendTasks},
|
||||
task::Tasks,
|
||||
util::pactl_wrapper,
|
||||
};
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ use wgui::{
|
||||
self,
|
||||
prelude::{length, percent},
|
||||
},
|
||||
task::Tasks,
|
||||
widget::{
|
||||
ConstructEssentials,
|
||||
div::WidgetDiv,
|
||||
@@ -29,7 +30,6 @@ use wgui::{
|
||||
|
||||
use crate::{
|
||||
frontend::{FrontendTask, FrontendTasks},
|
||||
task::Tasks,
|
||||
util::{
|
||||
cover_art_fetcher::{self, CoverArt},
|
||||
popup_manager::MountPopupParams,
|
||||
|
||||
@@ -13,6 +13,7 @@ use wgui::{
|
||||
layout::{Layout, WidgetID},
|
||||
parser::{Fetchable, ParseDocumentParams, ParserState},
|
||||
taffy::{self, prelude::length},
|
||||
task::Tasks,
|
||||
widget::{
|
||||
ConstructEssentials,
|
||||
div::WidgetDiv,
|
||||
@@ -21,13 +22,10 @@ use wgui::{
|
||||
};
|
||||
use wlx_common::dash_interface::BoxDashInterface;
|
||||
|
||||
use crate::{
|
||||
task::Tasks,
|
||||
util::{
|
||||
self,
|
||||
desktop_finder::{self},
|
||||
various::get_desktop_file_icon_path,
|
||||
},
|
||||
use crate::util::{
|
||||
self,
|
||||
desktop_finder::{self},
|
||||
various::get_desktop_file_icon_path,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
|
||||
@@ -10,16 +10,16 @@ use wgui::{
|
||||
parser::{Fetchable, ParseDocumentParams, ParserState},
|
||||
renderer_vk::text::{FontWeight, HorizontalAlign, TextStyle},
|
||||
taffy::{self, prelude::length},
|
||||
task::Tasks,
|
||||
widget::{
|
||||
label::{WidgetLabel, WidgetLabelParams},
|
||||
ConstructEssentials,
|
||||
label::{WidgetLabel, WidgetLabelParams},
|
||||
},
|
||||
};
|
||||
use wlx_common::dash_interface::BoxDashInterface;
|
||||
|
||||
use crate::{
|
||||
frontend::{FrontendTask, FrontendTasks},
|
||||
task::Tasks,
|
||||
util::popup_manager::{MountPopupParams, PopupHandle},
|
||||
views::window_options,
|
||||
};
|
||||
|
||||
@@ -8,13 +8,13 @@ use wgui::{
|
||||
i18n::Translation,
|
||||
layout::{Layout, WidgetID},
|
||||
parser::{Fetchable, ParseDocumentParams, ParserState},
|
||||
task::Tasks,
|
||||
widget::ConstructEssentials,
|
||||
};
|
||||
use wlx_common::dash_interface::BoxDashInterface;
|
||||
|
||||
use crate::{
|
||||
frontend::{FrontendTask, FrontendTasks},
|
||||
task::Tasks,
|
||||
views::window_list::construct_window_button,
|
||||
};
|
||||
|
||||
@@ -80,9 +80,9 @@ impl View {
|
||||
c.finish()?;
|
||||
}
|
||||
|
||||
tasks.handle_button(btn_close, Task::Close);
|
||||
tasks.handle_button(btn_kill, Task::Kill);
|
||||
tasks.handle_button(btn_show_hide, Task::SetVisible(!params.window.visible));
|
||||
tasks.handle_button(&btn_close, Task::Close);
|
||||
tasks.handle_button(&btn_kill, Task::Kill);
|
||||
tasks.handle_button(&btn_show_hide, Task::SetVisible(!params.window.visible));
|
||||
|
||||
Ok(Self {
|
||||
state,
|
||||
|
||||
@@ -131,7 +131,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
MouseScrollDelta::LineDelta(x, y) => {
|
||||
testbed
|
||||
.layout()
|
||||
.borrow_mut()
|
||||
.push_event(
|
||||
&wgui::event::Event::MouseWheel(MouseWheelEvent {
|
||||
delta: Vec2::new(x, y),
|
||||
@@ -146,7 +145,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
MouseScrollDelta::PixelDelta(pos) => {
|
||||
testbed
|
||||
.layout()
|
||||
.borrow_mut()
|
||||
.push_event(
|
||||
&wgui::event::Event::MouseWheel(MouseWheelEvent {
|
||||
delta: Vec2::new(pos.x as f32 / 5.0, pos.y as f32 / 5.0),
|
||||
@@ -167,7 +165,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
if matches!(state, winit::event::ElementState::Pressed) {
|
||||
testbed
|
||||
.layout()
|
||||
.borrow_mut()
|
||||
.push_event(
|
||||
&wgui::event::Event::MouseDown(MouseDownEvent {
|
||||
pos: mouse / scale,
|
||||
@@ -181,7 +178,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
} else {
|
||||
testbed
|
||||
.layout()
|
||||
.borrow_mut()
|
||||
.push_event(
|
||||
&wgui::event::Event::MouseUp(MouseUpEvent {
|
||||
pos: mouse / scale,
|
||||
@@ -202,7 +198,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
mouse = vec2(position.x as _, position.y as _);
|
||||
testbed
|
||||
.layout()
|
||||
.borrow_mut()
|
||||
.push_event(
|
||||
&wgui::event::Event::MouseMotion(MouseMotionEvent {
|
||||
pos: mouse / scale,
|
||||
@@ -225,11 +220,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
"Debug draw enabled\n\tAqua: widget boundary\n\tMagenta: Scissoring (separate render pass)"
|
||||
);
|
||||
}
|
||||
testbed.layout().borrow_mut().mark_redraw();
|
||||
testbed.layout().mark_redraw();
|
||||
}
|
||||
|
||||
if event.physical_key == PhysicalKey::Code(KeyCode::F11) {
|
||||
testbed.layout().borrow_mut().print_tree();
|
||||
testbed.layout().print_tree();
|
||||
}
|
||||
|
||||
if event.physical_key == PhysicalKey::Code(KeyCode::Equal) {
|
||||
@@ -290,7 +285,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}
|
||||
|
||||
while timestep.on_tick() {
|
||||
testbed.layout().borrow_mut().tick().unwrap();
|
||||
testbed.layout().tick().unwrap();
|
||||
}
|
||||
|
||||
testbed
|
||||
@@ -301,7 +296,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
if !render_context.dirty && !testbed.layout().borrow_mut().check_toggle_needs_redraw() {
|
||||
if !render_context.dirty && !testbed.layout().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;
|
||||
@@ -336,19 +331,18 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.begin_rendering(tgt, WGfxClearMode::Clear([0.0, 0.0, 0.0, 0.1]))
|
||||
.unwrap();
|
||||
|
||||
let mut layout = testbed.layout().borrow_mut();
|
||||
let layout = testbed.layout();
|
||||
let globals = layout.state.globals.clone();
|
||||
let mut globals = globals.get();
|
||||
|
||||
let mut draw_params = wgui::drawing::DrawParams {
|
||||
globals: &mut globals,
|
||||
layout: &mut layout,
|
||||
layout,
|
||||
debug_draw: debug_draw_enabled,
|
||||
timestep_alpha: timestep.alpha,
|
||||
};
|
||||
|
||||
let primitives = wgui::drawing::draw(&mut draw_params).unwrap();
|
||||
drop(layout);
|
||||
|
||||
let draw_result = render_context
|
||||
.draw(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use wgui::layout::RcLayout;
|
||||
use wgui::layout::Layout;
|
||||
|
||||
pub mod testbed_any;
|
||||
pub mod testbed_dashboard;
|
||||
@@ -12,5 +12,5 @@ pub struct TestbedUpdateParams {
|
||||
|
||||
pub trait Testbed {
|
||||
fn update(&mut self, params: TestbedUpdateParams) -> anyhow::Result<()>;
|
||||
fn layout(&self) -> &RcLayout;
|
||||
fn layout(&mut self) -> &mut Layout;
|
||||
}
|
||||
|
||||
@@ -9,12 +9,12 @@ use wgui::{
|
||||
assets::AssetPath,
|
||||
font_config::WguiFontConfig,
|
||||
globals::WguiGlobals,
|
||||
layout::{LayoutParams, RcLayout},
|
||||
layout::{Layout, LayoutParams},
|
||||
parser::{ParseDocumentParams, ParserState},
|
||||
};
|
||||
|
||||
pub struct TestbedAny {
|
||||
pub layout: RcLayout,
|
||||
pub layout: Layout,
|
||||
|
||||
#[allow(dead_code)]
|
||||
state: ParserState,
|
||||
@@ -43,23 +43,20 @@ impl TestbedAny {
|
||||
},
|
||||
&LayoutParams::default(),
|
||||
)?;
|
||||
Ok(Self {
|
||||
layout: layout.as_rc(),
|
||||
state,
|
||||
})
|
||||
Ok(Self { layout, state })
|
||||
}
|
||||
}
|
||||
|
||||
impl Testbed for TestbedAny {
|
||||
fn update(&mut self, params: TestbedUpdateParams) -> anyhow::Result<()> {
|
||||
self.layout.borrow_mut().update(
|
||||
self.layout.update(
|
||||
Vec2::new(params.width, params.height),
|
||||
params.timestep_alpha,
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn layout(&self) -> &RcLayout {
|
||||
&self.layout
|
||||
fn layout(&mut self) -> &mut Layout {
|
||||
&mut self.layout
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use dash_frontend::{
|
||||
frontend,
|
||||
settings::{self, SettingsIO},
|
||||
};
|
||||
use wgui::layout::RcLayout;
|
||||
use wgui::layout::Layout;
|
||||
use wlx_common::dash_interface_emulated::DashInterfaceEmulated;
|
||||
|
||||
struct SimpleSettingsIO {
|
||||
@@ -53,8 +53,7 @@ impl settings::SettingsIO for SimpleSettingsIO {
|
||||
}
|
||||
|
||||
pub struct TestbedDashboard {
|
||||
layout: RcLayout,
|
||||
frontend: frontend::RcFrontend,
|
||||
frontend: frontend::Frontend,
|
||||
}
|
||||
|
||||
impl TestbedDashboard {
|
||||
@@ -62,26 +61,22 @@ impl TestbedDashboard {
|
||||
let settings = SimpleSettingsIO::new();
|
||||
let interface = DashInterfaceEmulated::new();
|
||||
|
||||
let (frontend, layout) = frontend::Frontend::new(frontend::InitParams {
|
||||
let frontend = frontend::Frontend::new(frontend::InitParams {
|
||||
settings: Box::new(settings),
|
||||
interface: Box::new(interface),
|
||||
})?;
|
||||
Ok(Self { frontend, layout })
|
||||
Ok(Self { frontend })
|
||||
}
|
||||
}
|
||||
|
||||
impl Testbed for TestbedDashboard {
|
||||
fn update(&mut self, params: TestbedUpdateParams) -> anyhow::Result<()> {
|
||||
let mut frontend = self.frontend.borrow_mut();
|
||||
frontend.update(
|
||||
&self.frontend,
|
||||
params.width,
|
||||
params.height,
|
||||
params.timestep_alpha,
|
||||
)
|
||||
self
|
||||
.frontend
|
||||
.update(params.width, params.height, params.timestep_alpha)
|
||||
}
|
||||
|
||||
fn layout(&self) -> &RcLayout {
|
||||
&self.layout
|
||||
fn layout(&mut self) -> &mut Layout {
|
||||
&mut self.frontend.layout
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::{cell::RefCell, collections::VecDeque, path::PathBuf, rc::Rc};
|
||||
use std::{cell::RefCell, path::PathBuf, rc::Rc};
|
||||
|
||||
use crate::{
|
||||
assets,
|
||||
@@ -17,9 +17,10 @@ use wgui::{
|
||||
font_config::WguiFontConfig,
|
||||
globals::WguiGlobals,
|
||||
i18n::Translation,
|
||||
layout::{Layout, LayoutParams, RcLayout, Widget},
|
||||
layout::{Layout, LayoutParams, Widget},
|
||||
parser::{Fetchable, ParseDocumentExtra, ParseDocumentParams, ParserState},
|
||||
taffy,
|
||||
task::Tasks,
|
||||
widget::{label::WidgetLabel, rectangle::WidgetRectangle},
|
||||
windowing::{WguiWindow, WguiWindowParams},
|
||||
};
|
||||
@@ -29,16 +30,15 @@ pub enum TestbedTask {
|
||||
}
|
||||
|
||||
struct Data {
|
||||
tasks: VecDeque<TestbedTask>,
|
||||
#[allow(dead_code)]
|
||||
state: ParserState,
|
||||
|
||||
popup_window: WguiWindow,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct TestbedGeneric {
|
||||
pub layout: RcLayout,
|
||||
pub layout: Layout,
|
||||
tasks: Tasks<TestbedTask>,
|
||||
|
||||
globals: WguiGlobals,
|
||||
data: Rc<RefCell<Data>>,
|
||||
@@ -168,19 +168,19 @@ impl TestbedGeneric {
|
||||
}));
|
||||
|
||||
let testbed = Self {
|
||||
layout: layout.as_rc(),
|
||||
layout,
|
||||
tasks: Default::default(),
|
||||
globals: globals.clone(),
|
||||
data: Rc::new(RefCell::new(Data {
|
||||
state,
|
||||
tasks: Default::default(),
|
||||
popup_window: WguiWindow::default(),
|
||||
})),
|
||||
};
|
||||
|
||||
button_popup.on_click({
|
||||
let testbed = testbed.clone();
|
||||
let tasks = testbed.tasks.clone();
|
||||
Box::new(move |_, _| {
|
||||
testbed.push_task(TestbedTask::ShowPopup);
|
||||
tasks.push(TestbedTask::ShowPopup);
|
||||
Ok(())
|
||||
})
|
||||
});
|
||||
@@ -188,19 +188,14 @@ impl TestbedGeneric {
|
||||
Ok(testbed)
|
||||
}
|
||||
|
||||
fn push_task(&self, task: TestbedTask) {
|
||||
self.data.borrow_mut().tasks.push_back(task);
|
||||
}
|
||||
|
||||
fn process_task(
|
||||
&mut self,
|
||||
task: &TestbedTask,
|
||||
params: &mut TestbedUpdateParams,
|
||||
layout: &mut Layout,
|
||||
data: &mut Data,
|
||||
) -> anyhow::Result<()> {
|
||||
match task {
|
||||
TestbedTask::ShowPopup => self.show_popup(params, layout, data)?,
|
||||
TestbedTask::ShowPopup => self.show_popup(params, data)?,
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -209,13 +204,12 @@ impl TestbedGeneric {
|
||||
fn show_popup(
|
||||
&mut self,
|
||||
_params: &mut TestbedUpdateParams,
|
||||
layout: &mut Layout,
|
||||
data: &mut Data,
|
||||
) -> anyhow::Result<()> {
|
||||
data.popup_window.open(&mut WguiWindowParams {
|
||||
globals: self.globals.clone(),
|
||||
position: Vec2::new(128.0, 128.0),
|
||||
layout,
|
||||
layout: &mut self.layout,
|
||||
title: Translation::from_raw_text("foo"),
|
||||
extra: Default::default(),
|
||||
})?;
|
||||
@@ -226,25 +220,22 @@ impl TestbedGeneric {
|
||||
|
||||
impl Testbed for TestbedGeneric {
|
||||
fn update(&mut self, mut params: TestbedUpdateParams) -> anyhow::Result<()> {
|
||||
let layout = self.layout.clone();
|
||||
let data = self.data.clone();
|
||||
|
||||
let mut layout = layout.borrow_mut();
|
||||
let mut data = data.borrow_mut();
|
||||
|
||||
layout.update(
|
||||
self.layout.update(
|
||||
Vec2::new(params.width, params.height),
|
||||
params.timestep_alpha,
|
||||
)?;
|
||||
|
||||
while let Some(task) = data.tasks.pop_front() {
|
||||
self.process_task(&task, &mut params, &mut layout, &mut data)?;
|
||||
for task in self.tasks.drain() {
|
||||
self.process_task(&task, &mut params, &mut data)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn layout(&self) -> &RcLayout {
|
||||
&self.layout
|
||||
fn layout(&mut self) -> &mut Layout {
|
||||
&mut self.layout
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,8 +163,6 @@ pub struct Layout {
|
||||
pub animations: Animations,
|
||||
}
|
||||
|
||||
pub type RcLayout = Rc<RefCell<Layout>>;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct LayoutParams {
|
||||
pub resize_to_parent: bool,
|
||||
@@ -226,10 +224,6 @@ impl Layout {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_rc(self) -> RcLayout {
|
||||
Rc::new(RefCell::new(self))
|
||||
}
|
||||
|
||||
pub fn add_topmost_child(
|
||||
&mut self,
|
||||
widget: WidgetState,
|
||||
|
||||
@@ -35,6 +35,7 @@ pub mod layout;
|
||||
pub mod parser;
|
||||
pub mod renderer_vk;
|
||||
pub mod stack;
|
||||
pub mod task;
|
||||
pub mod widget;
|
||||
pub mod windowing;
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use crate::components::button::ComponentButton;
|
||||
use std::{cell::RefCell, collections::VecDeque, rc::Rc};
|
||||
|
||||
use wgui::components::button::ComponentButton;
|
||||
|
||||
pub struct Tasks<TaskType>(Rc<RefCell<VecDeque<TaskType>>>);
|
||||
|
||||
impl<T> Clone for Tasks<T> {
|
||||
@@ -32,7 +31,7 @@ impl<TaskType: 'static> Default for Tasks<TaskType> {
|
||||
}
|
||||
|
||||
impl<TaskType: Clone + 'static> Tasks<TaskType> {
|
||||
pub fn handle_button(&self, button: Rc<ComponentButton>, task: TaskType) {
|
||||
pub fn handle_button(&self, button: &Rc<ComponentButton>, task: TaskType) {
|
||||
button.on_click({
|
||||
let this = self.clone();
|
||||
Box::new(move |_, _| {
|
||||
Reference in New Issue
Block a user