diff --git a/assets/ui/preferences.blp b/assets/ui/preferences.blp index cdd7d97..a19cec8 100644 --- a/assets/ui/preferences.blp +++ b/assets/ui/preferences.blp @@ -24,287 +24,6 @@ Gtk.Box preferences { }; separator: Gtk.Separator {}; - - content: Gtk.Stack stack { - Gtk.StackPage { - title: "General"; - - child: Adw.PreferencesPage { - Adw.PreferencesGroup { - title: "General"; - - Adw.ComboRow { - title: "Launcher language"; - - model: Gtk.StringList { - strings [ - "English", - "German", - "Russian", - "French", - "Chinese" - ] - }; - } - } - - Adw.PreferencesGroup { - title: "Status"; - - Adw.ActionRow { - title: "Game version"; - - Gtk.Label { - label: "2.7.0"; - - styles ["success"] - } - } - - Adw.ActionRow { - title: "Patch version"; - - Gtk.Label { - label: "2.7.0"; - - styles ["success"] - } - } - - Gtk.Box { - orientation: horizontal; - spacing: 8; - margin-top: 16; - - Gtk.Button { - label: "Revert patch"; - } - - Gtk.Button { - label: "Re-apply patch"; - } - } - } - - Adw.PreferencesGroup { - title: "Wine version"; - - Adw.ExpanderRow { - title: "Wine-GE"; - - Adw.ActionRow { - title: "7-16"; - } - - Adw.ActionRow { - title: "7-15"; - } - - Adw.ActionRow { - title: "7-14"; - } - - Adw.ActionRow { - title: "7-12"; - } - - Adw.ActionRow { - title: "7-10"; - } - - Adw.ActionRow { - title: "7-9"; - } - } - - Adw.ExpanderRow { - title: "Proton-GE"; - - Adw.ActionRow { - title: "7-16"; - } - - Adw.ActionRow { - title: "7-15"; - } - - Adw.ActionRow { - title: "7-14"; - } - - Adw.ActionRow { - title: "7-12"; - } - - Adw.ActionRow { - title: "7-10"; - } - - Adw.ActionRow { - title: "7-9"; - } - } - - Adw.ExpanderRow { - title: "Lutris"; - - Adw.ActionRow { - title: "7-16"; - } - - Adw.ActionRow { - title: "7-15"; - } - - Adw.ActionRow { - title: "7-14"; - } - - Adw.ActionRow { - title: "7-12"; - } - - Adw.ActionRow { - title: "7-10"; - } - - Adw.ActionRow { - title: "7-9"; - } - } - } - - Adw.PreferencesGroup { - title: "DXVK version"; - - Adw.ExpanderRow { - title: "Vanilla"; - - Adw.ActionRow { - title: "1.10.1"; - } - - Adw.ActionRow { - title: "1.10"; - } - - Adw.ActionRow { - title: "1.9.4"; - } - - Adw.ActionRow { - title: "1.9.3"; - } - - Adw.ActionRow { - title: "1.9.2"; - } - - Adw.ActionRow { - title: "1.9.1"; - } - } - - Adw.ExpanderRow { - title: "Async"; - subtitle: "This version is not recommended for usage as can lead to anti-cheat detection"; - - Adw.ActionRow { - title: "1.10.1"; - } - - Adw.ActionRow { - title: "1.10"; - } - - Adw.ActionRow { - title: "1.9.4"; - } - - Adw.ActionRow { - title: "1.9.3"; - } - - Adw.ActionRow { - title: "1.9.2"; - } - - Adw.ActionRow { - title: "1.9.1"; - } - } - } - }; - } - - Gtk.StackPage { - title: "Enhancements"; - - child: Adw.PreferencesPage { - title: "Enhancements"; - - Adw.PreferencesGroup { - title: "Wine"; - - Adw.ComboRow { - title: "HUD"; - - model: Gtk.StringList { - strings [ - "None", - "DXVK", - "MangoHUD" - ] - }; - } - - Adw.ComboRow { - title: "Synchronization"; - subtitle: "Technology used to synchronize inner wine events"; - - model: Gtk.StringList { - strings [ - "None", - "ESync", - "FSync", - "Futex2" - ] - }; - } - - Adw.ComboRow { - title: "FSR"; - subtitle: "AMD FSR scales game resolution while rendering the game with the lower one"; - - model: Gtk.StringList { - strings [ - "Ultra Quality", - "Quality", - "Performance", - "Balanced" - ] - }; - - Gtk.Switch { - valign: center; - } - } - } - - Adw.PreferencesGroup { - title: "Game"; - - Adw.ActionRow { - title: "Gamemode"; - subtitle: "This prioritizes the game over the rest of the processes"; - - Gtk.Switch { - valign: center; - } - } - } - }; - } - }; + content: Gtk.Stack stack {}; } } diff --git a/assets/ui/preferences_enhanced.blp b/assets/ui/preferences_enhanced.blp new file mode 100644 index 0000000..d4bc55b --- /dev/null +++ b/assets/ui/preferences_enhanced.blp @@ -0,0 +1,67 @@ +using Gtk 4.0; +using Adw 1; + +Adw.PreferencesPage enhanced_page { + title: "Enhancements"; + + Adw.PreferencesGroup { + title: "Wine"; + + Adw.ComboRow { + title: "HUD"; + + model: Gtk.StringList { + strings [ + "None", + "DXVK", + "MangoHUD" + ] + }; + } + + Adw.ComboRow { + title: "Synchronization"; + subtitle: "Technology used to synchronize inner wine events"; + + model: Gtk.StringList { + strings [ + "None", + "ESync", + "FSync", + "Futex2" + ] + }; + } + + Adw.ComboRow { + title: "FSR"; + subtitle: "AMD FSR scales game resolution while rendering the game with the lower one"; + + model: Gtk.StringList { + strings [ + "Ultra Quality", + "Quality", + "Performance", + "Balanced" + ] + }; + + Gtk.Switch { + valign: center; + } + } + } + + Adw.PreferencesGroup { + title: "Game"; + + Adw.ActionRow { + title: "Gamemode"; + subtitle: "This prioritizes the game over the rest of the processes"; + + Gtk.Switch { + valign: center; + } + } + } +} diff --git a/assets/ui/preferences_general.blp b/assets/ui/preferences_general.blp new file mode 100644 index 0000000..29c9822 --- /dev/null +++ b/assets/ui/preferences_general.blp @@ -0,0 +1,209 @@ +using Gtk 4.0; +using Adw 1; + +Adw.PreferencesPage general_page { + Adw.PreferencesGroup { + title: "General"; + + Adw.ComboRow { + title: "Launcher language"; + + model: Gtk.StringList { + strings [ + "English", + "German", + "Russian", + "French", + "Chinese" + ] + }; + } + } + + Adw.PreferencesGroup { + title: "Status"; + + Adw.ActionRow { + title: "Game version"; + + Gtk.Label { + label: "2.7.0"; + + styles ["success"] + } + } + + Adw.ActionRow { + title: "Patch version"; + + Gtk.Label { + label: "2.7.0"; + + styles ["success"] + } + } + + Gtk.Box { + orientation: horizontal; + spacing: 8; + margin-top: 16; + + Gtk.Button { + label: "Revert patch"; + } + + Gtk.Button { + label: "Re-apply patch"; + } + } + } + + Adw.PreferencesGroup { + title: "Wine version"; + + Adw.ExpanderRow { + title: "Wine-GE"; + + Adw.ActionRow { + title: "7-16"; + } + + Adw.ActionRow { + title: "7-15"; + } + + Adw.ActionRow { + title: "7-14"; + } + + Adw.ActionRow { + title: "7-12"; + } + + Adw.ActionRow { + title: "7-10"; + } + + Adw.ActionRow { + title: "7-9"; + } + } + + Adw.ExpanderRow { + title: "Proton-GE"; + + Adw.ActionRow { + title: "7-16"; + } + + Adw.ActionRow { + title: "7-15"; + } + + Adw.ActionRow { + title: "7-14"; + } + + Adw.ActionRow { + title: "7-12"; + } + + Adw.ActionRow { + title: "7-10"; + } + + Adw.ActionRow { + title: "7-9"; + } + } + + Adw.ExpanderRow { + title: "Lutris"; + + Adw.ActionRow { + title: "7-16"; + } + + Adw.ActionRow { + title: "7-15"; + } + + Adw.ActionRow { + title: "7-14"; + } + + Adw.ActionRow { + title: "7-12"; + } + + Adw.ActionRow { + title: "7-10"; + } + + Adw.ActionRow { + title: "7-9"; + } + } + } + + Adw.PreferencesGroup { + title: "DXVK version"; + + Adw.ExpanderRow { + title: "Vanilla"; + + Adw.ActionRow { + title: "1.10.1"; + } + + Adw.ActionRow { + title: "1.10"; + } + + Adw.ActionRow { + title: "1.9.4"; + } + + Adw.ActionRow { + title: "1.9.3"; + } + + Adw.ActionRow { + title: "1.9.2"; + } + + Adw.ActionRow { + title: "1.9.1"; + } + } + + Adw.ExpanderRow { + title: "Async"; + subtitle: "This version is not recommended for usage as can lead to anti-cheat detection"; + + Adw.ActionRow { + title: "1.10.1"; + } + + Adw.ActionRow { + title: "1.10"; + } + + Adw.ActionRow { + title: "1.9.4"; + } + + Adw.ActionRow { + title: "1.9.3"; + } + + Adw.ActionRow { + title: "1.9.2"; + } + + Adw.ActionRow { + title: "1.9.1"; + } + } + } +} diff --git a/src/main.rs b/src/main.rs index 4be13de..0abda41 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,7 @@ fn main() { // Init app window and show it application.connect_activate(|app| { - let app = MainApp::new(app); + let app = MainApp::new(app).unwrap(); app.open_preferences.connect_clicked(move |_| { app.leaflet.set_visible_child_name("preferences_page"); diff --git a/src/ui/main.rs b/src/ui/main.rs index 4646644..ef8c749 100644 --- a/src/ui/main.rs +++ b/src/ui/main.rs @@ -2,24 +2,7 @@ use gtk4::{self as gtk, prelude::*}; use libadwaita::{self as adw, prelude::*}; use super::get_object; - -pub struct PreferencesPage { - pub preferences: gtk::Box, - pub preferences_go_back: gtk::Button -} - -impl PreferencesPage { - pub fn new() -> Self { - let builder = gtk::Builder::from_string(include_str!("../../assets/ui/.dist/preferences.ui")); - - let result = Self { - preferences: get_object(&builder, "preferences"), - preferences_go_back: get_object(&builder, "preferences_go_back") - }; - - result - } -} +use super::preferences::PreferencesStack; pub struct App { pub window: adw::ApplicationWindow, @@ -29,32 +12,32 @@ pub struct App { } impl App { - pub fn new(app: >k::Application) -> Self { + pub fn new(app: >k::Application) -> Result { // Create builder from UI file let builder = gtk::Builder::from_string(include_str!("../../assets/ui/.dist/main.ui")); // Parse objects from builder let result = Self { - window: get_object(&builder, "window"), - leaflet: get_object(&builder, "leaflet"), - launch_game: get_object(&builder, "launch_game"), - open_preferences: get_object(&builder, "open_preferences") + window: get_object(&builder, "window")?, + leaflet: get_object(&builder, "leaflet")?, + launch_game: get_object(&builder, "launch_game")?, + open_preferences: get_object(&builder, "open_preferences")? }; // Add preferences page to the leaflet - let page = PreferencesPage::new(); + let stack = PreferencesStack::new()?; let leaflet = result.leaflet.clone(); - result.leaflet.append(&page.preferences).set_name(Some("preferences_page")); + result.leaflet.append(&stack.preferences).set_name(Some("preferences_page")); // Go back button for preferences page - page.preferences_go_back.connect_clicked(move |_| { + stack.preferences_go_back.connect_clicked(move |_| { leaflet.navigate(adw::NavigationDirection::Back); }); // Bind app to the window result.window.set_application(Some(app)); - result + Ok(result) } } diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 93d6279..83dba12 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -1,10 +1,14 @@ use gtk4::{self as gtk, prelude::*}; mod main; +mod preferences; pub use main::App as MainApp; /// This function loads object from builder or panics if it doesn't exist -pub fn get_object>(builder: >k::Builder, name: &str) -> T { - builder.object::(name).unwrap() +pub fn get_object>(builder: >k::Builder, name: &str) -> Result { + match builder.object::(name) { + Some(object) => Ok(object), + None => Err(format!("Failed to parse object '{}'", name)) + } } diff --git a/src/ui/preferences/enhanced_page.rs b/src/ui/preferences/enhanced_page.rs new file mode 100644 index 0000000..8e4a1cf --- /dev/null +++ b/src/ui/preferences/enhanced_page.rs @@ -0,0 +1,18 @@ +use gtk4::{self as gtk, prelude::*}; +use libadwaita::{self as adw, prelude::*}; + +use crate::ui::get_object; + +pub struct Page; + +impl Page { + pub fn get() -> Result { + let builder = gtk::Builder::from_string(include_str!("../../../assets/ui/.dist/preferences_enhanced.ui")); + + Ok(get_object(&builder, "enhanced_page")?) + } + + pub fn title() -> String { + String::from("Enhanced") + } +} diff --git a/src/ui/preferences/general_page.rs b/src/ui/preferences/general_page.rs new file mode 100644 index 0000000..06ecda7 --- /dev/null +++ b/src/ui/preferences/general_page.rs @@ -0,0 +1,18 @@ +use gtk4::{self as gtk, prelude::*}; +use libadwaita::{self as adw, prelude::*}; + +use crate::ui::get_object; + +pub struct Page; + +impl Page { + pub fn get() -> Result { + let builder = gtk::Builder::from_string(include_str!("../../../assets/ui/.dist/preferences_general.ui")); + + Ok(get_object(&builder, "general_page")?) + } + + pub fn title() -> String { + String::from("General") + } +} diff --git a/src/ui/preferences/mod.rs b/src/ui/preferences/mod.rs new file mode 100644 index 0000000..f7ec8ca --- /dev/null +++ b/src/ui/preferences/mod.rs @@ -0,0 +1,35 @@ +use gtk4::{self as gtk, prelude::*}; +use libadwaita::{self as adw, prelude::*}; + +use crate::ui::get_object; + +mod general_page; +mod enhanced_page; + +pub mod pages { + pub use super::general_page::Page as GeneralPage; + pub use super::enhanced_page::Page as EnhancedPage; +} + +pub struct PreferencesStack { + pub preferences: gtk::Box, + pub preferences_go_back: gtk::Button, + pub stack: gtk::Stack +} + +impl PreferencesStack { + pub fn new() -> Result { + let builder = gtk::Builder::from_string(include_str!("../../../assets/ui/.dist/preferences.ui")); + + let result = Self { + preferences: get_object(&builder, "preferences")?, + preferences_go_back: get_object(&builder, "preferences_go_back")?, + stack: get_object(&builder, "stack")? + }; + + result.stack.add_titled(&pages::GeneralPage::get()?, None, &pages::GeneralPage::title()); + result.stack.add_titled(&pages::EnhancedPage::get()?, None, &pages::EnhancedPage::title()); + + Ok(result) + } +}