audit input

This commit is contained in:
2026-11-07 17:00:36 +07:00
parent fd36ada35e
commit ffbb732f5f
9 changed files with 437 additions and 144 deletions
+8 -4
View File
@@ -23,6 +23,10 @@ pub use system::{AccessibilityPreferences, PartialPalette, SourceKind, SystemThe
use gpui::{App, Global, Hsla, Pixels, WindowAppearance, px};
use std::time::Duration;
/// The hairline width of the control border every button and field paints;
/// sized outside the stated metrics so control sizes match across platforms.
pub const BORDER_WIDTH: Pixels = px(1.0);
/// Light or dark, resolved from the system appearance.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, serde::Deserialize)]
#[serde(rename_all = "lowercase")]
@@ -459,17 +463,17 @@ impl SizeTable {
/// Sets the medium class's text-field height to the platform's stated value.
pub fn set_input_height(&mut self, medium_input_height: Pixels) {
let ratio = medium_input_height / self.medium.input_height;
self.small.input_height *= ratio;
self.small.input_height = (self.small.input_height * ratio).floor();
self.medium.input_height = medium_input_height;
self.large.input_height *= ratio;
self.large.input_height = (self.large.input_height * ratio).floor();
}
/// Sets the medium class's control height to the platform's stated value.
pub fn set_control_height(&mut self, medium_control_height: Pixels) {
let ratio = medium_control_height / self.medium.control_height;
self.small.control_height *= ratio;
self.small.control_height = (self.small.control_height * ratio).floor();
self.medium.control_height = medium_control_height;
self.large.control_height *= ratio;
self.large.control_height = (self.large.control_height * ratio).floor();
}
/// Sets the medium class's menu row height to the platform's stated value.
+6 -16
View File
@@ -449,17 +449,11 @@ mod tests {
let mut stated = system(ThemeVariant::Light, PartialPalette::default(), None);
stated.input_height = Some(px(24.));
let resolved = resolve(&stated, None, None);
// The medium class takes the stated height verbatim, and the other
// classes keep their derived ratio to the medium class.
assert_eq!(resolved.sizes.medium.input_height, px(24.));
// Derive what small would be without the statement, scale it by the
// stated-to-derived ratio, and compare.
let derived = SizeTable::with_root_font_size(px(16.));
let scale = px(24.) / derived.medium.input_height;
let expected_small = derived.small.input_height * scale;
assert!((resolved.sizes.small.input_height - expected_small).abs() < px(0.01));
let expected_small = (derived.small.input_height * scale).floor();
assert_eq!(resolved.sizes.small.input_height, expected_small);
}
#[test]
@@ -471,14 +465,10 @@ mod tests {
let derived = SizeTable::with_root_font_size(px(16.));
let scale = px(32.) / derived.medium.control_height;
assert!(
(resolved.sizes.small.control_height - derived.small.control_height * scale).abs()
< px(0.01)
);
assert!(
(resolved.sizes.large.control_height - derived.large.control_height * scale).abs()
< px(0.01)
);
let expected_small = (derived.small.control_height * scale).floor();
let expected_large = (derived.large.control_height * scale).floor();
assert_eq!(resolved.sizes.small.control_height, expected_small);
assert_eq!(resolved.sizes.large.control_height, expected_large);
}
#[test]