Center switch knob inside its border
- Account for the track border when positioning the switch thumb.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user