ailloli_ui_editor/style.rs
1//! Generic editor and scrollbar visual defaults.
2
3use ailloli_ui_core::{Color, FontId};
4
5/// Visual metrics and colors used by the editor engine.
6///
7/// Geometry is in logical pixels. `caret_blink_ms <= 0` disables blinking and
8/// keeps the caret visible; callers should provide finite non-negative geometry.
9///
10/// # Examples
11///
12/// ```
13/// use ailloli_ui_core::FontId;
14/// use ailloli_ui_editor::EditorStyle;
15/// let style = EditorStyle::default();
16/// assert_eq!(style.font, FontId::Mono);
17/// assert_eq!((style.px_size, style.line_height, style.pad), (13, 18.0, 10.0));
18/// ```
19#[derive(Debug, Clone, Copy, PartialEq)]
20pub struct EditorStyle {
21 /// Editor background color.
22 pub bg: Color,
23 /// Default foreground text color.
24 pub fg: Color,
25 /// Caret color.
26 pub caret: Color,
27 /// Selection highlight color.
28 pub selection_bg: Color,
29 /// Blink half-period in milliseconds; non-positive means always visible.
30 pub caret_blink_ms: i64,
31 /// Font family identifier passed to text layout.
32 pub font: FontId,
33 /// Font size in logical pixels.
34 pub px_size: u16,
35 /// Minimum visual line height in logical pixels.
36 pub line_height: f32,
37 /// Uniform content inset in logical pixels.
38 pub pad: f32,
39}
40
41/// Supplies the dark neutral editor palette and fixed logical metrics.
42impl Default for EditorStyle {
43 /// Returns 13 px mono text, 18 px lines, 10 px padding, and 500 ms blink.
44 fn default() -> Self {
45 Self {
46 bg: Color::hex("#0f1117").expect("hex"),
47 fg: Color::hex("#ebebf0").expect("hex"),
48 caret: Color::hex("#f2f2f7").expect("hex"),
49 selection_bg: Color::hex("#2563eb59").expect("hex"),
50 caret_blink_ms: 500,
51 font: FontId::Mono,
52 px_size: 13,
53 line_height: 18.0,
54 pad: 10.0,
55 }
56 }
57}
58
59/// Visual style used by editor-owned scrollbars.
60///
61/// This mirrors the public `ScrollView` scrollbar defaults without depending on
62/// `ailloli_ui_widgets`, because the editor engine is UI-adapter agnostic.
63///
64/// # Examples
65///
66/// ```
67/// use ailloli_ui_editor::EditorScrollbarStyle;
68/// let style = EditorScrollbarStyle::default();
69/// assert_eq!((style.thickness, style.min_thumb_len, style.inset, style.radius), (6.0, 24.0, 3.0, 3.0));
70/// ```
71#[derive(Debug, Clone, Copy, PartialEq)]
72pub struct EditorScrollbarStyle {
73 /// Track color.
74 pub track_color: Color,
75 /// Scroll thumb color.
76 pub thumb_color: Color,
77 /// Overlay bar thickness in logical pixels.
78 pub thickness: f32,
79 /// Minimum thumb length in logical pixels.
80 pub min_thumb_len: f32,
81 /// Distance from viewport edges in logical pixels.
82 pub inset: f32,
83 /// Thumb/track corner radius in logical pixels.
84 pub radius: f32,
85}
86
87/// Supplies conservative overlay-scrollbar defaults.
88impl Default for EditorScrollbarStyle {
89 /// Returns a 6 px bar with 24 px minimum thumb and 3 px inset/radius.
90 fn default() -> Self {
91 Self {
92 track_color: Color::rgba(148, 163, 184, 0.16),
93 thumb_color: Color::rgba(148, 163, 184, 0.56),
94 thickness: 6.0,
95 min_thumb_len: 24.0,
96 inset: 3.0,
97 radius: 3.0,
98 }
99 }
100}
101
102/// Enables or disables editor-owned scrollbars and selects their style.
103///
104/// # Examples
105///
106/// ```
107/// use ailloli_ui_editor::EditorScrollbarConfig;
108/// let config = EditorScrollbarConfig::default();
109/// assert!(config.enabled);
110/// assert_eq!(config.style.thickness, 6.0);
111/// ```
112#[derive(Debug, Clone, Copy, PartialEq)]
113pub struct EditorScrollbarConfig {
114 /// Whether the adapter should paint editor-owned scrollbars.
115 pub enabled: bool,
116 /// Visual scrollbar metrics and colors.
117 pub style: EditorScrollbarStyle,
118}
119
120/// Enables scrollbars with [`EditorScrollbarStyle::default`].
121impl Default for EditorScrollbarConfig {
122 /// Returns enabled scrollbars.
123 fn default() -> Self {
124 Self {
125 enabled: true,
126 style: EditorScrollbarStyle::default(),
127 }
128 }
129}