fix: keep a check on the saved Power Efficiency preset

Bold alone lost to the hover fill: with the pointer on another row, two
rows were filled and nothing said which was saved. The saved preset now
keeps a check wherever the highlight goes, and the pointer moves the same
single highlight the arrow keys do. The menu is wider so Drain My Battery
still fits beside the check.
This commit is contained in:
Harold Hunt
2026-09-29 12:52:40 -04:00
parent 5a170a1b18
commit 464e476c9e
3 changed files with 33 additions and 8 deletions
+9
View File
@@ -1736,6 +1736,15 @@ fn the_power_menu_offers_only_what_the_cpus_can_tell_apart(
draw(cx);
assert_eq!(read(&view, cx, |app| app.power_menu), Some(1));
// The pointer takes the highlight, and the check stays on what is saved.
let miser = cx.debug_bounds(Power::Miser.key()).expect("row");
cx.simulate_mouse_move(miser.center(), None, Modifiers::none());
draw(cx);
assert_eq!(read(&view, cx, |app| app.power_menu), Some(0));
let balanced = cx.debug_bounds(Power::Balanced.key()).expect("row");
let check = cx.debug_bounds("power-check").expect("check");
assert!(balanced.contains(&check.center()), "check on {check:?}");
// A disabled row ignores the click and leaves the menu to be dismissed.
let drain = cx.debug_bounds(Power::DrainMyBattery.key()).expect("row");
cx.simulate_click(drain.center(), Modifiers::none());
+3 -2
View File
@@ -73,8 +73,9 @@ pub mod size {
pub const SIBLING_MENU: Rems = Rems(24.0);
pub const SIBLING_MENU_HEIGHT: Rems = Rems(32.0);
/// The Power Efficiency menu: narrower than a sibling menu, since its
/// names are four known words.
pub const POWER_MENU: Rems = Rems(20.0);
/// names are four known words, but wide enough for Drain My Battery
/// beside the check, bar and count.
pub const POWER_MENU: Rems = Rems(22.0);
/// One bar of the Power Efficiency gauge.
pub const SIGNAL_BAR: Rems = Rems(0.1875);
/// A list row's share bar.
+21 -6
View File
@@ -1106,6 +1106,15 @@ fn power_efficiency(app: &Disktree, cx: &Context<'_, Disktree>) -> Div {
.when(index == highlighted && offered, |this| {
this.bg(theme.hover_fill())
})
// The saved preset keeps its check wherever the highlight goes;
// bold alone read as losing to the fill under the pointer.
.child(div().flex_shrink_0().w(icon::SM).when(current, |this| {
this.debug_selector(|| "power-check".into()).child(
gpui_omarchy::icon(gpui_omarchy::IconName::Check)
.size(icon::SM)
.text_color(theme.accent),
)
}))
.child(
div()
.flex_1()
@@ -1136,12 +1145,18 @@ fn power_efficiency(app: &Disktree, cx: &Context<'_, Disktree>) -> Div {
// A preset this machine cannot tell apart from the one below it is
// shown, so the scale stays the same everywhere, but not offered.
let row = if offered {
row.hover(|style| style.bg(theme.hover_fill())).on_click(
cx.listener(move |this, _, window, cx| {
this.set_power_efficiency(preset, cx);
window.focus(&this.focus, cx);
}),
)
// The pointer moves the one highlight the arrows move, so two
// filled rows never compete with the check.
row.on_hover(cx.listener(move |this, hovered: &bool, _, cx| {
if *hovered && this.power_menu.is_some() {
this.power_menu = Some(index);
cx.notify();
}
}))
.on_click(cx.listener(move |this, _, window, cx| {
this.set_power_efficiency(preset, cx);
window.focus(&this.focus, cx);
}))
} else {
let below = PowerEfficiency::ALL[index - 1].name();
with_tooltip(