From 25acf1eef93665a3ec199c0a8a0db91e96ebc73c Mon Sep 17 00:00:00 2001 From: MCOfficer Date: Wed, 16 Sep 2026 15:20:00 +0200 Subject: [PATCH 1/2] Style sort headers to look less like buttons --- src/gui.rs | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/gui.rs b/src/gui.rs index e795201..12714ba 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -262,10 +262,47 @@ impl ThrottleApp { }); } + /// Adjust the style to make sort headers look less like regular buttons. + /// This only affects the local Ui (the Grid), not Menus or Modals. + /// TODO: Looks ugly and could affect unrelated buttons, replace with "classes" in egui 0.37+: + /// https://github.com/emilk/egui/pull/8153 + /// https://github.com/emilk/egui/blob/7ba3db/examples/styling_engine/src/main.rs + fn sort_header_button_style(&mut self, ui: &mut egui::Ui, col_selected: bool) { + let style = ui.style_mut(); + let widgets_style = &mut style.visuals.widgets; + + let transparent = egui::Color32::TRANSPARENT; + // Use a gray-ish luminance (0.3) with variable opacity -> works for light and dark theme + let selected = egui::Rgba::from_luminance_alpha(0.3, 0.15).into(); + let hovered = egui::Rgba::from_luminance_alpha(0.3, 0.25).into(); + + widgets_style.active.weak_bg_fill = hovered; // "active" = while being clicked + widgets_style.hovered.weak_bg_fill = hovered; + widgets_style.inactive.weak_bg_fill = if col_selected { selected } else { transparent }; + + widgets_style.active.bg_stroke = egui::Stroke::NONE; + widgets_style.hovered.bg_stroke = egui::Stroke::NONE; + widgets_style.inactive.bg_stroke = egui::Stroke::NONE; + } + /// Adjust the sort state when a header is clicked. fn sort_header(&mut self, ui: &mut egui::Ui, label: &str, col: SortColumn) { let text = egui::RichText::new(label).strong(); - if ui.button(text).clicked() { + let grow = egui::Atom::grow(); + + let direction_text = (self.sort_column == col) + .then_some(if self.sort_desc { "▼" } else { "▲" }) + .unwrap_or_default(); + // The default font is missing the arrows, use the bundled monospace font (Hack) instead + let direction = egui::RichText::new(direction_text).monospace(); + + self.sort_header_button_style(ui, self.sort_column == col); + let button = egui::Button::new((text, grow)) + .right_text(direction) + .min_size(ui.available_size()) + .corner_radius(0); + + if ui.add(button).clicked() { if self.sort_column == col { self.sort_desc = !self.sort_desc; } else { From f4851d00fcaf7194020f749fa9e4778eaa58c528 Mon Sep 17 00:00:00 2001 From: Francesco Gruosso <64712227+FrancescoCoding@users.noreply.github.com> Date: Wed, 16 Sep 2026 17:46:16 +0100 Subject: [PATCH 2/2] Satisfy clippy in sort_header Replace the then_some/unwrap_or_default chain with a plain if/else, bind the column comparison once, and take &self in the style helper. --- src/gui.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/gui.rs b/src/gui.rs index 57f8ae5..8077faf 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -272,7 +272,7 @@ impl ThrottleApp { /// TODO: Looks ugly and could affect unrelated buttons, replace with "classes" in egui 0.37+: /// https://github.com/emilk/egui/pull/8153 /// https://github.com/emilk/egui/blob/7ba3db/examples/styling_engine/src/main.rs - fn sort_header_button_style(&mut self, ui: &mut egui::Ui, col_selected: bool) { + fn sort_header_button_style(&self, ui: &mut egui::Ui, col_selected: bool) { let style = ui.style_mut(); let widgets_style = &mut style.visuals.widgets; @@ -294,21 +294,26 @@ impl ThrottleApp { fn sort_header(&mut self, ui: &mut egui::Ui, label: &str, col: SortColumn) { let text = egui::RichText::new(label).strong(); let grow = egui::Atom::grow(); + let col_selected = self.sort_column == col; - let direction_text = (self.sort_column == col) - .then_some(if self.sort_desc { "▼" } else { "▲" }) - .unwrap_or_default(); + let direction_text = if !col_selected { + "" + } else if self.sort_desc { + "▼" + } else { + "▲" + }; // The default font is missing the arrows, use the bundled monospace font (Hack) instead let direction = egui::RichText::new(direction_text).monospace(); - self.sort_header_button_style(ui, self.sort_column == col); + self.sort_header_button_style(ui, col_selected); let button = egui::Button::new((text, grow)) .right_text(direction) .min_size(ui.available_size()) .corner_radius(0); if ui.add(button).clicked() { - if self.sort_column == col { + if col_selected { self.sort_desc = !self.sort_desc; } else { self.sort_column = col;