[skip ci] refactor dash?

This commit is contained in:
galister
2025-12-26 19:28:13 +09:00
parent e9540a4d27
commit f29de34de2
10 changed files with 174 additions and 218 deletions

View File

@@ -1,4 +1,4 @@
use std::{cell::RefCell, path::PathBuf, rc::Rc}; use std::{path::PathBuf, rc::Rc};
use chrono::Timelike; use chrono::Timelike;
use glam::Vec2; use glam::Vec2;
@@ -8,7 +8,7 @@ use wgui::{
font_config::WguiFontConfig, font_config::WguiFontConfig,
globals::WguiGlobals, globals::WguiGlobals,
i18n::Translation, i18n::Translation,
layout::{LayoutParams, RcLayout, WidgetID}, layout::{Layout, LayoutParams, WidgetID},
parser::{Fetchable, ParseDocumentParams, ParserState}, parser::{Fetchable, ParseDocumentParams, ParserState},
widget::{label::WidgetLabel, rectangle::WidgetRectangle}, widget::{label::WidgetLabel, rectangle::WidgetRectangle},
windowing::{WguiWindow, WguiWindowParams, WguiWindowParamsExtra, WguiWindowPlacement}, windowing::{WguiWindow, WguiWindowParams, WguiWindowParamsExtra, WguiWindowPlacement},
@@ -18,8 +18,8 @@ use wlx_common::{dash_interface::BoxDashInterface, timestep::Timestep};
use crate::{ use crate::{
assets, settings, assets, settings,
tab::{ tab::{
Tab, TabParams, TabType, TabUpdateParams, apps::TabApps, games::TabGames, home::TabHome, monado::TabMonado, apps::TabApps, games::TabGames, home::TabHome, monado::TabMonado, processes::TabProcesses, settings::TabSettings,
processes::TabProcesses, settings::TabSettings, Tab, TabType,
}, },
task::Tasks, task::Tasks,
util::{ util::{
@@ -38,7 +38,7 @@ pub struct FrontendWidgets {
pub type FrontendTasks = Tasks<FrontendTask>; pub type FrontendTasks = Tasks<FrontendTask>;
pub struct Frontend { pub struct Frontend {
pub layout: RcLayout, pub layout: Layout,
globals: WguiGlobals, globals: WguiGlobals,
pub settings: Box<dyn settings::SettingsIO>, pub settings: Box<dyn settings::SettingsIO>,
@@ -70,8 +70,6 @@ pub struct InitParams {
pub interface: BoxDashInterface, pub interface: BoxDashInterface,
} }
pub type RcFrontend = Rc<RefCell<Frontend>>;
#[derive(Clone)] #[derive(Clone)]
pub enum FrontendTask { pub enum FrontendTask {
SetTab(TabType), SetTab(TabType),
@@ -86,7 +84,7 @@ pub enum FrontendTask {
} }
impl Frontend { impl Frontend {
pub fn new(params: InitParams) -> anyhow::Result<(RcFrontend, RcLayout)> { pub fn new(params: InitParams) -> anyhow::Result<Frontend> {
let mut assets = Box::new(assets::Asset {}); let mut assets = Box::new(assets::Asset {});
let font_binary_bold = assets.load_from_path_gzip("Quicksand-Bold.ttf.gz")?; let font_binary_bold = assets.load_from_path_gzip("Quicksand-Bold.ttf.gz")?;
@@ -121,8 +119,6 @@ impl Frontend {
let toast_manager = ToastManager::new(); let toast_manager = ToastManager::new();
let rc_layout = layout.as_rc();
let tasks = FrontendTasks::new(); let tasks = FrontendTasks::new();
tasks.push(FrontendTask::SetTab(TabType::Home)); tasks.push(FrontendTask::SetTab(TabType::Home));
@@ -132,8 +128,8 @@ impl Frontend {
let mut timestep = Timestep::new(); let mut timestep = Timestep::new();
timestep.set_tps(30.0); // 30 ticks per second timestep.set_tps(30.0); // 30 ticks per second
let frontend = Self { let mut frontend = Self {
layout: rc_layout.clone(), layout,
state, state,
current_tab: None, current_tab: None,
globals, globals,
@@ -157,28 +153,22 @@ impl Frontend {
frontend.update_background()?; frontend.update_background()?;
frontend.update_time()?; frontend.update_time()?;
let res = Rc::new(RefCell::new(frontend)); Frontend::register_widgets(&mut frontend)?;
Frontend::register_widgets(&res)?; Ok(frontend)
Ok((res, rc_layout))
} }
pub fn update(&mut self, rc_this: &RcFrontend, width: f32, height: f32, timestep_alpha: f32) -> anyhow::Result<()> { pub fn update(&mut self, width: f32, height: f32, timestep_alpha: f32) -> anyhow::Result<()> {
let mut tasks = self.tasks.drain(); let mut tasks = self.tasks.drain();
while let Some(task) = tasks.pop_front() { while let Some(task) = tasks.pop_front() {
self.process_task(rc_this, task)?; self.process_task(task)?;
} }
if let Some(tab) = &mut self.current_tab { if let Some(mut tab) = self.current_tab.take() {
let mut layout = self.layout.borrow_mut(); tab.update(self)?;
tab.update(TabUpdateParams { self.current_tab = Some(tab);
layout: &mut layout,
interface: &mut self.interface,
executor: &mut self.executor,
})?;
} }
// process async runtime tasks // process async runtime tasks
@@ -197,22 +187,19 @@ impl Frontend {
} }
{ {
let mut layout = self.layout.borrow_mut();
// always 30 times per second // always 30 times per second
while self.timestep.on_tick() { while self.timestep.on_tick() {
self.toast_manager.tick(&self.globals, &mut layout)?; self.toast_manager.tick(&self.globals, &mut self.layout)?;
} }
layout.update(Vec2::new(width, height), timestep_alpha)?; self.layout.update(Vec2::new(width, height), timestep_alpha)?;
} }
Ok(()) Ok(())
} }
fn update_time(&self) -> anyhow::Result<()> { fn update_time(&mut self) -> anyhow::Result<()> {
let mut layout = self.layout.borrow_mut(); let mut c = self.layout.start_common();
let mut c = layout.start_common();
let mut common = c.common(); let mut common = c.common();
{ {
@@ -240,11 +227,10 @@ impl Frontend {
} }
fn mount_popup(&mut self, params: MountPopupParams) -> anyhow::Result<()> { fn mount_popup(&mut self, params: MountPopupParams) -> anyhow::Result<()> {
let mut layout = self.layout.borrow_mut();
self.popup_manager.mount_popup( self.popup_manager.mount_popup(
self.globals.clone(), self.globals.clone(),
self.settings.as_ref(), self.settings.as_ref(),
&mut layout, &mut self.layout,
&mut self.interface, &mut self.interface,
self.tasks.clone(), self.tasks.clone(),
params, params,
@@ -253,17 +239,15 @@ impl Frontend {
} }
fn refresh_popup_manager(&mut self) -> anyhow::Result<()> { fn refresh_popup_manager(&mut self) -> anyhow::Result<()> {
let mut layout = self.layout.borrow_mut(); let mut c = self.layout.start_common();
let mut c = layout.start_common();
self.popup_manager.refresh(c.common().alterables); self.popup_manager.refresh(c.common().alterables);
c.finish()?; c.finish()?;
Ok(()) Ok(())
} }
fn update_background(&self) -> anyhow::Result<()> { fn update_background(&self) -> anyhow::Result<()> {
let layout = self.layout.borrow_mut(); let Some(mut rect) = self
.layout
let Some(mut rect) = layout
.state .state
.widgets .widgets
.get_as::<WidgetRectangle>(self.widgets.id_rect_content) .get_as::<WidgetRectangle>(self.widgets.id_rect_content)
@@ -283,13 +267,9 @@ impl Frontend {
Ok(()) Ok(())
} }
pub fn get_layout(&self) -> &RcLayout { fn process_task(&mut self, task: FrontendTask) -> anyhow::Result<()> {
&self.layout
}
fn process_task(&mut self, rc_this: &RcFrontend, task: FrontendTask) -> anyhow::Result<()> {
match task { match task {
FrontendTask::SetTab(tab_type) => self.set_tab(tab_type, rc_this)?, FrontendTask::SetTab(tab_type) => self.set_tab(tab_type)?,
FrontendTask::RefreshClock => self.update_time()?, FrontendTask::RefreshClock => self.update_time()?,
FrontendTask::RefreshBackground => self.update_background()?, FrontendTask::RefreshBackground => self.update_background()?,
FrontendTask::MountPopup(params) => self.mount_popup(params)?, FrontendTask::MountPopup(params) => self.mount_popup(params)?,
@@ -302,29 +282,18 @@ impl Frontend {
Ok(()) Ok(())
} }
fn set_tab(&mut self, tab_type: TabType, rc_this: &RcFrontend) -> anyhow::Result<()> { fn set_tab(&mut self, tab_type: TabType) -> anyhow::Result<()> {
log::info!("Setting tab to {tab_type:?}"); log::info!("Setting tab to {tab_type:?}");
let mut layout = self.layout.borrow_mut(); let widget_content = self.state.fetch_widget(&self.layout.state, "content")?;
let widget_content = self.state.fetch_widget(&layout.state, "content")?; self.layout.remove_children(widget_content.id);
layout.remove_children(widget_content.id);
let tab_params = TabParams {
globals: &self.globals,
layout: &mut layout,
parent_id: widget_content.id,
frontend: rc_this,
//frontend_widgets: &self.widgets,
settings: self.settings.get_mut(),
frontend_tasks: &self.tasks,
};
let tab: Box<dyn Tab> = match tab_type { let tab: Box<dyn Tab> = match tab_type {
TabType::Home => Box::new(TabHome::new(tab_params)?), TabType::Home => Box::new(TabHome::new(self, widget_content.id)?),
TabType::Apps => Box::new(TabApps::new(tab_params)?), TabType::Apps => Box::new(TabApps::new(self, widget_content.id)?),
TabType::Games => Box::new(TabGames::new(tab_params)?), TabType::Games => Box::new(TabGames::new(self, widget_content.id)?),
TabType::Monado => Box::new(TabMonado::new(tab_params)?), TabType::Monado => Box::new(TabMonado::new(self, widget_content.id)?),
TabType::Processes => Box::new(TabProcesses::new(tab_params)?), TabType::Processes => Box::new(TabProcesses::new(self, widget_content.id)?),
TabType::Settings => Box::new(TabSettings::new(tab_params)?), TabType::Settings => Box::new(TabSettings::new(self, widget_content.id)?),
}; };
self.current_tab = Some(tab); self.current_tab = Some(tab);
@@ -332,46 +301,44 @@ impl Frontend {
Ok(()) Ok(())
} }
fn register_widgets(rc_this: &RcFrontend) -> anyhow::Result<()> { fn register_widgets(&mut self) -> anyhow::Result<()> {
let this = rc_this.borrow_mut();
// ################################ // ################################
// SIDE BUTTONS // SIDE BUTTONS
// ################################ // ################################
// "Home" side button // "Home" side button
this.tasks.handle_button( self.tasks.handle_button(
this.state.fetch_component_as::<ComponentButton>("btn_side_home")?, self.state.fetch_component_as::<ComponentButton>("btn_side_home")?,
FrontendTask::SetTab(TabType::Home), FrontendTask::SetTab(TabType::Home),
); );
// "Apps" side button // "Apps" side button
this.tasks.handle_button( self.tasks.handle_button(
this.state.fetch_component_as::<ComponentButton>("btn_side_apps")?, self.state.fetch_component_as::<ComponentButton>("btn_side_apps")?,
FrontendTask::SetTab(TabType::Apps), FrontendTask::SetTab(TabType::Apps),
); );
// "Games" side button // "Games" side button
this.tasks.handle_button( self.tasks.handle_button(
this.state.fetch_component_as::<ComponentButton>("btn_side_games")?, self.state.fetch_component_as::<ComponentButton>("btn_side_games")?,
FrontendTask::SetTab(TabType::Games), FrontendTask::SetTab(TabType::Games),
); );
// "Monado side button" // "Monado side button"
this.tasks.handle_button( self.tasks.handle_button(
this.state.fetch_component_as::<ComponentButton>("btn_side_monado")?, self.state.fetch_component_as::<ComponentButton>("btn_side_monado")?,
FrontendTask::SetTab(TabType::Monado), FrontendTask::SetTab(TabType::Monado),
); );
// "Processes" side button // "Processes" side button
this.tasks.handle_button( self.tasks.handle_button(
this.state.fetch_component_as::<ComponentButton>("btn_side_processes")?, self.state.fetch_component_as::<ComponentButton>("btn_side_processes")?,
FrontendTask::SetTab(TabType::Processes), FrontendTask::SetTab(TabType::Processes),
); );
// "Settings" side button // "Settings" side button
this.tasks.handle_button( self.tasks.handle_button(
this.state.fetch_component_as::<ComponentButton>("btn_side_settings")?, self.state.fetch_component_as::<ComponentButton>("btn_side_settings")?,
FrontendTask::SetTab(TabType::Settings), FrontendTask::SetTab(TabType::Settings),
); );
@@ -380,14 +347,14 @@ impl Frontend {
// ################################ // ################################
// "Audio" bottom bar button // "Audio" bottom bar button
this.tasks.handle_button( self.tasks.handle_button(
this.state.fetch_component_as::<ComponentButton>("btn_audio")?, self.state.fetch_component_as::<ComponentButton>("btn_audio")?,
FrontendTask::ShowAudioSettings, FrontendTask::ShowAudioSettings,
); );
// "Recenter playspace" bottom bar button // "Recenter playspace" bottom bar button
this.tasks.handle_button( self.tasks.handle_button(
this.state.fetch_component_as::<ComponentButton>("btn_recenter")?, self.state.fetch_component_as::<ComponentButton>("btn_recenter")?,
FrontendTask::RecenterPlayspace, FrontendTask::RecenterPlayspace,
); );
@@ -395,12 +362,10 @@ impl Frontend {
} }
fn action_show_audio_settings(&mut self) -> anyhow::Result<()> { fn action_show_audio_settings(&mut self) -> anyhow::Result<()> {
let mut layout = self.layout.borrow_mut();
self.window_audio_settings.open(&mut WguiWindowParams { self.window_audio_settings.open(&mut WguiWindowParams {
globals: self.globals.clone(), globals: self.globals.clone(),
position: Vec2::new(64.0, 64.0), position: Vec2::new(64.0, 64.0),
layout: &mut layout, layout: &mut self.layout,
title: Translation::from_translation_key("AUDIO.SETTINGS"), title: Translation::from_translation_key("AUDIO.SETTINGS"),
extra: WguiWindowParamsExtra { extra: WguiWindowParamsExtra {
fixed_width: Some(400.0), fixed_width: Some(400.0),
@@ -414,7 +379,7 @@ impl Frontend {
self.view_audio_settings = Some(views::audio_settings::View::new(views::audio_settings::Params { self.view_audio_settings = Some(views::audio_settings::View::new(views::audio_settings::Params {
globals: self.globals.clone(), globals: self.globals.clone(),
frontend_tasks: self.tasks.clone(), frontend_tasks: self.tasks.clone(),
layout: &mut layout, layout: &mut self.layout,
parent_id: content.id, parent_id: content.id,
on_update: { on_update: {
let tasks = self.tasks.clone(); let tasks = self.tasks.clone();
@@ -431,8 +396,7 @@ impl Frontend {
return Ok(()); return Ok(());
}; };
let mut layout = self.layout.borrow_mut(); view.update(&mut self.layout)?;
view.update(&mut layout)?;
Ok(()) Ok(())
} }

View File

@@ -5,13 +5,13 @@ use wgui::{
components::button::{ButtonClickCallback, ComponentButton}, components::button::{ButtonClickCallback, ComponentButton},
globals::WguiGlobals, globals::WguiGlobals,
i18n::Translation, i18n::Translation,
layout::WidgetPair, layout::{WidgetID, WidgetPair},
parser::{Fetchable, ParseDocumentParams, ParserState}, parser::{Fetchable, ParseDocumentParams, ParserState},
}; };
use crate::{ use crate::{
frontend::{FrontendTask, FrontendTasks, RcFrontend}, frontend::{Frontend, FrontendTask, FrontendTasks},
tab::{Tab, TabParams, TabType}, tab::{Tab, TabType},
task::Tasks, task::Tasks,
util::{ util::{
self, self,
@@ -49,7 +49,7 @@ impl Tab for TabApps {
TabType::Apps TabType::Apps
} }
fn update(&mut self, params: super::TabUpdateParams) -> anyhow::Result<()> { fn update(&mut self, frontend: &mut Frontend) -> anyhow::Result<()> {
let mut state = self.state.borrow_mut(); let mut state = self.state.borrow_mut();
for task in self.tasks.drain() { for task in self.tasks.drain() {
@@ -59,7 +59,7 @@ impl Tab for TabApps {
} }
if let Some((_, launcher)) = &mut state.launcher { if let Some((_, launcher)) = &mut state.launcher {
launcher.update(params.layout, params.interface)?; launcher.update(&mut frontend.layout, &mut frontend.interface)?;
} }
Ok(()) Ok(())
} }
@@ -72,7 +72,6 @@ struct AppList {
// called after the user clicks any desktop entry // called after the user clicks any desktop entry
fn on_app_click( fn on_app_click(
frontend: RcFrontend,
frontend_tasks: FrontendTasks, frontend_tasks: FrontendTasks,
globals: WguiGlobals, globals: WguiGlobals,
entry: DesktopEntry, entry: DesktopEntry,
@@ -80,48 +79,45 @@ fn on_app_click(
tasks: Tasks<Task>, tasks: Tasks<Task>,
) -> ButtonClickCallback { ) -> ButtonClickCallback {
Box::new(move |_common, _evt| { Box::new(move |_common, _evt| {
frontend frontend_tasks.push(FrontendTask::MountPopup(MountPopupParams {
.borrow_mut() title: Translation::from_raw_text(&entry.app_name),
.tasks on_content: {
.push(FrontendTask::MountPopup(MountPopupParams { // this is awful
title: Translation::from_raw_text(&entry.app_name), let state = state.clone();
on_content: { let entry = entry.clone();
// this is awful let globals = globals.clone();
let state = state.clone(); let frontend_tasks = frontend_tasks.clone();
let entry = entry.clone(); let tasks = tasks.clone();
let globals = globals.clone();
let frontend_tasks = frontend_tasks.clone();
let tasks = tasks.clone();
Rc::new(move |data| { Rc::new(move |data| {
let on_launched = { let on_launched = {
let tasks = tasks.clone(); let tasks = tasks.clone();
Box::new(move || tasks.push(Task::CloseLauncher)) Box::new(move || tasks.push(Task::CloseLauncher))
}; };
let view = app_launcher::View::new(app_launcher::Params { let view = app_launcher::View::new(app_launcher::Params {
entry: entry.clone(), entry: entry.clone(),
globals: &globals, globals: &globals,
layout: data.layout, layout: data.layout,
parent_id: data.id_content, parent_id: data.id_content,
frontend_tasks: &frontend_tasks, frontend_tasks: &frontend_tasks,
settings: data.settings, settings: data.settings,
on_launched, on_launched,
})?; })?;
state.borrow_mut().launcher = Some((data.handle, view)); state.borrow_mut().launcher = Some((data.handle, view));
Ok(()) Ok(())
}) })
}, },
})); }));
Ok(()) Ok(())
}) })
} }
impl TabApps { impl TabApps {
pub fn new(mut tab_params: TabParams) -> anyhow::Result<Self> { pub fn new(frontend: &mut Frontend, parent_id: WidgetID) -> anyhow::Result<Self> {
let doc_params = &ParseDocumentParams { let doc_params = &ParseDocumentParams {
globals: tab_params.globals.clone(), globals: frontend.layout.state.globals.clone(),
path: AssetPath::BuiltIn("gui/tab/apps.xml"), path: AssetPath::BuiltIn("gui/tab/apps.xml"),
extra: Default::default(), extra: Default::default(),
}; };
@@ -129,26 +125,24 @@ impl TabApps {
gtk::init()?; gtk::init()?;
let entries = util::desktop_finder::find_entries()?; let entries = util::desktop_finder::find_entries()?;
let frontend_tasks = tab_params.frontend_tasks.clone(); let frontend_tasks = frontend.tasks.clone();
let frontend = tab_params.frontend.clone(); let globals = frontend.layout.state.globals.clone();
let globals = tab_params.globals.clone();
let tasks = Tasks::new(); let tasks = Tasks::new();
let state = Rc::new(RefCell::new(State { launcher: None })); let state = Rc::new(RefCell::new(State { launcher: None }));
let mut parser_state = wgui::parser::parse_from_assets(doc_params, tab_params.layout, tab_params.parent_id)?; let mut parser_state = wgui::parser::parse_from_assets(doc_params, &mut frontend.layout, parent_id)?;
let app_list_parent = parser_state.fetch_widget(&tab_params.layout.state, "app_list_parent")?; let app_list_parent = parser_state.fetch_widget(&frontend.layout.state, "app_list_parent")?;
let mut app_list = AppList::default(); let mut app_list = AppList::default();
app_list.mount_entries( app_list.mount_entries(
frontend,
&entries, &entries,
&mut parser_state, &mut parser_state,
doc_params, doc_params,
&mut tab_params,
&app_list_parent, &app_list_parent,
|button, entry| { |button, entry| {
// Set up the click handler for the app button // Set up the click handler for the app button
button.on_click(on_app_click( button.on_click(on_app_click(
frontend.clone(),
frontend_tasks.clone(), frontend_tasks.clone(),
globals.clone(), globals.clone(),
entry.clone(), entry.clone(),
@@ -171,9 +165,9 @@ impl TabApps {
impl AppList { impl AppList {
fn mount_entry( fn mount_entry(
&mut self, &mut self,
frontend: &mut Frontend,
parser_state: &mut ParserState, parser_state: &mut ParserState,
doc_params: &ParseDocumentParams, doc_params: &ParseDocumentParams,
params: &mut TabParams,
list_parent: &WidgetPair, list_parent: &WidgetPair,
entry: &DesktopEntry, entry: &DesktopEntry,
) -> anyhow::Result<Rc<ComponentButton>> { ) -> anyhow::Result<Rc<ComponentButton>> {
@@ -200,21 +194,27 @@ impl AppList {
template_params.insert(Rc::from("name"), Rc::from(entry.app_name.as_str())); template_params.insert(Rc::from("name"), Rc::from(entry.app_name.as_str()));
let data = parser_state.parse_template(doc_params, "AppEntry", params.layout, list_parent.id, template_params)?; let data = parser_state.parse_template(
doc_params,
"AppEntry",
&mut frontend.layout,
list_parent.id,
template_params,
)?;
data.fetch_component_as::<ComponentButton>("button") data.fetch_component_as::<ComponentButton>("button")
} }
fn mount_entries( fn mount_entries(
&mut self, &mut self,
frontend: &mut Frontend,
entries: &[DesktopEntry], entries: &[DesktopEntry],
parser_state: &mut ParserState, parser_state: &mut ParserState,
doc_params: &ParseDocumentParams, doc_params: &ParseDocumentParams,
params: &mut TabParams,
list_parent: &WidgetPair, list_parent: &WidgetPair,
on_button: impl Fn(Rc<ComponentButton>, &DesktopEntry), on_button: impl Fn(Rc<ComponentButton>, &DesktopEntry),
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
for entry in entries { for entry in entries {
let button = self.mount_entry(parser_state, doc_params, params, list_parent, entry)?; let button = self.mount_entry(frontend, parser_state, doc_params, list_parent, entry)?;
on_button(button, entry); on_button(button, entry);
} }
Ok(()) Ok(())

View File

@@ -1,10 +1,12 @@
use wgui::{ use wgui::{
assets::AssetPath, assets::AssetPath,
layout::WidgetID,
parser::{Fetchable, ParseDocumentParams, ParserState}, parser::{Fetchable, ParseDocumentParams, ParserState},
}; };
use crate::{ use crate::{
tab::{Tab, TabParams, TabType}, frontend::Frontend,
tab::{Tab, TabType},
views::game_list, views::game_list,
}; };
@@ -20,31 +22,33 @@ impl Tab for TabGames {
TabType::Games TabType::Games
} }
fn update(&mut self, params: super::TabUpdateParams) -> anyhow::Result<()> { fn update(&mut self, frontend: &mut Frontend) -> anyhow::Result<()> {
self.view_game_list.update(params.layout, params.executor)?; self
.view_game_list
.update(&mut frontend.layout, &mut frontend.executor)?;
Ok(()) Ok(())
} }
} }
impl TabGames { impl TabGames {
pub fn new(params: TabParams) -> anyhow::Result<Self> { pub fn new(frontend: &mut Frontend, parent_id: WidgetID) -> anyhow::Result<Self> {
let state = wgui::parser::parse_from_assets( let state = wgui::parser::parse_from_assets(
&ParseDocumentParams { &ParseDocumentParams {
globals: params.globals.clone(), globals: frontend.layout.state.globals.clone(),
path: AssetPath::BuiltIn("gui/tab/games.xml"), path: AssetPath::BuiltIn("gui/tab/games.xml"),
extra: Default::default(), extra: Default::default(),
}, },
params.layout, &mut frontend.layout,
params.parent_id, parent_id,
)?; )?;
let game_list_parent = state.get_widget_id("game_list_parent")?; let game_list_parent = state.get_widget_id("game_list_parent")?;
let view_game_list = game_list::View::new(game_list::Params { let view_game_list = game_list::View::new(game_list::Params {
frontend_tasks: params.frontend_tasks.clone(), frontend_tasks: frontend.tasks.clone(),
globals: params.globals, globals: frontend.layout.state.globals.clone(),
layout: params.layout, layout: &mut frontend.layout,
parent_id: game_list_parent, parent_id: game_list_parent,
})?; })?;

View File

@@ -3,15 +3,15 @@ use wgui::{
components::button::ComponentButton, components::button::ComponentButton,
event::CallbackDataCommon, event::CallbackDataCommon,
i18n::Translation, i18n::Translation,
layout::Widget, layout::{Widget, WidgetID},
parser::{Fetchable, ParseDocumentParams, ParserState}, parser::{Fetchable, ParseDocumentParams, ParserState},
widget::label::WidgetLabel, widget::label::WidgetLabel,
}; };
use crate::{ use crate::{
frontend::FrontendTask, frontend::{Frontend, FrontendTask},
settings, settings,
tab::{Tab, TabParams, TabType}, tab::{Tab, TabType},
various, various,
}; };
@@ -45,20 +45,20 @@ fn configure_label_hello(common: &mut CallbackDataCommon, label_hello: Widget, s
} }
impl TabHome { impl TabHome {
pub fn new(params: TabParams) -> anyhow::Result<Self> { pub fn new(frontend: &mut Frontend, parent_id: WidgetID) -> anyhow::Result<Self> {
let state = wgui::parser::parse_from_assets( let state = wgui::parser::parse_from_assets(
&ParseDocumentParams { &ParseDocumentParams {
globals: params.globals.clone(), globals: frontend.layout.state.globals.clone(),
path: AssetPath::BuiltIn("gui/tab/home.xml"), path: AssetPath::BuiltIn("gui/tab/home.xml"),
extra: Default::default(), extra: Default::default(),
}, },
params.layout, &mut frontend.layout,
params.parent_id, parent_id,
)?; )?;
let mut c = params.layout.start_common(); let mut c = frontend.layout.start_common();
let widget_label = state.fetch_widget(&c.layout.state, "label_hello")?.widget; let widget_label = state.fetch_widget(&c.layout.state, "label_hello")?.widget;
configure_label_hello(&mut c.common(), widget_label, params.settings); configure_label_hello(&mut c.common(), widget_label, frontend.settings.get_mut());
let btn_apps = state.fetch_component_as::<ComponentButton>("btn_apps")?; let btn_apps = state.fetch_component_as::<ComponentButton>("btn_apps")?;
let btn_games = state.fetch_component_as::<ComponentButton>("btn_games")?; let btn_games = state.fetch_component_as::<ComponentButton>("btn_games")?;
@@ -66,7 +66,7 @@ impl TabHome {
let btn_processes = state.fetch_component_as::<ComponentButton>("btn_processes")?; let btn_processes = state.fetch_component_as::<ComponentButton>("btn_processes")?;
let btn_settings = state.fetch_component_as::<ComponentButton>("btn_settings")?; let btn_settings = state.fetch_component_as::<ComponentButton>("btn_settings")?;
let tasks = params.frontend_tasks; let tasks = &mut frontend.tasks;
tasks.handle_button(btn_apps, FrontendTask::SetTab(TabType::Apps)); tasks.handle_button(btn_apps, FrontendTask::SetTab(TabType::Apps));
tasks.handle_button(btn_games, FrontendTask::SetTab(TabType::Games)); tasks.handle_button(btn_games, FrontendTask::SetTab(TabType::Games));
tasks.handle_button(btn_monado, FrontendTask::SetTab(TabType::Monado)); tasks.handle_button(btn_monado, FrontendTask::SetTab(TabType::Monado));

View File

@@ -1,13 +1,4 @@
use wgui::{ use crate::frontend::Frontend;
globals::WguiGlobals,
layout::{Layout, WidgetID},
};
use wlx_common::dash_interface::BoxDashInterface;
use crate::{
frontend::{FrontendTasks, RcFrontend},
util::various::AsyncExecutor,
};
pub mod apps; pub mod apps;
pub mod games; pub mod games;
@@ -26,26 +17,11 @@ pub enum TabType {
Settings, Settings,
} }
pub struct TabParams<'a> {
pub globals: &'a WguiGlobals,
pub layout: &'a mut Layout,
pub parent_id: WidgetID,
pub frontend: &'a RcFrontend,
pub settings: &'a mut crate::settings::Settings,
pub frontend_tasks: &'a FrontendTasks,
}
pub struct TabUpdateParams<'a> {
pub layout: &'a mut Layout,
pub interface: &'a mut BoxDashInterface,
pub executor: &'a mut AsyncExecutor,
}
pub trait Tab { pub trait Tab {
#[allow(dead_code)] #[allow(dead_code)]
fn get_type(&self) -> TabType; fn get_type(&self) -> TabType;
fn update(&mut self, _params: TabUpdateParams) -> anyhow::Result<()> { fn update(&mut self, _: &mut Frontend) -> anyhow::Result<()> {
Ok(()) Ok(())
} }
} }

View File

@@ -1,9 +1,13 @@
use wgui::{ use wgui::{
assets::AssetPath, assets::AssetPath,
layout::WidgetID,
parser::{ParseDocumentParams, ParserState}, parser::{ParseDocumentParams, ParserState},
}; };
use crate::tab::{Tab, TabParams, TabType}; use crate::{
frontend::Frontend,
tab::{Tab, TabType},
};
pub struct TabMonado { pub struct TabMonado {
#[allow(dead_code)] #[allow(dead_code)]
@@ -17,15 +21,15 @@ impl Tab for TabMonado {
} }
impl TabMonado { impl TabMonado {
pub fn new(params: TabParams) -> anyhow::Result<Self> { pub fn new(frontend: &mut Frontend, parent_id: WidgetID) -> anyhow::Result<Self> {
let state = wgui::parser::parse_from_assets( let state = wgui::parser::parse_from_assets(
&ParseDocumentParams { &ParseDocumentParams {
globals: params.globals.clone(), globals: frontend.layout.state.globals.clone(),
path: AssetPath::BuiltIn("gui/tab/monado.xml"), path: AssetPath::BuiltIn("gui/tab/monado.xml"),
extra: Default::default(), extra: Default::default(),
}, },
params.layout, &mut frontend.layout,
params.parent_id, parent_id,
)?; )?;
Ok(Self { state }) Ok(Self { state })

View File

@@ -1,10 +1,12 @@
use wgui::{ use wgui::{
assets::AssetPath, assets::AssetPath,
layout::WidgetID,
parser::{Fetchable, ParseDocumentParams, ParserState}, parser::{Fetchable, ParseDocumentParams, ParserState},
}; };
use crate::{ use crate::{
tab::{Tab, TabParams, TabType, TabUpdateParams}, frontend::Frontend,
tab::{Tab, TabType},
views::{process_list, window_list}, views::{process_list, window_list},
}; };
@@ -21,37 +23,42 @@ impl Tab for TabProcesses {
TabType::Games TabType::Games
} }
fn update(&mut self, params: TabUpdateParams) -> anyhow::Result<()> { fn update(&mut self, frontend: &mut Frontend) -> anyhow::Result<()> {
self.view_window_list.update(params.layout, params.interface)?; self
self.view_process_list.update(params.layout, params.interface)?; .view_window_list
.update(&mut frontend.layout, &mut frontend.interface)?;
self
.view_process_list
.update(&mut frontend.layout, &mut frontend.interface)?;
Ok(()) Ok(())
} }
} }
impl TabProcesses { impl TabProcesses {
pub fn new(params: TabParams) -> anyhow::Result<Self> { pub fn new(frontend: &mut Frontend, parent_id: WidgetID) -> anyhow::Result<Self> {
let globals = frontend.layout.state.globals.clone();
let state = wgui::parser::parse_from_assets( let state = wgui::parser::parse_from_assets(
&ParseDocumentParams { &ParseDocumentParams {
globals: params.globals.clone(), globals: globals.clone(),
path: AssetPath::BuiltIn("gui/tab/processes.xml"), path: AssetPath::BuiltIn("gui/tab/processes.xml"),
extra: Default::default(), extra: Default::default(),
}, },
params.layout, &mut frontend.layout,
params.parent_id, parent_id,
)?; )?;
Ok(Self { Ok(Self {
view_window_list: window_list::View::new(window_list::Params { view_window_list: window_list::View::new(window_list::Params {
layout: params.layout, layout: &mut frontend.layout,
parent_id: state.get_widget_id("window_list_parent")?, parent_id: state.get_widget_id("window_list_parent")?,
globals: params.globals, globals: globals.clone(),
frontend_tasks: params.frontend_tasks.clone(), frontend_tasks: frontend.tasks.clone(),
on_click: None, on_click: None,
})?, })?,
view_process_list: process_list::View::new(process_list::Params { view_process_list: process_list::View::new(process_list::Params {
layout: params.layout, layout: &mut frontend.layout,
parent_id: state.get_widget_id("process_list_parent")?, parent_id: state.get_widget_id("process_list_parent")?,
globals: params.globals.clone(), globals,
})?, })?,
state, state,
}) })

View File

@@ -3,13 +3,14 @@ use std::rc::Rc;
use wgui::{ use wgui::{
assets::AssetPath, assets::AssetPath,
components::checkbox::ComponentCheckbox, components::checkbox::ComponentCheckbox,
layout::WidgetID,
parser::{Fetchable, ParseDocumentParams, ParserState}, parser::{Fetchable, ParseDocumentParams, ParserState},
}; };
use crate::{ use crate::{
frontend::{Frontend, FrontendTask}, frontend::{Frontend, FrontendTask},
settings, settings,
tab::{Tab, TabParams, TabType}, tab::{Tab, TabType},
}; };
pub struct TabSettings { pub struct TabSettings {
@@ -24,12 +25,12 @@ impl Tab for TabSettings {
} }
fn init_setting_checkbox( fn init_setting_checkbox(
params: &mut TabParams, frontend: &mut Frontend,
checkbox: Rc<ComponentCheckbox>, checkbox: Rc<ComponentCheckbox>,
fetch_callback: fn(&mut settings::Settings) -> &mut bool, fetch_callback: fn(&mut settings::Settings) -> &mut bool,
change_callback: Option<fn(&mut Frontend, bool)>, change_callback: Option<fn(&mut Frontend, bool)>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let mut c = params.layout.start_common(); let mut c = frontend.layout.start_common();
checkbox.set_checked(&mut c.common(), *fetch_callback(params.settings)); checkbox.set_checked(&mut c.common(), *fetch_callback(params.settings));
let rc_frontend = params.frontend.clone(); let rc_frontend = params.frontend.clone();
@@ -51,26 +52,26 @@ fn init_setting_checkbox(
} }
impl TabSettings { impl TabSettings {
pub fn new(mut params: TabParams) -> anyhow::Result<Self> { pub fn new(frontend: &mut Frontend, parent_id: WidgetID) -> anyhow::Result<Self> {
let state = wgui::parser::parse_from_assets( let state = wgui::parser::parse_from_assets(
&ParseDocumentParams { &ParseDocumentParams {
globals: params.globals.clone(), globals: frontend.layout.state.globals.clone(),
path: AssetPath::BuiltIn("gui/tab/settings.xml"), path: AssetPath::BuiltIn("gui/tab/settings.xml"),
extra: Default::default(), extra: Default::default(),
}, },
params.layout, &mut frontend.layout,
params.parent_id, parent_id,
)?; )?;
init_setting_checkbox( init_setting_checkbox(
&mut params, frontend,
state.data.fetch_component_as::<ComponentCheckbox>("cb_hide_username")?, state.data.fetch_component_as::<ComponentCheckbox>("cb_hide_username")?,
|settings| &mut settings.home_screen.hide_username, |settings| &mut settings.home_screen.hide_username,
None, None,
)?; )?;
init_setting_checkbox( init_setting_checkbox(
&mut params, frontend,
state.data.fetch_component_as::<ComponentCheckbox>("cb_am_pm_clock")?, state.data.fetch_component_as::<ComponentCheckbox>("cb_am_pm_clock")?,
|settings| &mut settings.general.am_pm_clock, |settings| &mut settings.general.am_pm_clock,
Some(|frontend, _| { Some(|frontend, _| {
@@ -79,7 +80,7 @@ impl TabSettings {
)?; )?;
init_setting_checkbox( init_setting_checkbox(
&mut params, frontend,
state state
.data .data
.fetch_component_as::<ComponentCheckbox>("cb_opaque_background")?, .fetch_component_as::<ComponentCheckbox>("cb_opaque_background")?,
@@ -90,7 +91,7 @@ impl TabSettings {
)?; )?;
init_setting_checkbox( init_setting_checkbox(
&mut params, frontend,
state state
.data .data
.fetch_component_as::<ComponentCheckbox>("cb_xwayland_by_default")?, .fetch_component_as::<ComponentCheckbox>("cb_xwayland_by_default")?,

View File

@@ -46,7 +46,7 @@ enum Task {
} }
pub struct Params<'a> { pub struct Params<'a> {
pub globals: &'a WguiGlobals, pub globals: WguiGlobals,
pub frontend_tasks: FrontendTasks, pub frontend_tasks: FrontendTasks,
pub layout: &'a mut Layout, pub layout: &'a mut Layout,
pub parent_id: WidgetID, pub parent_id: WidgetID,

View File

@@ -11,8 +11,8 @@ use wgui::{
renderer_vk::text::{FontWeight, HorizontalAlign, TextStyle}, renderer_vk::text::{FontWeight, HorizontalAlign, TextStyle},
taffy::{self, prelude::length}, taffy::{self, prelude::length},
widget::{ widget::{
ConstructEssentials,
label::{WidgetLabel, WidgetLabelParams}, label::{WidgetLabel, WidgetLabelParams},
ConstructEssentials,
}, },
}; };
use wlx_common::dash_interface::BoxDashInterface; use wlx_common::dash_interface::BoxDashInterface;
@@ -32,7 +32,7 @@ enum Task {
} }
pub struct Params<'a> { pub struct Params<'a> {
pub globals: &'a WguiGlobals, pub globals: WguiGlobals,
pub frontend_tasks: FrontendTasks, pub frontend_tasks: FrontendTasks,
pub layout: &'a mut Layout, pub layout: &'a mut Layout,
pub parent_id: WidgetID, pub parent_id: WidgetID,