1use fret_core::{Color, Corners, Edges, Px};
2
3use crate::ThemeSnapshot;
4use crate::element::RingStyle;
5
6#[derive(Debug, Clone)]
7pub struct TextInputStyle {
8 pub padding: Edges,
9 pub background: Color,
10 pub border: Edges,
11 pub border_color: Color,
12 pub border_color_focused: Color,
13 pub focus_ring: Option<RingStyle>,
14 pub corner_radii: Corners,
15 pub text_color: Color,
16 pub placeholder_color: Color,
17 pub selection_color: Color,
18 pub caret_color: Color,
19 pub preedit_bg_color: Color,
20 pub preedit_color: Color,
21 pub preedit_underline_color: Color,
22}
23
24impl Default for TextInputStyle {
25 fn default() -> Self {
26 Self {
27 padding: Edges {
28 top: Px(6.0),
29 right: Px(8.0),
30 bottom: Px(6.0),
31 left: Px(8.0),
32 },
33 background: Color {
34 r: 0.12,
35 g: 0.12,
36 b: 0.16,
37 a: 1.0,
38 },
39 border: Edges::all(Px(1.0)),
40 border_color: Color {
41 r: 0.0,
42 g: 0.0,
43 b: 0.0,
44 a: 0.35,
45 },
46 border_color_focused: Color {
47 r: 0.6,
48 g: 0.75,
49 b: 1.0,
50 a: 0.9,
51 },
52 focus_ring: None,
53 corner_radii: Corners::all(Px(6.0)),
54 text_color: Color {
55 r: 0.92,
56 g: 0.92,
57 b: 0.92,
58 a: 1.0,
59 },
60 placeholder_color: Color {
61 r: 0.92,
62 g: 0.92,
63 b: 0.92,
64 a: 0.5,
65 },
66 selection_color: Color {
67 r: 0.24,
68 g: 0.34,
69 b: 0.52,
70 a: 1.0,
71 },
72 caret_color: Color {
73 r: 0.90,
74 g: 0.90,
75 b: 0.92,
76 a: 1.0,
77 },
78 preedit_bg_color: Color {
79 r: 0.24,
80 g: 0.34,
81 b: 0.52,
82 a: 0.22,
83 },
84 preedit_color: Color {
85 r: 0.85,
86 g: 0.65,
87 b: 0.95,
88 a: 1.0,
89 },
90 preedit_underline_color: Color {
91 r: 0.85,
92 g: 0.65,
93 b: 0.95,
94 a: 1.0,
95 },
96 }
97 }
98}
99
100impl TextInputStyle {
101 pub fn from_theme(theme: ThemeSnapshot) -> Self {
102 Self {
103 padding: Edges {
104 top: Px(6.0),
105 right: theme.metric_token("metric.padding.sm"),
106 bottom: Px(6.0),
107 left: theme.metric_token("metric.padding.sm"),
108 },
109 background: theme.color_token("card"),
110 border: Edges::all(Px(1.0)),
111 border_color: theme.color_token("border"),
112 border_color_focused: theme.color_token("ring"),
113 focus_ring: None,
114 corner_radii: Corners::all(theme.metric_token("metric.radius.sm")),
115 text_color: theme.color_token("foreground"),
116 placeholder_color: theme.color_token("muted-foreground"),
117 selection_color: theme.color_token("selection.background"),
118 caret_color: theme.color_token("foreground"),
119 preedit_bg_color: {
120 let mut bg = theme.color_token("selection.background");
121 bg.a = (bg.a * 0.35).clamp(0.0, 1.0);
122 bg
123 },
124 preedit_color: theme.color_token("primary"),
125 preedit_underline_color: theme.color_token("primary"),
126 }
127 }
128}