From e2ec1fa7c25f07f4f204b478912863753e9a3b5b Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Thu, 12 Nov 2026 19:09:51 +0700 Subject: [PATCH] core: use typography roles for text styling --- crates/core/src/alert.rs | 8 ++------ crates/core/src/dialog.rs | 15 ++++----------- crates/core/src/empty_state.rs | 10 ++++------ crates/data/src/list.rs | 4 ++-- crates/data/src/sidebar.rs | 7 +++---- crates/editor/src/markdown.rs | 17 ++++++++++------- 6 files changed, 25 insertions(+), 36 deletions(-) diff --git a/crates/core/src/alert.rs b/crates/core/src/alert.rs index 4291484..2eda291 100644 --- a/crates/core/src/alert.rs +++ b/crates/core/src/alert.rs @@ -7,7 +7,7 @@ use gpui::{ StatefulInteractiveElement as _, Styled as _, Window, deferred, div, ease_out_quint, }; 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 crate::button::{Button, ButtonVariant}; @@ -144,7 +144,6 @@ impl RenderOnce for Alert { let shadows = theme.elevations.popover.shadows(); let metrics = theme.sizes.resolve(Size::Medium); let icon_size = metrics.icon_size; - let title_size = metrics.text_size; let caption_size = metrics.caption_size; div() @@ -178,11 +177,8 @@ impl RenderOnce for Alert { .when_some(self.title.clone(), |alert, title| { alert.child( div() - .text_size(title_size) + .typeset(TextRole::Headline, cx) .text_color(foreground) - .when(self.message.is_some(), |title| { - title.font_weight(gpui::FontWeight::SEMIBOLD) - }) .child(title), ) }) diff --git a/crates/core/src/dialog.rs b/crates/core/src/dialog.rs index 0c34639..4b5da66 100644 --- a/crates/core/src/dialog.rs +++ b/crates/core/src/dialog.rs @@ -2,13 +2,13 @@ use gpui::prelude::FluentBuilder as _; use std::rc::Rc; use gpui::{ - Animation, AnimationExt as _, AnyElement, App, DefiniteLength, ElementId, FontWeight, + Animation, AnimationExt as _, AnyElement, App, DefiniteLength, ElementId, InteractiveElement as _, IntoElement, KeyDownEvent, MouseButton, ParentElement as _, RenderOnce, Role, ScrollHandle, SharedString, StatefulInteractiveElement as _, Styled as _, Window, canvas, div, ease_out_quint, relative, }; 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::common::{Sizable, v_flex}; @@ -139,7 +139,7 @@ impl RenderOnce for Dialog { 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(); ( theme.colors.overlay, @@ -152,7 +152,6 @@ impl RenderOnce for Dialog { theme.colors.surface, theme.radius.overlay, theme.elevations.dialog.shadows(), - theme.sizes.medium.text_size, theme.motion.overlay, ) }; @@ -224,13 +223,7 @@ impl RenderOnce for Dialog { .justify_end() .gap_2() .when_some(self.title.clone(), |row, title| { - row.child( - div() - .flex_1() - .text_size(title_size) - .font_weight(FontWeight::SEMIBOLD) - .child(title), - ) + row.child(div().flex_1().typeset(TextRole::Title3, cx).child(title)) }) .when(show_close, |row| { row.child( diff --git a/crates/core/src/empty_state.rs b/crates/core/src/empty_state.rs index 2cc5ae2..cfffdfa 100644 --- a/crates/core/src/empty_state.rs +++ b/crates/core/src/empty_state.rs @@ -1,10 +1,10 @@ use gpui::prelude::FluentBuilder as _; use gpui::{ App, IntoElement, ParentElement as _, RenderOnce, SharedString, StyleRefinement, Styled as _, - Window, div, relative, + Window, div, }; 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}; @@ -91,16 +91,14 @@ impl RenderOnce for EmptyState { }) .child( div() - .text_size(metrics.text_size) - .font_weight(gpui::FontWeight::MEDIUM) + .typeset(TextRole::Title3, cx) .text_color(foreground) - .line_height(relative(1.3)) .child(self.headline), ) .when_some(self.hint, |state, hint| { state.child( div() - .text_size(metrics.caption_size) + .typeset(TextRole::Subheadline, cx) .text_color(muted_foreground) .child(hint), ) diff --git a/crates/data/src/list.rs b/crates/data/src/list.rs index 36ad026..553bb18 100644 --- a/crates/data/src/list.rs +++ b/crates/data/src/list.rs @@ -7,7 +7,7 @@ use gpui::{ Styled as _, Window, div, }; 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}; /// The change reporter, fired with the next selection by pointer and keys. @@ -243,7 +243,7 @@ impl ListItem { row.child( div() .flex_none() - .text_sm() + .typeset(TextRole::Subheadline, cx) .text_color(if selected { theme.colors.primary_foreground } else { diff --git a/crates/data/src/sidebar.rs b/crates/data/src/sidebar.rs index 78fd1b2..2f97e56 100644 --- a/crates/data/src/sidebar.rs +++ b/crates/data/src/sidebar.rs @@ -12,7 +12,7 @@ use gpui::{ Styled as _, Window, div, }; 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}; /// The change reporter, fired with the next selected row by pointer and keys. @@ -407,8 +407,7 @@ impl SidebarEntry { .px_2() .pt_2() .pb_1() - .text_sm() - .font_weight(gpui::FontWeight::MEDIUM) + .typeset(TextRole::Headline, cx) .text_color(theme.colors.muted_foreground) .role(Role::Heading) .child(label) @@ -465,7 +464,7 @@ impl SidebarEntry { row.child( div() .flex_none() - .text_sm() + .typeset(TextRole::Subheadline, cx) .text_color(if selected { theme.colors.primary_foreground } else { diff --git a/crates/editor/src/markdown.rs b/crates/editor/src/markdown.rs index 495a886..ff84cd8 100644 --- a/crates/editor/src/markdown.rs +++ b/crates/editor/src/markdown.rs @@ -20,7 +20,9 @@ use gpui_native_core::button::{Button, ButtonVariant}; use gpui_native_core::checkbox::Checkbox; use gpui_native_core::common::Sizable as _; 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 std::borrow::Borrow as _; @@ -32,8 +34,6 @@ use std::sync::Arc; use crate::highlight::{HighlightedCode, Language, highlight, plain}; 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. const BLOCK_GAP: f32 = 0.75; /// The tighter bottom padding between list items, in root font sizes. @@ -1497,7 +1497,12 @@ fn heading_row( cx: &App, ) -> AnyElement { 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( indent, @@ -1508,9 +1513,7 @@ fn heading_row( ctx.block_id, cx, ) - .text_size(theme.root_font_size * scale) - .line_height(relative(1.3)) - .font_weight(FontWeight::SEMIBOLD) + .typeset(role, cx) .child(text_child(spans, ctx.block_id, ctx.piece_context(0), cx)), cx, )