Theme · Platform: one platform for buttons and caps, icon themes, frosted panes
theme::Platform moves out of typography and shell's ControlsStyle folds into it; the theme's platform starts as the system's. Window buttons Ely draws, the title bar's layout and every key cap follow it, secondary included, through typography::keys::keystroke; a title bar whose buttons the OS draws follows the OS. primitives::IconTheme lays an owner's rules by file name and extension over Ely's map, for every file icon. shell::Vibrancy fills a pane with the palette's new glass, translucent so a window opened Blurred shows its backdrop, solid under high contrast. gpui 0.2.2 has no Mica; that line stays blocked.
This commit is contained in:
1 parent
7f2205c811
commit
d3cfc71ead
30 files changed
+593
-162
No files matched your search
+16
-12
@@ -1,13 +1,13 @@
|
||||
use gpui::{
|
||||
App, ClickEvent, ElementId, FocusHandle, FontWeight, Hsla, IntoElement, Keystroke, MouseButton,
|
||||
App, ClickEvent, ElementId, FocusHandle, FontWeight, Hsla, IntoElement, MouseButton,
|
||||
RenderOnce, SharedString, Window, div, prelude::*, transparent_black,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
motion::Spinner,
|
||||
primitives::{FocusRing, Icon, IconName},
|
||||
theme::{ActiveTheme, ControlSize, IconSize, Mix, Palette, Radius, TextSize},
|
||||
typography::keys::{Platform, keystroke_labels},
|
||||
theme::{ActiveTheme, ControlSize, IconSize, Mix, Palette, Platform, Radius, TextSize},
|
||||
typography::keys::{keystroke, keystroke_labels},
|
||||
};
|
||||
|
||||
pub(crate) type ClickHandler = Box<dyn Fn(&ClickEvent, &mut Window, &mut App) + 'static>;
|
||||
@@ -112,11 +112,15 @@ pub(crate) enum Slot {
|
||||
Last,
|
||||
}
|
||||
|
||||
/// A keystroke as the platform spells it: `⌘S`, or `Ctrl+S`.
|
||||
pub(crate) fn shortcut_text(stroke: &Keystroke) -> String {
|
||||
let platform = Platform::current();
|
||||
/// Fails on a keystroke gpui cannot read, when a builder takes it.
|
||||
pub(crate) fn keystroke_of(source: &str) {
|
||||
keystroke(source, Platform::current());
|
||||
}
|
||||
|
||||
/// A keystroke in gpui key syntax as `platform` spells it: `⌘S`, or `Ctrl+S`.
|
||||
pub(crate) fn shortcut_text(source: &str, platform: Platform) -> String {
|
||||
let glue = if platform == Platform::Mac { "" } else { "+" };
|
||||
keystroke_labels(stroke, platform).join(glue)
|
||||
keystroke_labels(&keystroke(source, platform), platform).join(glue)
|
||||
}
|
||||
|
||||
#[derive(IntoElement)]
|
||||
@@ -125,7 +129,7 @@ pub struct Button {
|
||||
label: SharedString,
|
||||
icon: Option<IconName>,
|
||||
trailing_icon: Option<IconName>,
|
||||
shortcut: Option<Keystroke>,
|
||||
shortcut: Option<SharedString>,
|
||||
variant: ButtonVariant,
|
||||
size: ControlSize,
|
||||
disabled: bool,
|
||||
@@ -181,9 +185,8 @@ impl Button {
|
||||
|
||||
/// Shows the keystroke that also runs it, e.g. `"cmd-s"`. Panics on a bad keystroke.
|
||||
pub fn shortcut(mut self, keystroke: &str) -> Self {
|
||||
let parsed = Keystroke::parse(keystroke)
|
||||
.unwrap_or_else(|error| panic!("button shortcut {keystroke:?}: {error}"));
|
||||
self.shortcut = Some(parsed);
|
||||
keystroke_of(keystroke);
|
||||
self.shortcut = Some(SharedString::from(keystroke.to_string()));
|
||||
self
|
||||
}
|
||||
|
||||
@@ -226,7 +229,8 @@ impl RenderOnce for Button {
|
||||
let link = self.variant == ButtonVariant::Link;
|
||||
let icon = |name| Icon::new(name).size(icon_size).color(tone.fg);
|
||||
let radius = theme.radius(Radius::Md);
|
||||
let hint = self.shortcut.as_ref().map(shortcut_text);
|
||||
let platform = cx.theme().platform;
|
||||
let hint = self.shortcut.map(|source| shortcut_text(&source, platform));
|
||||
let spinner = (self.id.clone(), "spinner");
|
||||
let parts = div()
|
||||
.flex()
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use gpui::{
|
||||
App, ElementId, Entity, FontWeight, InteractiveElement, IntoElement, Keystroke, ParentElement,
|
||||
RenderOnce, SharedString, StatefulInteractiveElement, Styled, Window, div, prelude::*,
|
||||
App, ElementId, Entity, FontWeight, InteractiveElement, IntoElement, ParentElement, RenderOnce,
|
||||
SharedString, StatefulInteractiveElement, Styled, Window, div, prelude::*,
|
||||
};
|
||||
|
||||
use super::button::shortcut_text;
|
||||
use super::button::{keystroke_of, shortcut_text};
|
||||
use crate::{
|
||||
primitives::{FocusRing, Icon, IconName},
|
||||
theme::{ActiveTheme, ControlSize, IconSize, Radius, TextSize},
|
||||
@@ -19,7 +19,7 @@ pub struct QuickAction {
|
||||
icon: IconName,
|
||||
label: SharedString,
|
||||
note: Option<SharedString>,
|
||||
shortcut: Option<Keystroke>,
|
||||
shortcut: Option<SharedString>,
|
||||
run: Run,
|
||||
}
|
||||
|
||||
@@ -45,9 +45,8 @@ impl QuickAction {
|
||||
|
||||
/// Panics on a bad keystroke.
|
||||
pub fn shortcut(mut self, keystroke: &str) -> Self {
|
||||
let parsed = Keystroke::parse(keystroke)
|
||||
.unwrap_or_else(|error| panic!("quick action shortcut {keystroke:?}: {error}"));
|
||||
self.shortcut = Some(parsed);
|
||||
keystroke_of(keystroke);
|
||||
self.shortcut = Some(SharedString::from(keystroke.to_string()));
|
||||
self
|
||||
}
|
||||
}
|
||||
@@ -171,7 +170,7 @@ impl RenderOnce for QuickActions {
|
||||
div()
|
||||
.text_size(theme.text_size(TextSize::Xs))
|
||||
.text_color(colors.fg_subtle)
|
||||
.child(shortcut_text(stroke)),
|
||||
.child(shortcut_text(stroke, theme.platform)),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user