core: use typography roles for text styling
This commit is contained in:
@@ -7,7 +7,7 @@ use gpui::{
|
|||||||
StatefulInteractiveElement as _, Styled as _, Window, deferred, div, ease_out_quint,
|
StatefulInteractiveElement as _, Styled as _, Window, deferred, div, ease_out_quint,
|
||||||
};
|
};
|
||||||
use gpui_native_icons::{Icon, IconRole, icon};
|
use gpui_native_icons::{Icon, IconRole, icon};
|
||||||
use gpui_native_theme::{ActiveTheme as _, ENTER_SLIDE_DISTANCE, Size};
|
use gpui_native_theme::{ActiveTheme as _, ENTER_SLIDE_DISTANCE, Size, TextRole, Typeset as _};
|
||||||
use gpui_native_utils::ResultLogErr as _;
|
use gpui_native_utils::ResultLogErr as _;
|
||||||
|
|
||||||
use crate::button::{Button, ButtonVariant};
|
use crate::button::{Button, ButtonVariant};
|
||||||
@@ -144,7 +144,6 @@ impl RenderOnce for Alert {
|
|||||||
let shadows = theme.elevations.popover.shadows();
|
let shadows = theme.elevations.popover.shadows();
|
||||||
let metrics = theme.sizes.resolve(Size::Medium);
|
let metrics = theme.sizes.resolve(Size::Medium);
|
||||||
let icon_size = metrics.icon_size;
|
let icon_size = metrics.icon_size;
|
||||||
let title_size = metrics.text_size;
|
|
||||||
let caption_size = metrics.caption_size;
|
let caption_size = metrics.caption_size;
|
||||||
|
|
||||||
div()
|
div()
|
||||||
@@ -178,11 +177,8 @@ impl RenderOnce for Alert {
|
|||||||
.when_some(self.title.clone(), |alert, title| {
|
.when_some(self.title.clone(), |alert, title| {
|
||||||
alert.child(
|
alert.child(
|
||||||
div()
|
div()
|
||||||
.text_size(title_size)
|
.typeset(TextRole::Headline, cx)
|
||||||
.text_color(foreground)
|
.text_color(foreground)
|
||||||
.when(self.message.is_some(), |title| {
|
|
||||||
title.font_weight(gpui::FontWeight::SEMIBOLD)
|
|
||||||
})
|
|
||||||
.child(title),
|
.child(title),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ use gpui::prelude::FluentBuilder as _;
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use gpui::{
|
use gpui::{
|
||||||
Animation, AnimationExt as _, AnyElement, App, DefiniteLength, ElementId, FontWeight,
|
Animation, AnimationExt as _, AnyElement, App, DefiniteLength, ElementId,
|
||||||
InteractiveElement as _, IntoElement, KeyDownEvent, MouseButton, ParentElement as _,
|
InteractiveElement as _, IntoElement, KeyDownEvent, MouseButton, ParentElement as _,
|
||||||
RenderOnce, Role, ScrollHandle, SharedString, StatefulInteractiveElement as _, Styled as _,
|
RenderOnce, Role, ScrollHandle, SharedString, StatefulInteractiveElement as _, Styled as _,
|
||||||
Window, canvas, div, ease_out_quint, relative,
|
Window, canvas, div, ease_out_quint, relative,
|
||||||
};
|
};
|
||||||
use gpui_native_icons::IconRole;
|
use gpui_native_icons::IconRole;
|
||||||
use gpui_native_theme::ActiveTheme as _;
|
use gpui_native_theme::{ActiveTheme as _, TextRole, Typeset as _};
|
||||||
|
|
||||||
use crate::button::{Button, ButtonVariant};
|
use crate::button::{Button, ButtonVariant};
|
||||||
use crate::common::{Sizable, v_flex};
|
use crate::common::{Sizable, v_flex};
|
||||||
@@ -139,7 +139,7 @@ impl RenderOnce for Dialog {
|
|||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
let (scrim_color, border, foreground, surface, radius, shadows, title_size, enter_duration) = {
|
let (scrim_color, border, foreground, surface, radius, shadows, enter_duration) = {
|
||||||
let theme = cx.theme();
|
let theme = cx.theme();
|
||||||
(
|
(
|
||||||
theme.colors.overlay,
|
theme.colors.overlay,
|
||||||
@@ -152,7 +152,6 @@ impl RenderOnce for Dialog {
|
|||||||
theme.colors.surface,
|
theme.colors.surface,
|
||||||
theme.radius.overlay,
|
theme.radius.overlay,
|
||||||
theme.elevations.dialog.shadows(),
|
theme.elevations.dialog.shadows(),
|
||||||
theme.sizes.medium.text_size,
|
|
||||||
theme.motion.overlay,
|
theme.motion.overlay,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
@@ -224,13 +223,7 @@ impl RenderOnce for Dialog {
|
|||||||
.justify_end()
|
.justify_end()
|
||||||
.gap_2()
|
.gap_2()
|
||||||
.when_some(self.title.clone(), |row, title| {
|
.when_some(self.title.clone(), |row, title| {
|
||||||
row.child(
|
row.child(div().flex_1().typeset(TextRole::Title3, cx).child(title))
|
||||||
div()
|
|
||||||
.flex_1()
|
|
||||||
.text_size(title_size)
|
|
||||||
.font_weight(FontWeight::SEMIBOLD)
|
|
||||||
.child(title),
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
.when(show_close, |row| {
|
.when(show_close, |row| {
|
||||||
row.child(
|
row.child(
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use gpui::prelude::FluentBuilder as _;
|
use gpui::prelude::FluentBuilder as _;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
App, IntoElement, ParentElement as _, RenderOnce, SharedString, StyleRefinement, Styled as _,
|
App, IntoElement, ParentElement as _, RenderOnce, SharedString, StyleRefinement, Styled as _,
|
||||||
Window, div, relative,
|
Window, div,
|
||||||
};
|
};
|
||||||
use gpui_native_icons::Icon;
|
use gpui_native_icons::Icon;
|
||||||
use gpui_native_theme::{ActiveTheme as _, Size};
|
use gpui_native_theme::{ActiveTheme as _, Size, TextRole, Typeset as _};
|
||||||
|
|
||||||
use crate::common::{StyledExt, v_flex};
|
use crate::common::{StyledExt, v_flex};
|
||||||
|
|
||||||
@@ -91,16 +91,14 @@ impl RenderOnce for EmptyState {
|
|||||||
})
|
})
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.text_size(metrics.text_size)
|
.typeset(TextRole::Title3, cx)
|
||||||
.font_weight(gpui::FontWeight::MEDIUM)
|
|
||||||
.text_color(foreground)
|
.text_color(foreground)
|
||||||
.line_height(relative(1.3))
|
|
||||||
.child(self.headline),
|
.child(self.headline),
|
||||||
)
|
)
|
||||||
.when_some(self.hint, |state, hint| {
|
.when_some(self.hint, |state, hint| {
|
||||||
state.child(
|
state.child(
|
||||||
div()
|
div()
|
||||||
.text_size(metrics.caption_size)
|
.typeset(TextRole::Subheadline, cx)
|
||||||
.text_color(muted_foreground)
|
.text_color(muted_foreground)
|
||||||
.child(hint),
|
.child(hint),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use gpui::{
|
|||||||
Styled as _, Window, div,
|
Styled as _, Window, div,
|
||||||
};
|
};
|
||||||
use gpui_native_icons::Icon;
|
use gpui_native_icons::Icon;
|
||||||
use gpui_native_theme::ActiveTheme as _;
|
use gpui_native_theme::{ActiveTheme as _, TextRole, Typeset as _};
|
||||||
use gpui_native_utils::{nav_key, paint_selectable_row, selectable_label_color};
|
use gpui_native_utils::{nav_key, paint_selectable_row, selectable_label_color};
|
||||||
|
|
||||||
/// The change reporter, fired with the next selection by pointer and keys.
|
/// The change reporter, fired with the next selection by pointer and keys.
|
||||||
@@ -243,7 +243,7 @@ impl ListItem {
|
|||||||
row.child(
|
row.child(
|
||||||
div()
|
div()
|
||||||
.flex_none()
|
.flex_none()
|
||||||
.text_sm()
|
.typeset(TextRole::Subheadline, cx)
|
||||||
.text_color(if selected {
|
.text_color(if selected {
|
||||||
theme.colors.primary_foreground
|
theme.colors.primary_foreground
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ use gpui::{
|
|||||||
Styled as _, Window, div,
|
Styled as _, Window, div,
|
||||||
};
|
};
|
||||||
use gpui_native_core::scroll_area::ScrollArea;
|
use gpui_native_core::scroll_area::ScrollArea;
|
||||||
use gpui_native_theme::ActiveTheme as _;
|
use gpui_native_theme::{ActiveTheme as _, TextRole, Typeset as _};
|
||||||
use gpui_native_utils::{nav_key, paint_selectable_row, selectable_label_color};
|
use gpui_native_utils::{nav_key, paint_selectable_row, selectable_label_color};
|
||||||
|
|
||||||
/// The change reporter, fired with the next selected row by pointer and keys.
|
/// The change reporter, fired with the next selected row by pointer and keys.
|
||||||
@@ -407,8 +407,7 @@ impl SidebarEntry {
|
|||||||
.px_2()
|
.px_2()
|
||||||
.pt_2()
|
.pt_2()
|
||||||
.pb_1()
|
.pb_1()
|
||||||
.text_sm()
|
.typeset(TextRole::Headline, cx)
|
||||||
.font_weight(gpui::FontWeight::MEDIUM)
|
|
||||||
.text_color(theme.colors.muted_foreground)
|
.text_color(theme.colors.muted_foreground)
|
||||||
.role(Role::Heading)
|
.role(Role::Heading)
|
||||||
.child(label)
|
.child(label)
|
||||||
@@ -465,7 +464,7 @@ impl SidebarEntry {
|
|||||||
row.child(
|
row.child(
|
||||||
div()
|
div()
|
||||||
.flex_none()
|
.flex_none()
|
||||||
.text_sm()
|
.typeset(TextRole::Subheadline, cx)
|
||||||
.text_color(if selected {
|
.text_color(if selected {
|
||||||
theme.colors.primary_foreground
|
theme.colors.primary_foreground
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -20,7 +20,9 @@ use gpui_native_core::button::{Button, ButtonVariant};
|
|||||||
use gpui_native_core::checkbox::Checkbox;
|
use gpui_native_core::checkbox::Checkbox;
|
||||||
use gpui_native_core::common::Sizable as _;
|
use gpui_native_core::common::Sizable as _;
|
||||||
use gpui_native_core::scrollbar::{Scrollbar, ScrollbarVisibility};
|
use gpui_native_core::scrollbar::{Scrollbar, ScrollbarVisibility};
|
||||||
use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, CODE_OVERSCROLL_MAX, Size};
|
use gpui_native_theme::{
|
||||||
|
ActiveTheme as _, BORDER_WIDTH, CODE_OVERSCROLL_MAX, Size, TextRole, Typeset as _,
|
||||||
|
};
|
||||||
use pulldown_cmark::{CodeBlockKind, Event, HeadingLevel, Options, Parser, Tag, TagEnd};
|
use pulldown_cmark::{CodeBlockKind, Event, HeadingLevel, Options, Parser, Tag, TagEnd};
|
||||||
|
|
||||||
use std::borrow::Borrow as _;
|
use std::borrow::Borrow as _;
|
||||||
@@ -32,8 +34,6 @@ use std::sync::Arc;
|
|||||||
use crate::highlight::{HighlightedCode, Language, highlight, plain};
|
use crate::highlight::{HighlightedCode, Language, highlight, plain};
|
||||||
use crate::utils::code_line;
|
use crate::utils::code_line;
|
||||||
|
|
||||||
/// Heading scale steps relative to the root font size, H1 first.
|
|
||||||
const HEADING_SCALES: [f32; 6] = [1.9, 1.5, 1.25, 1.1, 1.0, 0.95];
|
|
||||||
/// The bottom padding between sibling blocks, in root font sizes.
|
/// The bottom padding between sibling blocks, in root font sizes.
|
||||||
const BLOCK_GAP: f32 = 0.75;
|
const BLOCK_GAP: f32 = 0.75;
|
||||||
/// The tighter bottom padding between list items, in root font sizes.
|
/// The tighter bottom padding between list items, in root font sizes.
|
||||||
@@ -1497,7 +1497,12 @@ fn heading_row(
|
|||||||
cx: &App,
|
cx: &App,
|
||||||
) -> AnyElement {
|
) -> AnyElement {
|
||||||
let theme = cx.theme();
|
let theme = cx.theme();
|
||||||
let scale = HEADING_SCALES[(level.level() - 1).min(HEADING_SCALES.len() - 1)];
|
let role = match level {
|
||||||
|
MarkdownHeading::H1 => TextRole::Title,
|
||||||
|
MarkdownHeading::H2 => TextRole::Title2,
|
||||||
|
MarkdownHeading::H3 => TextRole::Title3,
|
||||||
|
MarkdownHeading::H4 | MarkdownHeading::H5 | MarkdownHeading::H6 => TextRole::Headline,
|
||||||
|
};
|
||||||
|
|
||||||
indented_frame(
|
indented_frame(
|
||||||
indent,
|
indent,
|
||||||
@@ -1508,9 +1513,7 @@ fn heading_row(
|
|||||||
ctx.block_id,
|
ctx.block_id,
|
||||||
cx,
|
cx,
|
||||||
)
|
)
|
||||||
.text_size(theme.root_font_size * scale)
|
.typeset(role, cx)
|
||||||
.line_height(relative(1.3))
|
|
||||||
.font_weight(FontWeight::SEMIBOLD)
|
|
||||||
.child(text_child(spans, ctx.block_id, ctx.piece_context(0), cx)),
|
.child(text_child(spans, ctx.block_id, ctx.piece_context(0), cx)),
|
||||||
cx,
|
cx,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user