1use std::collections::HashMap;
20
21use crate::canvas::{FontSpec, FontWeight, Shadow};
22use crate::color::Color;
23use crate::component::ControlState;
24use crate::geometry::Bounds;
25
26#[derive(Clone, Debug, PartialEq)]
28pub enum ColorRef {
29 Token(String),
30 Value(Color),
31}
32
33impl From<Color> for ColorRef {
34 fn from(c: Color) -> Self {
35 ColorRef::Value(c)
36 }
37}
38
39impl From<&str> for ColorRef {
41 fn from(s: &str) -> Self {
42 match Color::from_hex(s) {
43 Some(c) if s.trim_start().starts_with('#') => ColorRef::Value(c),
44 _ => ColorRef::Token(s.to_string()),
45 }
46 }
47}
48
49#[derive(Clone, Debug, PartialEq)]
51pub enum Metric {
52 Token(String),
53 Value(f32),
54}
55
56impl From<f32> for Metric {
57 fn from(v: f32) -> Self {
58 Metric::Value(v)
59 }
60}
61
62impl From<&str> for Metric {
63 fn from(s: &str) -> Self {
64 Metric::Token(s.to_string())
65 }
66}
67
68#[derive(Clone, Debug, Default, PartialEq)]
70pub struct StyleProps {
71 pub fill: Option<ColorRef>,
72 pub text: Option<ColorRef>,
73 pub border_color: Option<ColorRef>,
74 pub border_width: Option<f32>,
75 pub radius: Option<Metric>,
77 pub padding: Option<Bounds>,
78 pub font: Option<String>,
80 pub opacity: Option<f32>,
81 pub transition: Option<Metric>,
83 pub shadow: Option<String>,
85 pub material: Option<String>,
88 pub reveal: Option<String>,
92 pub reveal_color: Option<ColorRef>,
95 pub reveal_radius: Option<f32>,
97 pub text_case: Option<String>,
99 pub letter_spacing: Option<f32>,
101 pub border_sides: Option<Bounds>,
104 pub border_style: Option<String>,
106 pub line_height: Option<f32>,
109 pub font_weight: Option<crate::canvas::FontWeight>,
112 pub font_size: Option<f32>,
113 pub italic: Option<bool>,
114 pub gap: Option<f32>,
118 pub icon_size: Option<f32>,
121 pub icon_color: Option<ColorRef>,
122 pub icon_gap: Option<f32>,
123 pub width: Option<f32>,
126 pub item_height: Option<f32>,
128 pub separator_height: Option<f32>,
130 pub thumb: Option<ColorRef>,
133 pub scroll_bar: Option<Box<Style>>,
135}
136
137#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
139pub enum Material {
140 #[default]
141 None,
142 Glass,
144 Frosted,
146}
147
148#[derive(Clone, Copy, Debug, Default, PartialEq)]
151pub struct Reveal {
152 pub border: bool,
154 pub background: bool,
156 pub color: Color,
158 pub radius: f32,
160}
161
162impl Reveal {
163 pub fn on(&self) -> bool {
165 (self.border || self.background) && self.radius > 0.0 && self.color.a > 0
166 }
167}
168
169impl Material {
170 pub fn parse(name: &str) -> Material {
171 match name {
172 "glass" => Material::Glass,
173 "frosted" | "acrylic" => Material::Frosted,
174 _ => Material::None,
175 }
176 }
177
178 pub fn blur(self) -> f32 {
180 match self {
181 Material::None => 0.0,
182 Material::Glass => 8.0,
183 Material::Frosted => 22.0,
184 }
185 }
186}
187
188impl StyleProps {
189 pub fn new() -> Self {
190 Self::default()
191 }
192
193 pub fn fill(mut self, c: impl Into<ColorRef>) -> Self {
194 self.fill = Some(c.into());
195 self
196 }
197
198 pub fn text(mut self, c: impl Into<ColorRef>) -> Self {
199 self.text = Some(c.into());
200 self
201 }
202
203 pub fn border(mut self, c: impl Into<ColorRef>, width: f32) -> Self {
204 self.border_color = Some(c.into());
205 self.border_width = Some(width);
206 self
207 }
208
209 pub fn radius(mut self, m: impl Into<Metric>) -> Self {
210 self.radius = Some(m.into());
211 self
212 }
213
214 pub fn padding(mut self, b: impl Into<Bounds>) -> Self {
215 self.padding = Some(b.into());
216 self
217 }
218
219 pub fn font(mut self, name: &str) -> Self {
220 self.font = Some(name.to_string());
221 self
222 }
223
224 pub fn opacity(mut self, v: f32) -> Self {
225 self.opacity = Some(v);
226 self
227 }
228
229 pub fn transition(mut self, m: impl Into<Metric>) -> Self {
230 self.transition = Some(m.into());
231 self
232 }
233
234 pub fn shadow(mut self, token: &str) -> Self {
235 self.shadow = Some(token.to_string());
236 self
237 }
238
239 pub fn material(mut self, name: &str) -> Self {
241 self.material = Some(name.to_string());
242 self
243 }
244
245 pub fn reveal(mut self, mode: &str) -> Self {
247 self.reveal = Some(mode.to_string());
248 self
249 }
250
251 fn without(&self, mask: &StyleProps) -> StyleProps {
254 let mut out = self.clone();
255 if mask.fill.is_some() {
256 out.fill = None;
257 }
258 if mask.text.is_some() {
259 out.text = None;
260 }
261 if mask.border_color.is_some() {
262 out.border_color = None;
263 }
264 if mask.border_width.is_some() {
265 out.border_width = None;
266 }
267 if mask.radius.is_some() {
268 out.radius = None;
269 }
270 if mask.padding.is_some() {
271 out.padding = None;
272 }
273 if mask.font.is_some() {
274 out.font = None;
275 }
276 if mask.opacity.is_some() {
277 out.opacity = None;
278 }
279 if mask.transition.is_some() {
280 out.transition = None;
281 }
282 if mask.shadow.is_some() {
283 out.shadow = None;
284 }
285 if mask.material.is_some() {
286 out.material = None;
287 }
288 if mask.reveal.is_some() {
289 out.reveal = None;
290 }
291 if mask.reveal_color.is_some() {
292 out.reveal_color = None;
293 }
294 if mask.reveal_radius.is_some() {
295 out.reveal_radius = None;
296 }
297 if mask.text_case.is_some() {
298 out.text_case = None;
299 }
300 if mask.letter_spacing.is_some() {
301 out.letter_spacing = None;
302 }
303 if mask.border_sides.is_some() {
304 out.border_sides = None;
305 }
306 if mask.border_style.is_some() {
307 out.border_style = None;
308 }
309 if mask.line_height.is_some() {
310 out.line_height = None;
311 }
312 if mask.font_weight.is_some() {
313 out.font_weight = None;
314 }
315 if mask.font_size.is_some() {
316 out.font_size = None;
317 }
318 if mask.italic.is_some() {
319 out.italic = None;
320 }
321 if mask.gap.is_some() {
322 out.gap = None;
323 }
324 if mask.icon_size.is_some() {
325 out.icon_size = None;
326 }
327 if mask.icon_color.is_some() {
328 out.icon_color = None;
329 }
330 if mask.icon_gap.is_some() {
331 out.icon_gap = None;
332 }
333 if mask.width.is_some() {
334 out.width = None;
335 }
336 if mask.item_height.is_some() {
337 out.item_height = None;
338 }
339 if mask.separator_height.is_some() {
340 out.separator_height = None;
341 }
342 if mask.thumb.is_some() {
343 out.thumb = None;
344 }
345 out
346 }
347
348 pub fn merge(&mut self, other: &StyleProps) {
350 if other.fill.is_some() {
351 self.fill.clone_from(&other.fill);
352 }
353 if other.text.is_some() {
354 self.text.clone_from(&other.text);
355 }
356 if other.border_color.is_some() {
357 self.border_color.clone_from(&other.border_color);
358 }
359 if other.border_width.is_some() {
360 self.border_width = other.border_width;
361 }
362 if other.radius.is_some() {
363 self.radius.clone_from(&other.radius);
364 }
365 if other.padding.is_some() {
366 self.padding = other.padding;
367 }
368 if other.font.is_some() {
369 self.font.clone_from(&other.font);
370 }
371 if other.opacity.is_some() {
372 self.opacity = other.opacity;
373 }
374 if other.transition.is_some() {
375 self.transition.clone_from(&other.transition);
376 }
377 if other.shadow.is_some() {
378 self.shadow.clone_from(&other.shadow);
379 }
380 if other.material.is_some() {
381 self.material.clone_from(&other.material);
382 }
383 if other.reveal.is_some() {
384 self.reveal.clone_from(&other.reveal);
385 }
386 if other.reveal_color.is_some() {
387 self.reveal_color.clone_from(&other.reveal_color);
388 }
389 if other.reveal_radius.is_some() {
390 self.reveal_radius = other.reveal_radius;
391 }
392 if other.text_case.is_some() {
393 self.text_case.clone_from(&other.text_case);
394 }
395 if other.letter_spacing.is_some() {
396 self.letter_spacing = other.letter_spacing;
397 }
398 if other.gap.is_some() {
399 self.gap = other.gap;
400 }
401 if other.border_sides.is_some() {
402 self.border_sides = other.border_sides;
403 }
404 if other.border_style.is_some() {
405 self.border_style.clone_from(&other.border_style);
406 }
407 if other.line_height.is_some() {
408 self.line_height = other.line_height;
409 }
410 if other.font_weight.is_some() {
411 self.font_weight = other.font_weight;
412 }
413 if other.font_size.is_some() {
414 self.font_size = other.font_size;
415 }
416 if other.italic.is_some() {
417 self.italic = other.italic;
418 }
419 if other.icon_size.is_some() {
420 self.icon_size = other.icon_size;
421 }
422 if other.icon_color.is_some() {
423 self.icon_color.clone_from(&other.icon_color);
424 }
425 if other.icon_gap.is_some() {
426 self.icon_gap = other.icon_gap;
427 }
428 if other.width.is_some() {
429 self.width = other.width;
430 }
431 if other.item_height.is_some() {
432 self.item_height = other.item_height;
433 }
434 if other.separator_height.is_some() {
435 self.separator_height = other.separator_height;
436 }
437 if other.thumb.is_some() {
438 self.thumb.clone_from(&other.thumb);
439 }
440 if let Some(bar) = &other.scroll_bar {
441 match &mut self.scroll_bar {
442 Some(mine) => mine.merge(bar),
443 None => self.scroll_bar = Some(bar.clone()),
444 }
445 }
446 }
447}
448
449#[derive(Clone, Debug, Default, PartialEq)]
451pub struct Style {
452 pub base: StyleProps,
453 pub hover: StyleProps,
454 pub pressed: StyleProps,
455 pub focused: StyleProps,
456 pub checked: StyleProps,
457 pub disabled: StyleProps,
458}
459
460impl Style {
461 pub fn new(base: StyleProps) -> Self {
462 Self { base, ..Default::default() }
463 }
464
465 pub fn hover(mut self, p: StyleProps) -> Self {
466 self.hover = p;
467 self
468 }
469
470 pub fn pressed(mut self, p: StyleProps) -> Self {
471 self.pressed = p;
472 self
473 }
474
475 pub fn focused(mut self, p: StyleProps) -> Self {
476 self.focused = p;
477 self
478 }
479
480 pub fn checked(mut self, p: StyleProps) -> Self {
481 self.checked = p;
482 self
483 }
484
485 pub fn disabled(mut self, p: StyleProps) -> Self {
486 self.disabled = p;
487 self
488 }
489
490 pub fn merge(&mut self, other: &Style) {
492 self.base.merge(&other.base);
493 self.hover.merge(&other.hover);
494 self.pressed.merge(&other.pressed);
495 self.focused.merge(&other.focused);
496 self.checked.merge(&other.checked);
497 self.disabled.merge(&other.disabled);
498 }
499
500 fn state(&self, index: usize) -> &StyleProps {
502 match index {
503 0 => &self.hover,
504 1 => &self.pressed,
505 2 => &self.focused,
506 3 => &self.checked,
507 _ => &self.disabled,
508 }
509 }
510}
511
512#[derive(Clone, Debug, PartialEq)]
514pub struct ResolvedStyle {
515 pub fill: Color,
516 pub text: Color,
517 pub border_color: Color,
518 pub border_width: f32,
519 pub radius: f32,
520 pub padding: Bounds,
521 pub font: FontSpec,
522 pub opacity: f32,
523 pub transition_ms: f32,
524 pub shadow: Option<Shadow>,
526 pub material: Material,
528 pub reveal: Reveal,
530 pub text_case: crate::text::TextCase,
532 pub letter_spacing: f32,
534 pub border_sides: Option<Bounds>,
536 pub border_dash: Vec<f32>,
538 pub line_height: f32,
540 pub gap: Option<f32>,
542 pub icon_size: Option<f32>,
544 pub icon_color: Option<Color>,
545 pub icon_gap: Option<f32>,
546 pub scroll_bar: Option<Box<Style>>,
548}
549
550impl ResolvedStyle {
551 pub fn border_stroke(&self, color: Color, width: f32) -> crate::canvas::Stroke {
553 let stroke = crate::canvas::Stroke::new(color, width);
554 if self.border_dash.is_empty() { stroke } else { stroke.dashed(self.border_dash.clone()) }
555 }
556}
557
558impl Default for ResolvedStyle {
559 fn default() -> Self {
560 Self {
561 fill: Color::TRANSPARENT,
562 text: Color::BLACK,
563 border_color: Color::TRANSPARENT,
564 border_width: 0.0,
565 radius: 0.0,
566 padding: Bounds::ZERO,
567 font: FontSpec::default(),
568 opacity: 1.0,
569 transition_ms: 0.0,
570 shadow: None,
571 material: Material::None,
572 reveal: Reveal::default(),
573 text_case: crate::text::TextCase::None,
574 letter_spacing: 0.0,
575 border_sides: None,
576 border_dash: Vec::new(),
577 line_height: 0.0,
578 gap: None,
579 icon_size: None,
580 icon_color: None,
581 icon_gap: None,
582 scroll_bar: None,
583 }
584 }
585}
586
587impl ResolvedStyle {
588 pub fn lerp(&self, other: &ResolvedStyle, t: f32) -> ResolvedStyle {
591 let mix = |a: f32, b: f32| a + (b - a) * t;
592 ResolvedStyle {
593 fill: self.fill.lerp(other.fill, t),
594 text: self.text.lerp(other.text, t),
595 border_color: self.border_color.lerp(other.border_color, t),
596 border_width: mix(self.border_width, other.border_width),
597 radius: mix(self.radius, other.radius),
598 padding: other.padding,
599 font: other.font.clone(),
600 opacity: mix(self.opacity, other.opacity),
601 transition_ms: other.transition_ms,
602 shadow: match (self.shadow, other.shadow) {
603 (Some(a), Some(b)) => Some(Shadow {
604 color: a.color.lerp(b.color, t),
605 blur: mix(a.blur, b.blur),
606 offset: crate::PointF::new(mix(a.offset.x, b.offset.x), mix(a.offset.y, b.offset.y)),
607 spread: mix(a.spread, b.spread),
608 }),
609 _ => other.shadow,
610 },
611 material: other.material,
612 reveal: other.reveal,
613 text_case: other.text_case,
614 letter_spacing: mix(self.letter_spacing, other.letter_spacing),
615 border_sides: other.border_sides,
616 border_dash: other.border_dash.clone(),
617 line_height: mix(self.line_height, other.line_height),
618 gap: other.gap,
619 icon_size: other.icon_size,
620 icon_color: match (self.icon_color, other.icon_color) {
621 (Some(a), Some(b)) => Some(a.lerp(b, t)),
622 _ => other.icon_color,
623 },
624 icon_gap: other.icon_gap,
625 scroll_bar: other.scroll_bar.clone(),
626 }
627 }
628}
629
630#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
634pub enum Look {
635 #[default]
637 Aylis,
638 Material2,
640 Material3,
642 Ios7,
644 Ios13,
646 Ios26,
648 Win7,
650 Win10,
652 Win11,
654 WinPhone,
656}
657
658impl crate::prop::PropEnum for Look {
659 const NAMES: &'static [&'static str] = &["aylis", "material2", "material3", "ios7", "ios13", "ios26", "win7", "win10", "win11", "winphone"];
660
661 fn from_index(index: usize) -> Option<Self> {
662 [
663 Look::Aylis,
664 Look::Material2,
665 Look::Material3,
666 Look::Ios7,
667 Look::Ios13,
668 Look::Ios26,
669 Look::Win7,
670 Look::Win10,
671 Look::Win11,
672 Look::WinPhone,
673 ]
674 .get(index)
675 .copied()
676 }
677
678 fn index(self) -> usize {
679 self as usize
680 }
681}
682
683impl Look {
684 pub fn is_material(self) -> bool {
685 matches!(self, Look::Material2 | Look::Material3)
686 }
687
688 pub fn is_ios(self) -> bool {
689 matches!(self, Look::Ios7 | Look::Ios13 | Look::Ios26)
690 }
691
692 pub fn is_windows(self) -> bool {
693 matches!(self, Look::Win7 | Look::Win10 | Look::Win11 | Look::WinPhone)
694 }
695}
696
697#[derive(Clone, Debug, Default, PartialEq)]
699pub struct Theme {
700 pub name: String,
701 pub family: String,
704 pub dark: bool,
706 pub look: Look,
708 pub colors: HashMap<String, Color>,
709 pub fonts: HashMap<String, FontSpec>,
710 pub radius: HashMap<String, f32>,
711 pub spacing: HashMap<String, f32>,
712 pub durations: HashMap<String, f32>,
714 pub shadows: HashMap<String, Shadow>,
715 pub styles: HashMap<String, Style>,
717 pub components: HashMap<String, String>,
719}
720
721impl Theme {
722 pub fn apply_font_family(&mut self, family: &str) {
725 if family.is_empty() {
726 return;
727 }
728 for font in self.fonts.values_mut() {
729 if font.family != "monospace" && !font.family.to_lowercase().contains("mono") {
730 font.family = family.to_string();
731 }
732 }
733 }
734
735 pub fn new(name: impl Into<String>) -> Self {
736 Self { name: name.into(), ..Default::default() }
737 }
738
739 pub fn light() -> Self {
741 let mut t = Theme::new("Aylis Light");
742 t.family = "Aylis".into();
743 t.set_colors(&[
744 ("background", "#F5F5F7"),
745 ("surface", "#FFFFFF"),
746 ("text", "#1F2328"),
747 ("text_muted", "#6B7280"),
748 ("border", "#D0D7DE"),
749 ("primary", "#2563EB"),
750 ("primary_hover", "#3B82F6"),
751 ("primary_pressed", "#1D4ED8"),
752 ("on_primary", "#FFFFFF"),
753 ("on_danger", "#FFFFFF"),
755 ("on_success", "#FFFFFF"),
756 ("danger", "#DC2626"),
757 ("danger_hover", "#EF4444"),
758 ("danger_pressed", "#B91C1C"),
759 ("success", "#16A34A"),
760 ("warning", "#D97706"),
761 ("focus_ring", "#3B82F6"),
762 ("accent", "#9333EA"),
763 ("hover_overlay", "#0000000F"),
764 ("glass_fill", "#FFFFFF73"),
765 ("primary_container", "#DBEAFE"),
766 ("on_primary_container", "#1E3A8A"),
767 ("selection", "#2563EB40"),
768 ("track", "#D0D7DE"),
769 ("surface_2", "#F0F1F4"),
770 ("info", "#0284C7"),
771 ("primary_soft", "#2563EB1A"),
772 ("success_soft", "#16A34A1A"),
773 ("warning_soft", "#D977061F"),
774 ("danger_soft", "#DC26261A"),
775 ("info_soft", "#0284C71A"),
776 ("meter_low", "#16A34A"),
777 ("meter_mid", "#EAB308"),
778 ("meter_high", "#DC2626"),
779 ("presence_online", "#16A34A"),
780 ("presence_away", "#EAB308"),
781 ("presence_busy", "#DC2626"),
782 ("presence_offline", "#9CA3AF"),
783 ]);
784 t.shadows.insert("sm".into(), Shadow::new(Color::rgba(15, 23, 42, 20), 4.0, 0.0, 1.0));
785 t.shadows.insert("md".into(), Shadow::new(Color::rgba(15, 23, 42, 28), 12.0, 0.0, 4.0));
786 t.shadows.insert("lg".into(), Shadow::new(Color::rgba(15, 23, 42, 36), 28.0, 0.0, 10.0));
787 t.shadows.insert("2xl".into(), Shadow::new(Color::rgba(15, 23, 42, 64), 50.0, 0.0, 25.0));
789 t.add_standard_tokens();
790 t.add_standard_styles();
791 t
792 }
793
794 pub fn dark() -> Self {
796 let mut t = Theme::new("Aylis Dark");
797 t.family = "Aylis".into();
798 t.dark = true;
799 t.set_colors(&[
800 ("background", "#1E1E1E"),
801 ("surface", "#252526"),
802 ("text", "#E6E6E6"),
803 ("text_muted", "#9A9A9A"),
804 ("border", "#3C3C3C"),
805 ("primary", "#3B82F6"),
806 ("primary_hover", "#60A5FA"),
807 ("primary_pressed", "#2563EB"),
808 ("on_primary", "#FFFFFF"),
809 ("on_danger", "#FFFFFF"),
811 ("on_success", "#FFFFFF"),
812 ("danger", "#EF4444"),
813 ("danger_hover", "#F87171"),
814 ("danger_pressed", "#DC2626"),
815 ("success", "#22C55E"),
816 ("warning", "#F59E0B"),
817 ("focus_ring", "#60A5FA"),
818 ("accent", "#A855F7"),
819 ("hover_overlay", "#FFFFFF14"),
820 ("glass_fill", "#1E1E2273"),
821 ("primary_container", "#1E3A8A"),
822 ("on_primary_container", "#DBEAFE"),
823 ("selection", "#3B82F660"),
824 ("track", "#4A4A4F"),
825 ("surface_2", "#2D2D30"),
826 ("info", "#38BDF8"),
827 ("primary_soft", "#3B82F62E"),
828 ("success_soft", "#22C55E29"),
829 ("warning_soft", "#F59E0B29"),
830 ("danger_soft", "#EF444429"),
831 ("info_soft", "#38BDF829"),
832 ("meter_low", "#22C55E"),
833 ("meter_mid", "#FACC15"),
834 ("meter_high", "#EF4444"),
835 ("presence_online", "#22C55E"),
836 ("presence_away", "#FACC15"),
837 ("presence_busy", "#EF4444"),
838 ("presence_offline", "#6B7280"),
839 ]);
840 t.shadows.insert("sm".into(), Shadow::new(Color::rgba(0, 0, 0, 70), 4.0, 0.0, 1.0));
841 t.shadows.insert("md".into(), Shadow::new(Color::rgba(0, 0, 0, 90), 14.0, 0.0, 4.0));
842 t.shadows.insert("lg".into(), Shadow::new(Color::rgba(0, 0, 0, 110), 30.0, 0.0, 10.0));
843 t.shadows.insert("2xl".into(), Shadow::new(Color::rgba(0, 0, 0, 150), 50.0, 0.0, 25.0));
844 t.add_standard_tokens();
845 t.add_standard_styles();
846 t
847 }
848
849 fn set_colors(&mut self, colors: &[(&str, &str)]) {
850 for (name, hex) in colors {
851 let color = Color::from_hex(hex).expect("cor inválida no tema padrão");
852 self.colors.insert(name.to_string(), color);
853 }
854 }
855
856 fn add_standard_tokens(&mut self) {
857 self.fonts.insert("default".into(), FontSpec::new("", 14.0));
858 self.fonts.insert("title".into(), FontSpec::new("", 20.0).weight(FontWeight::Bold));
859 self.fonts.insert("heading".into(), FontSpec::new("", 16.0).weight(FontWeight::SemiBold));
860 self.fonts.insert("small".into(), FontSpec::new("", 12.0));
861 self.fonts.insert("strong".into(), FontSpec::new("", 14.0).weight(FontWeight::SemiBold));
862 self.fonts.insert("mono".into(), FontSpec::new("monospace", 13.0));
863 for (k, v) in [("sm", 4.0), ("md", 6.0), ("lg", 10.0)] {
864 self.radius.insert(k.into(), v);
865 }
866 for (k, v) in [("xs", 4.0), ("sm", 8.0), ("md", 12.0), ("lg", 16.0)] {
867 self.spacing.insert(k.into(), v);
868 }
869 for (k, v) in [("fast", 120.0), ("normal", 200.0), ("slow", 350.0)] {
870 self.durations.insert(k.into(), v);
871 }
872 }
873
874 fn add_standard_styles(&mut self) {
875 self.set_style("Form", Style::new(StyleProps::new().fill("background").text("text")));
876 self.set_style(
877 "Panel",
878 Style::new(StyleProps::new().fill("surface").border("border", 1.0).radius("sm")),
879 );
880 self.set_style("Label", Style::new(StyleProps::new().text("text")));
881 self.set_style(
882 "Button",
883 Style::new(
884 StyleProps::new()
885 .fill("primary")
886 .text("on_primary")
887 .radius("md")
888 .padding((12.0, 6.0))
889 .transition("fast"),
890 )
891 .hover(StyleProps::new().fill("primary_hover"))
892 .pressed(StyleProps::new().fill("primary_pressed"))
893 .focused(StyleProps::new().border("focus_ring", 2.0))
894 .disabled(StyleProps::new().opacity(0.5)),
895 );
896 self.set_style(
897 "Button.danger",
898 Style::new(StyleProps::new().fill("danger").text("on_danger"))
899 .hover(StyleProps::new().fill("danger_hover"))
900 .pressed(StyleProps::new().fill("danger_pressed")),
901 );
902 self.set_style(
904 "Button.round",
905 Style::new(StyleProps::new().fill("primary").text("on_primary").radius(999.0).border(Color::TRANSPARENT, 0.0))
906 .hover(StyleProps::new().fill("primary_hover"))
907 .pressed(StyleProps::new().fill("primary_pressed")),
908 );
909 self.set_style(
910 "Button.flat",
911 Style::new(StyleProps::new().fill(Color::TRANSPARENT).text("primary"))
912 .hover(StyleProps::new().fill("hover_overlay"))
913 .pressed(StyleProps::new().fill("hover_overlay")),
914 );
915 self.set_style(
916 "Edit",
917 Style::new(
918 StyleProps::new()
919 .fill("surface")
920 .text("text")
921 .border("border", 1.0)
922 .radius("sm")
923 .padding((8.0, 4.0)),
924 )
925 .hover(StyleProps::new().border("text_muted", 1.0))
926 .focused(StyleProps::new().border("focus_ring", 2.0))
927 .disabled(StyleProps::new().opacity(0.5)),
928 );
929 self.set_style(
930 "ComboBox",
931 Style::new(
932 StyleProps::new().fill("surface").text("text").border("border", 1.0).radius("sm").padding((8.0, 4.0)),
933 )
934 .hover(StyleProps::new().border("text_muted", 1.0))
935 .focused(StyleProps::new().border("focus_ring", 2.0))
936 .disabled(StyleProps::new().opacity(0.5)),
937 );
938 for class in ["CheckBox", "RadioButton"] {
940 self.set_style(
941 class,
942 Style::new(
943 StyleProps::new().fill("surface").text("text").border("text_muted", 1.5).radius("sm").transition("fast"),
944 )
945 .hover(StyleProps::new().border("primary", 1.5))
946 .checked(StyleProps::new().fill("primary").border("primary", 1.5))
947 .focused(StyleProps::new().border("focus_ring", 2.0))
948 .disabled(StyleProps::new().opacity(0.5)),
949 );
950 }
951 self.set_style(
953 "Switch",
954 Style::new(StyleProps::new().fill("track").text("text").transition("normal"))
955 .checked(StyleProps::new().fill("primary"))
956 .focused(StyleProps::new().border("focus_ring", 2.0))
957 .disabled(StyleProps::new().opacity(0.5)),
958 );
959 self.set_style("ProgressBar", Style::new(StyleProps::new().fill("track").radius(4.0)));
961 for class in ["Memo", "ListBox", "ListView", "TreeView", "Calendar"] {
963 self.set_style(
964 class,
965 Style::new(StyleProps::new().fill("surface").text("text").border("border", 1.0).radius("sm").padding((6.0, 4.0)))
966 .focused(StyleProps::new().border("focus_ring", 2.0))
967 .disabled(StyleProps::new().opacity(0.5)),
968 );
969 self.set_style(
972 &format!("{class}.flat"),
973 Style::new(StyleProps::new().border(Color::TRANSPARENT, 0.0))
974 .focused(StyleProps::new().border(Color::TRANSPARENT, 0.0)),
975 );
976 }
977 self.set_style(
980 "CodeEditor",
981 Style::new(StyleProps::new().fill("surface").text("text").border(Color::TRANSPARENT, 0.0).radius(0.0).padding((4.0, 2.0)))
982 .focused(StyleProps::new().border(Color::TRANSPARENT, 0.0))
983 .disabled(StyleProps::new().opacity(0.5)),
984 );
985 self.set_style("TabStrip", Style::new(StyleProps::new().fill("surface_2").text("text").border(Color::TRANSPARENT, 0.0)));
988 self.set_style(
990 "TrackBar",
991 Style::new(StyleProps::new().fill("track").text("text").radius(3.0))
992 .focused(StyleProps::new().border("focus_ring", 2.0))
993 .disabled(StyleProps::new().opacity(0.5)),
994 );
995 self.set_style("GroupBox", Style::new(StyleProps::new().text("text").border("border", 1.0).radius("md")));
996 self.set_style("Expander", Style::new(StyleProps::new().fill("surface").text("text").border("border", 1.0).radius("md")));
997 self.set_style("TabControl", Style::new(StyleProps::new().fill("surface").text("text").border("border", 1.0).radius("md")));
998 self.set_style("TabItem", Style::new(StyleProps::new().text("text")));
999 self.set_style("StatusBar", Style::new(StyleProps::new().fill("surface").text("text_muted").border("border", 1.0)));
1000 self.set_style("ToolBar", Style::new(StyleProps::new().fill("surface").text("text").border("border", 1.0)));
1001 self.set_style("RadioGroup", Style::new(StyleProps::new().text("text").border("border", 1.0).radius("md")));
1002 self.set_style("Chart", Style::new(StyleProps::new().fill("surface").text("text").border("border", 1.0).radius("md")));
1003 self.add_variant_styles();
1004 }
1005
1006 fn add_variant_styles(&mut self) {
1008 self.set_style(
1010 "Button.secondary",
1011 Style::new(StyleProps::new().fill("surface").text("text").border("border", 1.0))
1012 .hover(StyleProps::new().fill("surface_2").border("text_muted", 1.0))
1013 .pressed(StyleProps::new().fill("track")),
1014 );
1015 self.set_style(
1016 "Button.outline",
1017 Style::new(StyleProps::new().fill(Color::TRANSPARENT).text("primary").border("primary", 1.0))
1018 .hover(StyleProps::new().fill("primary_soft"))
1019 .pressed(StyleProps::new().fill("primary_soft")),
1020 );
1021 self.set_style(
1022 "Button.success",
1023 Style::new(StyleProps::new().fill("success").text("on_success"))
1024 .hover(StyleProps::new().opacity(0.9))
1025 .pressed(StyleProps::new().opacity(0.8)),
1026 );
1027 self.set_style(
1029 "Button.positive",
1030 Style::new(StyleProps::new().fill("success").text("on_success")).hover(StyleProps::new().opacity(0.9)).pressed(StyleProps::new().opacity(0.8)),
1031 );
1032 self.set_style(
1033 "Button.negative",
1034 Style::new(StyleProps::new().fill("danger").text("on_danger")).hover(StyleProps::new().fill("danger_hover")).pressed(StyleProps::new().fill("danger_pressed")),
1035 );
1036 self.set_style(
1037 "Button.accent",
1038 Style::new(StyleProps::new().fill("accent").text("on_primary")).hover(StyleProps::new().opacity(0.9)).pressed(StyleProps::new().opacity(0.8)),
1039 );
1040 self.set_style("Button.rounded", Style::new(StyleProps::new().radius(28.0)));
1041 self.set_style("Button.unelevated", Style::new(StyleProps::new().shadow("none")));
1042 self.set_style(
1043 "Button.push",
1044 Style::new(StyleProps::new().border(Color::rgba(0, 0, 0, 0x40), 3.0)).pressed(StyleProps::new().fill("primary_pressed").border(Color::rgba(0, 0, 0, 0x40), 1.0)),
1045 );
1046 self.set_style("Button.glossy", Style::new(StyleProps::new().fill("primary_hover").shadow("md")).hover(StyleProps::new().fill("primary")));
1047 self.set_style(
1048 "Button.icon",
1049 Style::new(StyleProps::new().fill(Color::TRANSPARENT).text("text").padding(6.0).radius("md"))
1050 .hover(StyleProps::new().fill("hover_overlay"))
1051 .pressed(StyleProps::new().fill("track"))
1052 .checked(StyleProps::new().fill("primary_soft").text("primary")),
1053 );
1054 self.set_style(
1055 "Button.fab",
1056 Style::new(StyleProps::new().fill("primary").text("on_primary").radius(999.0).shadow("md").padding(10.0))
1057 .hover(StyleProps::new().fill("primary_hover").shadow("lg"))
1058 .pressed(StyleProps::new().fill("primary_pressed").shadow("sm")),
1059 );
1060 self.set_style(
1061 "Button.link",
1062 Style::new(StyleProps::new().fill(Color::TRANSPARENT).text("primary").padding((2.0, 2.0)))
1063 .hover(StyleProps::new().fill(Color::TRANSPARENT).text("primary_hover"))
1064 .pressed(StyleProps::new().fill(Color::TRANSPARENT).text("primary_pressed")),
1065 );
1066 self.set_style(
1067 "Button.pill",
1068 Style::new(StyleProps::new().fill("surface_2").text("text").radius(999.0).padding((14.0, 6.0)))
1069 .hover(StyleProps::new().fill("track"))
1070 .checked(StyleProps::new().fill("primary").text("on_primary")),
1071 );
1072 self.set_style(
1075 "Button.elevated",
1076 Style::new(StyleProps::new().fill("surface").text("primary").radius(999.0).shadow("sm"))
1077 .hover(StyleProps::new().shadow("md"))
1078 .pressed(StyleProps::new().fill("surface_2")),
1079 );
1080 self.set_style(
1081 "Button.tonal",
1082 Style::new(StyleProps::new().fill("primary_soft").text("primary").border(Color::TRANSPARENT, 0.0).radius(999.0))
1083 .hover(StyleProps::new().shadow("sm")),
1084 );
1085 self.set_style(
1086 "Button.text",
1087 Style::new(StyleProps::new().fill(Color::TRANSPARENT).text("primary").border(Color::TRANSPARENT, 0.0).shadow("none"))
1088 .hover(StyleProps::new().fill("primary_soft")),
1089 );
1090 self.set_style(
1091 "Button.fab_extended",
1092 Style::new(StyleProps::new().fill("primary_container").text("on_primary_container").radius(16.0).shadow("md").padding((16.0, 0.0)))
1093 .hover(StyleProps::new().shadow("lg")),
1094 );
1095 self.set_style(
1096 "Button.icon_filled",
1097 Style::new(StyleProps::new().fill("primary").text("on_primary").radius(999.0).padding(6.0)).hover(StyleProps::new().fill("primary_hover")),
1098 );
1099 self.set_style(
1100 "Button.icon_tonal",
1101 Style::new(StyleProps::new().fill("primary_soft").text("primary").radius(999.0).padding(6.0)).hover(StyleProps::new().shadow("sm")),
1102 );
1103 self.set_style(
1104 "Button.icon_outlined",
1105 Style::new(StyleProps::new().fill(Color::TRANSPARENT).text("text").border("border", 1.0).radius(999.0).padding(6.0))
1106 .hover(StyleProps::new().fill("hover_overlay")),
1107 );
1108 self.set_style(
1109 "Button.glass",
1110 Style::new(StyleProps::new().fill("glass_fill").text("text").border(Color::TRANSPARENT, 0.0).radius(999.0).shadow("sm").material("glass"))
1111 .pressed(StyleProps::new().opacity(0.8)),
1112 );
1113 self.set_style(
1114 "Button.glass_prominent",
1115 Style::new(StyleProps::new().fill("primary").text("on_primary").border(Color::TRANSPARENT, 0.0).radius(999.0).shadow("sm").material("glass"))
1116 .pressed(StyleProps::new().opacity(0.85)),
1117 );
1118 self.set_style(
1120 "Edit.filled",
1121 Style::new(StyleProps::new().fill("surface_2").border(Color::TRANSPARENT, 0.0).radius(4.0).padding((14.0, 4.0)))
1122 .hover(StyleProps::new().fill("track")),
1123 );
1124 self.set_style(
1125 "Edit.outlined",
1126 Style::new(StyleProps::new().fill(Color::TRANSPARENT).border("border", 1.0).radius(4.0).padding((14.0, 4.0)))
1127 .focused(StyleProps::new().border("primary", 2.0)),
1128 );
1129 let outlined = self.styles["Edit.outlined"].clone();
1131 self.set_style("ComboBox.outlined", outlined);
1132 self.set_style(
1133 "Edit.search",
1134 Style::new(StyleProps::new().fill("surface_2").border(Color::TRANSPARENT, 1.0).radius(999.0).padding((12.0, 4.0)))
1135 .hover(StyleProps::new().border("border", 1.0))
1136 .focused(StyleProps::new().fill("surface").border("focus_ring", 2.0)),
1137 );
1138 self.set_style(
1139 "Edit.flat",
1140 Style::new(StyleProps::new().fill(Color::TRANSPARENT).border(Color::TRANSPARENT, 0.0).radius(0.0))
1141 .hover(StyleProps::new().fill("hover_overlay").border(Color::TRANSPARENT, 0.0))
1142 .focused(StyleProps::new().border(Color::TRANSPARENT, 0.0)),
1143 );
1144 self.set_style("Panel.card", Style::new(StyleProps::new().fill("surface").border("border", 1.0).radius("lg").shadow("sm")));
1146 self.set_style("Card", Style::new(StyleProps::new().fill("surface").text("text").border("border", 1.0).radius("lg").shadow("sm")));
1148 self.set_style("Popover", Style::new(StyleProps::new().fill("surface").text("text").border("border", 1.0).radius("md").shadow("lg").padding(12.0)));
1149 self.set_style("Card.flat", Style::new(StyleProps::new().shadow("none")));
1150 self.set_style("Card.bordered", Style::new(StyleProps::new().border("border", 1.0).shadow("none")));
1151 self.set_style("Panel.flat", Style::new(StyleProps::new().fill("surface").border(Color::TRANSPARENT, 0.0).radius(0.0)));
1152 self.set_style("Panel.sidebar", Style::new(StyleProps::new().fill("surface_2").border("border", 1.0).radius(0.0)));
1153 self.set_style("Panel.overlay", Style::new(StyleProps::new().fill("surface").border("border", 1.0).radius("lg").shadow("lg")));
1154 self.set_style("Panel.filled", Style::new(StyleProps::new().fill("surface_2").border(Color::TRANSPARENT, 0.0).radius("lg").shadow("none")));
1155 self.set_style("Panel.outlined", Style::new(StyleProps::new().fill("surface").border("border", 1.0).radius("lg").shadow("none")));
1156 self.set_style("Panel.glass", Style::new(StyleProps::new().fill("glass_fill").border(Color::TRANSPARENT, 0.0).radius("lg").shadow("md").material("glass")));
1157 self.set_style("Button.reveal", Style::new(StyleProps::new().reveal("both")));
1159 self.set_style("Panel.reveal", Style::new(StyleProps::new().border("border", 1.0).reveal("border")));
1160 self.set_style("ToolBar.floating", Style::new(StyleProps::new().fill("surface_2").border(Color::TRANSPARENT, 0.0).radius(999.0).shadow("md").padding(6.0)));
1161 self.set_style("Label.title", Style::new(StyleProps::new().font("title")));
1163 self.set_style("Label.heading", Style::new(StyleProps::new().font("heading")));
1164 self.set_style("Label.muted", Style::new(StyleProps::new().text("text_muted")));
1165 self.set_style("Label.caption", Style::new(StyleProps::new().text("text_muted").font("small")));
1166 self.set_style("Label.mono", Style::new(StyleProps::new().font("mono")));
1167 self.set_style(
1169 "Label.kbd",
1170 Style::new(StyleProps::new().font("mono").fill("surface_2").border("border", 1.0).radius(4.0).padding((6.0, 1.0))),
1171 );
1172 self.set_style("Label.link", Style::new(StyleProps::new().text("primary")).hover(StyleProps::new().text("primary_hover")));
1173 self.set_style("Label.error", Style::new(StyleProps::new().text("danger").font("small")));
1174 self.set_style("ProgressBar.thin", Style::new(StyleProps::new().radius(2.0)));
1176 self.set_style("ProgressBar.success", Style::new(StyleProps::new().text("success")));
1177 self.set_style("ProgressBar.danger", Style::new(StyleProps::new().text("danger")));
1178 self.set_style("Switch.success", Style::new(StyleProps::new()).checked(StyleProps::new().fill("success")));
1180 self.set_style("CheckBox.round", Style::new(StyleProps::new().radius(999.0)));
1181 self.set_style("Icon", Style::new(StyleProps::new().text("text")));
1183 let hint = if self.dark {
1187 StyleProps::new().fill("surface_2").text("text").border("border", 1.0)
1188 } else {
1189 StyleProps::new().fill("text").text("surface")
1190 };
1191 self.set_style("Hint", Style::new(hint.radius("sm").padding((8.0, 5.0)).font("small").shadow("md")));
1192 self.set_style("Icon.muted", Style::new(StyleProps::new().text("text_muted")));
1193 self.set_style("Badge", Style::new(StyleProps::new().fill("surface_2").text("text_muted").radius(999.0).padding((8.0, 2.0)).font("small")));
1194 for tone in ["primary", "success", "warning", "danger", "info"] {
1195 self.set_style(&format!("Badge.{tone}"), Style::new(StyleProps::new().fill(format!("{tone}_soft").as_str()).text(tone)));
1196 }
1197 self.set_style("Badge.live", Style::new(StyleProps::new().fill("danger").text("on_primary").font("strong")));
1198 self.set_style("Badge.outline", Style::new(StyleProps::new().fill(Color::TRANSPARENT).text("text").border("border", 1.0)));
1199 self.set_style("Banner", Style::new(StyleProps::new().text("text").radius("md").padding((12.0, 10.0))));
1200 self.set_style(
1201 "SegmentedControl",
1202 Style::new(StyleProps::new().fill("surface_2").text("text").radius("md").transition("fast")).disabled(StyleProps::new().opacity(0.5)),
1203 );
1204 self.set_style("LevelMeter", Style::new(StyleProps::new().fill("track").radius(2.0)));
1205 self.set_style(
1206 "HotkeyEdit",
1207 Style::new(StyleProps::new().fill("surface").text("text").border("border", 1.0).radius("sm").padding((8.0, 4.0)))
1208 .hover(StyleProps::new().border("text_muted", 1.0))
1209 .focused(StyleProps::new().border("focus_ring", 2.0))
1210 .disabled(StyleProps::new().opacity(0.5)),
1211 );
1212 self.set_style("SeekBar", Style::new(StyleProps::new().text("text")).disabled(StyleProps::new().opacity(0.5)));
1213 self.set_style("NodeGraph", Style::new(StyleProps::new().fill("background").text("text").border("border", 1.0).radius("lg")));
1214 self.set_style("ChatView", Style::new(StyleProps::new().fill("background").text("text")));
1215 self.set_style("DirectionPad", Style::new(StyleProps::new().text("text")).disabled(StyleProps::new().opacity(0.5)));
1216 }
1217
1218 pub fn set_style(&mut self, key: &str, style: Style) {
1219 self.styles.insert(key.to_string(), style);
1220 }
1221
1222 pub fn family_name(&self) -> &str {
1224 if self.family.is_empty() { &self.name } else { &self.family }
1225 }
1226
1227 pub fn mix(&mut self, class: &str, theme: &str) {
1230 if theme.is_empty() {
1231 self.components.remove(class);
1232 } else {
1233 self.components.insert(class.to_string(), theme.to_string());
1234 }
1235 }
1236
1237 pub fn mixed_for(&self, classes: &[&str]) -> Option<&str> {
1240 if self.components.is_empty() {
1241 return None;
1242 }
1243 classes.iter().find_map(|c| self.components.get(*c).map(String::as_str))
1244 }
1245
1246 pub fn variants_of(&self, class: &str) -> Vec<String> {
1248 let prefix = format!("{class}.");
1249 let mut v: Vec<String> = self.styles.keys().filter_map(|k| k.strip_prefix(&prefix).map(str::to_string)).collect();
1250 v.sort();
1251 v
1252 }
1253
1254 pub fn style(&self, key: &str) -> Option<&Style> {
1255 self.styles.get(key)
1256 }
1257
1258 pub fn color(&self, token: &str) -> Color {
1261 self.colors.get(token).copied().or_else(|| self.resolve_color(token)).unwrap_or(Color::TRANSPARENT)
1262 }
1263
1264 pub fn color_of(&self, c: &ColorRef) -> Color {
1265 match c {
1266 ColorRef::Value(v) => *v,
1267 ColorRef::Token(t) => self.color(t),
1268 }
1269 }
1270
1271 fn metric(map: &HashMap<String, f32>, m: &Metric) -> f32 {
1272 match m {
1273 Metric::Value(v) => *v,
1274 Metric::Token(t) => map.get(t).copied().unwrap_or(0.0),
1275 }
1276 }
1277
1278 pub fn reach(&self, classes: &[&str], variant: &str) -> f32 {
1285 let mut reach: f32 = 0.0;
1286 let mut add = |s: &Style| {
1287 for props in [&s.base, &s.hover, &s.pressed, &s.focused, &s.checked, &s.disabled] {
1288 if let Some(shadow) = props.shadow.as_deref().and_then(|t| self.shadows.get(t)) {
1289 reach = reach.max(shadow.reach());
1290 }
1291 }
1292 };
1293 for class in classes {
1294 if let Some(s) = self.styles.get(*class) {
1295 add(s);
1296 }
1297 if !variant.is_empty() {
1298 if let Some(s) = self.styles.get(&format!("{class}.{variant}")) {
1299 add(s);
1300 }
1301 }
1302 }
1303 reach
1304 }
1305
1306 pub fn resolve(&self, classes: &[&str], variant: &str, state: ControlState) -> ResolvedStyle {
1307 let mut layers: Vec<&Style> = Vec::new();
1308 for class in classes.iter().rev() {
1309 if let Some(s) = self.styles.get(*class) {
1310 layers.push(s);
1311 }
1312 if !variant.is_empty() {
1313 if let Some(s) = self.styles.get(&format!("{class}.{variant}")) {
1314 layers.push(s);
1315 }
1316 }
1317 }
1318
1319 let mut acc = StyleProps::default();
1320 for s in &layers {
1321 acc.merge(&s.base);
1322 }
1323 let mut later = vec![StyleProps::default(); layers.len()];
1330 for k in (0..layers.len().saturating_sub(1)).rev() {
1331 let mut m = later[k + 1].clone();
1332 m.merge(&layers[k + 1].base);
1333 m.scroll_bar = None;
1334 later[k] = m;
1335 }
1336 let active = [state.hover, state.pressed, state.focused, state.checked, state.disabled];
1337 let checked_as_pressed = state.checked && layers.iter().all(|s| s.checked == StyleProps::default());
1340 for (i, on) in active.into_iter().enumerate() {
1341 if on {
1342 let index = if i == 3 && checked_as_pressed { 1 } else { i };
1343 for (k, s) in layers.iter().enumerate() {
1344 let state = s.state(index);
1345 if index > 1 || later[k] == StyleProps::default() {
1346 acc.merge(state);
1347 } else {
1348 acc.merge(&state.without(&later[k]));
1349 }
1350 }
1351 }
1352 }
1353
1354 let defaults = ResolvedStyle::default();
1355 ResolvedStyle {
1356 fill: acc.fill.as_ref().map_or(defaults.fill, |c| self.color_of(c)),
1357 text: acc
1358 .text
1359 .as_ref()
1360 .map(|c| self.color_of(c))
1361 .or_else(|| self.colors.get("text").copied())
1362 .unwrap_or(defaults.text),
1363 border_color: acc.border_color.as_ref().map_or(defaults.border_color, |c| self.color_of(c)),
1364 border_width: acc.border_width.unwrap_or(defaults.border_width),
1365 radius: acc.radius.as_ref().map_or(0.0, |m| Self::metric(&self.radius, m)),
1366 padding: acc.padding.unwrap_or(defaults.padding),
1367 font: {
1368 let mut font = self.fonts.get(acc.font.as_deref().unwrap_or("default")).cloned().unwrap_or(defaults.font);
1369 if let Some(w) = acc.font_weight {
1370 font.weight = w;
1371 }
1372 if let Some(size) = acc.font_size {
1373 font.size = size;
1374 }
1375 if let Some(italic) = acc.italic {
1376 font.italic = italic;
1377 }
1378 font
1379 },
1380 line_height: acc.line_height.unwrap_or(0.0),
1381 opacity: acc.opacity.unwrap_or(1.0),
1382 transition_ms: acc.transition.as_ref().map_or(0.0, |m| Self::metric(&self.durations, m)),
1383 shadow: acc.shadow.as_deref().and_then(|t| self.shadows.get(t)).copied(),
1384 material: acc.material.as_deref().map_or(Material::None, Material::parse),
1385 reveal: {
1386 let (border, background) = match acc.reveal.as_deref() {
1387 Some("border") => (true, false),
1388 Some("background") => (false, true),
1389 Some("both") => (true, true),
1390 _ => (false, false),
1391 };
1392 let color = acc
1393 .reveal_color
1394 .as_ref()
1395 .map(|c| self.color_of(c))
1396 .or_else(|| self.colors.get("reveal").copied())
1397 .unwrap_or(if self.dark { Color::rgba(255, 255, 255, 90) } else { Color::rgba(0, 0, 0, 56) });
1398 Reveal { border, background, color, radius: acc.reveal_radius.unwrap_or(96.0).max(0.0) }
1399 },
1400 text_case: match acc.text_case.as_deref() {
1401 Some("upper") => crate::text::TextCase::Upper,
1402 Some("lower") => crate::text::TextCase::Lower,
1403 _ => crate::text::TextCase::None,
1404 },
1405 letter_spacing: acc.letter_spacing.unwrap_or(0.0),
1406 gap: acc.gap,
1407 border_sides: acc.border_sides,
1408 border_dash: match acc.border_style.as_deref() {
1409 Some("dashed") => vec![6.0, 4.0],
1410 Some("dotted") => vec![1.5, 3.0],
1411 _ => Vec::new(),
1412 },
1413 icon_size: acc.icon_size,
1414 icon_color: acc.icon_color.as_ref().map(|c| self.color_of(c)),
1415 icon_gap: acc.icon_gap,
1416 scroll_bar: acc.scroll_bar,
1417 }
1418 }
1419
1420 pub fn menu_metrics(&self) -> MenuMetrics {
1424 let Some(style) = self.styles.get("PopupMenu") else { return MenuMetrics::default() };
1425 let p = &style.base;
1426 let positive = |v: Option<f32>| v.filter(|v| *v > 0.0);
1427 MenuMetrics { width: positive(p.width), item_height: positive(p.item_height), separator_height: p.separator_height.map(|v| v.max(0.0)) }
1428 }
1429
1430 pub fn scroll_bar(&self, own: Option<&Style>, hover: bool) -> ScrollBarLook {
1435 let mut acc = StyleProps::default();
1436 let layers = [self.styles.get("ScrollBar"), own];
1437 for s in layers.iter().flatten() {
1438 acc.merge(&s.base);
1439 }
1440 if hover {
1441 for s in layers.iter().flatten() {
1442 acc.merge(&s.hover);
1443 }
1444 }
1445 ScrollBarLook {
1446 width: acc.width.map(|w| w.max(0.0)),
1447 track: acc.fill.as_ref().map(|c| self.color_of(c)),
1448 thumb: acc.thumb.as_ref().map(|c| self.color_of(c)),
1449 radius: acc.radius.as_ref().map(|m| Self::metric(&self.radius, m)),
1450 }
1451 }
1452}
1453
1454#[derive(Clone, Copy, Debug, Default, PartialEq)]
1456pub struct MenuMetrics {
1457 pub width: Option<f32>,
1459 pub item_height: Option<f32>,
1461 pub separator_height: Option<f32>,
1463}
1464
1465#[derive(Clone, Copy, Debug, Default, PartialEq)]
1467pub struct ScrollBarLook {
1468 pub width: Option<f32>,
1470 pub track: Option<Color>,
1472 pub thumb: Option<Color>,
1474 pub radius: Option<f32>,
1476}