Theme · Editing: segments that give way, every color named
SegmentedControl's segments now give way when narrow, their labels ending in an ellipsis, down to twice a control's height each; past that the strip scrolls as before. The pill's border and padding moved onto the scrolling strip, and the row inside it takes that floor as its least width, so the strip scrolls exactly to its last segment. The palette macro now writes each color's name from its field: Palette and Syntax gain NAMES and token_mut for every color, the quiet fills too. Tests press a density segment and each slider, and fit the density strip in 280px with the text a step and a half larger.
This commit is contained in:
1 parent
9160fdc931
commit
84bc45df5f
5 files changed
+167
-121
No files matched your search
+69
-104
@@ -31,16 +31,33 @@ impl<const N: usize> Mix for [Hsla; N] {
|
||||
}
|
||||
|
||||
macro_rules! mixable {
|
||||
($(#[$meta:meta])* $name:ident { $($field:ident: $ty:ty),* $(,)? }) => {
|
||||
($(#[$meta:meta])* $name:ident { $($color:ident),* $(,)? ; $($field:ident: $ty:ty),* $(,)? }) => {
|
||||
$(#[$meta])*
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct $name {
|
||||
$(pub $color: Hsla,)*
|
||||
$(pub $field: $ty,)*
|
||||
}
|
||||
|
||||
impl Mix for $name {
|
||||
fn mix(&self, to: &Self, t: f32) -> Self {
|
||||
Self { $($field: self.$field.mix(&to.$field, t),)* }
|
||||
Self {
|
||||
$($color: self.$color.mix(&to.$color, t),)*
|
||||
$($field: self.$field.mix(&to.$field, t),)*
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl $name {
|
||||
/// The names of its colors, each a field's.
|
||||
pub const NAMES: &'static [&'static str] = &[$(stringify!($color)),*];
|
||||
|
||||
/// The color named `token`, a field's name; any other name fails.
|
||||
pub fn token_mut(&mut self, token: &str) -> &mut Hsla {
|
||||
match token {
|
||||
$(stringify!($color) => &mut self.$color,)*
|
||||
other => panic!("no {} color {other}", stringify!($name).to_lowercase()),
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -49,60 +66,62 @@ macro_rules! mixable {
|
||||
mixable!(
|
||||
/// Code token colors.
|
||||
Syntax {
|
||||
keyword: Hsla,
|
||||
string: Hsla,
|
||||
number: Hsla,
|
||||
comment: Hsla,
|
||||
function: Hsla,
|
||||
type_name: Hsla,
|
||||
constant: Hsla,
|
||||
property: Hsla,
|
||||
tag: Hsla,
|
||||
attribute: Hsla,
|
||||
operator: Hsla,
|
||||
punctuation: Hsla,
|
||||
variable: Hsla,
|
||||
keyword,
|
||||
string,
|
||||
number,
|
||||
comment,
|
||||
function,
|
||||
type_name,
|
||||
constant,
|
||||
property,
|
||||
tag,
|
||||
attribute,
|
||||
operator,
|
||||
punctuation,
|
||||
variable,
|
||||
;
|
||||
}
|
||||
);
|
||||
|
||||
mixable!(
|
||||
/// Semantic colors. Components read these, never literals.
|
||||
Palette {
|
||||
bg: Hsla,
|
||||
surface: Hsla,
|
||||
sunken: Hsla,
|
||||
overlay: Hsla,
|
||||
hover: Hsla,
|
||||
active: Hsla,
|
||||
border: Hsla,
|
||||
border_strong: Hsla,
|
||||
fg: Hsla,
|
||||
fg_muted: Hsla,
|
||||
fg_subtle: Hsla,
|
||||
fg_disabled: Hsla,
|
||||
accent: Hsla,
|
||||
accent_hover: Hsla,
|
||||
on_accent: Hsla,
|
||||
on_media: Hsla,
|
||||
focus: Hsla,
|
||||
link: Hsla,
|
||||
selection: Hsla,
|
||||
success: Hsla,
|
||||
warning: Hsla,
|
||||
danger: Hsla,
|
||||
info: Hsla,
|
||||
success_subtle: Hsla,
|
||||
warning_subtle: Hsla,
|
||||
danger_subtle: Hsla,
|
||||
info_subtle: Hsla,
|
||||
backdrop: Hsla,
|
||||
media_backdrop: Hsla,
|
||||
shimmer: Hsla,
|
||||
shadow: Hsla,
|
||||
tooltip_bg: Hsla,
|
||||
tooltip_fg: Hsla,
|
||||
paper: Hsla,
|
||||
ink: Hsla,
|
||||
bg,
|
||||
surface,
|
||||
sunken,
|
||||
overlay,
|
||||
hover,
|
||||
active,
|
||||
border,
|
||||
border_strong,
|
||||
fg,
|
||||
fg_muted,
|
||||
fg_subtle,
|
||||
fg_disabled,
|
||||
accent,
|
||||
accent_hover,
|
||||
on_accent,
|
||||
on_media,
|
||||
focus,
|
||||
link,
|
||||
selection,
|
||||
success,
|
||||
warning,
|
||||
danger,
|
||||
info,
|
||||
success_subtle,
|
||||
warning_subtle,
|
||||
danger_subtle,
|
||||
info_subtle,
|
||||
backdrop,
|
||||
media_backdrop,
|
||||
shimmer,
|
||||
shadow,
|
||||
tooltip_bg,
|
||||
tooltip_fg,
|
||||
paper,
|
||||
ink,
|
||||
;
|
||||
chart: [Hsla; 8],
|
||||
ansi: [Hsla; 16],
|
||||
syntax: Syntax,
|
||||
@@ -122,61 +141,7 @@ pub const HUE_NAMES: [&str; 8] = [
|
||||
"Blue", "Teal", "Ochre", "Rose", "Violet", "Green", "Rust", "Cyan",
|
||||
];
|
||||
|
||||
impl Syntax {
|
||||
/// The color of the token kind named `token`, a field's name; any other name fails.
|
||||
pub fn token_mut(&mut self, token: &str) -> &mut Hsla {
|
||||
match token {
|
||||
"keyword" => &mut self.keyword,
|
||||
"string" => &mut self.string,
|
||||
"number" => &mut self.number,
|
||||
"comment" => &mut self.comment,
|
||||
"function" => &mut self.function,
|
||||
"type_name" => &mut self.type_name,
|
||||
"constant" => &mut self.constant,
|
||||
"property" => &mut self.property,
|
||||
"tag" => &mut self.tag,
|
||||
"attribute" => &mut self.attribute,
|
||||
"operator" => &mut self.operator,
|
||||
"punctuation" => &mut self.punctuation,
|
||||
"variable" => &mut self.variable,
|
||||
other => panic!("no syntax color {other}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Palette {
|
||||
/// The color named `token`, a field's name; any other name fails.
|
||||
pub fn token_mut(&mut self, token: &str) -> &mut Hsla {
|
||||
match token {
|
||||
"bg" => &mut self.bg,
|
||||
"surface" => &mut self.surface,
|
||||
"sunken" => &mut self.sunken,
|
||||
"overlay" => &mut self.overlay,
|
||||
"hover" => &mut self.hover,
|
||||
"active" => &mut self.active,
|
||||
"border" => &mut self.border,
|
||||
"border_strong" => &mut self.border_strong,
|
||||
"fg" => &mut self.fg,
|
||||
"fg_muted" => &mut self.fg_muted,
|
||||
"fg_subtle" => &mut self.fg_subtle,
|
||||
"fg_disabled" => &mut self.fg_disabled,
|
||||
"accent" => &mut self.accent,
|
||||
"accent_hover" => &mut self.accent_hover,
|
||||
"on_accent" => &mut self.on_accent,
|
||||
"focus" => &mut self.focus,
|
||||
"link" => &mut self.link,
|
||||
"selection" => &mut self.selection,
|
||||
"success" => &mut self.success,
|
||||
"warning" => &mut self.warning,
|
||||
"danger" => &mut self.danger,
|
||||
"info" => &mut self.info,
|
||||
"tooltip_bg" => &mut self.tooltip_bg,
|
||||
"tooltip_fg" => &mut self.tooltip_fg,
|
||||
"shadow" => &mut self.shadow,
|
||||
other => panic!("no palette color {other}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// The chart color at `hue`; a hue past the chart fails, naming `owner`.
|
||||
pub fn hue(&self, hue: usize, owner: impl std::fmt::Display) -> Hsla {
|
||||
*self
|
||||
|
||||
+22
-5
@@ -1,6 +1,6 @@
|
||||
use gpui::{TestAppContext, hsla};
|
||||
|
||||
use super::{ActiveTheme, Mode, Palette, Theme};
|
||||
use super::{ActiveTheme, Mode, Palette, Syntax, Theme};
|
||||
|
||||
/// An owner's palette serves its own mode; the other keeps Ely's, and none brings Ely's back.
|
||||
#[gpui::test]
|
||||
@@ -19,12 +19,29 @@ fn an_owners_palette_serves_its_mode_alone(cx: &mut TestAppContext) {
|
||||
assert_eq!(cx.read(|cx| cx.theme().palette()), Palette::light(false));
|
||||
}
|
||||
|
||||
/// Every color of the palette and of code answers to its field's name, the quiet fills too.
|
||||
#[test]
|
||||
fn every_named_color_answers() {
|
||||
fn every_color_answers_to_its_name() {
|
||||
let mut palette = Palette::light(false);
|
||||
*palette.token_mut("accent") = hsla(0.1, 0.2, 0.3, 1.0);
|
||||
assert_eq!(palette.accent, hsla(0.1, 0.2, 0.3, 1.0));
|
||||
*palette.syntax.token_mut("comment") = hsla(0.4, 0.2, 0.3, 1.0);
|
||||
for (ix, name) in Palette::NAMES.iter().enumerate() {
|
||||
*palette.token_mut(name) = hsla(ix as f32 / 64.0, 0.5, 0.5, 1.0);
|
||||
}
|
||||
assert_eq!(Palette::NAMES.len(), 35, "every color of the palette");
|
||||
let at = |name: &str| {
|
||||
Palette::NAMES
|
||||
.iter()
|
||||
.position(|each| *each == name)
|
||||
.expect("a name")
|
||||
};
|
||||
assert_eq!(
|
||||
palette.success_subtle,
|
||||
hsla(at("success_subtle") as f32 / 64.0, 0.5, 0.5, 1.0)
|
||||
);
|
||||
assert_eq!(palette.ink, hsla(at("ink") as f32 / 64.0, 0.5, 0.5, 1.0));
|
||||
for name in Syntax::NAMES {
|
||||
*palette.syntax.token_mut(name) = hsla(0.4, 0.2, 0.3, 1.0);
|
||||
}
|
||||
assert_eq!(Syntax::NAMES.len(), 13, "every color of code");
|
||||
assert_eq!(palette.syntax.comment, hsla(0.4, 0.2, 0.3, 1.0));
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user