mirror of
https://github.com/13hannes11/toolbx-tuner.git
synced 2024-09-03 23:21:00 +02:00
refactor into separate files for app structure
This commit is contained in:
1
src/ui/components/mod.rs
Normal file
1
src/ui/components/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod toolbox_settings;
|
||||
4
src/ui/components/toolbox_settings/messages.rs
Normal file
4
src/ui/components/toolbox_settings/messages.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
pub enum ToolboxSettingsDialogMsg {
|
||||
Show,
|
||||
Close,
|
||||
}
|
||||
4
src/ui/components/toolbox_settings/mod.rs
Normal file
4
src/ui/components/toolbox_settings/mod.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
pub mod messages;
|
||||
pub mod model;
|
||||
pub mod update;
|
||||
pub mod widgets;
|
||||
20
src/ui/components/toolbox_settings/model.rs
Normal file
20
src/ui/components/toolbox_settings/model.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
use relm4::Sender;
|
||||
use relm4::{Model, RelmComponent};
|
||||
|
||||
use crate::ui::app::model::AppModel;
|
||||
|
||||
use super::{messages::ToolboxSettingsDialogMsg, widgets::ToolboxSettingsDialogWidgets};
|
||||
|
||||
#[derive(relm4::Components)]
|
||||
pub struct AppComponents {
|
||||
pub toolbox_settings_dialog: RelmComponent<ToolboxSettingsDialogModel, AppModel>,
|
||||
}
|
||||
pub struct ToolboxSettingsDialogModel {
|
||||
pub hidden: bool,
|
||||
}
|
||||
|
||||
impl Model for ToolboxSettingsDialogModel {
|
||||
type Msg = ToolboxSettingsDialogMsg;
|
||||
type Widgets = ToolboxSettingsDialogWidgets;
|
||||
type Components = ();
|
||||
}
|
||||
24
src/ui/components/toolbox_settings/update.rs
Normal file
24
src/ui/components/toolbox_settings/update.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
use relm4::{ComponentUpdate, Sender};
|
||||
|
||||
use crate::ui::app::{messages::AppMsg, model::AppModel};
|
||||
|
||||
use super::{messages::ToolboxSettingsDialogMsg, model::ToolboxSettingsDialogModel};
|
||||
|
||||
impl ComponentUpdate<AppModel> for ToolboxSettingsDialogModel {
|
||||
fn init_model(_parent_model: &AppModel) -> Self {
|
||||
ToolboxSettingsDialogModel { hidden: true }
|
||||
}
|
||||
|
||||
fn update(
|
||||
&mut self,
|
||||
msg: ToolboxSettingsDialogMsg,
|
||||
_components: &(),
|
||||
_sender: Sender<ToolboxSettingsDialogMsg>,
|
||||
parent_sender: Sender<AppMsg>,
|
||||
) {
|
||||
match msg {
|
||||
ToolboxSettingsDialogMsg::Show => self.hidden = false,
|
||||
ToolboxSettingsDialogMsg::Close => self.hidden = true,
|
||||
}
|
||||
}
|
||||
}
|
||||
89
src/ui/components/toolbox_settings/widgets.rs
Normal file
89
src/ui/components/toolbox_settings/widgets.rs
Normal file
@@ -0,0 +1,89 @@
|
||||
use relm4::adw;
|
||||
use relm4::adw::prelude::BoxExt;
|
||||
use relm4::adw::prelude::GtkWindowExt;
|
||||
use relm4::adw::prelude::ListBoxRowExt;
|
||||
use relm4::adw::prelude::WidgetExt;
|
||||
use relm4::adw::traits::ActionRowExt;
|
||||
use relm4::adw::traits::PreferencesGroupExt;
|
||||
use relm4::adw::traits::PreferencesPageExt;
|
||||
use relm4::adw::traits::PreferencesRowExt;
|
||||
use relm4::adw::traits::PreferencesWindowExt;
|
||||
use relm4::gtk;
|
||||
use relm4::send;
|
||||
use relm4::WidgetPlus;
|
||||
use relm4::Widgets;
|
||||
|
||||
use crate::ui::app::model::AppModel;
|
||||
use crate::ui::components::toolbox_settings::messages::ToolboxSettingsDialogMsg;
|
||||
use crate::ui::ui_strings::FOLDER_PICKER_ICON;
|
||||
use crate::ui::ui_strings::FOLDER_PICKER_TOOLTIP;
|
||||
|
||||
use super::model::ToolboxSettingsDialogModel;
|
||||
|
||||
#[relm4::widget(pub)]
|
||||
impl Widgets<ToolboxSettingsDialogModel, AppModel> for ToolboxSettingsDialogWidgets {
|
||||
view! {
|
||||
adw::PreferencesWindow {
|
||||
set_title: Some("Preferences: <Toolbox_name>"),
|
||||
set_transient_for: parent!{Some(&parent_widgets.main_window)},
|
||||
set_modal: true,
|
||||
set_visible: watch!(!model.hidden),
|
||||
connect_close_request(sender) => move |_| {
|
||||
send!(sender, ToolboxSettingsDialogMsg::Close);
|
||||
gtk::Inhibit(true)
|
||||
},
|
||||
add = &adw::PreferencesPage {
|
||||
add = &adw::PreferencesGroup {
|
||||
set_title: "Updates",
|
||||
add = &adw::PreferencesRow {
|
||||
set_title: "Update Policy",
|
||||
set_child = Some(&adw::ActionRow) {
|
||||
set_title: "Update Policy",
|
||||
add_suffix = >k::Box {
|
||||
append = >k::DropDown::from_strings(&[
|
||||
"Update automatically",
|
||||
"Notify about updates",
|
||||
"Do nothing"
|
||||
]) {
|
||||
set_margin_all: 15,
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
add = &adw::PreferencesGroup {
|
||||
set_title: "Home Folder",
|
||||
add = &adw::PreferencesRow {
|
||||
set_title: "Seperate Home Folder",
|
||||
set_child = Some(&adw::ActionRow) {
|
||||
set_title: "Use separate home folder",
|
||||
add_suffix = >k::Box {
|
||||
append = >k::Switch {
|
||||
set_margin_all: 15,
|
||||
set_tooltip_text: Some("Use separate home folder"),
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
add = &adw::PreferencesRow {
|
||||
set_title: "Home Folder Path",
|
||||
set_child = Some(&adw::ActionRow) {
|
||||
set_title: "Home folder path",
|
||||
add_suffix = >k::Box {
|
||||
set_margin_all: 15,
|
||||
add_css_class: "linked",
|
||||
append = >k::Entry {
|
||||
set_hexpand: true,
|
||||
},
|
||||
append = >k::Button::from_icon_name(FOLDER_PICKER_ICON) {
|
||||
set_tooltip_text: Some(FOLDER_PICKER_TOOLTIP),
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user