1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#[macro_export]
macro_rules! impl_style_builders {
([$($gen:tt)*], $ty:ty) => {
$crate::__impl_style_builders_body!([<$($gen)*>] $ty);
};
($ty:ty) => {
$crate::__impl_style_builders_body!([] $ty);
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __impl_style_builders_body {
([$($gen:tt)*] $ty:ty) => {
impl $($gen)* $ty {
// --- Background colors ---
pub fn bg(mut self, color: egui::Color32) -> Self {
self.style.bg = Some(color);
self
}
pub fn hover_bg(mut self, color: egui::Color32) -> Self {
self.style.hover_bg = Some(color);
self
}
pub fn active_bg(mut self, color: egui::Color32) -> Self {
self.style.active_bg = Some(color);
self
}
pub fn focus_bg(mut self, color: egui::Color32) -> Self {
self.style.focus_bg = Some(color);
self
}
/// Set the accent colour — maps to `selection.bg_fill` in egui
/// (slider trailing fill, text-selection highlight, focus ring).
pub fn accent(mut self, color: egui::Color32) -> Self {
self.style.accent = Some(color);
self
}
pub fn hover_accent(mut self, color: egui::Color32) -> Self {
self.style.hover_accent = Some(color);
self
}
// --- Text properties ---
pub fn text_color(mut self, color: egui::Color32) -> Self {
self.style.text_color = Some(color);
self
}
pub fn font_size(mut self, size: f32) -> Self {
self.style.font_size = Some(size);
self
}
// --- Border / Stroke ---
pub fn border(mut self, width: f32, color: egui::Color32) -> Self {
self.style.border = Some(egui::Stroke::new(width, color));
self
}
pub fn hover_border(mut self, width: f32, color: egui::Color32) -> Self {
self.style.hover_border = Some(egui::Stroke::new(width, color));
self
}
pub fn focus_border(mut self, width: f32, color: egui::Color32) -> Self {
self.style.focus_border = Some(egui::Stroke::new(width, color));
self
}
// --- Geometry ---
pub fn corner_radius(mut self, corner_radius: impl Into<egui::CornerRadius>) -> Self {
self.style.corner_radius = Some(corner_radius.into());
self
}
pub fn padding(mut self, padding: impl Into<egui::Margin>) -> Self {
self.style.padding = Some(padding.into());
self
}
pub fn margin_top(mut self, val: f32) -> Self {
let mut m = self.style.margin.unwrap_or_default();
m.top = val.round().clamp(i8::MIN as f32, i8::MAX as f32) as i8;
self.style.margin = Some(m);
self
}
pub fn margin_bottom(mut self, val: f32) -> Self {
let mut m = self.style.margin.unwrap_or_default();
m.bottom = val.round().clamp(i8::MIN as f32, i8::MAX as f32) as i8;
self.style.margin = Some(m);
self
}
pub fn margin_left(mut self, val: f32) -> Self {
let mut m = self.style.margin.unwrap_or_default();
m.left = val.round().clamp(i8::MIN as f32, i8::MAX as f32) as i8;
self.style.margin = Some(m);
self
}
pub fn margin_right(mut self, val: f32) -> Self {
let mut m = self.style.margin.unwrap_or_default();
m.right = val.round().clamp(i8::MIN as f32, i8::MAX as f32) as i8;
self.style.margin = Some(m);
self
}
// --- Sizing ---
pub fn full_width(mut self) -> Self {
self.style.full_width = true;
self
}
pub fn min_width(mut self, width: f32) -> Self {
self.style.min_width = Some(width);
self
}
pub fn max_width(mut self, width: f32) -> Self {
self.style.max_width = Some(width);
self
}
pub fn min_height(mut self, height: f32) -> Self {
self.style.min_height = Some(height);
self
}
pub fn max_height(mut self, height: f32) -> Self {
self.style.max_height = Some(height);
self
}
// --- Interaction ---
pub fn cursor(mut self, icon: egui::CursorIcon) -> Self {
self.style.cursor_icon = Some(icon);
self
}
pub fn visible(mut self, visible: bool) -> Self {
self.style.visible = Some(visible);
self
}
// --- Decorations ---
// --- Background image ---
/// Set a background texture drawn on top of `bg` fill, clipped to the
/// same rounded rect. Accepts `egui::Image`, `egui::ImageSource`, or
/// an `include_image!(...)` macro result.
///
/// Texture loading is the app's responsibility — install loaders via
/// `egui_extras::install_image_loaders` or register textures with
/// `ctx.load_texture`. egui_styled only paints, never loads.
pub fn background_image(mut self, image: impl Into<egui::Image<'static>>) -> Self {
self.style.background_image = Some(image.into());
self
}
/// Override the fill mode for `background_image`.
/// Default: [`BackgroundImageFit::Stretch`] (maps full texture over the rect).
pub fn background_image_fit(
mut self,
fit: $crate::style::shared_style::BackgroundImageFit,
) -> Self {
self.style.background_image_fit = fit;
self
}
/// Multiply the background image colour by `tint` (default: `WHITE` = no tint).
pub fn background_image_tint(mut self, tint: egui::Color32) -> Self {
self.style.background_image_tint = Some(tint);
self
}
/// Paint an offset stroke rect behind the widget.
/// Multiple calls append; each shadow uses the widget's `corner_radius`.
pub fn shadow(mut self, offset: egui::Vec2, width: f32, color: egui::Color32) -> Self {
self.style.shadows.push($crate::style::shared_style::Shadow {
offset,
stroke: egui::Stroke::new(width, color),
fill: None,
});
self
}
/// Paint a filled (+ optionally stroked) offset rect behind the widget.
/// Use for conventional drop shadows.
pub fn shadow_filled(mut self, offset: egui::Vec2, color: egui::Color32) -> Self {
self.style.shadows.push($crate::style::shared_style::Shadow {
offset,
stroke: egui::Stroke::NONE,
fill: Some(color),
});
self
}
}
impl $($gen)* $crate::apply::Apply for $ty {}
};
}