Components list: added working "recommended only" switcher

This commit is contained in:
Observer KRypt0n_ 2023-01-22 11:56:56 +02:00
parent 48d7f0fc06
commit f168862cc7
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2
6 changed files with 163 additions and 108 deletions

View file

@ -3,13 +3,15 @@ use relm4::prelude::*;
use adw::prelude::*; use adw::prelude::*;
pub struct ComponentGroup { pub struct ComponentGroup {
pub title: String pub title: String,
pub show_recommended_only: bool,
pub versions: Vec<Controller<super::ComponentVersion>>
} }
#[derive(Debug)] #[derive(Debug)]
pub enum AppMsg { pub enum AppMsg {
Install, ShowRecommendedOnly(bool)
Remove
} }
#[relm4::component(pub)] #[relm4::component(pub)]
@ -30,16 +32,22 @@ impl SimpleComponent for ComponentGroup {
_sender: ComponentSender<Self>, _sender: ComponentSender<Self>,
) -> ComponentParts<Self> { ) -> ComponentParts<Self> {
let model = ComponentGroup { let model = ComponentGroup {
title: init.title title: init.title,
show_recommended_only: true,
versions: init.versions
.into_iter()
.map(|version| {
super::ComponentVersion::builder()
.launch(version)
.detach()
})
.collect()
}; };
let widgets = view_output!(); let widgets = view_output!();
for version in init.versions { for version in &model.versions {
let version = super::ComponentVersion::builder()
.launch(version)
.detach();
widgets.group.add_row(version.widget()); widgets.group.add_row(version.widget());
} }
@ -47,8 +55,17 @@ impl SimpleComponent for ComponentGroup {
} }
fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) { fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
tracing::debug!("Called about dialog event: {:?}", msg); tracing::debug!("Called component group [{}] event: {:?}", self.title, msg);
// todo match msg {
AppMsg::ShowRecommendedOnly(state) => {
self.show_recommended_only = state;
// todo
for version in &self.versions {
version.sender().send(super::version::AppMsg::ShowRecommendedOnly(state)).unwrap();
}
}
}
} }
} }

View file

@ -3,13 +3,15 @@ use relm4::prelude::*;
use adw::prelude::*; use adw::prelude::*;
pub struct ComponentsList { pub struct ComponentsList {
_download_folder: String pub _download_folder: String,
pub show_recommended_only: bool,
pub groups: Vec<Controller<super::ComponentGroup>>
} }
#[derive(Debug)] #[derive(Debug)]
pub enum AppMsg { pub enum AppMsg {
Install, ShowRecommendedOnly(bool)
Remove
} }
#[relm4::component(pub)] #[relm4::component(pub)]
@ -28,16 +30,22 @@ impl SimpleComponent for ComponentsList {
_sender: ComponentSender<Self>, _sender: ComponentSender<Self>,
) -> ComponentParts<Self> { ) -> ComponentParts<Self> {
let model = ComponentsList { let model = ComponentsList {
_download_folder: init.download_folder _download_folder: init.download_folder,
show_recommended_only: true,
groups: init.groups
.into_iter()
.map(|group| {
super::ComponentGroup::builder()
.launch(group)
.detach()
})
.collect()
}; };
let widgets = view_output!(); let widgets = view_output!();
for group in init.groups { for group in &model.groups {
let group = super::ComponentGroup::builder()
.launch(group)
.detach();
widgets.group.add(group.widget()); widgets.group.add(group.widget());
} }
@ -45,8 +53,17 @@ impl SimpleComponent for ComponentsList {
} }
fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) { fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
tracing::debug!("Called about dialog event: {:?}", msg); tracing::debug!("Called components list event: {:?}", msg);
// todo match msg {
AppMsg::ShowRecommendedOnly(state) => {
self.show_recommended_only = state;
// todo
for group in &self.groups {
group.sender().send(super::group::AppMsg::ShowRecommendedOnly(state)).unwrap();
}
}
}
} }
} }

View file

@ -6,6 +6,8 @@ pub use list::*;
pub use group::*; pub use group::*;
pub use version::*; pub use version::*;
use anime_launcher_sdk::components::*;
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub struct ComponentsListPattern { pub struct ComponentsListPattern {
pub download_folder: String, pub download_folder: String,
@ -18,8 +20,47 @@ pub struct ComponentsListGroup {
pub versions: Vec<ComponentsListVersion> pub versions: Vec<ComponentsListVersion>
} }
impl From<wine::Group> for ComponentsListGroup {
fn from(group: wine::Group) -> Self {
Self {
title: group.name,
versions: group.versions.into_iter().map(|version| version.into()).collect()
}
}
}
impl From<dxvk::Group> for ComponentsListGroup {
fn from(group: dxvk::Group) -> Self {
Self {
title: group.name,
versions: group.versions.into_iter().map(|version| version.into()).collect()
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub struct ComponentsListVersion { pub struct ComponentsListVersion {
pub title: String, pub title: String,
pub url: String pub uri: String,
pub recommended: bool
}
impl From<wine::Version> for ComponentsListVersion {
fn from(version: wine::Version) -> Self {
Self {
title: version.title,
uri: version.uri,
recommended: version.recommended
}
}
}
impl From<dxvk::Version> for ComponentsListVersion {
fn from(version: dxvk::Version) -> Self {
Self {
title: version.name,
uri: version.uri,
recommended: version.recommended
}
}
} }

View file

@ -3,13 +3,14 @@ use relm4::prelude::*;
use adw::prelude::*; use adw::prelude::*;
pub struct ComponentVersion { pub struct ComponentVersion {
pub title: String pub title: String,
pub recommended: bool,
pub show_recommended_only: bool
} }
#[derive(Debug)] #[derive(Debug)]
pub enum AppMsg { pub enum AppMsg {
Install, ShowRecommendedOnly(bool)
Remove
} }
#[relm4::component(pub)] #[relm4::component(pub)]
@ -20,7 +21,10 @@ impl SimpleComponent for ComponentVersion {
view! { view! {
row = adw::ActionRow { row = adw::ActionRow {
set_title: &model.title set_title: &model.title,
#[watch]
set_visible: !model.show_recommended_only || model.recommended
} }
} }
@ -30,7 +34,9 @@ impl SimpleComponent for ComponentVersion {
_sender: ComponentSender<Self>, _sender: ComponentSender<Self>,
) -> ComponentParts<Self> { ) -> ComponentParts<Self> {
let model = ComponentVersion { let model = ComponentVersion {
title: init.title title: init.title,
recommended: init.recommended,
show_recommended_only: true
}; };
let widgets = view_output!(); let widgets = view_output!();
@ -39,8 +45,10 @@ impl SimpleComponent for ComponentVersion {
} }
fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) { fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
tracing::debug!("Called about dialog event: {:?}", msg); tracing::debug!("Called component version [{}] event: {:?}", self.title, msg);
// todo match msg {
AppMsg::ShowRecommendedOnly(state) => self.show_recommended_only = state
}
} }
} }

View file

@ -142,8 +142,10 @@ impl WidgetTemplate for General {
set_title: &tr("recommended-only"), set_title: &tr("recommended-only"),
set_subtitle: &tr("wine-recommended-description"), set_subtitle: &tr("wine-recommended-description"),
#[name(wine_recommended_only)]
add_suffix = &gtk::Switch { add_suffix = &gtk::Switch {
set_valign: gtk::Align::Center set_valign: gtk::Align::Center,
set_state: true
} }
} }
}, },
@ -162,8 +164,10 @@ impl WidgetTemplate for General {
set_title: &tr("recommended-only"), set_title: &tr("recommended-only"),
set_subtitle: &tr("dxvk-recommended-description"), set_subtitle: &tr("dxvk-recommended-description"),
#[name(dxvk_recommended_only)]
add_suffix = &gtk::Switch { add_suffix = &gtk::Switch {
set_valign: gtk::Align::Center set_valign: gtk::Align::Center,
set_state: true
} }
} }
}, },

View file

@ -3,7 +3,9 @@ use relm4::prelude::*;
use gtk::prelude::*; use gtk::prelude::*;
use adw::prelude::*; use adw::prelude::*;
use crate::ui::components::*; use anime_launcher_sdk::components::*;
use crate::ui::components::{self, *};
use crate::i18n::tr; use crate::i18n::tr;
@ -12,10 +14,16 @@ pub struct App {
dxvk_components: Controller<ComponentsList> dxvk_components: Controller<ComponentsList>
} }
#[derive(Debug)]
pub enum AppMsg {
WineRecommendedOnly(bool),
DxvkRecommendedOnly(bool)
}
#[relm4::component(pub)] #[relm4::component(pub)]
impl SimpleComponent for App { impl SimpleComponent for App {
type Init = gtk::Window; type Init = gtk::Window;
type Input = (); type Input = AppMsg;
type Output = (); type Output = ();
view! { view! {
@ -36,10 +44,24 @@ impl SimpleComponent for App {
add = model.wine_components.widget(), add = model.wine_components.widget(),
}, },
#[template_child]
wine_recommended_only {
connect_state_notify[sender] => move |switch| {
sender.input(AppMsg::WineRecommendedOnly(switch.state()));
}
},
#[template_child] #[template_child]
dxvk_versions { dxvk_versions {
add = model.dxvk_components.widget(), add = model.dxvk_components.widget(),
} },
#[template_child]
dxvk_recommended_only {
connect_state_notify[sender] => move |switch| {
sender.input(AppMsg::DxvkRecommendedOnly(switch.state()));
}
},
}, },
#[template] #[template]
@ -56,90 +78,20 @@ impl SimpleComponent for App {
fn init( fn init(
parent: Self::Init, parent: Self::Init,
root: &Self::Root, root: &Self::Root,
_sender: ComponentSender<Self>, sender: ComponentSender<Self>,
) -> ComponentParts<Self> { ) -> ComponentParts<Self> {
let model = App { let model = App {
wine_components: ComponentsList::builder() wine_components: ComponentsList::builder()
.launch(ComponentsListPattern { .launch(ComponentsListPattern {
download_folder: String::from("/tmp"), download_folder: String::from("/tmp"),
groups: vec![ groups: wine::get_groups().into_iter().map(|group| group.into()).collect()
ComponentsListGroup {
title: String::from("Test group 1"),
versions: vec![
ComponentsListVersion {
title: String::from("Test version 1"),
url: String::from("/")
},
ComponentsListVersion {
title: String::from("Test version 2"),
url: String::from("/")
},
ComponentsListVersion {
title: String::from("Test version 3"),
url: String::from("/")
}
]
},
ComponentsListGroup {
title: String::from("Test group 2"),
versions: vec![
ComponentsListVersion {
title: String::from("Test version 1"),
url: String::from("/")
},
ComponentsListVersion {
title: String::from("Test version 2"),
url: String::from("/")
},
ComponentsListVersion {
title: String::from("Test version 3"),
url: String::from("/")
}
]
}
]
}) })
.detach(), .detach(),
dxvk_components: ComponentsList::builder() dxvk_components: ComponentsList::builder()
.launch(ComponentsListPattern { .launch(ComponentsListPattern {
download_folder: String::from("/tmp"), download_folder: String::from("/tmp"),
groups: vec![ groups: dxvk::get_groups().into_iter().map(|group| group.into()).collect()
ComponentsListGroup {
title: String::from("Test group 1"),
versions: vec![
ComponentsListVersion {
title: String::from("Test version 1"),
url: String::from("/")
},
ComponentsListVersion {
title: String::from("Test version 2"),
url: String::from("/")
},
ComponentsListVersion {
title: String::from("Test version 3"),
url: String::from("/")
}
]
},
ComponentsListGroup {
title: String::from("Test group 2"),
versions: vec![
ComponentsListVersion {
title: String::from("Test version 1"),
url: String::from("/")
},
ComponentsListVersion {
title: String::from("Test version 2"),
url: String::from("/")
},
ComponentsListVersion {
title: String::from("Test version 3"),
url: String::from("/")
}
]
}
]
}) })
.detach(), .detach(),
}; };
@ -150,4 +102,20 @@ impl SimpleComponent for App {
ComponentParts { model, widgets } ComponentParts { model, widgets }
} }
fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
tracing::debug!("Called preferences window event: {:?}", msg);
match msg {
AppMsg::WineRecommendedOnly(state) => {
// todo
self.wine_components.sender().send(components::list::AppMsg::ShowRecommendedOnly(state)).unwrap();
}
AppMsg::DxvkRecommendedOnly(state) => {
// todo
self.dxvk_components.sender().send(components::list::AppMsg::ShowRecommendedOnly(state)).unwrap();
}
}
}
} }