Center switch knob inside its border

- Account for the track border when positioning the switch thumb.
This commit is contained in:
2026-11-16 18:43:19 +07:00
parent d59481c0a0
commit eebe267258
+4 -3
View File
@@ -6,7 +6,7 @@ use gpui::{
RenderOnce, Role, SharedString, SpringAnimation, StatefulInteractiveElement as _,
StyleRefinement, Styled as _, Toggled, Window, div, px,
};
use gpui_native_theme::{ActiveTheme as _, CONTROL_SPRING, DISABLED_OPACITY, Size};
use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, CONTROL_SPRING, DISABLED_OPACITY, Size};
use gpui_native_utils::focus_ring;
use crate::common::{Sizable, StyledExt as _, h_flex};
@@ -109,8 +109,9 @@ impl RenderOnce for Switch {
let track_width = metrics.switch_width;
let knob = metrics.switch_knob;
let inset = (track_height - knob) / 2.;
let travel = track_width - knob - inset * 2.;
// Absolute children sit inside the track's border, so remove it from the inset.
let inset = (track_height - knob) / 2. - BORDER_WIDTH;
let travel = track_width - BORDER_WIDTH * 2. - knob - inset * 2.;
let next = !self.checked;
let on_change = self.on_change;