From eebe267258ae79827d527263198cc0d02e9c77e8 Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Mon, 16 Nov 2026 18:43:19 +0700 Subject: [PATCH] Center switch knob inside its border - Account for the track border when positioning the switch thumb. --- crates/core/src/switch.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/core/src/switch.rs b/crates/core/src/switch.rs index 3685161..c688e95 100644 --- a/crates/core/src/switch.rs +++ b/crates/core/src/switch.rs @@ -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;