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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
#[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 ---
/// Set the base background fill colour.
pub fn bg(mut self, color: egui::Color32) -> Self {
self.style.bg = Some(color);
self
}
/// Background fill while the pointer is hovering. Falls back to
/// [`bg`](Self::bg) when unset.
pub fn hover_bg(mut self, color: egui::Color32) -> Self {
self.style.hover_bg = Some(color);
self
}
/// Background fill while the widget is pressed/active. Falls back to
/// [`hover_bg`](Self::hover_bg) / [`bg`](Self::bg) when unset.
pub fn active_bg(mut self, color: egui::Color32) -> Self {
self.style.active_bg = Some(color);
self
}
/// Background fill while the widget has keyboard focus. Falls back to
/// [`bg`](Self::bg) when unset.
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
}
/// Accent colour while hovering. Falls back to [`accent`](Self::accent)
/// when unset.
pub fn hover_accent(mut self, color: egui::Color32) -> Self {
self.style.hover_accent = Some(color);
self
}
// --- Text properties ---
/// Set the text/foreground colour for the widget's label.
pub fn text_color(mut self, color: egui::Color32) -> Self {
self.style.text_color = Some(color);
self
}
/// Text/foreground colour while the pointer is hovering. Falls back
/// to [`text_color`](Self::text_color) when unset.
pub fn hover_text_color(mut self, color: egui::Color32) -> Self {
self.style.hover_text_color = Some(color);
self
}
/// Text/foreground colour while the widget has keyboard focus.
/// Falls back to [`hover_text_color`](Self::hover_text_color) /
/// [`text_color`](Self::text_color) when unset.
pub fn focus_text_color(mut self, color: egui::Color32) -> Self {
self.style.focus_text_color = Some(color);
self
}
/// Set the label font size in points. On widgets with a dedicated
/// `font` builder, an explicit `font` takes precedence.
pub fn font_size(mut self, size: f32) -> Self {
self.style.font_size = Some(size);
self
}
// --- Border / Stroke ---
/// Set the base border stroke (`width` in points, `color`).
pub fn border(mut self, width: f32, color: egui::Color32) -> Self {
self.style.border = Some(egui::Stroke::new(width, color));
self
}
/// Border stroke while hovering. Falls back to [`border`](Self::border)
/// when unset.
pub fn hover_border(mut self, width: f32, color: egui::Color32) -> Self {
self.style.hover_border = Some(egui::Stroke::new(width, color));
self
}
/// Border stroke while focused. Falls back to [`border`](Self::border)
/// when unset.
pub fn focus_border(mut self, width: f32, color: egui::Color32) -> Self {
self.style.focus_border = Some(egui::Stroke::new(width, color));
self
}
// Per-side borders
//
// CSS-style individual edges. Each unset side falls back to the
// uniform `border` for the same state. When any side is set, the
// border is painted as straight per-edge line segments (no
// corner-radius rounding of partial borders).
/// Set the base top border (`width` in points, `color`).
pub fn border_top(mut self, width: f32, color: egui::Color32) -> Self {
self.style.border_sides.top = Some(egui::Stroke::new(width, color));
self
}
/// Set the base right border (`width` in points, `color`).
pub fn border_right(mut self, width: f32, color: egui::Color32) -> Self {
self.style.border_sides.right = Some(egui::Stroke::new(width, color));
self
}
/// Set the base bottom border (`width` in points, `color`).
pub fn border_bottom(mut self, width: f32, color: egui::Color32) -> Self {
self.style.border_sides.bottom = Some(egui::Stroke::new(width, color));
self
}
/// Set the base left border (`width` in points, `color`).
pub fn border_left(mut self, width: f32, color: egui::Color32) -> Self {
self.style.border_sides.left = Some(egui::Stroke::new(width, color));
self
}
/// Set the base left **and** right borders in one call.
pub fn border_x(mut self, width: f32, color: egui::Color32) -> Self {
let s = egui::Stroke::new(width, color);
self.style.border_sides.left = Some(s);
self.style.border_sides.right = Some(s);
self
}
/// Set the base top **and** bottom borders in one call.
pub fn border_y(mut self, width: f32, color: egui::Color32) -> Self {
let s = egui::Stroke::new(width, color);
self.style.border_sides.top = Some(s);
self.style.border_sides.bottom = Some(s);
self
}
/// Top border while hovering. Falls back to [`border_top`](Self::border_top).
pub fn hover_border_top(mut self, width: f32, color: egui::Color32) -> Self {
self.style.hover_border_sides.top = Some(egui::Stroke::new(width, color));
self
}
/// Right border while hovering. Falls back to [`border_right`](Self::border_right).
pub fn hover_border_right(mut self, width: f32, color: egui::Color32) -> Self {
self.style.hover_border_sides.right = Some(egui::Stroke::new(width, color));
self
}
/// Bottom border while hovering. Falls back to [`border_bottom`](Self::border_bottom).
pub fn hover_border_bottom(mut self, width: f32, color: egui::Color32) -> Self {
self.style.hover_border_sides.bottom = Some(egui::Stroke::new(width, color));
self
}
/// Left border while hovering. Falls back to [`border_left`](Self::border_left).
pub fn hover_border_left(mut self, width: f32, color: egui::Color32) -> Self {
self.style.hover_border_sides.left = Some(egui::Stroke::new(width, color));
self
}
/// Left and right borders while hovering.
pub fn hover_border_x(mut self, width: f32, color: egui::Color32) -> Self {
let s = egui::Stroke::new(width, color);
self.style.hover_border_sides.left = Some(s);
self.style.hover_border_sides.right = Some(s);
self
}
/// Top and bottom borders while hovering.
pub fn hover_border_y(mut self, width: f32, color: egui::Color32) -> Self {
let s = egui::Stroke::new(width, color);
self.style.hover_border_sides.top = Some(s);
self.style.hover_border_sides.bottom = Some(s);
self
}
/// Top border while focused. Falls back to [`border_top`](Self::border_top).
pub fn focus_border_top(mut self, width: f32, color: egui::Color32) -> Self {
self.style.focus_border_sides.top = Some(egui::Stroke::new(width, color));
self
}
/// Right border while focused. Falls back to [`border_right`](Self::border_right).
pub fn focus_border_right(mut self, width: f32, color: egui::Color32) -> Self {
self.style.focus_border_sides.right = Some(egui::Stroke::new(width, color));
self
}
/// Bottom border while focused. Falls back to [`border_bottom`](Self::border_bottom).
pub fn focus_border_bottom(mut self, width: f32, color: egui::Color32) -> Self {
self.style.focus_border_sides.bottom = Some(egui::Stroke::new(width, color));
self
}
/// Left border while focused. Falls back to [`border_left`](Self::border_left).
pub fn focus_border_left(mut self, width: f32, color: egui::Color32) -> Self {
self.style.focus_border_sides.left = Some(egui::Stroke::new(width, color));
self
}
/// Left and right borders while focused.
pub fn focus_border_x(mut self, width: f32, color: egui::Color32) -> Self {
let s = egui::Stroke::new(width, color);
self.style.focus_border_sides.left = Some(s);
self.style.focus_border_sides.right = Some(s);
self
}
/// Top and bottom borders while focused.
pub fn focus_border_y(mut self, width: f32, color: egui::Color32) -> Self {
let s = egui::Stroke::new(width, color);
self.style.focus_border_sides.top = Some(s);
self.style.focus_border_sides.bottom = Some(s);
self
}
// --- Geometry ---
/// Set the corner radius. Accepts an `f32` (uniform) or any
/// `Into<egui::CornerRadius>` for per-corner control.
pub fn corner_radius(mut self, corner_radius: impl Into<egui::CornerRadius>) -> Self {
self.style.corner_radius = Some(corner_radius.into());
self
}
/// Set inner padding (space between the border and the content).
/// Accepts any `Into<egui::Margin>`.
pub fn padding(mut self, padding: impl Into<egui::Margin>) -> Self {
self.style.padding = Some(padding.into());
self
}
/// Set the top outer margin in points (space outside the border).
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
}
/// Set the bottom outer margin in points (space outside the border).
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
}
/// Set the left outer margin in points (space outside the border).
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
}
/// Set the right outer margin in points (space outside the border).
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 ---
/// Stretch the widget to fill the available width of its parent.
pub fn full_width(mut self) -> Self {
self.style.full_width = true;
self
}
/// Stretch the widget to fill the available height of its parent.
pub fn full_height(mut self) -> Self {
self.style.full_height = true;
self
}
/// Set a minimum width in points.
pub fn min_width(mut self, width: f32) -> Self {
self.style.min_width = Some(width);
self
}
/// Set a maximum width in points.
pub fn max_width(mut self, width: f32) -> Self {
self.style.max_width = Some(width);
self
}
/// Set a minimum height in points.
pub fn min_height(mut self, height: f32) -> Self {
self.style.min_height = Some(height);
self
}
/// Set a maximum height in points.
pub fn max_height(mut self, height: f32) -> Self {
self.style.max_height = Some(height);
self
}
/// Set width as a percentage (0–100) of the parent's available width.
/// Resolves to a definite size at render time, superseding `full_width`.
/// Composes with `min_width`/`max_width` as clamps after resolution.
pub fn width_pct(mut self, pct: f32) -> Self {
self.style.width_pct = Some(pct);
self
}
/// Set height as a percentage (0–100) of the parent's available height.
/// Resolves to a definite size at render time, superseding `full_height`.
/// Composes with `min_height`/`max_height` as clamps after resolution.
pub fn height_pct(mut self, pct: f32) -> Self {
self.style.height_pct = Some(pct);
self
}
/// Derive height from width (width ÷ height, e.g. `16.0/9.0`).
/// Requires a definite width (`width_pct` or `full_width`); no-op otherwise.
/// Overridden by an explicit `height_pct` or `full_height`.
pub fn aspect_ratio(mut self, ratio: f32) -> Self {
self.style.aspect_ratio = Some(ratio);
self
}
// --- Interaction ---
/// Set the cursor icon shown while hovering the widget.
pub fn cursor(mut self, icon: egui::CursorIcon) -> Self {
self.style.cursor_icon = Some(icon);
self
}
/// Show or hide the widget. When `false` the widget still occupies
/// its layout space but is not painted or interactive.
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`](crate::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
}
/// Fade the background image in over `seconds` the first time its
/// texture finishes loading, instead of snapping in. Default: no fade.
pub fn background_image_fade_in(mut self, seconds: f32) -> Self {
self.style.background_image_fade_in = Some(seconds);
self
}
/// Reveal the whole area — background image *and* body content — in
/// together over `seconds`, the first time the image's texture
/// finishes loading. The `bg` backdrop stays opaque, so the area
/// reveals as a unit instead of content showing over a bare backdrop
/// while the art is still decoding.
pub fn reveal_with_background_image(mut self, seconds: f32) -> Self {
self.style.background_image_fade_in = Some(seconds);
self.style.background_image_fade_content = true;
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
}
// ── Background gradient ────────────────────────────────────────
/// Four-corner bilinear gradient painted over the solid `bg` fill.
/// Colors are interpolated across the rect using a cached 2×2 GPU texture,
/// so `corner_radius` is respected. See also `bg_gradient_v` / `bg_gradient_h`
/// for two-stop shortcuts and `bg_gradient_stops` for N-stop ramps.
pub fn bg_gradient(
mut self,
top_left: egui::Color32,
top_right: egui::Color32,
bottom_left: egui::Color32,
bottom_right: egui::Color32,
) -> Self {
self.style.bg_gradient = Some($crate::style::shared_style::Gradient::Corners(
$crate::style::shared_style::BgGradient::corners(
top_left, top_right, bottom_left, bottom_right,
),
));
self
}
/// Vertical two-stop gradient (top → bottom). Shorthand for `bg_gradient`.
pub fn bg_gradient_v(mut self, top: egui::Color32, bottom: egui::Color32) -> Self {
self.style.bg_gradient = Some($crate::style::shared_style::Gradient::Corners(
$crate::style::shared_style::BgGradient::vertical(top, bottom),
));
self
}
/// Horizontal two-stop gradient (left → right). Shorthand for `bg_gradient`.
pub fn bg_gradient_h(mut self, left: egui::Color32, right: egui::Color32) -> Self {
self.style.bg_gradient = Some($crate::style::shared_style::Gradient::Corners(
$crate::style::shared_style::BgGradient::horizontal(left, right),
));
self
}
/// `bg_gradient` applied when hovered.
pub fn hover_bg_gradient(
mut self,
top_left: egui::Color32,
top_right: egui::Color32,
bottom_left: egui::Color32,
bottom_right: egui::Color32,
) -> Self {
self.style.hover_bg_gradient = Some($crate::style::shared_style::Gradient::Corners(
$crate::style::shared_style::BgGradient::corners(
top_left, top_right, bottom_left, bottom_right,
),
));
self
}
/// Vertical two-stop `hover_bg_gradient`.
pub fn hover_bg_gradient_v(mut self, top: egui::Color32, bottom: egui::Color32) -> Self {
self.style.hover_bg_gradient = Some($crate::style::shared_style::Gradient::Corners(
$crate::style::shared_style::BgGradient::vertical(top, bottom),
));
self
}
/// Horizontal two-stop `hover_bg_gradient`.
pub fn hover_bg_gradient_h(mut self, left: egui::Color32, right: egui::Color32) -> Self {
self.style.hover_bg_gradient = Some($crate::style::shared_style::Gradient::Corners(
$crate::style::shared_style::BgGradient::horizontal(left, right),
));
self
}
/// `bg_gradient` applied when active (pointer pressed).
pub fn active_bg_gradient(
mut self,
top_left: egui::Color32,
top_right: egui::Color32,
bottom_left: egui::Color32,
bottom_right: egui::Color32,
) -> Self {
self.style.active_bg_gradient = Some($crate::style::shared_style::Gradient::Corners(
$crate::style::shared_style::BgGradient::corners(
top_left, top_right, bottom_left, bottom_right,
),
));
self
}
/// Vertical two-stop `active_bg_gradient`.
pub fn active_bg_gradient_v(mut self, top: egui::Color32, bottom: egui::Color32) -> Self {
self.style.active_bg_gradient = Some($crate::style::shared_style::Gradient::Corners(
$crate::style::shared_style::BgGradient::vertical(top, bottom),
));
self
}
/// Horizontal two-stop `active_bg_gradient`.
pub fn active_bg_gradient_h(mut self, left: egui::Color32, right: egui::Color32) -> Self {
self.style.active_bg_gradient = Some($crate::style::shared_style::Gradient::Corners(
$crate::style::shared_style::BgGradient::horizontal(left, right),
));
self
}
/// `bg_gradient` applied when focused.
pub fn focus_bg_gradient(
mut self,
top_left: egui::Color32,
top_right: egui::Color32,
bottom_left: egui::Color32,
bottom_right: egui::Color32,
) -> Self {
self.style.focus_bg_gradient = Some($crate::style::shared_style::Gradient::Corners(
$crate::style::shared_style::BgGradient::corners(
top_left, top_right, bottom_left, bottom_right,
),
));
self
}
/// Vertical two-stop `focus_bg_gradient`.
pub fn focus_bg_gradient_v(mut self, top: egui::Color32, bottom: egui::Color32) -> Self {
self.style.focus_bg_gradient = Some($crate::style::shared_style::Gradient::Corners(
$crate::style::shared_style::BgGradient::vertical(top, bottom),
));
self
}
/// Horizontal two-stop `focus_bg_gradient`.
pub fn focus_bg_gradient_h(mut self, left: egui::Color32, right: egui::Color32) -> Self {
self.style.focus_bg_gradient = Some($crate::style::shared_style::Gradient::Corners(
$crate::style::shared_style::BgGradient::horizontal(left, right),
));
self
}
// ── Multi-stop linear gradient (e.g. rainbow) ─────────────────
/// Vertical N-stop linear gradient over the solid `bg` fill. `stops` are
/// `(position, color)` pairs with position in `0.0..=1.0` (sorted for you).
/// Respects `corner_radius`. Use `bg_gradient_stops_h` for horizontal.
pub fn bg_gradient_stops(
mut self,
stops: impl IntoIterator<Item = (f32, egui::Color32)>,
) -> Self {
self.style.bg_gradient = Some($crate::style::shared_style::Gradient::Linear(
$crate::style::shared_style::LinearGradient::new(
stops,
$crate::style::shared_style::GradientAxis::Vertical,
),
));
self
}
/// Horizontal N-stop linear gradient. See [`bg_gradient_stops`](Self::bg_gradient_stops).
pub fn bg_gradient_stops_h(
mut self,
stops: impl IntoIterator<Item = (f32, egui::Color32)>,
) -> Self {
self.style.bg_gradient = Some($crate::style::shared_style::Gradient::Linear(
$crate::style::shared_style::LinearGradient::new(
stops,
$crate::style::shared_style::GradientAxis::Horizontal,
),
));
self
}
/// `bg_gradient_stops` applied when hovered.
pub fn hover_bg_gradient_stops(
mut self,
stops: impl IntoIterator<Item = (f32, egui::Color32)>,
) -> Self {
self.style.hover_bg_gradient = Some($crate::style::shared_style::Gradient::Linear(
$crate::style::shared_style::LinearGradient::new(
stops,
$crate::style::shared_style::GradientAxis::Vertical,
),
));
self
}
/// `bg_gradient_stops` applied when active (pointer pressed).
pub fn active_bg_gradient_stops(
mut self,
stops: impl IntoIterator<Item = (f32, egui::Color32)>,
) -> Self {
self.style.active_bg_gradient = Some($crate::style::shared_style::Gradient::Linear(
$crate::style::shared_style::LinearGradient::new(
stops,
$crate::style::shared_style::GradientAxis::Vertical,
),
));
self
}
/// `bg_gradient_stops` applied when focused.
pub fn focus_bg_gradient_stops(
mut self,
stops: impl IntoIterator<Item = (f32, egui::Color32)>,
) -> Self {
self.style.focus_bg_gradient = Some($crate::style::shared_style::Gradient::Linear(
$crate::style::shared_style::LinearGradient::new(
stops,
$crate::style::shared_style::GradientAxis::Vertical,
),
));
self
}
// ── Inner glow ────────────────────────────────────────────────
/// Inward glow: `width` logical pixels deep, fading from `color` at the
/// edge to transparent toward the center. Drawn as a smooth vertex-colored
/// ring that follows `corner_radius`.
pub fn inner_glow(mut self, width: f32, color: egui::Color32) -> Self {
self.style.inner_glow =
Some($crate::style::shared_style::InnerGlow::new(width, color));
self
}
/// Inner glow drawn only from the given `sides`.
/// See [`inner_glow`](Self::inner_glow); partial selections draw straight
/// bands (corners are not rounded).
pub fn inner_glow_sides(
mut self,
sides: $crate::style::shared_style::Sides,
width: f32,
color: egui::Color32,
) -> Self {
self.style.inner_glow =
Some($crate::style::shared_style::InnerGlow::with_sides(width, color, sides));
self
}
/// Inner glow from the top edge only.
pub fn inner_glow_top(self, width: f32, color: egui::Color32) -> Self {
self.inner_glow_sides($crate::style::shared_style::Sides::TOP, width, color)
}
/// Inner glow from the bottom edge only.
pub fn inner_glow_bottom(self, width: f32, color: egui::Color32) -> Self {
self.inner_glow_sides($crate::style::shared_style::Sides::BOTTOM, width, color)
}
/// Inner glow from the left edge only.
pub fn inner_glow_left(self, width: f32, color: egui::Color32) -> Self {
self.inner_glow_sides($crate::style::shared_style::Sides::LEFT, width, color)
}
/// Inner glow from the right edge only.
pub fn inner_glow_right(self, width: f32, color: egui::Color32) -> Self {
self.inner_glow_sides($crate::style::shared_style::Sides::RIGHT, width, color)
}
/// Inner glow from the left and right edges.
pub fn inner_glow_x(self, width: f32, color: egui::Color32) -> Self {
self.inner_glow_sides($crate::style::shared_style::Sides::X, width, color)
}
/// Inner glow from the top and bottom edges.
pub fn inner_glow_y(self, width: f32, color: egui::Color32) -> Self {
self.inner_glow_sides($crate::style::shared_style::Sides::Y, width, color)
}
/// `inner_glow` applied when hovered.
pub fn hover_inner_glow(mut self, width: f32, color: egui::Color32) -> Self {
self.style.hover_inner_glow =
Some($crate::style::shared_style::InnerGlow::new(width, color));
self
}
/// `inner_glow` applied when active (pointer pressed).
pub fn active_inner_glow(mut self, width: f32, color: egui::Color32) -> Self {
self.style.active_inner_glow =
Some($crate::style::shared_style::InnerGlow::new(width, color));
self
}
/// `inner_glow` applied when focused.
pub fn focus_inner_glow(mut self, width: f32, color: egui::Color32) -> Self {
self.style.focus_inner_glow =
Some($crate::style::shared_style::InnerGlow::new(width, color));
self
}
// ── Border gradient ───────────────────────────────────────────
/// Vertically-interpolated border: `top` color at the top edge, `bottom`
/// at the bottom, linearly interpolated down. Wins over uniform `border` and
/// per-side overrides. Corner radius is not rounded (straight mitered edges).
pub fn border_gradient(
mut self,
width: f32,
top: egui::Color32,
bottom: egui::Color32,
) -> Self {
self.style.border_gradient =
Some($crate::style::shared_style::BorderGradient::new(width, top, bottom));
self
}
/// `border_gradient` applied when hovered.
pub fn hover_border_gradient(
mut self,
width: f32,
top: egui::Color32,
bottom: egui::Color32,
) -> Self {
self.style.hover_border_gradient =
Some($crate::style::shared_style::BorderGradient::new(width, top, bottom));
self
}
/// `border_gradient` applied when active (pointer pressed).
pub fn active_border_gradient(
mut self,
width: f32,
top: egui::Color32,
bottom: egui::Color32,
) -> Self {
self.style.active_border_gradient =
Some($crate::style::shared_style::BorderGradient::new(width, top, bottom));
self
}
/// `border_gradient` applied when focused.
pub fn focus_border_gradient(
mut self,
width: f32,
top: egui::Color32,
bottom: egui::Color32,
) -> Self {
self.style.focus_border_gradient =
Some($crate::style::shared_style::BorderGradient::new(width, top, bottom));
self
}
}
impl $($gen)* $crate::apply::Apply for $ty {}
};
}
#[cfg(test)]
mod tests {
/// Compile-time coverage: every SharedStyle field must have a builder here.
/// Add a call below whenever you add a field to SharedStyle. This test fails
/// to COMPILE (not at runtime) if a builder is missing.
#[test]
fn all_shared_builders_compile() {
use crate::Styled;
let _ = Styled::frame()
.bg(egui::Color32::RED)
.hover_bg(egui::Color32::RED)
.active_bg(egui::Color32::RED)
.focus_bg(egui::Color32::RED)
.accent(egui::Color32::RED)
.hover_accent(egui::Color32::RED)
.text_color(egui::Color32::RED)
.hover_text_color(egui::Color32::RED)
.focus_text_color(egui::Color32::RED)
.font_size(14.0)
.border(1.0, egui::Color32::RED)
.hover_border(1.0, egui::Color32::RED)
.focus_border(1.0, egui::Color32::RED)
.border_top(1.0, egui::Color32::RED)
.border_right(1.0, egui::Color32::RED)
.border_bottom(1.0, egui::Color32::RED)
.border_left(1.0, egui::Color32::RED)
.corner_radius(4.0)
.padding(8.0)
.margin_top(4.0)
.margin_bottom(4.0)
.margin_left(4.0)
.margin_right(4.0)
.full_width()
.full_height()
.min_width(10.0)
.max_width(100.0)
.min_height(10.0)
.max_height(100.0)
.width_pct(50.0)
.height_pct(50.0)
.aspect_ratio(1.0)
.cursor(egui::CursorIcon::Default)
.visible(true)
.shadow(egui::Vec2::ZERO, 1.0, egui::Color32::BLACK)
.shadow_filled(egui::Vec2::ZERO, egui::Color32::BLACK)
.bg_gradient(
egui::Color32::RED,
egui::Color32::RED,
egui::Color32::RED,
egui::Color32::RED,
)
.bg_gradient_v(egui::Color32::RED, egui::Color32::BLUE)
.bg_gradient_h(egui::Color32::RED, egui::Color32::BLUE)
.hover_bg_gradient(
egui::Color32::RED,
egui::Color32::RED,
egui::Color32::RED,
egui::Color32::RED,
)
.hover_bg_gradient_v(egui::Color32::RED, egui::Color32::BLUE)
.hover_bg_gradient_h(egui::Color32::RED, egui::Color32::BLUE)
.active_bg_gradient(
egui::Color32::RED,
egui::Color32::RED,
egui::Color32::RED,
egui::Color32::RED,
)
.active_bg_gradient_v(egui::Color32::RED, egui::Color32::BLUE)
.active_bg_gradient_h(egui::Color32::RED, egui::Color32::BLUE)
.focus_bg_gradient(
egui::Color32::RED,
egui::Color32::RED,
egui::Color32::RED,
egui::Color32::RED,
)
.focus_bg_gradient_v(egui::Color32::RED, egui::Color32::BLUE)
.focus_bg_gradient_h(egui::Color32::RED, egui::Color32::BLUE)
.bg_gradient_stops([(0.0, egui::Color32::RED), (1.0, egui::Color32::BLUE)])
.bg_gradient_stops_h([(0.0, egui::Color32::RED), (1.0, egui::Color32::BLUE)])
.hover_bg_gradient_stops([(0.0, egui::Color32::RED), (1.0, egui::Color32::BLUE)])
.active_bg_gradient_stops([(0.0, egui::Color32::RED), (1.0, egui::Color32::BLUE)])
.focus_bg_gradient_stops([(0.0, egui::Color32::RED), (1.0, egui::Color32::BLUE)])
.inner_glow(8.0, egui::Color32::RED)
.inner_glow_sides(crate::Sides::ALL, 8.0, egui::Color32::RED)
.inner_glow_top(8.0, egui::Color32::RED)
.inner_glow_bottom(8.0, egui::Color32::RED)
.inner_glow_left(8.0, egui::Color32::RED)
.inner_glow_right(8.0, egui::Color32::RED)
.inner_glow_x(8.0, egui::Color32::RED)
.inner_glow_y(8.0, egui::Color32::RED)
.hover_inner_glow(8.0, egui::Color32::RED)
.active_inner_glow(8.0, egui::Color32::RED)
.focus_inner_glow(8.0, egui::Color32::RED)
.border_gradient(2.0, egui::Color32::RED, egui::Color32::BLUE)
.hover_border_gradient(2.0, egui::Color32::RED, egui::Color32::BLUE)
.active_border_gradient(2.0, egui::Color32::RED, egui::Color32::BLUE)
.focus_border_gradient(2.0, egui::Color32::RED, egui::Color32::BLUE);
// font_id: set via widget-specific .font() builder — intentional omission.
// background_image_fade_content: set via .reveal_with_background_image() — intentional alias.
}
}