generics + DashInterface impl (#334)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use std::{cell::RefCell, collections::HashMap, rc::Rc};
|
||||
use std::{cell::RefCell, collections::HashMap, marker::PhantomData, rc::Rc};
|
||||
|
||||
use wgui::{
|
||||
assets::AssetPath,
|
||||
@@ -28,7 +28,7 @@ struct State {
|
||||
view_launcher: Option<(PopupHandle, views::app_launcher::View)>,
|
||||
}
|
||||
|
||||
pub struct TabApps {
|
||||
pub struct TabApps<T> {
|
||||
#[allow(dead_code)]
|
||||
parser_state: ParserState,
|
||||
|
||||
@@ -36,14 +36,15 @@ pub struct TabApps {
|
||||
entries: Vec<DesktopEntry>,
|
||||
app_list: AppList,
|
||||
tasks: Tasks<Task>,
|
||||
marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl Tab for TabApps {
|
||||
impl<T> Tab<T> for TabApps<T> {
|
||||
fn get_type(&self) -> TabType {
|
||||
TabType::Apps
|
||||
}
|
||||
|
||||
fn update(&mut self, frontend: &mut Frontend) -> anyhow::Result<()> {
|
||||
fn update(&mut self, frontend: &mut Frontend<T>, data: &mut T) -> anyhow::Result<()> {
|
||||
let mut state = self.state.borrow_mut();
|
||||
|
||||
for task in self.tasks.drain() {
|
||||
@@ -53,7 +54,7 @@ impl Tab for TabApps {
|
||||
}
|
||||
|
||||
if let Some((_, launcher)) = &mut state.view_launcher {
|
||||
launcher.update(&mut frontend.layout, &mut frontend.interface)?;
|
||||
launcher.update(&mut frontend.layout, &mut frontend.interface, data)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -108,8 +109,8 @@ fn on_app_click(
|
||||
})
|
||||
}
|
||||
|
||||
impl TabApps {
|
||||
pub fn new(frontend: &mut Frontend, parent_id: WidgetID) -> anyhow::Result<Self> {
|
||||
impl<T> TabApps<T> {
|
||||
pub fn new(frontend: &mut Frontend<T>, parent_id: WidgetID) -> anyhow::Result<Self> {
|
||||
let doc_params = &ParseDocumentParams {
|
||||
globals: frontend.layout.state.globals.clone(),
|
||||
path: AssetPath::BuiltIn("gui/tab/apps.xml"),
|
||||
@@ -151,14 +152,15 @@ impl TabApps {
|
||||
entries,
|
||||
state,
|
||||
tasks,
|
||||
marker: PhantomData,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl AppList {
|
||||
fn mount_entry(
|
||||
fn mount_entry<T>(
|
||||
&mut self,
|
||||
frontend: &mut Frontend,
|
||||
frontend: &mut Frontend<T>,
|
||||
parser_state: &mut ParserState,
|
||||
doc_params: &ParseDocumentParams,
|
||||
list_parent: &WidgetPair,
|
||||
@@ -197,9 +199,9 @@ impl AppList {
|
||||
data.fetch_component_as::<ComponentButton>("button")
|
||||
}
|
||||
|
||||
fn mount_entries(
|
||||
fn mount_entries<T>(
|
||||
&mut self,
|
||||
frontend: &mut Frontend,
|
||||
frontend: &mut Frontend<T>,
|
||||
entries: &[DesktopEntry],
|
||||
parser_state: &mut ParserState,
|
||||
doc_params: &ParseDocumentParams,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use wgui::{
|
||||
assets::AssetPath,
|
||||
layout::WidgetID,
|
||||
@@ -10,26 +12,27 @@ use crate::{
|
||||
views::game_list,
|
||||
};
|
||||
|
||||
pub struct TabGames {
|
||||
pub struct TabGames<T> {
|
||||
#[allow(dead_code)]
|
||||
pub state: ParserState,
|
||||
|
||||
view_game_list: game_list::View,
|
||||
marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl Tab for TabGames {
|
||||
impl<T> Tab<T> for TabGames<T> {
|
||||
fn get_type(&self) -> TabType {
|
||||
TabType::Games
|
||||
}
|
||||
|
||||
fn update(&mut self, frontend: &mut Frontend) -> anyhow::Result<()> {
|
||||
fn update(&mut self, frontend: &mut Frontend<T>, _data: &mut T) -> anyhow::Result<()> {
|
||||
self.view_game_list.update(&mut frontend.layout, &frontend.executor)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl TabGames {
|
||||
pub fn new(frontend: &mut Frontend, parent_id: WidgetID) -> anyhow::Result<Self> {
|
||||
impl<T> TabGames<T> {
|
||||
pub fn new(frontend: &mut Frontend<T>, parent_id: WidgetID) -> anyhow::Result<Self> {
|
||||
let state = wgui::parser::parse_from_assets(
|
||||
&ParseDocumentParams {
|
||||
globals: frontend.layout.state.globals.clone(),
|
||||
@@ -50,6 +53,10 @@ impl TabGames {
|
||||
parent_id: game_list_parent,
|
||||
})?;
|
||||
|
||||
Ok(Self { state, view_game_list })
|
||||
Ok(Self {
|
||||
state,
|
||||
view_game_list,
|
||||
marker: PhantomData,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use wgui::{
|
||||
assets::AssetPath,
|
||||
components::button::ComponentButton,
|
||||
@@ -15,12 +17,13 @@ use crate::{
|
||||
various,
|
||||
};
|
||||
|
||||
pub struct TabHome {
|
||||
pub struct TabHome<T> {
|
||||
#[allow(dead_code)]
|
||||
pub state: ParserState,
|
||||
marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl Tab for TabHome {
|
||||
impl<T> Tab<T> for TabHome<T> {
|
||||
fn get_type(&self) -> TabType {
|
||||
TabType::Home
|
||||
}
|
||||
@@ -44,8 +47,8 @@ fn configure_label_hello(common: &mut CallbackDataCommon, label_hello: Widget, s
|
||||
label_hello.set_text(common, Translation::from_raw_text(&translated));
|
||||
}
|
||||
|
||||
impl TabHome {
|
||||
pub fn new(frontend: &mut Frontend, parent_id: WidgetID) -> anyhow::Result<Self> {
|
||||
impl<T> TabHome<T> {
|
||||
pub fn new(frontend: &mut Frontend<T>, parent_id: WidgetID) -> anyhow::Result<Self> {
|
||||
let state = wgui::parser::parse_from_assets(
|
||||
&ParseDocumentParams {
|
||||
globals: frontend.layout.state.globals.clone(),
|
||||
@@ -73,6 +76,9 @@ impl TabHome {
|
||||
tasks.handle_button(&btn_processes, FrontendTask::SetTab(TabType::Processes));
|
||||
tasks.handle_button(&btn_settings, FrontendTask::SetTab(TabType::Settings));
|
||||
|
||||
Ok(Self { state })
|
||||
Ok(Self {
|
||||
state,
|
||||
marker: PhantomData,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,11 +17,11 @@ pub enum TabType {
|
||||
Settings,
|
||||
}
|
||||
|
||||
pub trait Tab {
|
||||
pub trait Tab<T> {
|
||||
#[allow(dead_code)]
|
||||
fn get_type(&self) -> TabType;
|
||||
|
||||
fn update(&mut self, _: &mut Frontend) -> anyhow::Result<()> {
|
||||
fn update(&mut self, _: &mut Frontend<T>, _: &mut T) -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use wgui::{
|
||||
assets::AssetPath,
|
||||
layout::WidgetID,
|
||||
@@ -9,19 +11,20 @@ use crate::{
|
||||
tab::{Tab, TabType},
|
||||
};
|
||||
|
||||
pub struct TabMonado {
|
||||
pub struct TabMonado<T> {
|
||||
#[allow(dead_code)]
|
||||
pub state: ParserState,
|
||||
marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl Tab for TabMonado {
|
||||
impl<T> Tab<T> for TabMonado<T> {
|
||||
fn get_type(&self) -> TabType {
|
||||
TabType::Games
|
||||
}
|
||||
}
|
||||
|
||||
impl TabMonado {
|
||||
pub fn new(frontend: &mut Frontend, parent_id: WidgetID) -> anyhow::Result<Self> {
|
||||
impl<T> TabMonado<T> {
|
||||
pub fn new(frontend: &mut Frontend<T>, parent_id: WidgetID) -> anyhow::Result<Self> {
|
||||
let state = wgui::parser::parse_from_assets(
|
||||
&ParseDocumentParams {
|
||||
globals: frontend.layout.state.globals.clone(),
|
||||
@@ -32,6 +35,9 @@ impl TabMonado {
|
||||
parent_id,
|
||||
)?;
|
||||
|
||||
Ok(Self { state })
|
||||
Ok(Self {
|
||||
state,
|
||||
marker: PhantomData,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use wgui::{
|
||||
assets::AssetPath,
|
||||
layout::WidgetID,
|
||||
@@ -10,32 +12,33 @@ use crate::{
|
||||
views::{process_list, window_list},
|
||||
};
|
||||
|
||||
pub struct TabProcesses {
|
||||
pub struct TabProcesses<T> {
|
||||
#[allow(dead_code)]
|
||||
pub state: ParserState,
|
||||
|
||||
view_window_list: window_list::View,
|
||||
view_process_list: process_list::View,
|
||||
marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl Tab for TabProcesses {
|
||||
impl<T> Tab<T> for TabProcesses<T> {
|
||||
fn get_type(&self) -> TabType {
|
||||
TabType::Games
|
||||
}
|
||||
|
||||
fn update(&mut self, frontend: &mut Frontend) -> anyhow::Result<()> {
|
||||
fn update(&mut self, frontend: &mut Frontend<T>, data: &mut T) -> anyhow::Result<()> {
|
||||
self
|
||||
.view_window_list
|
||||
.update(&mut frontend.layout, &mut frontend.interface)?;
|
||||
.update(&mut frontend.layout, &mut frontend.interface, data)?;
|
||||
self
|
||||
.view_process_list
|
||||
.update(&mut frontend.layout, &mut frontend.interface)?;
|
||||
.update(&mut frontend.layout, &mut frontend.interface, data)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl TabProcesses {
|
||||
pub fn new(frontend: &mut Frontend, parent_id: WidgetID) -> anyhow::Result<Self> {
|
||||
impl<T> TabProcesses<T> {
|
||||
pub fn new(frontend: &mut Frontend<T>, parent_id: WidgetID) -> anyhow::Result<Self> {
|
||||
let globals = frontend.layout.state.globals.clone();
|
||||
let state = wgui::parser::parse_from_assets(
|
||||
&ParseDocumentParams {
|
||||
@@ -61,6 +64,7 @@ impl TabProcesses {
|
||||
globals,
|
||||
})?,
|
||||
state,
|
||||
marker: PhantomData,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::rc::Rc;
|
||||
use std::{marker::PhantomData, rc::Rc};
|
||||
|
||||
use wgui::{
|
||||
assets::AssetPath,
|
||||
@@ -18,19 +18,20 @@ enum Task {
|
||||
ToggleSetting(SettingType, bool),
|
||||
}
|
||||
|
||||
pub struct TabSettings {
|
||||
pub struct TabSettings<T> {
|
||||
#[allow(dead_code)]
|
||||
pub state: ParserState,
|
||||
|
||||
tasks: Tasks<Task>,
|
||||
marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl Tab for TabSettings {
|
||||
impl<T> Tab<T> for TabSettings<T> {
|
||||
fn get_type(&self) -> TabType {
|
||||
TabType::Settings
|
||||
}
|
||||
|
||||
fn update(&mut self, frontend: &mut Frontend) -> anyhow::Result<()> {
|
||||
fn update(&mut self, frontend: &mut Frontend<T>, _data: &mut T) -> anyhow::Result<()> {
|
||||
for task in self.tasks.drain() {
|
||||
match task {
|
||||
Task::ToggleSetting(setting, n) => self.toggle_setting(frontend, setting, n),
|
||||
@@ -60,8 +61,8 @@ impl SettingType {
|
||||
}
|
||||
}
|
||||
|
||||
fn init_setting_checkbox(
|
||||
frontend: &mut Frontend,
|
||||
fn init_setting_checkbox<T>(
|
||||
frontend: &mut Frontend<T>,
|
||||
tasks: &Tasks<Task>,
|
||||
checkbox: Rc<ComponentCheckbox>,
|
||||
setting: SettingType,
|
||||
@@ -86,8 +87,8 @@ fn init_setting_checkbox(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
impl TabSettings {
|
||||
pub fn new(frontend: &mut Frontend, parent_id: WidgetID) -> anyhow::Result<Self> {
|
||||
impl<T> TabSettings<T> {
|
||||
pub fn new(frontend: &mut Frontend<T>, parent_id: WidgetID) -> anyhow::Result<Self> {
|
||||
let state = wgui::parser::parse_from_assets(
|
||||
&ParseDocumentParams {
|
||||
globals: frontend.layout.state.globals.clone(),
|
||||
@@ -136,10 +137,14 @@ impl TabSettings {
|
||||
None,
|
||||
)?;
|
||||
|
||||
Ok(Self { state, tasks })
|
||||
Ok(Self {
|
||||
state,
|
||||
tasks,
|
||||
marker: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
fn toggle_setting(&mut self, frontend: &mut Frontend, setting: SettingType, state: bool) {
|
||||
fn toggle_setting(&mut self, frontend: &mut Frontend<T>, setting: SettingType, state: bool) {
|
||||
*setting.get_bool(frontend.settings.get_mut()) = state;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user