gpui_component/text/
style.rs1use std::sync::Arc;
2
3use gpui::{px, rems, Pixels, Rems, StyleRefinement};
4
5use crate::highlighter::HighlightTheme;
6
7#[derive(Clone)]
9pub struct TextViewStyle {
10 pub paragraph_gap: Rems,
12 pub heading_base_font_size: Pixels,
14 pub heading_font_size: Option<Arc<dyn Fn(u8, Pixels) -> Pixels + Send + Sync + 'static>>,
19 pub highlight_theme: Arc<HighlightTheme>,
21 pub code_block: StyleRefinement,
23 pub is_dark: bool,
24}
25
26impl PartialEq for TextViewStyle {
27 fn eq(&self, other: &Self) -> bool {
28 self.paragraph_gap == other.paragraph_gap
29 && self.heading_base_font_size == other.heading_base_font_size
30 && self.highlight_theme == other.highlight_theme
31 }
32}
33
34impl Default for TextViewStyle {
35 fn default() -> Self {
36 Self {
37 paragraph_gap: rems(1.),
38 heading_base_font_size: px(14.),
39 heading_font_size: None,
40 highlight_theme: HighlightTheme::default_light().clone(),
41 code_block: StyleRefinement::default(),
42 is_dark: false,
43 }
44 }
45}
46
47impl TextViewStyle {
48 pub fn paragraph_gap(mut self, gap: Rems) -> Self {
50 self.paragraph_gap = gap;
51 self
52 }
53
54 pub fn heading_font_size<F>(mut self, f: F) -> Self
55 where
56 F: Fn(u8, Pixels) -> Pixels + Send + Sync + 'static,
57 {
58 self.heading_font_size = Some(Arc::new(f));
59 self
60 }
61
62 pub fn code_block(mut self, style: StyleRefinement) -> Self {
64 self.code_block = style;
65 self
66 }
67}