create trait UiExt
This commit is contained in:
+11
-13
@@ -1,6 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
features,
|
features,
|
||||||
gui::{settings::Settings, tools},
|
gui::{settings::Settings, tools, ui_ext::UiExt},
|
||||||
util::{consts::game::WINDOW_TITLE, meta::Meta, persistent_state::PersistentState, win},
|
util::{consts::game::WINDOW_TITLE, meta::Meta, persistent_state::PersistentState, win},
|
||||||
};
|
};
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
@@ -57,7 +57,7 @@ impl eframe::App for App {
|
|||||||
.exact_height(25.0)
|
.exact_height(25.0)
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| {
|
ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| {
|
||||||
tools::build_menu::<Stage>(ui, &mut self.stage);
|
ui.build_menu(&mut self.stage);
|
||||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||||
let button = ui
|
let button = ui
|
||||||
.add_enabled(!self.flags.elevated, egui::Button::new("Elevate"))
|
.add_enabled(!self.flags.elevated, egui::Button::new("Elevate"))
|
||||||
@@ -92,7 +92,7 @@ impl eframe::App for App {
|
|||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
fn show_game_section(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
fn show_game_section(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||||
tools::header(ui, "Game");
|
ui.header("Game");
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
if ui.button("Launch").clicked() {
|
if ui.button("Launch").clicked() {
|
||||||
features::launch::launch(&self.launch.selected);
|
features::launch::launch(&self.launch.selected);
|
||||||
@@ -101,7 +101,7 @@ impl App {
|
|||||||
.selected_text(self.launch.selected.to_string())
|
.selected_text(self.launch.selected.to_string())
|
||||||
.width(120.0)
|
.width(120.0)
|
||||||
.show_ui(ui, |ui| {
|
.show_ui(ui, |ui| {
|
||||||
tools::build_menu(ui, &mut self.launch.selected);
|
ui.build_menu(&mut self.launch.selected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
let force_close_button = ui.add_sized(
|
let force_close_button = ui.add_sized(
|
||||||
@@ -113,7 +113,7 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn show_session_section(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
fn show_session_section(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||||
tools::header(ui, "Session");
|
ui.header("Session");
|
||||||
ui.add_enabled_ui(!self.empty_session.disabled, |ui| {
|
ui.add_enabled_ui(!self.empty_session.disabled, |ui| {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
if ui.button("Empty current session").clicked() {
|
if ui.button("Empty current session").clicked() {
|
||||||
@@ -144,7 +144,7 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn show_network_section(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
fn show_network_section(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||||
tools::header(ui, "Network");
|
ui.header("Network");
|
||||||
egui::Frame::new()
|
egui::Frame::new()
|
||||||
.outer_margin(egui::vec2(0.0, -2.0))
|
.outer_margin(egui::vec2(0.0, -2.0))
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
@@ -152,12 +152,10 @@ impl App {
|
|||||||
let label = ui.horizontal(|ui| {
|
let label = ui.horizontal(|ui| {
|
||||||
let label = ui.label("Game's network access");
|
let label = ui.label("Game's network access");
|
||||||
ui.add_space(1.0);
|
ui.add_space(1.0);
|
||||||
ui.add(
|
ui.create_indicator_dot(self.game_networking.blocked_status.to_color32())
|
||||||
egui::Image::new(egui::include_image!("../../assets/circle.svg"))
|
.on_hover_text(
|
||||||
.max_size([4.0, 4.0].into())
|
"This turns yellow if GTA Tools\ncannot find your game.",
|
||||||
.tint(self.game_networking.blocked_status.to_color32()),
|
);
|
||||||
)
|
|
||||||
.on_hover_text("This turns yellow if GTA Tools\ncannot find your game.");
|
|
||||||
self.game_networking.if_failed_return_to_boolean();
|
self.game_networking.if_failed_return_to_boolean();
|
||||||
label
|
label
|
||||||
});
|
});
|
||||||
@@ -198,7 +196,7 @@ impl App {
|
|||||||
egui::ComboBox::from_id_salt("Theme")
|
egui::ComboBox::from_id_salt("Theme")
|
||||||
.selected_text(self.settings.theme.to_string())
|
.selected_text(self.settings.theme.to_string())
|
||||||
.show_ui(ui, |ui| {
|
.show_ui(ui, |ui| {
|
||||||
tools::build_menu(ui, &mut self.settings.theme);
|
ui.build_menu(&mut self.settings.theme);
|
||||||
});
|
});
|
||||||
if selection != self.settings.theme {
|
if selection != self.settings.theme {
|
||||||
catppuccin_egui::set_theme(ctx, self.settings.theme.into());
|
catppuccin_egui::set_theme(ctx, self.settings.theme.into());
|
||||||
|
|||||||
+2
-1
@@ -2,6 +2,7 @@ use crate::{
|
|||||||
gui::{
|
gui::{
|
||||||
app::{App, WINDOW_SIZE},
|
app::{App, WINDOW_SIZE},
|
||||||
tools,
|
tools,
|
||||||
|
ui_ext::UiExt,
|
||||||
},
|
},
|
||||||
util::consts::{
|
util::consts::{
|
||||||
APP_STORAGE_PATH,
|
APP_STORAGE_PATH,
|
||||||
@@ -55,7 +56,7 @@ impl App {
|
|||||||
egui::ComboBox::from_id_salt("blocked_status")
|
egui::ComboBox::from_id_salt("blocked_status")
|
||||||
.selected_text(&self.game_networking.blocked_status.to_string())
|
.selected_text(&self.game_networking.blocked_status.to_string())
|
||||||
.show_ui(ui, |ui| {
|
.show_ui(ui, |ui| {
|
||||||
tools::build_menu(ui, &mut self.game_networking.blocked_status);
|
ui.build_menu(&mut self.game_networking.blocked_status);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,3 +4,4 @@ mod debug;
|
|||||||
pub mod run;
|
pub mod run;
|
||||||
pub mod settings;
|
pub mod settings;
|
||||||
mod tools;
|
mod tools;
|
||||||
|
mod ui_ext;
|
||||||
|
|||||||
@@ -11,25 +11,6 @@ pub fn load_icon() -> egui::IconData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn header(ui: &mut egui::Ui, text: &str) {
|
|
||||||
ui.horizontal(|ui| {
|
|
||||||
ui.label(egui::RichText::new(text).font(egui::FontId::new(
|
|
||||||
12.5,
|
|
||||||
egui::FontFamily::Name("Ubuntu-Regular".into()),
|
|
||||||
)));
|
|
||||||
ui.add(egui::Separator::default().horizontal());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn build_menu<E>(ui: &mut egui::Ui, current_value: &mut E)
|
|
||||||
where
|
|
||||||
E: strum::IntoEnumIterator + std::fmt::Display + std::cmp::PartialEq + Copy,
|
|
||||||
{
|
|
||||||
E::iter().for_each(|variant| {
|
|
||||||
ui.selectable_value(current_value, variant, variant.to_string());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn debug_keycombo_pressed(ctx: &egui::Context) -> bool {
|
pub fn 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))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
use eframe::egui;
|
||||||
|
|
||||||
|
pub trait UiExt {
|
||||||
|
fn header(&mut self, text: &str);
|
||||||
|
fn build_menu<E>(&mut self, current_value: &mut E)
|
||||||
|
where
|
||||||
|
E: strum::IntoEnumIterator + std::fmt::Display + std::cmp::PartialEq + Copy;
|
||||||
|
fn create_indicator_dot(&mut self, colour: impl Into<egui::Color32>) -> egui::Response;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl UiExt for egui::Ui {
|
||||||
|
fn header(&mut self, text: &str) {
|
||||||
|
self.horizontal(|ui| {
|
||||||
|
ui.label(egui::RichText::new(text).font(egui::FontId::new(
|
||||||
|
12.5,
|
||||||
|
egui::FontFamily::Name("Ubuntu-Regular".into()),
|
||||||
|
)));
|
||||||
|
ui.add(egui::Separator::default().horizontal());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_menu<E>(&mut self, current_value: &mut E)
|
||||||
|
where
|
||||||
|
E: strum::IntoEnumIterator + std::fmt::Display + std::cmp::PartialEq + Copy,
|
||||||
|
{
|
||||||
|
E::iter().for_each(|variant| {
|
||||||
|
self.selectable_value(current_value, variant, variant.to_string());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create_indicator_dot(&mut self, colour: impl Into<egui::Color32>) -> egui::Response {
|
||||||
|
self.add(
|
||||||
|
egui::Image::new(egui::include_image!("../../assets/circle.svg"))
|
||||||
|
.max_size([4.0, 4.0].into())
|
||||||
|
.tint(colour),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user