From 6248e8379ffd11ea6d02551edc4eaef56acd1be7 Mon Sep 17 00:00:00 2001 From: futile Date: Tue, 8 Apr 2025 10:50:34 +0100 Subject: [PATCH] change ui stuff --- src/gui.rs | 24 +++++++++++++++++++----- src/util/mod.rs | 1 + src/util/ui_ext.rs | 21 +++++++++++++++++++++ 3 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 src/util/ui_ext.rs diff --git a/src/gui.rs b/src/gui.rs index 395e07a..ec92708 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -9,6 +9,7 @@ use crate::{ util::{ consts::{ENHANCED, LEGACY}, elevation, + ui_ext::UiExt, }, }; use eframe::egui; @@ -89,6 +90,7 @@ impl eframe::App for App { self.launch.selected = persistent_state.launcher; } } + ctx.style_mut(|style| style.spacing.item_spacing = egui::vec2(3.0, 3.0)); self.initialized = true; } self.run_timers(); @@ -212,7 +214,10 @@ impl App { ); }); }); - let force_close_button = ui.button(&self.force_close.button_text); + let force_close_button = ui.add_sized_left_aligned( + [105.0, 0.0], + egui::Button::new(&self.force_close.button_text), + ); if force_close_button.clicked() && !self.force_close.prompting { self.force_close.prompting(); self.current_frame = true; @@ -244,7 +249,7 @@ impl App { }); }); ui.checkbox(&mut self.anti_afk.enabled, "Anti AFK") - .on_hover_text("You should be tabbed in\nwhile this is enabled."); + .on_hover_text("You should be tabbed in\nfor this to work."); if self.anti_afk.enabled && self.anti_afk.interval.elapsed() >= features::anti_afk::INTERVAL { features::anti_afk::activate(); @@ -258,12 +263,21 @@ impl App { .stroke(egui::Stroke::new(1.0, THEME.overlay1)) .show(ui, |ui| { let response = ui.add_enabled_ui(self.elevated, |ui| { - ui.label("Game's network access"); + let label = ui.label("Game's network access"); ui.horizontal(|ui| { - if ui.button("Block").clicked() { + let available_width = label.rect.width(); + let spacing = ui.spacing().item_spacing.x; + let button_width = (available_width - spacing) / 2.0; + if ui + .add_sized([button_width, 18.0], egui::Button::new("Block")) + .clicked() + { features::game_networking::block_all(&mut self.sysinfo); }; - if ui.button("Unblock").clicked() { + if ui + .add_sized([button_width, 18.0], egui::Button::new("Unblock")) + .clicked() + { features::game_networking::unblock_all(); }; }); diff --git a/src/util/mod.rs b/src/util/mod.rs index 69cbec7..0cbd0e7 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -1,3 +1,4 @@ pub mod consts; pub mod countdown; pub mod elevation; +pub mod ui_ext; diff --git a/src/util/ui_ext.rs b/src/util/ui_ext.rs new file mode 100644 index 0000000..b11e592 --- /dev/null +++ b/src/util/ui_ext.rs @@ -0,0 +1,21 @@ +use eframe::egui; + +pub trait UiExt { + fn add_sized_left_aligned( + &mut self, + max_size: impl Into, + widget: impl egui::Widget, + ) -> egui::Response; +} + +impl UiExt for egui::Ui { + fn add_sized_left_aligned( + &mut self, + max_size: impl Into, + widget: impl egui::Widget, + ) -> egui::Response { + let layout = egui::Layout::top_down_justified(egui::Align::LEFT); + self.allocate_ui_with_layout(max_size.into(), layout, |ui| ui.add(widget)) + .inner + } +}