mirror of
https://github.com/an-anime-team/sleepy-launcher.git
synced 2024-11-25 22:30:22 +03:00
Components list: added working "recommended only" switcher
This commit is contained in:
parent
48d7f0fc06
commit
f168862cc7
6 changed files with 163 additions and 108 deletions
|
@ -3,13 +3,15 @@ use relm4::prelude::*;
|
|||
use adw::prelude::*;
|
||||
|
||||
pub struct ComponentGroup {
|
||||
pub title: String
|
||||
pub title: String,
|
||||
pub show_recommended_only: bool,
|
||||
|
||||
pub versions: Vec<Controller<super::ComponentVersion>>
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum AppMsg {
|
||||
Install,
|
||||
Remove
|
||||
ShowRecommendedOnly(bool)
|
||||
}
|
||||
|
||||
#[relm4::component(pub)]
|
||||
|
@ -30,16 +32,22 @@ impl SimpleComponent for ComponentGroup {
|
|||
_sender: ComponentSender<Self>,
|
||||
) -> ComponentParts<Self> {
|
||||
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!();
|
||||
|
||||
for version in init.versions {
|
||||
let version = super::ComponentVersion::builder()
|
||||
.launch(version)
|
||||
.detach();
|
||||
|
||||
for version in &model.versions {
|
||||
widgets.group.add_row(version.widget());
|
||||
}
|
||||
|
||||
|
@ -47,8 +55,17 @@ impl SimpleComponent for ComponentGroup {
|
|||
}
|
||||
|
||||
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);
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,13 +3,15 @@ use relm4::prelude::*;
|
|||
use adw::prelude::*;
|
||||
|
||||
pub struct ComponentsList {
|
||||
_download_folder: String
|
||||
pub _download_folder: String,
|
||||
pub show_recommended_only: bool,
|
||||
|
||||
pub groups: Vec<Controller<super::ComponentGroup>>
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum AppMsg {
|
||||
Install,
|
||||
Remove
|
||||
ShowRecommendedOnly(bool)
|
||||
}
|
||||
|
||||
#[relm4::component(pub)]
|
||||
|
@ -28,16 +30,22 @@ impl SimpleComponent for ComponentsList {
|
|||
_sender: ComponentSender<Self>,
|
||||
) -> ComponentParts<Self> {
|
||||
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!();
|
||||
|
||||
for group in init.groups {
|
||||
let group = super::ComponentGroup::builder()
|
||||
.launch(group)
|
||||
.detach();
|
||||
|
||||
for group in &model.groups {
|
||||
widgets.group.add(group.widget());
|
||||
}
|
||||
|
||||
|
@ -45,8 +53,17 @@ impl SimpleComponent for ComponentsList {
|
|||
}
|
||||
|
||||
fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
|
||||
tracing::debug!("Called about dialog event: {:?}", msg);
|
||||
tracing::debug!("Called components list event: {:?}", msg);
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ pub use list::*;
|
|||
pub use group::*;
|
||||
pub use version::*;
|
||||
|
||||
use anime_launcher_sdk::components::*;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct ComponentsListPattern {
|
||||
pub download_folder: String,
|
||||
|
@ -18,8 +20,47 @@ pub struct ComponentsListGroup {
|
|||
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)]
|
||||
pub struct ComponentsListVersion {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,13 +3,14 @@ use relm4::prelude::*;
|
|||
use adw::prelude::*;
|
||||
|
||||
pub struct ComponentVersion {
|
||||
pub title: String
|
||||
pub title: String,
|
||||
pub recommended: bool,
|
||||
pub show_recommended_only: bool
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum AppMsg {
|
||||
Install,
|
||||
Remove
|
||||
ShowRecommendedOnly(bool)
|
||||
}
|
||||
|
||||
#[relm4::component(pub)]
|
||||
|
@ -20,7 +21,10 @@ impl SimpleComponent for ComponentVersion {
|
|||
|
||||
view! {
|
||||
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>,
|
||||
) -> ComponentParts<Self> {
|
||||
let model = ComponentVersion {
|
||||
title: init.title
|
||||
title: init.title,
|
||||
recommended: init.recommended,
|
||||
show_recommended_only: true
|
||||
};
|
||||
|
||||
let widgets = view_output!();
|
||||
|
@ -39,8 +45,10 @@ impl SimpleComponent for ComponentVersion {
|
|||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -142,8 +142,10 @@ impl WidgetTemplate for General {
|
|||
set_title: &tr("recommended-only"),
|
||||
set_subtitle: &tr("wine-recommended-description"),
|
||||
|
||||
#[name(wine_recommended_only)]
|
||||
add_suffix = >k::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_subtitle: &tr("dxvk-recommended-description"),
|
||||
|
||||
#[name(dxvk_recommended_only)]
|
||||
add_suffix = >k::Switch {
|
||||
set_valign: gtk::Align::Center
|
||||
set_valign: gtk::Align::Center,
|
||||
set_state: true
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -3,7 +3,9 @@ use relm4::prelude::*;
|
|||
use gtk::prelude::*;
|
||||
use adw::prelude::*;
|
||||
|
||||
use crate::ui::components::*;
|
||||
use anime_launcher_sdk::components::*;
|
||||
|
||||
use crate::ui::components::{self, *};
|
||||
|
||||
use crate::i18n::tr;
|
||||
|
||||
|
@ -12,10 +14,16 @@ pub struct App {
|
|||
dxvk_components: Controller<ComponentsList>
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum AppMsg {
|
||||
WineRecommendedOnly(bool),
|
||||
DxvkRecommendedOnly(bool)
|
||||
}
|
||||
|
||||
#[relm4::component(pub)]
|
||||
impl SimpleComponent for App {
|
||||
type Init = gtk::Window;
|
||||
type Input = ();
|
||||
type Input = AppMsg;
|
||||
type Output = ();
|
||||
|
||||
view! {
|
||||
|
@ -36,11 +44,25 @@ impl SimpleComponent for App {
|
|||
add = model.wine_components.widget(),
|
||||
},
|
||||
|
||||
#[template_child]
|
||||
wine_recommended_only {
|
||||
connect_state_notify[sender] => move |switch| {
|
||||
sender.input(AppMsg::WineRecommendedOnly(switch.state()));
|
||||
}
|
||||
},
|
||||
|
||||
#[template_child]
|
||||
dxvk_versions {
|
||||
add = model.dxvk_components.widget(),
|
||||
},
|
||||
|
||||
#[template_child]
|
||||
dxvk_recommended_only {
|
||||
connect_state_notify[sender] => move |switch| {
|
||||
sender.input(AppMsg::DxvkRecommendedOnly(switch.state()));
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
#[template]
|
||||
add = &super::enhancements::Enhancements,
|
||||
|
@ -56,90 +78,20 @@ impl SimpleComponent for App {
|
|||
fn init(
|
||||
parent: Self::Init,
|
||||
root: &Self::Root,
|
||||
_sender: ComponentSender<Self>,
|
||||
sender: ComponentSender<Self>,
|
||||
) -> ComponentParts<Self> {
|
||||
let model = App {
|
||||
wine_components: ComponentsList::builder()
|
||||
.launch(ComponentsListPattern {
|
||||
download_folder: String::from("/tmp"),
|
||||
groups: vec![
|
||||
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("/")
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
groups: wine::get_groups().into_iter().map(|group| group.into()).collect()
|
||||
})
|
||||
.detach(),
|
||||
|
||||
dxvk_components: ComponentsList::builder()
|
||||
.launch(ComponentsListPattern {
|
||||
download_folder: String::from("/tmp"),
|
||||
groups: vec![
|
||||
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("/")
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
groups: dxvk::get_groups().into_iter().map(|group| group.into()).collect()
|
||||
})
|
||||
.detach(),
|
||||
};
|
||||
|
@ -150,4 +102,20 @@ impl SimpleComponent for App {
|
|||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue