[skip ci] refactor dash?
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use std::{cell::RefCell, path::PathBuf, rc::Rc};
|
||||
use std::{path::PathBuf, rc::Rc};
|
||||
|
||||
use chrono::Timelike;
|
||||
use glam::Vec2;
|
||||
@@ -8,7 +8,7 @@ use wgui::{
|
||||
font_config::WguiFontConfig,
|
||||
globals::WguiGlobals,
|
||||
i18n::Translation,
|
||||
layout::{LayoutParams, RcLayout, WidgetID},
|
||||
layout::{Layout, LayoutParams, WidgetID},
|
||||
parser::{Fetchable, ParseDocumentParams, ParserState},
|
||||
widget::{label::WidgetLabel, rectangle::WidgetRectangle},
|
||||
windowing::{WguiWindow, WguiWindowParams, WguiWindowParamsExtra, WguiWindowPlacement},
|
||||
@@ -18,8 +18,8 @@ use wlx_common::{dash_interface::BoxDashInterface, timestep::Timestep};
|
||||
use crate::{
|
||||
assets, settings,
|
||||
tab::{
|
||||
Tab, TabParams, TabType, TabUpdateParams, apps::TabApps, games::TabGames, home::TabHome, monado::TabMonado,
|
||||
processes::TabProcesses, settings::TabSettings,
|
||||
apps::TabApps, games::TabGames, home::TabHome, monado::TabMonado, processes::TabProcesses, settings::TabSettings,
|
||||
Tab, TabType,
|
||||
},
|
||||
task::Tasks,
|
||||
util::{
|
||||
@@ -38,7 +38,7 @@ pub struct FrontendWidgets {
|
||||
pub type FrontendTasks = Tasks<FrontendTask>;
|
||||
|
||||
pub struct Frontend {
|
||||
pub layout: RcLayout,
|
||||
pub layout: Layout,
|
||||
globals: WguiGlobals,
|
||||
|
||||
pub settings: Box<dyn settings::SettingsIO>,
|
||||
@@ -70,8 +70,6 @@ pub struct InitParams {
|
||||
pub interface: BoxDashInterface,
|
||||
}
|
||||
|
||||
pub type RcFrontend = Rc<RefCell<Frontend>>;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum FrontendTask {
|
||||
SetTab(TabType),
|
||||
@@ -86,7 +84,7 @@ pub enum FrontendTask {
|
||||
}
|
||||
|
||||
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 font_binary_bold = assets.load_from_path_gzip("Quicksand-Bold.ttf.gz")?;
|
||||
@@ -121,8 +119,6 @@ impl Frontend {
|
||||
|
||||
let toast_manager = ToastManager::new();
|
||||
|
||||
let rc_layout = layout.as_rc();
|
||||
|
||||
let tasks = FrontendTasks::new();
|
||||
tasks.push(FrontendTask::SetTab(TabType::Home));
|
||||
|
||||
@@ -132,8 +128,8 @@ impl Frontend {
|
||||
let mut timestep = Timestep::new();
|
||||
timestep.set_tps(30.0); // 30 ticks per second
|
||||
|
||||
let frontend = Self {
|
||||
layout: rc_layout.clone(),
|
||||
let mut frontend = Self {
|
||||
layout,
|
||||
state,
|
||||
current_tab: None,
|
||||
globals,
|
||||
@@ -157,28 +153,22 @@ impl Frontend {
|
||||
frontend.update_background()?;
|
||||
frontend.update_time()?;
|
||||
|
||||
let res = Rc::new(RefCell::new(frontend));
|
||||
Frontend::register_widgets(&mut frontend)?;
|
||||
|
||||
Frontend::register_widgets(&res)?;
|
||||
|
||||
Ok((res, rc_layout))
|
||||
Ok(frontend)
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
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 {
|
||||
let mut layout = self.layout.borrow_mut();
|
||||
if let Some(mut tab) = self.current_tab.take() {
|
||||
tab.update(self)?;
|
||||
|
||||
tab.update(TabUpdateParams {
|
||||
layout: &mut layout,
|
||||
interface: &mut self.interface,
|
||||
executor: &mut self.executor,
|
||||
})?;
|
||||
self.current_tab = Some(tab);
|
||||
}
|
||||
|
||||
// process async runtime tasks
|
||||
@@ -197,22 +187,19 @@ impl Frontend {
|
||||
}
|
||||
|
||||
{
|
||||
let mut layout = self.layout.borrow_mut();
|
||||
|
||||
// always 30 times per second
|
||||
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(())
|
||||
}
|
||||
|
||||
fn update_time(&self) -> anyhow::Result<()> {
|
||||
let mut layout = self.layout.borrow_mut();
|
||||
let mut c = layout.start_common();
|
||||
fn update_time(&mut self) -> anyhow::Result<()> {
|
||||
let mut c = self.layout.start_common();
|
||||
let mut common = c.common();
|
||||
|
||||
{
|
||||
@@ -240,11 +227,10 @@ impl Frontend {
|
||||
}
|
||||
|
||||
fn mount_popup(&mut self, params: MountPopupParams) -> anyhow::Result<()> {
|
||||
let mut layout = self.layout.borrow_mut();
|
||||
self.popup_manager.mount_popup(
|
||||
self.globals.clone(),
|
||||
self.settings.as_ref(),
|
||||
&mut layout,
|
||||
&mut self.layout,
|
||||
&mut self.interface,
|
||||
self.tasks.clone(),
|
||||
params,
|
||||
@@ -253,17 +239,15 @@ impl Frontend {
|
||||
}
|
||||
|
||||
fn refresh_popup_manager(&mut self) -> anyhow::Result<()> {
|
||||
let mut layout = self.layout.borrow_mut();
|
||||
let mut c = layout.start_common();
|
||||
let mut c = self.layout.start_common();
|
||||
self.popup_manager.refresh(c.common().alterables);
|
||||
c.finish()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update_background(&self) -> anyhow::Result<()> {
|
||||
let layout = self.layout.borrow_mut();
|
||||
|
||||
let Some(mut rect) = layout
|
||||
let Some(mut rect) = self
|
||||
.layout
|
||||
.state
|
||||
.widgets
|
||||
.get_as::<WidgetRectangle>(self.widgets.id_rect_content)
|
||||
@@ -283,13 +267,9 @@ impl Frontend {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_layout(&self) -> &RcLayout {
|
||||
&self.layout
|
||||
}
|
||||
|
||||
fn process_task(&mut self, rc_this: &RcFrontend, task: FrontendTask) -> anyhow::Result<()> {
|
||||
fn process_task(&mut self, task: FrontendTask) -> anyhow::Result<()> {
|
||||
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::RefreshBackground => self.update_background()?,
|
||||
FrontendTask::MountPopup(params) => self.mount_popup(params)?,
|
||||
@@ -302,29 +282,18 @@ impl Frontend {
|
||||
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:?}");
|
||||
let mut layout = self.layout.borrow_mut();
|
||||
let widget_content = self.state.fetch_widget(&layout.state, "content")?;
|
||||
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 widget_content = self.state.fetch_widget(&self.layout.state, "content")?;
|
||||
self.layout.remove_children(widget_content.id);
|
||||
|
||||
let tab: Box<dyn Tab> = match tab_type {
|
||||
TabType::Home => Box::new(TabHome::new(tab_params)?),
|
||||
TabType::Apps => Box::new(TabApps::new(tab_params)?),
|
||||
TabType::Games => Box::new(TabGames::new(tab_params)?),
|
||||
TabType::Monado => Box::new(TabMonado::new(tab_params)?),
|
||||
TabType::Processes => Box::new(TabProcesses::new(tab_params)?),
|
||||
TabType::Settings => Box::new(TabSettings::new(tab_params)?),
|
||||
TabType::Home => Box::new(TabHome::new(self, widget_content.id)?),
|
||||
TabType::Apps => Box::new(TabApps::new(self, widget_content.id)?),
|
||||
TabType::Games => Box::new(TabGames::new(self, widget_content.id)?),
|
||||
TabType::Monado => Box::new(TabMonado::new(self, widget_content.id)?),
|
||||
TabType::Processes => Box::new(TabProcesses::new(self, widget_content.id)?),
|
||||
TabType::Settings => Box::new(TabSettings::new(self, widget_content.id)?),
|
||||
};
|
||||
|
||||
self.current_tab = Some(tab);
|
||||
@@ -332,46 +301,44 @@ impl Frontend {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn register_widgets(rc_this: &RcFrontend) -> anyhow::Result<()> {
|
||||
let this = rc_this.borrow_mut();
|
||||
|
||||
fn register_widgets(&mut self) -> anyhow::Result<()> {
|
||||
// ################################
|
||||
// SIDE BUTTONS
|
||||
// ################################
|
||||
|
||||
// "Home" side button
|
||||
this.tasks.handle_button(
|
||||
this.state.fetch_component_as::<ComponentButton>("btn_side_home")?,
|
||||
self.tasks.handle_button(
|
||||
self.state.fetch_component_as::<ComponentButton>("btn_side_home")?,
|
||||
FrontendTask::SetTab(TabType::Home),
|
||||
);
|
||||
|
||||
// "Apps" side button
|
||||
this.tasks.handle_button(
|
||||
this.state.fetch_component_as::<ComponentButton>("btn_side_apps")?,
|
||||
self.tasks.handle_button(
|
||||
self.state.fetch_component_as::<ComponentButton>("btn_side_apps")?,
|
||||
FrontendTask::SetTab(TabType::Apps),
|
||||
);
|
||||
|
||||
// "Games" side button
|
||||
this.tasks.handle_button(
|
||||
this.state.fetch_component_as::<ComponentButton>("btn_side_games")?,
|
||||
self.tasks.handle_button(
|
||||
self.state.fetch_component_as::<ComponentButton>("btn_side_games")?,
|
||||
FrontendTask::SetTab(TabType::Games),
|
||||
);
|
||||
|
||||
// "Monado side button"
|
||||
this.tasks.handle_button(
|
||||
this.state.fetch_component_as::<ComponentButton>("btn_side_monado")?,
|
||||
self.tasks.handle_button(
|
||||
self.state.fetch_component_as::<ComponentButton>("btn_side_monado")?,
|
||||
FrontendTask::SetTab(TabType::Monado),
|
||||
);
|
||||
|
||||
// "Processes" side button
|
||||
this.tasks.handle_button(
|
||||
this.state.fetch_component_as::<ComponentButton>("btn_side_processes")?,
|
||||
self.tasks.handle_button(
|
||||
self.state.fetch_component_as::<ComponentButton>("btn_side_processes")?,
|
||||
FrontendTask::SetTab(TabType::Processes),
|
||||
);
|
||||
|
||||
// "Settings" side button
|
||||
this.tasks.handle_button(
|
||||
this.state.fetch_component_as::<ComponentButton>("btn_side_settings")?,
|
||||
self.tasks.handle_button(
|
||||
self.state.fetch_component_as::<ComponentButton>("btn_side_settings")?,
|
||||
FrontendTask::SetTab(TabType::Settings),
|
||||
);
|
||||
|
||||
@@ -380,14 +347,14 @@ impl Frontend {
|
||||
// ################################
|
||||
|
||||
// "Audio" bottom bar button
|
||||
this.tasks.handle_button(
|
||||
this.state.fetch_component_as::<ComponentButton>("btn_audio")?,
|
||||
self.tasks.handle_button(
|
||||
self.state.fetch_component_as::<ComponentButton>("btn_audio")?,
|
||||
FrontendTask::ShowAudioSettings,
|
||||
);
|
||||
|
||||
// "Recenter playspace" bottom bar button
|
||||
this.tasks.handle_button(
|
||||
this.state.fetch_component_as::<ComponentButton>("btn_recenter")?,
|
||||
self.tasks.handle_button(
|
||||
self.state.fetch_component_as::<ComponentButton>("btn_recenter")?,
|
||||
FrontendTask::RecenterPlayspace,
|
||||
);
|
||||
|
||||
@@ -395,12 +362,10 @@ impl Frontend {
|
||||
}
|
||||
|
||||
fn action_show_audio_settings(&mut self) -> anyhow::Result<()> {
|
||||
let mut layout = self.layout.borrow_mut();
|
||||
|
||||
self.window_audio_settings.open(&mut WguiWindowParams {
|
||||
globals: self.globals.clone(),
|
||||
position: Vec2::new(64.0, 64.0),
|
||||
layout: &mut layout,
|
||||
layout: &mut self.layout,
|
||||
title: Translation::from_translation_key("AUDIO.SETTINGS"),
|
||||
extra: WguiWindowParamsExtra {
|
||||
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 {
|
||||
globals: self.globals.clone(),
|
||||
frontend_tasks: self.tasks.clone(),
|
||||
layout: &mut layout,
|
||||
layout: &mut self.layout,
|
||||
parent_id: content.id,
|
||||
on_update: {
|
||||
let tasks = self.tasks.clone();
|
||||
@@ -431,8 +396,7 @@ impl Frontend {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let mut layout = self.layout.borrow_mut();
|
||||
view.update(&mut layout)?;
|
||||
view.update(&mut self.layout)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -5,13 +5,13 @@ use wgui::{
|
||||
components::button::{ButtonClickCallback, ComponentButton},
|
||||
globals::WguiGlobals,
|
||||
i18n::Translation,
|
||||
layout::WidgetPair,
|
||||
layout::{WidgetID, WidgetPair},
|
||||
parser::{Fetchable, ParseDocumentParams, ParserState},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
frontend::{FrontendTask, FrontendTasks, RcFrontend},
|
||||
tab::{Tab, TabParams, TabType},
|
||||
frontend::{Frontend, FrontendTask, FrontendTasks},
|
||||
tab::{Tab, TabType},
|
||||
task::Tasks,
|
||||
util::{
|
||||
self,
|
||||
@@ -49,7 +49,7 @@ impl Tab for TabApps {
|
||||
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();
|
||||
|
||||
for task in self.tasks.drain() {
|
||||
@@ -59,7 +59,7 @@ impl Tab for TabApps {
|
||||
}
|
||||
|
||||
if let Some((_, launcher)) = &mut state.launcher {
|
||||
launcher.update(params.layout, params.interface)?;
|
||||
launcher.update(&mut frontend.layout, &mut frontend.interface)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -72,7 +72,6 @@ struct AppList {
|
||||
|
||||
// called after the user clicks any desktop entry
|
||||
fn on_app_click(
|
||||
frontend: RcFrontend,
|
||||
frontend_tasks: FrontendTasks,
|
||||
globals: WguiGlobals,
|
||||
entry: DesktopEntry,
|
||||
@@ -80,48 +79,45 @@ fn on_app_click(
|
||||
tasks: Tasks<Task>,
|
||||
) -> ButtonClickCallback {
|
||||
Box::new(move |_common, _evt| {
|
||||
frontend
|
||||
.borrow_mut()
|
||||
.tasks
|
||||
.push(FrontendTask::MountPopup(MountPopupParams {
|
||||
title: Translation::from_raw_text(&entry.app_name),
|
||||
on_content: {
|
||||
// this is awful
|
||||
let state = state.clone();
|
||||
let entry = entry.clone();
|
||||
let globals = globals.clone();
|
||||
let frontend_tasks = frontend_tasks.clone();
|
||||
let tasks = tasks.clone();
|
||||
frontend_tasks.push(FrontendTask::MountPopup(MountPopupParams {
|
||||
title: Translation::from_raw_text(&entry.app_name),
|
||||
on_content: {
|
||||
// this is awful
|
||||
let state = state.clone();
|
||||
let entry = entry.clone();
|
||||
let globals = globals.clone();
|
||||
let frontend_tasks = frontend_tasks.clone();
|
||||
let tasks = tasks.clone();
|
||||
|
||||
Rc::new(move |data| {
|
||||
let on_launched = {
|
||||
let tasks = tasks.clone();
|
||||
Box::new(move || tasks.push(Task::CloseLauncher))
|
||||
};
|
||||
Rc::new(move |data| {
|
||||
let on_launched = {
|
||||
let tasks = tasks.clone();
|
||||
Box::new(move || tasks.push(Task::CloseLauncher))
|
||||
};
|
||||
|
||||
let view = app_launcher::View::new(app_launcher::Params {
|
||||
entry: entry.clone(),
|
||||
globals: &globals,
|
||||
layout: data.layout,
|
||||
parent_id: data.id_content,
|
||||
frontend_tasks: &frontend_tasks,
|
||||
settings: data.settings,
|
||||
on_launched,
|
||||
})?;
|
||||
let view = app_launcher::View::new(app_launcher::Params {
|
||||
entry: entry.clone(),
|
||||
globals: &globals,
|
||||
layout: data.layout,
|
||||
parent_id: data.id_content,
|
||||
frontend_tasks: &frontend_tasks,
|
||||
settings: data.settings,
|
||||
on_launched,
|
||||
})?;
|
||||
|
||||
state.borrow_mut().launcher = Some((data.handle, view));
|
||||
Ok(())
|
||||
})
|
||||
},
|
||||
}));
|
||||
state.borrow_mut().launcher = Some((data.handle, view));
|
||||
Ok(())
|
||||
})
|
||||
},
|
||||
}));
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
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 {
|
||||
globals: tab_params.globals.clone(),
|
||||
globals: frontend.layout.state.globals.clone(),
|
||||
path: AssetPath::BuiltIn("gui/tab/apps.xml"),
|
||||
extra: Default::default(),
|
||||
};
|
||||
@@ -129,26 +125,24 @@ impl TabApps {
|
||||
gtk::init()?;
|
||||
let entries = util::desktop_finder::find_entries()?;
|
||||
|
||||
let frontend_tasks = tab_params.frontend_tasks.clone();
|
||||
let frontend = tab_params.frontend.clone();
|
||||
let globals = tab_params.globals.clone();
|
||||
let frontend_tasks = frontend.tasks.clone();
|
||||
let globals = frontend.layout.state.globals.clone();
|
||||
|
||||
let tasks = Tasks::new();
|
||||
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 app_list_parent = parser_state.fetch_widget(&tab_params.layout.state, "app_list_parent")?;
|
||||
let mut parser_state = wgui::parser::parse_from_assets(doc_params, &mut frontend.layout, parent_id)?;
|
||||
let app_list_parent = parser_state.fetch_widget(&frontend.layout.state, "app_list_parent")?;
|
||||
let mut app_list = AppList::default();
|
||||
app_list.mount_entries(
|
||||
frontend,
|
||||
&entries,
|
||||
&mut parser_state,
|
||||
doc_params,
|
||||
&mut tab_params,
|
||||
&app_list_parent,
|
||||
|button, entry| {
|
||||
// Set up the click handler for the app button
|
||||
button.on_click(on_app_click(
|
||||
frontend.clone(),
|
||||
frontend_tasks.clone(),
|
||||
globals.clone(),
|
||||
entry.clone(),
|
||||
@@ -171,9 +165,9 @@ impl TabApps {
|
||||
impl AppList {
|
||||
fn mount_entry(
|
||||
&mut self,
|
||||
frontend: &mut Frontend,
|
||||
parser_state: &mut ParserState,
|
||||
doc_params: &ParseDocumentParams,
|
||||
params: &mut TabParams,
|
||||
list_parent: &WidgetPair,
|
||||
entry: &DesktopEntry,
|
||||
) -> anyhow::Result<Rc<ComponentButton>> {
|
||||
@@ -200,21 +194,27 @@ impl AppList {
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
fn mount_entries(
|
||||
&mut self,
|
||||
frontend: &mut Frontend,
|
||||
entries: &[DesktopEntry],
|
||||
parser_state: &mut ParserState,
|
||||
doc_params: &ParseDocumentParams,
|
||||
params: &mut TabParams,
|
||||
list_parent: &WidgetPair,
|
||||
on_button: impl Fn(Rc<ComponentButton>, &DesktopEntry),
|
||||
) -> anyhow::Result<()> {
|
||||
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);
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
use wgui::{
|
||||
assets::AssetPath,
|
||||
layout::WidgetID,
|
||||
parser::{Fetchable, ParseDocumentParams, ParserState},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
tab::{Tab, TabParams, TabType},
|
||||
frontend::Frontend,
|
||||
tab::{Tab, TabType},
|
||||
views::game_list,
|
||||
};
|
||||
|
||||
@@ -20,31 +22,33 @@ impl Tab for TabGames {
|
||||
TabType::Games
|
||||
}
|
||||
|
||||
fn update(&mut self, params: super::TabUpdateParams) -> anyhow::Result<()> {
|
||||
self.view_game_list.update(params.layout, params.executor)?;
|
||||
fn update(&mut self, frontend: &mut Frontend) -> anyhow::Result<()> {
|
||||
self
|
||||
.view_game_list
|
||||
.update(&mut frontend.layout, &mut frontend.executor)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
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(
|
||||
&ParseDocumentParams {
|
||||
globals: params.globals.clone(),
|
||||
globals: frontend.layout.state.globals.clone(),
|
||||
path: AssetPath::BuiltIn("gui/tab/games.xml"),
|
||||
extra: Default::default(),
|
||||
},
|
||||
params.layout,
|
||||
params.parent_id,
|
||||
&mut frontend.layout,
|
||||
parent_id,
|
||||
)?;
|
||||
|
||||
let game_list_parent = state.get_widget_id("game_list_parent")?;
|
||||
|
||||
let view_game_list = game_list::View::new(game_list::Params {
|
||||
frontend_tasks: params.frontend_tasks.clone(),
|
||||
globals: params.globals,
|
||||
layout: params.layout,
|
||||
frontend_tasks: frontend.tasks.clone(),
|
||||
globals: frontend.layout.state.globals.clone(),
|
||||
layout: &mut frontend.layout,
|
||||
parent_id: game_list_parent,
|
||||
})?;
|
||||
|
||||
|
||||
@@ -3,15 +3,15 @@ use wgui::{
|
||||
components::button::ComponentButton,
|
||||
event::CallbackDataCommon,
|
||||
i18n::Translation,
|
||||
layout::Widget,
|
||||
layout::{Widget, WidgetID},
|
||||
parser::{Fetchable, ParseDocumentParams, ParserState},
|
||||
widget::label::WidgetLabel,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
frontend::FrontendTask,
|
||||
frontend::{Frontend, FrontendTask},
|
||||
settings,
|
||||
tab::{Tab, TabParams, TabType},
|
||||
tab::{Tab, TabType},
|
||||
various,
|
||||
};
|
||||
|
||||
@@ -45,20 +45,20 @@ fn configure_label_hello(common: &mut CallbackDataCommon, label_hello: Widget, s
|
||||
}
|
||||
|
||||
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(
|
||||
&ParseDocumentParams {
|
||||
globals: params.globals.clone(),
|
||||
globals: frontend.layout.state.globals.clone(),
|
||||
path: AssetPath::BuiltIn("gui/tab/home.xml"),
|
||||
extra: Default::default(),
|
||||
},
|
||||
params.layout,
|
||||
params.parent_id,
|
||||
&mut frontend.layout,
|
||||
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;
|
||||
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_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_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_games, FrontendTask::SetTab(TabType::Games));
|
||||
tasks.handle_button(btn_monado, FrontendTask::SetTab(TabType::Monado));
|
||||
|
||||
@@ -1,13 +1,4 @@
|
||||
use wgui::{
|
||||
globals::WguiGlobals,
|
||||
layout::{Layout, WidgetID},
|
||||
};
|
||||
use wlx_common::dash_interface::BoxDashInterface;
|
||||
|
||||
use crate::{
|
||||
frontend::{FrontendTasks, RcFrontend},
|
||||
util::various::AsyncExecutor,
|
||||
};
|
||||
use crate::frontend::Frontend;
|
||||
|
||||
pub mod apps;
|
||||
pub mod games;
|
||||
@@ -26,26 +17,11 @@ pub enum TabType {
|
||||
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 {
|
||||
#[allow(dead_code)]
|
||||
fn get_type(&self) -> TabType;
|
||||
|
||||
fn update(&mut self, _params: TabUpdateParams) -> anyhow::Result<()> {
|
||||
fn update(&mut self, _: &mut Frontend) -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
use wgui::{
|
||||
assets::AssetPath,
|
||||
layout::WidgetID,
|
||||
parser::{ParseDocumentParams, ParserState},
|
||||
};
|
||||
|
||||
use crate::tab::{Tab, TabParams, TabType};
|
||||
use crate::{
|
||||
frontend::Frontend,
|
||||
tab::{Tab, TabType},
|
||||
};
|
||||
|
||||
pub struct TabMonado {
|
||||
#[allow(dead_code)]
|
||||
@@ -17,15 +21,15 @@ impl Tab for 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(
|
||||
&ParseDocumentParams {
|
||||
globals: params.globals.clone(),
|
||||
globals: frontend.layout.state.globals.clone(),
|
||||
path: AssetPath::BuiltIn("gui/tab/monado.xml"),
|
||||
extra: Default::default(),
|
||||
},
|
||||
params.layout,
|
||||
params.parent_id,
|
||||
&mut frontend.layout,
|
||||
parent_id,
|
||||
)?;
|
||||
|
||||
Ok(Self { state })
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
use wgui::{
|
||||
assets::AssetPath,
|
||||
layout::WidgetID,
|
||||
parser::{Fetchable, ParseDocumentParams, ParserState},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
tab::{Tab, TabParams, TabType, TabUpdateParams},
|
||||
frontend::Frontend,
|
||||
tab::{Tab, TabType},
|
||||
views::{process_list, window_list},
|
||||
};
|
||||
|
||||
@@ -21,37 +23,42 @@ impl Tab for TabProcesses {
|
||||
TabType::Games
|
||||
}
|
||||
|
||||
fn update(&mut self, params: TabUpdateParams) -> anyhow::Result<()> {
|
||||
self.view_window_list.update(params.layout, params.interface)?;
|
||||
self.view_process_list.update(params.layout, params.interface)?;
|
||||
fn update(&mut self, frontend: &mut Frontend) -> anyhow::Result<()> {
|
||||
self
|
||||
.view_window_list
|
||||
.update(&mut frontend.layout, &mut frontend.interface)?;
|
||||
self
|
||||
.view_process_list
|
||||
.update(&mut frontend.layout, &mut frontend.interface)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
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(
|
||||
&ParseDocumentParams {
|
||||
globals: params.globals.clone(),
|
||||
globals: globals.clone(),
|
||||
path: AssetPath::BuiltIn("gui/tab/processes.xml"),
|
||||
extra: Default::default(),
|
||||
},
|
||||
params.layout,
|
||||
params.parent_id,
|
||||
&mut frontend.layout,
|
||||
parent_id,
|
||||
)?;
|
||||
|
||||
Ok(Self {
|
||||
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")?,
|
||||
globals: params.globals,
|
||||
frontend_tasks: params.frontend_tasks.clone(),
|
||||
globals: globals.clone(),
|
||||
frontend_tasks: frontend.tasks.clone(),
|
||||
on_click: None,
|
||||
})?,
|
||||
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")?,
|
||||
globals: params.globals.clone(),
|
||||
globals,
|
||||
})?,
|
||||
state,
|
||||
})
|
||||
|
||||
@@ -3,13 +3,14 @@ use std::rc::Rc;
|
||||
use wgui::{
|
||||
assets::AssetPath,
|
||||
components::checkbox::ComponentCheckbox,
|
||||
layout::WidgetID,
|
||||
parser::{Fetchable, ParseDocumentParams, ParserState},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
frontend::{Frontend, FrontendTask},
|
||||
settings,
|
||||
tab::{Tab, TabParams, TabType},
|
||||
tab::{Tab, TabType},
|
||||
};
|
||||
|
||||
pub struct TabSettings {
|
||||
@@ -24,12 +25,12 @@ impl Tab for TabSettings {
|
||||
}
|
||||
|
||||
fn init_setting_checkbox(
|
||||
params: &mut TabParams,
|
||||
frontend: &mut Frontend,
|
||||
checkbox: Rc<ComponentCheckbox>,
|
||||
fetch_callback: fn(&mut settings::Settings) -> &mut bool,
|
||||
change_callback: Option<fn(&mut Frontend, bool)>,
|
||||
) -> 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));
|
||||
let rc_frontend = params.frontend.clone();
|
||||
@@ -51,26 +52,26 @@ fn init_setting_checkbox(
|
||||
}
|
||||
|
||||
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(
|
||||
&ParseDocumentParams {
|
||||
globals: params.globals.clone(),
|
||||
globals: frontend.layout.state.globals.clone(),
|
||||
path: AssetPath::BuiltIn("gui/tab/settings.xml"),
|
||||
extra: Default::default(),
|
||||
},
|
||||
params.layout,
|
||||
params.parent_id,
|
||||
&mut frontend.layout,
|
||||
parent_id,
|
||||
)?;
|
||||
|
||||
init_setting_checkbox(
|
||||
&mut params,
|
||||
frontend,
|
||||
state.data.fetch_component_as::<ComponentCheckbox>("cb_hide_username")?,
|
||||
|settings| &mut settings.home_screen.hide_username,
|
||||
None,
|
||||
)?;
|
||||
|
||||
init_setting_checkbox(
|
||||
&mut params,
|
||||
frontend,
|
||||
state.data.fetch_component_as::<ComponentCheckbox>("cb_am_pm_clock")?,
|
||||
|settings| &mut settings.general.am_pm_clock,
|
||||
Some(|frontend, _| {
|
||||
@@ -79,7 +80,7 @@ impl TabSettings {
|
||||
)?;
|
||||
|
||||
init_setting_checkbox(
|
||||
&mut params,
|
||||
frontend,
|
||||
state
|
||||
.data
|
||||
.fetch_component_as::<ComponentCheckbox>("cb_opaque_background")?,
|
||||
@@ -90,7 +91,7 @@ impl TabSettings {
|
||||
)?;
|
||||
|
||||
init_setting_checkbox(
|
||||
&mut params,
|
||||
frontend,
|
||||
state
|
||||
.data
|
||||
.fetch_component_as::<ComponentCheckbox>("cb_xwayland_by_default")?,
|
||||
|
||||
@@ -46,7 +46,7 @@ enum Task {
|
||||
}
|
||||
|
||||
pub struct Params<'a> {
|
||||
pub globals: &'a WguiGlobals,
|
||||
pub globals: WguiGlobals,
|
||||
pub frontend_tasks: FrontendTasks,
|
||||
pub layout: &'a mut Layout,
|
||||
pub parent_id: WidgetID,
|
||||
|
||||
@@ -11,8 +11,8 @@ use wgui::{
|
||||
renderer_vk::text::{FontWeight, HorizontalAlign, TextStyle},
|
||||
taffy::{self, prelude::length},
|
||||
widget::{
|
||||
ConstructEssentials,
|
||||
label::{WidgetLabel, WidgetLabelParams},
|
||||
ConstructEssentials,
|
||||
},
|
||||
};
|
||||
use wlx_common::dash_interface::BoxDashInterface;
|
||||
@@ -32,7 +32,7 @@ enum Task {
|
||||
}
|
||||
|
||||
pub struct Params<'a> {
|
||||
pub globals: &'a WguiGlobals,
|
||||
pub globals: WguiGlobals,
|
||||
pub frontend_tasks: FrontendTasks,
|
||||
pub layout: &'a mut Layout,
|
||||
pub parent_id: WidgetID,
|
||||
|
||||
Reference in New Issue
Block a user