feat: unify theme system (#7)

Reviewed-on: #7
This commit was merged in pull request #7.
This commit is contained in:
2026-11-16 12:58:32 +00:00
parent 745a01d7af
commit aed3601c89
47 changed files with 888 additions and 1875 deletions
+4 -3
View File
@@ -12,7 +12,8 @@ use gpui::{
};
use gpui_native_core::scrollbar::{Scrollbar, ScrollbarHandle, ScrollbarVisibility};
use gpui_native_theme::{
ActiveTheme as _, ColorTokens, MONO_ADVANCE_RATIO, Ramps, WASH_ALPHA_SOFT,
ActiveTheme as _, CODE_GUTTER_WIDTH, CODE_LINE_HEIGHT, ColorTokens, MONO_ADVANCE_RATIO, Ramps,
WASH_ALPHA_SOFT,
};
use crate::highlight::{HighlightedCode, Language, Role, highlight};
@@ -256,7 +257,7 @@ impl Render for CodeViewState {
let colors = theme.colors;
let mono_font = theme.mono_font;
let text_size = theme.sizes.small.text_size;
let line_height = text_size * 1.5;
let line_height = text_size * CODE_LINE_HEIGHT;
let char_width = text_size * MONO_ADVANCE_RATIO;
let root_font_size = theme.root_font_size;
@@ -264,7 +265,7 @@ impl Render for CodeViewState {
let state = cx.entity();
let line_count = self.code.lines.len();
let selection = self.selection();
let gutter_width = root_font_size * 2.5;
let gutter_width = CODE_GUTTER_WIDTH;
let bounds_cell: std::rc::Rc<std::cell::RefCell<Option<Bounds<Pixels>>>> =
std::rc::Rc::new(std::cell::RefCell::new(None));
+9 -7
View File
@@ -13,7 +13,7 @@ use gpui::{
point, uniform_list,
};
use gpui_native_core::scrollbar::{Scrollbar, ScrollbarHandle, ScrollbarVisibility};
use gpui_native_theme::{ActiveTheme as _, MONO_ADVANCE_RATIO};
use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, CODE_GUTTER_WIDTH, MONO_ADVANCE_RATIO};
use similar::{Change, ChangeTag, TextDiff};
use std::ops::Range;
@@ -524,10 +524,10 @@ fn render_row(
.text_color(colors.muted_foreground)
.when(
options.indicators == DiffIndicators::Classic,
|row_element| row_element.child(div().w_10().flex_none()),
|row_element| row_element.child(div().w(CODE_GUTTER_WIDTH).flex_none()),
)
.when(options.line_numbers, |row_element| {
row_element.child(div().w_10().flex_none())
row_element.child(div().w(CODE_GUTTER_WIDTH).flex_none())
})
.when(
options.indicators == DiffIndicators::Bars && !options.line_numbers,
@@ -535,7 +535,7 @@ fn render_row(
row_element.child(
div()
.flex_none()
.border_l_4()
.border_l(BORDER_WIDTH * 4.0)
.border_color(gpui::transparent_black()),
)
},
@@ -654,14 +654,16 @@ fn render_row(
.map(|number| number.to_string())
.unwrap_or_default(),
)
.w_10()
.w(CODE_GUTTER_WIDTH)
.whitespace_nowrap()
.bg(match row.kind {
DiffRowKind::Context => wash_gutter(&colors),
_ => wash_strong(change_color),
})
.when(options.indicators == DiffIndicators::Bars, |number| {
number.border_l_4().border_color(change_color)
number
.border_l(BORDER_WIDTH * 4.0)
.border_color(change_color)
}),
)
})
@@ -672,7 +674,7 @@ fn render_row(
div()
.h_full()
.flex_none()
.border_l_4()
.border_l(BORDER_WIDTH * 4.0)
.border_color(change_color),
)
},
+17 -17
View File
@@ -9,19 +9,20 @@
use gpui::prelude::FluentBuilder as _;
use gpui::{
AnyElement, App, Bounds, ClipboardItem, Context, Div, Element, ElementId, Entity, FontStyle,
FontWeight, GlobalElementId, HighlightStyle, InspectorElementId, InteractiveElement as _,
InteractiveText, IntoElement, KeyBinding, LayoutId, ListAlignment, ListOffset, ListState,
MouseButton, MouseDownEvent, MouseMoveEvent, ObjectFit, ParentElement as _, Pixels,
Refineable as _, Render, SharedString, StatefulInteractiveElement as _, StrikethroughStyle,
StyleRefinement, Styled, StyledImage as _, StyledText, TextLayout, UnderlineStyle, Window,
actions, div, img, list, px, relative,
GlobalElementId, HighlightStyle, InspectorElementId, InteractiveElement as _, InteractiveText,
IntoElement, KeyBinding, LayoutId, ListAlignment, ListOffset, ListState, MouseButton,
MouseDownEvent, MouseMoveEvent, ObjectFit, ParentElement as _, Pixels, Refineable as _, Render,
SharedString, StatefulInteractiveElement as _, StrikethroughStyle, StyleRefinement, Styled,
StyledImage as _, StyledText, TextLayout, UnderlineStyle, Window, actions, div, img, list, px,
relative,
};
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, TextRole, Typeset as _,
ActiveTheme as _, BORDER_WIDTH, CODE_LINE_HEIGHT, CODE_OVERSCROLL_MAX, Size, TextRole,
Typeset as _,
};
use pulldown_cmark::{CodeBlockKind, Event, HeadingLevel, Options, Parser, Tag, TagEnd};
@@ -46,8 +47,6 @@ const QUOTE_INSET: f32 = 1.0;
const INDENT_STEP: f32 = 1.5;
/// The body line height.
const BODY_LINE_HEIGHT: f32 = 1.6;
/// The code line height inside fenced blocks.
const CODE_LINE_HEIGHT: f32 = 1.5;
/// The tallest a standalone image renders, in root font sizes.
const IMAGE_MAX_HEIGHT: f32 = 14.0;
/// The side of an inline image atom relative to the body text size.
@@ -1469,7 +1468,7 @@ fn block_frame(quote: bool, top: Pixels, bottom: Pixels, id: &ElementId, cx: &Ap
.pb(bottom)
.when(quote, |frame| {
frame
.border_l_2()
.border_l(BORDER_WIDTH * 2.0)
.border_color(theme.colors.border)
.pl(theme.root_font_size * QUOTE_INSET)
})
@@ -1546,8 +1545,9 @@ fn text_row(
.pr_1()
.child(match marker {
ListMarker::Bullet => div()
.text_color(theme.colors.muted_foreground)
.child("•")
.size(theme.spacing.unit)
.rounded(theme.radius.full)
.bg(theme.colors.muted_foreground)
.into_any_element(),
ListMarker::Ordered(number) => div()
.text_color(theme.colors.muted_foreground)
@@ -1721,7 +1721,7 @@ fn code_row(
.when_some(language.cloned(), |row, language| {
row.child(
div()
.text_xs()
.typeset(TextRole::Caption, cx)
.text_color(theme.colors.muted_foreground)
.child(language),
)
@@ -1845,7 +1845,7 @@ fn table_row(
.px_2()
.py_1()
.when(row.header, |cell_element| {
cell_element.font_weight(FontWeight::SEMIBOLD)
cell_element.font_weight(theme.typography.headline.weight)
})
.child(text_child(&cell.spans, &cell_id, piece, cx))
})
@@ -1981,7 +1981,7 @@ where
InlineStyle::Strong => highlights.push((
range,
HighlightStyle {
font_weight: Some(FontWeight::SEMIBOLD),
font_weight: Some(theme.typography.headline.weight),
..Default::default()
},
)),
@@ -1989,7 +1989,7 @@ where
range,
HighlightStyle {
font_style: Some(FontStyle::Italic),
font_weight: Some(FontWeight::SEMIBOLD),
font_weight: Some(theme.typography.headline.weight),
..Default::default()
},
)),
@@ -2017,7 +2017,7 @@ where
highlights.push((
range.clone(),
HighlightStyle {
color: Some(theme.colors.accent),
color: Some(theme.ramps.primary.base),
underline: Some(UnderlineStyle {
thickness: BORDER_WIDTH,
color: None,
+2 -2
View File
@@ -11,7 +11,7 @@ use gpui::StyledText;
#[cfg(any(feature = "code", feature = "markdown"))]
use gpui::{App, HighlightStyle, Hsla, IntoElement, ParentElement as _, Styled as _, div};
#[cfg(any(feature = "code", feature = "markdown"))]
use gpui_native_theme::{ActiveTheme as _, ColorTokens, Ramps};
use gpui_native_theme::{ActiveTheme as _, CODE_GUTTER_WIDTH, ColorTokens, Ramps};
#[cfg(feature = "diff")]
use gpui_native_theme::{WASH_ALPHA, WASH_ALPHA_GUTTER, WASH_ALPHA_STRONG};
@@ -74,7 +74,7 @@ where
let theme = cx.theme();
div()
.size_10()
.size(CODE_GUTTER_WIDTH)
.flex()
.items_center()
.justify_center()