Separated preferences pages, added better debugging

This commit is contained in:
Observer KRypt0n_ 2022-06-29 17:58:48 +02:00
parent a6940d6d62
commit 48d354cc4c
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2
9 changed files with 365 additions and 312 deletions

View file

@ -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 {};
}
}

View file

@ -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;
}
}
}
}

View file

@ -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";
}
}
}
}

View file

@ -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");

View file

@ -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: &gtk::Application) -> Self {
pub fn new(app: &gtk::Application) -> Result<Self, String> {
// 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)
}
}

View file

@ -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<T: IsA<gtk::glib::Object>>(builder: &gtk::Builder, name: &str) -> T {
builder.object::<T>(name).unwrap()
pub fn get_object<T: IsA<gtk::glib::Object>>(builder: &gtk::Builder, name: &str) -> Result<T, String> {
match builder.object::<T>(name) {
Some(object) => Ok(object),
None => Err(format!("Failed to parse object '{}'", name))
}
}

View file

@ -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<adw::PreferencesPage, String> {
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")
}
}

View file

@ -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<adw::PreferencesPage, String> {
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")
}
}

35
src/ui/preferences/mod.rs Normal file
View file

@ -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<Self, String> {
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)
}
}