implement ComboBox builder
This commit is contained in:
Generated
+25
-2
@@ -1377,6 +1377,7 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"static_vcruntime",
|
"static_vcruntime",
|
||||||
|
"strum 0.27.1",
|
||||||
"sysinfo",
|
"sysinfo",
|
||||||
"windows 0.61.1",
|
"windows 0.61.1",
|
||||||
"winreg",
|
"winreg",
|
||||||
@@ -1845,7 +1846,7 @@ dependencies = [
|
|||||||
"log",
|
"log",
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
"spirv",
|
"spirv",
|
||||||
"strum",
|
"strum 0.26.3",
|
||||||
"termcolor",
|
"termcolor",
|
||||||
"thiserror 2.0.12",
|
"thiserror 2.0.12",
|
||||||
"unicode-xid",
|
"unicode-xid",
|
||||||
@@ -2867,7 +2868,16 @@ version = "0.26.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06"
|
checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"strum_macros",
|
"strum_macros 0.26.4",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strum"
|
||||||
|
version = "0.27.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f64def088c51c9510a8579e3c5d67c65349dcf755e5479ad3d010aa6454e2c32"
|
||||||
|
dependencies = [
|
||||||
|
"strum_macros 0.27.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2883,6 +2893,19 @@ dependencies = [
|
|||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strum_macros"
|
||||||
|
version = "0.27.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c77a8c5abcaf0f9ce05d62342b7d298c346515365c36b673df4ebe3ced01fde8"
|
||||||
|
dependencies = [
|
||||||
|
"heck",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"rustversion",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.100"
|
version = "2.0.100"
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ image = { version = "0.25.6", default-features = false, features = ["png"] }
|
|||||||
open = "5.3.2"
|
open = "5.3.2"
|
||||||
serde = { version = "1.0.219", features = ["derive"] }
|
serde = { version = "1.0.219", features = ["derive"] }
|
||||||
serde_json = "1.0.140"
|
serde_json = "1.0.140"
|
||||||
|
strum = { version = "0.27.1", features = ["derive"] }
|
||||||
sysinfo = "0.34.2"
|
sysinfo = "0.34.2"
|
||||||
windows = { version = "0.61.1", features = [
|
windows = { version = "0.61.1", features = [
|
||||||
"Win32_UI_Input_KeyboardAndMouse",
|
"Win32_UI_Input_KeyboardAndMouse",
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{fmt::Display, path::PathBuf, process::Command};
|
use std::{fmt::Display, path::PathBuf, process::Command};
|
||||||
|
use strum::EnumIter;
|
||||||
use winreg::{RegKey, enums::HKEY_LOCAL_MACHINE};
|
use winreg::{RegKey, enums::HKEY_LOCAL_MACHINE};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Default, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Clone, Copy, Default, Debug, PartialEq, Eq, Serialize, Deserialize, EnumIter)]
|
||||||
pub enum Platform {
|
pub enum Platform {
|
||||||
#[default]
|
#[default]
|
||||||
Steam,
|
Steam,
|
||||||
|
|||||||
+17
-49
@@ -3,11 +3,8 @@ mod settings;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
features::{
|
features::{
|
||||||
self,
|
self, anti_afk::AntiAfk, empty_session::EmptySession, force_close::ForceClose,
|
||||||
anti_afk::AntiAfk,
|
launch::Launch,
|
||||||
empty_session::EmptySession,
|
|
||||||
force_close::ForceClose,
|
|
||||||
launch::{Launch, Platform},
|
|
||||||
},
|
},
|
||||||
gui::{persistent_state::PersistentState, settings::Settings},
|
gui::{persistent_state::PersistentState, settings::Settings},
|
||||||
util::{
|
util::{
|
||||||
@@ -170,26 +167,7 @@ impl App {
|
|||||||
if ui.button("Launch").clicked() {
|
if ui.button("Launch").clicked() {
|
||||||
features::launch::launch(&self.launch.selected);
|
features::launch::launch(&self.launch.selected);
|
||||||
};
|
};
|
||||||
egui::ComboBox::from_id_salt("")
|
build_combo_box::<features::launch::Platform>(ui, &mut self.launch.selected, "Launch");
|
||||||
.selected_text(self.launch.selected.to_string())
|
|
||||||
.width(120.0)
|
|
||||||
.show_ui(ui, |ui| {
|
|
||||||
ui.selectable_value(
|
|
||||||
&mut self.launch.selected,
|
|
||||||
Platform::Steam,
|
|
||||||
Platform::Steam.to_string(),
|
|
||||||
);
|
|
||||||
ui.selectable_value(
|
|
||||||
&mut self.launch.selected,
|
|
||||||
Platform::Rockstar,
|
|
||||||
Platform::Rockstar.to_string(),
|
|
||||||
);
|
|
||||||
ui.selectable_value(
|
|
||||||
&mut self.launch.selected,
|
|
||||||
Platform::Epic,
|
|
||||||
Platform::Epic.to_string(),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
let force_close_button = ui.add_sized(
|
let force_close_button = ui.add_sized(
|
||||||
[104.0, 0.0],
|
[104.0, 0.0],
|
||||||
@@ -305,30 +283,7 @@ impl App {
|
|||||||
fn show_settings(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
fn show_settings(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.label("Theme");
|
ui.label("Theme");
|
||||||
egui::ComboBox::from_id_salt("")
|
build_combo_box::<settings::Theme>(ui, &mut self.settings.theme, "Theme");
|
||||||
.selected_text(self.settings.theme.to_string())
|
|
||||||
.show_ui(ui, |ui| {
|
|
||||||
ui.selectable_value(
|
|
||||||
&mut self.settings.theme,
|
|
||||||
settings::Theme::CatppuccinLatte,
|
|
||||||
settings::Theme::CatppuccinLatte.to_string(),
|
|
||||||
);
|
|
||||||
ui.selectable_value(
|
|
||||||
&mut self.settings.theme,
|
|
||||||
settings::Theme::CatppuccinFrappe,
|
|
||||||
settings::Theme::CatppuccinFrappe.to_string(),
|
|
||||||
);
|
|
||||||
ui.selectable_value(
|
|
||||||
&mut self.settings.theme,
|
|
||||||
settings::Theme::CatppuccinMacchiato,
|
|
||||||
settings::Theme::CatppuccinMacchiato.to_string(),
|
|
||||||
);
|
|
||||||
ui.selectable_value(
|
|
||||||
&mut self.settings.theme,
|
|
||||||
settings::Theme::CatppuccinMocha,
|
|
||||||
settings::Theme::CatppuccinMocha.to_string(),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
ui.checkbox(&mut self.settings.start_elevated, "Always start elevated");
|
ui.checkbox(&mut self.settings.start_elevated, "Always start elevated");
|
||||||
}
|
}
|
||||||
@@ -384,6 +339,19 @@ impl Drop for App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn build_combo_box<E>(ui: &mut egui::Ui, current_value: &mut E, label: impl std::hash::Hash)
|
||||||
|
where
|
||||||
|
E: strum::IntoEnumIterator + std::fmt::Display + std::cmp::PartialEq + Copy,
|
||||||
|
{
|
||||||
|
egui::ComboBox::from_id_salt(label)
|
||||||
|
.selected_text(current_value.to_string())
|
||||||
|
.show_ui(ui, |ui| {
|
||||||
|
for v in E::iter() {
|
||||||
|
ui.selectable_value(current_value, v, v.to_string());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
fn check_debug_keycombo_pressed(ctx: &egui::Context) -> bool {
|
fn check_debug_keycombo_pressed(ctx: &egui::Context) -> bool {
|
||||||
ctx.input(|i| i.modifiers.all() && i.key_pressed(egui::Key::D))
|
ctx.input(|i| i.modifiers.all() && i.key_pressed(egui::Key::D))
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -1,7 +1,8 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
use strum::EnumIter;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, EnumIter)]
|
||||||
pub enum Theme {
|
pub enum Theme {
|
||||||
CatppuccinLatte,
|
CatppuccinLatte,
|
||||||
CatppuccinFrappe,
|
CatppuccinFrappe,
|
||||||
|
|||||||
Reference in New Issue
Block a user