1
//! Microsoft Office-style ribbon widget.
2
//!
3
//! Models the component hierarchy of the MS Ribbon (Office "Fluent" ribbon /
4
//! RibbonX `customUI` markup / Windows Ribbon Framework):
5
//!
6
//! ```text
7
//! Ribbon ─ app button ("FILE")            RibbonAppButton
8
//!        ─ tabs                           RibbonTab
9
//!            └─ groups                    RibbonGroup (label + dialog launcher)
10
//!                 └─ items                RibbonItem
11
//!                      ├─ LargeButton     RibbonButton (icon-over-label, full height)
12
//!                      ├─ SmallButton     RibbonButton (16px icon row)
13
//!                      ├─ Column / Row    RibbonColumn / RibbonRow (packing boxes)
14
//!                      ├─ Combo           embeds [`super::combobox::ComboBox`]
15
//!                      ├─ Drop            embeds [`super::drop_down::DropDown`]
16
//!                      ├─ Check           embeds [`super::check_box::CheckBox`]
17
//!                      ├─ Gallery         RibbonGallery (in-ribbon gallery + spinner)
18
//!                      ├─ Separator       thin vertical rule
19
//!                      └─ Custom          any user [`Dom`]
20
//! ```
21
//!
22
//! Mapping from RibbonX elements: `button[size=large]` → `LargeButton`,
23
//! `button`/`toggleButton` → `SmallButton` (+ `toggled`), `splitButton`/`menu`
24
//! → `RibbonArrow::Split`/`Menu`, `box`/`buttonGroup` → `Row`/`Column`,
25
//! `comboBox` → `Combo`, `dropDown` → `Drop`, `checkBox` → `Check`,
26
//! `gallery` → `Gallery`, `separator` → `Separator`,
27
//! `dialogBoxLauncher` → [`RibbonGroup::launcher`]. Contextual tabs, KeyTips,
28
//! the backstage view and automatic size collapsing are out of scope.
29
//!
30
//! Buttons are not re-implemented: every ribbon button (including the group
31
//! dialog launcher and the gallery spinner buttons) expands to the existing
32
//! [`super::button::Button`] widget with ribbon part styles injected through
33
//! `Button`'s public style fields. Embedded `Combo`/`Drop`/`Check` widgets
34
//! render exactly as configured — restyle them via their own public
35
//! `*_style` fields (see the ribbon example for an office-2013-style combobox).
36
//!
37
//! All visual parts of the ribbon itself are exposed on [`RibbonStyle`]
38
//! (defaults = the Office-2013-era look look, [`RibbonStyle::office_2013`]); replace any field
39
//! to re-theme without touching widget code.
40

            
41
use azul_core::{
42
    callbacks::{CoreCallback, CoreCallbackData, Update},
43
    dom::{
44
        Dom, DomNodeId, DomVec, EventFilter, HoverEventFilter, IdOrClass, IdOrClass::Class,
45
        IdOrClassVec,
46
    },
47
    refany::RefAny,
48
};
49
use azul_css::{
50
    dynamic_selector::OptionCssPropertyWithConditionsVec,
51
    impl_option, impl_vec, impl_vec_clone, impl_vec_debug, impl_vec_mut,
52
    system::{Handedness, SystemStyle},
53
};
54
// widget/render module pulls in the css property/value types it builds with
55
#[allow(clippy::wildcard_imports)]
56
use azul_css::{
57
    dynamic_selector::{
58
        CssPropertyWithConditions as Cond, CssPropertyWithConditionsVec, DynamicSelector,
59
        MinMaxRange,
60
    },
61
    props::{
62
        basic::{
63
            color::ColorU,
64
            font::{StyleFontFamily, StyleFontFamilyVec},
65
            *,
66
        },
67
        layout::*,
68
        property::CssProperty as P,
69
        style::*,
70
    },
71
    *,
72
};
73

            
74
use super::{
75
    button::{Button, OptionButtonOnClick},
76
    check_box::CheckBox,
77
    combobox::ComboBox,
78
    drop_down::DropDown,
79
    themes::flat,
80
};
81
use crate::callbacks::{Callback, CallbackInfo};
82

            
83
// -- Callbacks --
84

            
85
/// Callback signature invoked when a ribbon tab is clicked.
86
pub type RibbonOnTabClickCallbackType = extern "C" fn(RefAny, CallbackInfo, usize) -> Update;
87
impl_widget_callback!(
88
    RibbonOnTabClick,
89
    OptionRibbonOnTabClick,
90
    RibbonOnTabClickCallback,
91
    RibbonOnTabClickCallbackType
92
);
93

            
94
azul_core::impl_managed_callback! {
95
    wrapper:        RibbonOnTabClickCallback,
96
    info_ty:        CallbackInfo,
97
    return_ty:      Update,
98
    default_ret:    Update::DoNothing,
99
    invoker_static: RIBBON_ON_TAB_CLICK_INVOKER,
100
    invoker_ty:     AzRibbonOnTabClickCallbackInvoker,
101
    thunk_fn:       az_ribbon_on_tab_click_callback_thunk,
102
    setter_fn:      AzApp_setRibbonOnTabClickCallbackInvoker,
103
    from_handle_fn: AzRibbonOnTabClickCallback_createFromHostHandle,
104
    extra_args:     [ tab_index: usize ],
105
}
106

            
107
/// Callback signature invoked when a gallery cell is clicked (cell index).
108
pub type RibbonGalleryOnSelectCallbackType = extern "C" fn(RefAny, CallbackInfo, usize) -> Update;
109
impl_widget_callback!(
110
    RibbonGalleryOnSelect,
111
    OptionRibbonGalleryOnSelect,
112
    RibbonGalleryOnSelectCallback,
113
    RibbonGalleryOnSelectCallbackType
114
);
115

            
116
azul_core::impl_managed_callback! {
117
    wrapper:        RibbonGalleryOnSelectCallback,
118
    info_ty:        CallbackInfo,
119
    return_ty:      Update,
120
    default_ret:    Update::DoNothing,
121
    invoker_static: RIBBON_GALLERY_ON_SELECT_INVOKER,
122
    invoker_ty:     AzRibbonGalleryOnSelectCallbackInvoker,
123
    thunk_fn:       az_ribbon_gallery_on_select_callback_thunk,
124
    setter_fn:      AzApp_setRibbonGalleryOnSelectCallbackInvoker,
125
    from_handle_fn: AzRibbonGalleryOnSelectCallback_createFromHostHandle,
126
    extra_args:     [ cell_index: usize ],
127
}
128

            
129
// -- Font --
130

            
131
const SYSTEM_UI_STR: AzString = AzString::from_const_str("system:ui");
132
const SYSTEM_UI_FAMILIES: &[StyleFontFamily] = &[StyleFontFamily::System(SYSTEM_UI_STR)];
133
const SYSTEM_UI_FAMILY: StyleFontFamilyVec =
134
    StyleFontFamilyVec::from_const_slice(SYSTEM_UI_FAMILIES);
135

            
136
// -- the Office-2013-era look palette (seeds RibbonTheme::office_2013) --
137

            
138
const WHITE: ColorU = ColorU {
139
    r: 255,
140
    g: 255,
141
    b: 255,
142
    a: 255,
143
};
144
const TRANSPARENT: ColorU = ColorU {
145
    r: 0,
146
    g: 0,
147
    b: 0,
148
    a: 0,
149
};
150
/// Office 2013 accent blue (#2B579A): FILE tab, active tab text.
151
const W13_BLUE: ColorU = ColorU {
152
    r: 43,
153
    g: 87,
154
    b: 154,
155
    a: 255,
156
};
157
/// FILE tab hover fill (darker blue).
158
const W13_BLUE_HOVER: ColorU = ColorU {
159
    r: 30,
160
    g: 62,
161
    b: 111,
162
    a: 255,
163
};
164
/// Regular control text (#444444).
165
const W13_TEXT: ColorU = ColorU {
166
    r: 68,
167
    g: 68,
168
    b: 68,
169
    a: 255,
170
};
171
/// Group caption + secondary glyph gray (#676767).
172
const W13_LABEL_GRAY: ColorU = ColorU {
173
    r: 103,
174
    g: 103,
175
    b: 103,
176
    a: 255,
177
};
178
/// Monochrome icon gray.
179
const W13_ICON_GRAY: ColorU = ColorU {
180
    r: 80,
181
    g: 80,
182
    b: 80,
183
    a: 255,
184
};
185
/// Chrome border gray (#D4D4D4): tab underline, ribbon bottom border.
186
const W13_BORDER: ColorU = ColorU {
187
    r: 212,
188
    g: 212,
189
    b: 212,
190
    a: 255,
191
};
192
/// Group/segment separator gray (#E1E1E1).
193
const W13_SEP: ColorU = ColorU {
194
    r: 225,
195
    g: 225,
196
    b: 225,
197
    a: 255,
198
};
199
/// Hover fill (#CDE6F7).
200
const W13_HOVER_BG: ColorU = ColorU {
201
    r: 205,
202
    g: 230,
203
    b: 247,
204
    a: 255,
205
};
206
/// Hover/checked border (#92C0E0).
207
const W13_HOVER_BORDER: ColorU = ColorU {
208
    r: 146,
209
    g: 192,
210
    b: 224,
211
    a: 255,
212
};
213
/// Pressed fill (#B0D0EC).
214
const W13_PRESSED_BG: ColorU = ColorU {
215
    r: 176,
216
    g: 208,
217
    b: 236,
218
    a: 255,
219
};
220
/// Toggled-on fill (#C6DDF0).
221
const W13_CHECKED_BG: ColorU = ColorU {
222
    r: 198,
223
    g: 221,
224
    b: 240,
225
    a: 255,
226
};
227
/// Selected gallery cell fill (#EAF3FC).
228
const W13_SELECTED_BG: ColorU = ColorU {
229
    r: 234,
230
    g: 243,
231
    b: 252,
232
    a: 255,
233
};
234
/// Flat editable-field border gray (#ABABAB).
235
const W13_FIELD_BORDER: ColorU = ColorU {
236
    r: 171,
237
    g: 171,
238
    b: 171,
239
    a: 255,
240
};
241

            
242
// -- Theme --
243

            
244
/// Color palette from which a full [`RibbonStyle`] is derived via
245
/// [`RibbonStyle::from_theme`]. All fields are plain colors, so themes are
246
/// trivially constructible over FFI. Presets: [`RibbonTheme::office_2013`]
247
/// (the default) and [`RibbonTheme::from_system`], which extracts the
248
/// colors from the OS theme (accent color, selection color, separators).
249
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
250
#[repr(C)]
251
pub struct RibbonTheme {
252
    /// Chrome background: the ribbon's own surfaces (root, tab bar, tabs) and
253
    /// the control fills that match them (gallery frame, combo field).
254
    pub chrome_bg: ColorU,
255
    /// The tab-content band behind the groups, separately from
256
    /// [`Self::chrome_bg`] so an app can paint the two differently: a window
257
    /// whose background is a gradient wants the chrome TRANSPARENT, so the
258
    /// gradient runs unbroken from the title bar down, and the content band as
259
    /// a translucent overlay on it rather than an opaque slab that cuts it.
260
    ///
261
    /// Defaults to `chrome_bg` in every constructor, so a theme that says
262
    /// nothing looks exactly as it did.
263
    pub content_bg: ColorU,
264
    /// Accent: application button fill, active tab text.
265
    pub accent: ColorU,
266
    /// Application button hover fill.
267
    pub accent_hover: ColorU,
268
    /// Text on accent fills (application button label).
269
    pub accent_text: ColorU,
270
    /// Regular control text.
271
    pub text: ColorU,
272
    /// Group captions and secondary glyphs.
273
    pub label: ColorU,
274
    /// Monochrome icon glyphs.
275
    pub icon: ColorU,
276
    /// Chrome borders: tab underline, ribbon bottom border, gallery frame.
277
    pub border: ColorU,
278
    /// Group and segment separators.
279
    pub separator: ColorU,
280
    /// Hover fill on ribbon controls.
281
    pub hover_bg: ColorU,
282
    /// Hover and toggled-on border.
283
    pub hover_border: ColorU,
284
    /// Pressed fill.
285
    pub pressed_bg: ColorU,
286
    /// Toggled-on fill.
287
    pub checked_bg: ColorU,
288
    /// Selected gallery cell fill.
289
    pub selected_bg: ColorU,
290
    /// Editable field border (embedded comboboxes).
291
    pub field_border: ColorU,
292
}
293

            
294
impl RibbonTheme {
295
    /// The the Office-2013-era look palette: white chrome, #2B579A accents, #CDE6F7 hovers.
296
    #[must_use]
297
1385
    pub const fn office_2013() -> Self {
298
1385
        Self {
299
1385
            chrome_bg: WHITE,
300
1385
            content_bg: WHITE,
301
1385
            accent: W13_BLUE,
302
1385
            accent_hover: W13_BLUE_HOVER,
303
1385
            accent_text: WHITE,
304
1385
            text: W13_TEXT,
305
1385
            label: W13_LABEL_GRAY,
306
1385
            icon: W13_ICON_GRAY,
307
1385
            border: W13_BORDER,
308
1385
            separator: W13_SEP,
309
1385
            hover_bg: W13_HOVER_BG,
310
1385
            hover_border: W13_HOVER_BORDER,
311
1385
            pressed_bg: W13_PRESSED_BG,
312
1385
            checked_bg: W13_CHECKED_BG,
313
1385
            selected_bg: W13_SELECTED_BG,
314
1385
            field_border: W13_FIELD_BORDER,
315
1385
        }
316
1385
    }
317

            
318
    /// Extracts a ribbon palette from the OS theme (accent color, selection
319
    /// colors, separators). Colors the platform does not report fall back to
320
    /// the the Office-2013-era look palette. Pass `SystemStyle::detect()` for the live
321
    /// system theme, or a preset `SystemStyle` for platform mockups.
322
    /// Takes the style by value (FFI constructor convention).
323
    #[must_use]
324
6
    pub fn from_system(style: SystemStyle) -> Self {
325
6
        let d = Self::office_2013();
326
6
        let c = &style.colors;
327
        // Each ribbon field maps to ONE system color; a color the platform
328
        // does not report falls back to that field's own the Office-2013-era look value
329
        // (never to another derived value). No color arithmetic on purpose:
330
        // FFI-observable behavior stays trivial to reason about.
331
6
        let accent = c.accent.into_option();
332
6
        let selection = c.selection_background.into_option();
333
6
        let separator = c.separator.into_option();
334
6
        let inactive_selection = c.selection_background_inactive.into_option();
335
6
        let secondary_text = c.secondary_text.into_option();
336
6
        Self {
337
6
            chrome_bg: c.window_background.into_option().unwrap_or(d.chrome_bg),
338
6
            content_bg: c.window_background.into_option().unwrap_or(d.content_bg),
339
6
            accent: accent.unwrap_or(d.accent),
340
6
            accent_hover: selection.unwrap_or(d.accent_hover),
341
6
            accent_text: c.accent_text.into_option().unwrap_or(d.accent_text),
342
6
            text: c.text.into_option().unwrap_or(d.text),
343
6
            label: secondary_text.unwrap_or(d.label),
344
6
            icon: secondary_text.unwrap_or(d.icon),
345
6
            border: separator.unwrap_or(d.border),
346
6
            separator: separator.unwrap_or(d.separator),
347
6
            hover_bg: inactive_selection.unwrap_or(d.hover_bg),
348
6
            hover_border: accent.unwrap_or(d.hover_border),
349
6
            pressed_bg: selection.unwrap_or(d.pressed_bg),
350
6
            checked_bg: selection.unwrap_or(d.checked_bg),
351
6
            selected_bg: inactive_selection.unwrap_or(d.selected_bg),
352
6
            field_border: separator.unwrap_or(d.field_border),
353
6
        }
354
6
    }
355
}
356

            
357
impl RibbonTheme {
358
    /// The dark twin of this palette: what the ribbon paints on a dark window.
359
    ///
360
    /// Derived, not stored — the struct is the FFI palette and stays a set of
361
    /// LIGHT colours; every part builder emits each colour as a light/dark
362
    /// pair (`bg_both` & co.) and this is where the dark half comes from.
363
    ///
364
    /// Page-neutral fields — the white chrome and content band, the grey
365
    /// text, labels, icons, borders and separators, the hover/pressed/checked/
366
    /// selected greys, the field border — take the flat theme's dark tokens
367
    /// (`themes::flat`, the single source of dark values every widget shares),
368
    /// so a ribbon control and the button next to it agree on what "dark"
369
    /// is. A field that is its own colour — the accent, its hover, the label
370
    /// on it — keeps the light value: an accent fill does not change with the
371
    /// mode (`flat::button_states` makes the same call for a Primary button).
372
    /// A transparent light value stays transparent: an app that made the
373
    /// chrome see-through for a window gradient wants it see-through in dark
374
    /// mode too, not an opaque slab.
375
    ///
376
    /// The states the theme appends (`push_chrome_hover_fill` & co.) already
377
    /// use these same tokens, so a hovered control and the surface under it
378
    /// come from one palette.
379
    #[must_use]
380
199881
    pub(crate) const fn dark_counterpart(&self) -> Self {
381
2598453
        const fn neutral(light: ColorU, dark: ColorU) -> ColorU {
382
2598453
            if light.a == 0 {
383
2
                light
384
            } else {
385
2598451
                dark
386
            }
387
2598453
        }
388
199881
        Self {
389
199881
            chrome_bg: neutral(self.chrome_bg, flat::DARK_SUR),
390
199881
            content_bg: neutral(self.content_bg, flat::DARK_SUR),
391
199881
            accent: self.accent,
392
199881
            accent_hover: self.accent_hover,
393
199881
            accent_text: self.accent_text,
394
199881
            text: neutral(self.text, flat::DARK_INK),
395
199881
            label: neutral(self.label, flat::DARK_INK2),
396
199881
            icon: neutral(self.icon, flat::DARK_ICON),
397
199881
            border: neutral(self.border, flat::DARK_BD),
398
199881
            separator: neutral(self.separator, flat::DARK_SEP),
399
199881
            hover_bg: neutral(self.hover_bg, flat::DARK_HT),
400
199881
            hover_border: neutral(self.hover_border, flat::DARK_BD),
401
199881
            pressed_bg: neutral(self.pressed_bg, flat::DARK_PT),
402
199881
            checked_bg: neutral(self.checked_bg, flat::DARK_PT),
403
199881
            selected_bg: neutral(self.selected_bg, flat::DARK_HT),
404
199881
            field_border: neutral(self.field_border, flat::DARK_BD3),
405
199881
        }
406
199881
    }
407
}
408

            
409
impl Default for RibbonTheme {
410
    fn default() -> Self {
411
        Self::office_2013()
412
    }
413
}
414

            
415
// -- Colorless const part styles (shared by every theme) --
416

            
417
static GROUP_ITEMS_STYLE: &[Cond] = &[
418
    Cond::simple(P::const_box_sizing(LayoutBoxSizing::BorderBox)),
419
    Cond::simple(P::const_display(LayoutDisplay::Flex)),
420
    Cond::simple(P::const_flex_direction(LayoutFlexDirection::Row)),
421
    Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(0))),
422
    Cond::simple(P::const_height(LayoutHeight::const_px(68))),
423
    Cond::simple(P::const_align_items(LayoutAlignItems::Start)),
424
    Cond::simple(P::const_flex_shrink(LayoutFlexShrink {
425
        inner: FloatValue::const_new(0),
426
    })),
427
];
428

            
429
static GROUP_FOOTER_STYLE: &[Cond] = &[
430
    Cond::simple(P::const_box_sizing(LayoutBoxSizing::BorderBox)),
431
    Cond::simple(P::const_display(LayoutDisplay::Flex)),
432
    Cond::simple(P::const_flex_direction(LayoutFlexDirection::Row)),
433
    Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(0))),
434
    Cond::simple(P::const_height(LayoutHeight::const_px(18))),
435
    Cond::simple(P::const_align_items(LayoutAlignItems::Center)),
436
    Cond::simple(P::const_flex_shrink(LayoutFlexShrink {
437
        inner: FloatValue::const_new(0),
438
    })),
439
];
440

            
441
static FOOTER_SPACER_STYLE: &[Cond] = &[
442
    Cond::simple(P::const_width(LayoutWidth::const_px(18))),
443
    Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(0))),
444
    Cond::simple(P::const_flex_shrink(LayoutFlexShrink {
445
        inner: FloatValue::const_new(0),
446
    })),
447
];
448

            
449
static COLUMN_STYLE: &[Cond] = &[
450
    Cond::simple(P::const_display(LayoutDisplay::Flex)),
451
    Cond::simple(P::const_flex_direction(LayoutFlexDirection::Column)),
452
    Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(0))),
453
    Cond::simple(P::const_align_items(LayoutAlignItems::Start)),
454
    Cond::simple(P::const_flex_shrink(LayoutFlexShrink {
455
        inner: FloatValue::const_new(0),
456
    })),
457
];
458

            
459
static ROW_STYLE: &[Cond] = &[
460
    Cond::simple(P::const_display(LayoutDisplay::Flex)),
461
    Cond::simple(P::const_flex_direction(LayoutFlexDirection::Row)),
462
    Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(0))),
463
    Cond::simple(P::const_align_items(LayoutAlignItems::Center)),
464
    Cond::simple(P::const_margin_bottom(LayoutMarginBottom::const_px(5))),
465
    Cond::simple(P::const_flex_shrink(LayoutFlexShrink {
466
        inner: FloatValue::const_new(0),
467
    })),
468
];
469

            
470
static GALLERY_STRIP_STYLE: &[Cond] = &[
471
    Cond::simple(P::const_display(LayoutDisplay::Flex)),
472
    Cond::simple(P::const_flex_direction(LayoutFlexDirection::Row)),
473
    Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(1))),
474
    Cond::simple(P::const_overflow_x(LayoutOverflow::Hidden)),
475
    Cond::simple(P::const_overflow_y(LayoutOverflow::Hidden)),
476
];
477

            
478
static RIBBON_COMBO_TEXT_STYLE: &[Cond] = &[
479
    Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(1))),
480
    Cond::simple(P::const_text_align(StyleTextAlign::Left)),
481
    Cond::simple(P::const_padding_right(LayoutPaddingRight::const_px(2))),
482
];
483

            
484
// -- Responsive (@media) conditions --
485
//
486
// The mobile ribbon keeps the SEMANTICS of the desktop one - the same tabs,
487
// groups and items - and changes only presentation, so both chromes are
488
// emitted once and the viewport decides which is visible. That is how a
489
// responsive HTML page behaves, and it means no second widget tree, no
490
// duplicated callbacks and no state to keep in sync.
491
//
492
// `MOBILE_MAX_PX` is the breakpoint: at or below it the touch chrome shows.
493

            
494
/// Widest viewport that still gets the touch layout (a large phone in
495
/// landscape is still a phone).
496
pub const MOBILE_MAX_PX: f32 = 720.0;
497

            
498
static COND_MOBILE: &[DynamicSelector] = &[DynamicSelector::ViewportWidth(MinMaxRange {
499
    min: f32::NAN,
500
    max: MOBILE_MAX_PX,
501
})];
502

            
503
static COND_DESKTOP: &[DynamicSelector] = &[DynamicSelector::ViewportWidth(MinMaxRange {
504
    min: MOBILE_MAX_PX,
505
    max: f32::NAN,
506
})];
507

            
508
/// `display: none` unless the viewport is a phone.
509
4048
fn only_on_mobile(prop: P) -> Cond {
510
4048
    Cond::with_single_condition(prop, COND_MOBILE)
511
4048
}
512

            
513
/// `display: none` unless the viewport is a desktop.
514
fn only_on_desktop(prop: P) -> Cond {
515
    Cond::with_single_condition(prop, COND_DESKTOP)
516
}
517

            
518
/// Hidden by default, shown on phones.
519
2700
fn mobile_only_visibility(display: LayoutDisplay) -> [Cond; 2] {
520
2700
    [
521
2700
        Cond::simple(P::const_display(LayoutDisplay::None)),
522
2700
        only_on_mobile(P::const_display(display)),
523
2700
    ]
524
2700
}
525

            
526
/// Visible by default, hidden on phones.
527
fn desktop_only_visibility(display: LayoutDisplay) -> [Cond; 2] {
528
    [
529
        Cond::simple(P::const_display(display)),
530
        only_on_mobile(P::const_display(LayoutDisplay::None)),
531
    ]
532
}
533

            
534
// -- Theme -> property-list builders --
535
//
536
// Every themed ribbon part is built from `RibbonTheme` colors by the
537
// functions below; `RibbonStyle::office_2013()` is just
538
// `from_theme(&RibbonTheme::office_2013())`, so there is exactly one source
539
// of truth for each part's property list.
540

            
541
87629
fn bg_vec(c: ColorU) -> StyleBackgroundContentVec {
542
87629
    StyleBackgroundContentVec::from_vec(vec![StyleBackgroundContent::Color(c)])
543
87629
}
544

            
545
17046
fn cond_bg(c: ColorU) -> Cond {
546
17046
    Cond::simple(P::const_background_content(bg_vec(c)))
547
17046
}
548

            
549
1185
const fn cond_text_color(c: ColorU) -> Cond {
550
1185
    Cond::simple(P::const_text_color(StyleTextColor { inner: c }))
551
1185
}
552

            
553
/// the classic office-suite control metrics (22px small button, 66px large button, 26px tab)
554
/// are BORDER-BOX numbers: they include the padding and the 1px hover
555
/// border. CSS defaults to content-box, which inflated every control by its
556
/// padding+border - three 22px rows became 78px and overflowed the 68px item
557
/// area, painting over the group caption.
558
71656
const fn cond_border_box() -> Cond {
559
71656
    Cond::simple(P::const_box_sizing(LayoutBoxSizing::BorderBox))
560
71656
}
561

            
562
64951
fn push_padding(v: &mut Vec<Cond>, top: isize, right: isize, bottom: isize, left: isize) {
563
64951
    v.push(Cond::simple(P::const_padding_top(
564
64951
        LayoutPaddingTop::const_px(top),
565
    )));
566
64951
    v.push(Cond::simple(P::const_padding_right(
567
64951
        LayoutPaddingRight::const_px(right),
568
    )));
569
64951
    v.push(Cond::simple(P::const_padding_bottom(
570
64951
        LayoutPaddingBottom::const_px(bottom),
571
    )));
572
64951
    v.push(Cond::simple(P::const_padding_left(
573
64951
        LayoutPaddingLeft::const_px(left),
574
    )));
575
64951
}
576

            
577
/// 1px solid border on all four sides in the given color.
578
34017
fn push_box_border(v: &mut Vec<Cond>, c: ColorU) {
579
34017
    push_box_border_frame(v);
580
34017
    push_border_colors(v, c);
581
34017
}
582

            
583
/// The widths and styles of [`push_box_border`], without the colours.
584
39333
fn push_box_border_frame(v: &mut Vec<Cond>) {
585
39333
    v.push(Cond::simple(P::const_border_top_width(
586
39333
        LayoutBorderTopWidth::const_px(1),
587
    )));
588
39333
    v.push(Cond::simple(P::const_border_left_width(
589
39333
        LayoutBorderLeftWidth::const_px(1),
590
    )));
591
39333
    v.push(Cond::simple(P::const_border_right_width(
592
39333
        LayoutBorderRightWidth::const_px(1),
593
    )));
594
39333
    v.push(Cond::simple(P::const_border_bottom_width(
595
39333
        LayoutBorderBottomWidth::const_px(1),
596
    )));
597
39333
    v.push(Cond::simple(P::const_border_top_style(
598
39333
        StyleBorderTopStyle {
599
39333
            inner: BorderStyle::Solid,
600
39333
        },
601
    )));
602
39333
    v.push(Cond::simple(P::const_border_left_style(
603
39333
        StyleBorderLeftStyle {
604
39333
            inner: BorderStyle::Solid,
605
39333
        },
606
    )));
607
39333
    v.push(Cond::simple(P::const_border_right_style(
608
39333
        StyleBorderRightStyle {
609
39333
            inner: BorderStyle::Solid,
610
39333
        },
611
    )));
612
39333
    v.push(Cond::simple(P::const_border_bottom_style(
613
39333
        StyleBorderBottomStyle {
614
39333
            inner: BorderStyle::Solid,
615
39333
        },
616
    )));
617
39333
}
618

            
619
34017
fn push_border_colors(v: &mut Vec<Cond>, c: ColorU) {
620
34017
    v.push(Cond::simple(P::const_border_top_color(
621
34017
        StyleBorderTopColor { inner: c },
622
    )));
623
34017
    v.push(Cond::simple(P::const_border_left_color(
624
34017
        StyleBorderLeftColor { inner: c },
625
    )));
626
34017
    v.push(Cond::simple(P::const_border_right_color(
627
34017
        StyleBorderRightColor { inner: c },
628
    )));
629
34017
    v.push(Cond::simple(P::const_border_bottom_color(
630
34017
        StyleBorderBottomColor { inner: c },
631
    )));
632
34017
}
633

            
634
// -- Resting colours, light and dark --
635
//
636
// Every colour a part declares at rest is a PAIR: the light value from the
637
// palette, then its dark twin from `RibbonTheme::dark_counterpart`, in that
638
// order because inline declarations resolve last-match-wins — a twin pushed
639
// first would lose to the light value in dark mode. `Cond::themed` builds the
640
// pair so half of one cannot ship; `widgets::theme_pairs` checks whatever is
641
// still built by hand. Before this existed the ribbon declared its resting
642
// surfaces in light only (the states had twins, the chrome under them did
643
// not), which is a white Office-2013 bar on a dark window.
644
//
645
// Exempt, and declared with the plain `cond_bg` / `cond_text_color`: the
646
// surfaces that are their own colour in both modes — the application button's
647
// accent fill and the white label on it — and the transparent fills/borders
648
// that a hover paints over, which have no dark value to take.
649

            
650
/// A palette field in both modes: the light value from `t`, the dark from
651
/// [`RibbonTheme::dark_counterpart`].
652
199878
fn both(t: &RibbonTheme, field: fn(&RibbonTheme) -> ColorU) -> (ColorU, ColorU) {
653
199878
    (field(t), field(&t.dark_counterpart()))
654
199878
}
655

            
656
/// A background fill, light and dark.
657
35289
fn bg_both(t: &RibbonTheme, field: fn(&RibbonTheme) -> ColorU) -> [Cond; 2] {
658
35289
    let (light, dark) = both(t, field);
659
35289
    Cond::themed(
660
35289
        P::const_background_content(bg_vec(light)),
661
35289
        P::const_background_content(bg_vec(dark)),
662
    )
663
35289
}
664

            
665
/// A text colour, light and dark.
666
87053
fn text_both(t: &RibbonTheme, field: fn(&RibbonTheme) -> ColorU) -> [Cond; 2] {
667
87053
    let (light, dark) = both(t, field);
668
87053
    Cond::themed(
669
87053
        P::const_text_color(StyleTextColor { inner: light }),
670
87053
        P::const_text_color(StyleTextColor { inner: dark }),
671
    )
672
87053
}
673

            
674
/// The ACCENT as a TEXT colour on the neutral chrome — the active tab's
675
/// label, the mobile tab button and its chevron, the selected group-list
676
/// entry — light and dark.
677
///
678
/// The light half is the palette's accent, untouched. The dark half is the
679
/// flat theme's `DARK_ACC`, the same call `theme_tab` makes for its hover text
680
/// and `theme_combo_field` for its focus ring: the accent is a FILL colour,
681
/// and `#2B579A` as text on a dark surface is unreadable. Accent fills keep
682
/// their value in both modes (`theme_app_button`); this is for text.
683
5373
fn accent_text_both(t: &RibbonTheme) -> [Cond; 2] {
684
5373
    Cond::themed(
685
5373
        P::const_text_color(StyleTextColor { inner: t.accent }),
686
5373
        P::const_text_color(StyleTextColor {
687
5373
            inner: flat::DARK_ACC,
688
5373
        }),
689
    )
690
5373
}
691

            
692
#[derive(Clone, Copy)]
693
enum Edge {
694
    Top,
695
    Left,
696
    Right,
697
    Bottom,
698
}
699

            
700
268934
const fn edge_color(edge: Edge, c: ColorU) -> P {
701
268934
    match edge {
702
37954
        Edge::Top => P::const_border_top_color(StyleBorderTopColor { inner: c }),
703
43272
        Edge::Left => P::const_border_left_color(StyleBorderLeftColor { inner: c }),
704
92732
        Edge::Right => P::const_border_right_color(StyleBorderRightColor { inner: c }),
705
94976
        Edge::Bottom => P::const_border_bottom_color(StyleBorderBottomColor { inner: c }),
706
    }
707
268934
}
708

            
709
/// One edge's border colour, light and dark.
710
58559
fn push_edge_color_both(
711
58559
    v: &mut Vec<Cond>,
712
58559
    edge: Edge,
713
58559
    t: &RibbonTheme,
714
58559
    field: fn(&RibbonTheme) -> ColorU,
715
58559
) {
716
58559
    let (light, dark) = both(t, field);
717
58559
    v.extend(Cond::themed(
718
58559
        edge_color(edge, light),
719
58559
        edge_color(edge, dark),
720
    ));
721
58559
}
722

            
723
/// [`push_border_colors`] in both modes: the four light values first, in the
724
/// same order, then the four twins (the `hover_border_both` shape).
725
18977
fn push_border_colors_both(v: &mut Vec<Cond>, t: &RibbonTheme, field: fn(&RibbonTheme) -> ColorU) {
726
    const EDGES: [Edge; 4] = [Edge::Top, Edge::Left, Edge::Right, Edge::Bottom];
727
18977
    let (light, dark) = both(t, field);
728
94885
    for edge in EDGES {
729
75908
        v.push(Cond::simple(edge_color(edge, light)));
730
75908
    }
731
94885
    for edge in EDGES {
732
75908
        v.push(Cond::dark_theme(edge_color(edge, dark)));
733
75908
    }
734
18977
}
735

            
736
/// [`push_box_border`] with the colour in both modes.
737
5316
fn push_box_border_both(v: &mut Vec<Cond>, t: &RibbonTheme, field: fn(&RibbonTheme) -> ColorU) {
738
5316
    push_box_border_frame(v);
739
5316
    push_border_colors_both(v, t, field);
740
5316
}
741

            
742
/// [`push_bottom_border`] with the colour in both modes.
743
27164
fn push_bottom_border_both(v: &mut Vec<Cond>, t: &RibbonTheme, field: fn(&RibbonTheme) -> ColorU) {
744
27164
    push_bottom_border_frame(v);
745
27164
    push_edge_color_both(v, Edge::Bottom, t, field);
746
27164
}
747

            
748
// -- Interactive states --
749
//
750
// Hover, pressed and focus are NOT declared in this file. They are built by
751
// the theme module (`themes::flat::hover_bg_both` and friends), which returns
752
// each rule together with its dark twin, because the dark half needs that
753
// module's palette — `DARK_HT`, `DARK_PT`, `DARK_BD`, `DARK_ACC` — which this
754
// file cannot see. Declared here, a state could only ever name the light
755
// colour, which is how every ribbon control kept its light-blue hover on a
756
// dark surface.
757
//
758
// Which dark colour a rule takes depends on the SURFACE it sits on:
759
//
760
//   * the chrome — tab strip, buttons, launcher, gallery, the mobile lists — is page-neutral: white
761
//     in the Office look, the window background from `from_system`. Its dark twins are the theme's
762
//     tokens, exactly what `flat::button_states` gives the neutral button;
763
//   * the application button is an ACCENT fill in either mode, so its hover keeps the palette's own
764
//     `accent_hover` (`theme_app_button`);
765
//   * a hovered tab's text and a focused field's ring take the ACCENT, the one state colour with a
766
//     genuine per-mode value in both palettes, so their twins are `DARK_ACC` (`theme_tab`,
767
//     `theme_combo_field`).
768

            
769
/// Hover fill of a control on the neutral chrome, light and dark.
770
52830
fn push_chrome_hover_fill(v: &mut Vec<Cond>, t: &RibbonTheme) {
771
52830
    v.extend(flat::hover_bg_both(t.hover_bg, flat::DARK_HT));
772
52830
}
773

            
774
/// Hover border of a control on the neutral chrome, all four edges, light and
775
/// dark.
776
34017
fn push_chrome_hover_border(v: &mut Vec<Cond>, t: &RibbonTheme) {
777
34017
    v.extend(flat::hover_border_both(t.hover_border, flat::DARK_BD));
778
34017
}
779

            
780
/// Bottom border only (tab underline / ribbon bottom edge).
781
fn push_bottom_border(v: &mut Vec<Cond>, c: ColorU) {
782
    push_bottom_border_frame(v);
783
    v.push(Cond::simple(P::const_border_bottom_color(
784
        StyleBorderBottomColor { inner: c },
785
    )));
786
}
787

            
788
/// The width and style of [`push_bottom_border`], without the colour.
789
27164
fn push_bottom_border_frame(v: &mut Vec<Cond>) {
790
27164
    v.push(Cond::simple(P::const_border_bottom_width(
791
27164
        LayoutBorderBottomWidth::const_px(1),
792
    )));
793
27164
    v.push(Cond::simple(P::const_border_bottom_style(
794
27164
        StyleBorderBottomStyle {
795
27164
            inner: BorderStyle::Solid,
796
27164
        },
797
    )));
798
27164
}
799

            
800
/// Transparent-bordered, hover-highlighted button chassis shared by large
801
/// and small ribbon buttons.
802
11930
fn push_button_chassis(v: &mut Vec<Cond>, t: &RibbonTheme) {
803
11930
    v.push(cond_border_box());
804
11930
    v.push(Cond::simple(P::const_cursor(StyleCursor::Default)));
805
11930
    v.push(cond_bg(TRANSPARENT));
806
11930
    push_box_border(v, TRANSPARENT);
807
11930
    push_chrome_hover_fill(v, t);
808
11930
    push_chrome_hover_border(v, t);
809
    // Pressed: page-neutral chrome, so the dark twin is the theme's pressed
810
    // face — see the `Interactive states` note above.
811
11930
    v.extend(flat::active_bg_both(t.pressed_bg, flat::DARK_PT));
812
11930
}
813

            
814
1347
fn theme_container(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
815
1347
    let mut v = vec![
816
1347
        Cond::simple(P::const_display(LayoutDisplay::Flex)),
817
1347
        Cond::simple(P::const_flex_direction(LayoutFlexDirection::Column)),
818
1347
        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(0))),
819
1347
        Cond::simple(P::const_font_family(SYSTEM_UI_FAMILY)),
820
1347
        Cond::simple(P::const_font_size(StyleFontSize::const_px(12))),
821
    ];
822
1347
    v.extend(bg_both(t, |p| p.chrome_bg));
823
1347
    push_bottom_border_both(&mut v, t, |p| p.border);
824
1347
    CssPropertyWithConditionsVec::from_vec(v)
825
1347
}
826

            
827
1348
fn theme_tab_bar(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
828
1348
    let mut v = vec![
829
1348
        cond_border_box(),
830
1348
        Cond::simple(P::const_display(LayoutDisplay::Flex)),
831
        // Replaced by the full-width mobile tab button on phones. The
832
        // conditional MUST come after the unconditional value: inline
833
        // properties resolve last-match-wins.
834
1348
        only_on_mobile(P::const_display(LayoutDisplay::None)),
835
1348
        Cond::simple(P::const_flex_direction(LayoutFlexDirection::Row)),
836
1348
        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(0))),
837
1348
        Cond::simple(P::const_height(LayoutHeight::const_px(26))),
838
    ];
839
1348
    v.extend(bg_both(t, |p| p.chrome_bg));
840
1348
    CssPropertyWithConditionsVec::from_vec(v)
841
1348
}
842

            
843
1185
fn theme_app_button(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
844
1185
    let mut v: Vec<Cond> = vec![
845
1185
        cond_border_box(),
846
1185
        Cond::simple(P::const_display(LayoutDisplay::Flex)),
847
1185
        Cond::simple(P::const_flex_direction(LayoutFlexDirection::Row)),
848
1185
        Cond::simple(P::const_align_items(LayoutAlignItems::Center)),
849
1185
        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(0))),
850
    ];
851
1185
    v.push(Cond::simple(P::const_flex_shrink(LayoutFlexShrink {
852
1185
        inner: FloatValue::const_new(0),
853
1185
    })));
854
1185
    push_padding(&mut v, 7, 17, 7, 17);
855
    // Its own colour in both modes: an accent fill and the label on it are
856
    // the two resting surfaces with NO dark twin (see `dark_counterpart`).
857
1185
    v.push(cond_bg(t.accent));
858
1185
    v.push(cond_text_color(t.accent_text));
859
1185
    v.push(Cond::simple(P::const_font_size(StyleFontSize::const_px(
860
        12,
861
    ))));
862
1185
    v.push(Cond::simple(P::const_cursor(StyleCursor::Pointer)));
863
1185
    v.push(Cond::simple(P::user_select(StyleUserSelect::None)));
864
    // Hover, light and dark. The application button is an ACCENT fill in
865
    // either mode (`cond_bg(t.accent)` above has no dark variant), so the dark
866
    // twin is the palette's own `accent_hover` too: the theme's neutral grey
867
    // on a blue button would be wrong, and inventing a second blue is a design
868
    // decision this refactor has no business making — `flat::button_states`
869
    // makes the same call for a Primary button.
870
1185
    v.extend(flat::hover_bg_both(t.accent_hover, t.accent_hover));
871
1185
    CssPropertyWithConditionsVec::from_vec(v)
872
1185
}
873

            
874
8237
fn theme_tab(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
875
8237
    let mut v: Vec<Cond> = vec![
876
8237
        cond_border_box(),
877
8237
        Cond::simple(P::const_display(LayoutDisplay::Flex)),
878
8237
        Cond::simple(P::const_flex_direction(LayoutFlexDirection::Row)),
879
8237
        Cond::simple(P::const_align_items(LayoutAlignItems::Center)),
880
8237
        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(0))),
881
    ];
882
8237
    v.push(Cond::simple(P::const_flex_shrink(LayoutFlexShrink {
883
8237
        inner: FloatValue::const_new(0),
884
8237
    })));
885
8237
    push_padding(&mut v, 7, 13, 6, 13);
886
8237
    v.push(Cond::simple(P::const_cursor(StyleCursor::Pointer)));
887
8237
    v.push(Cond::simple(P::user_select(StyleUserSelect::None)));
888
8237
    v.extend(text_both(t, |p| p.text));
889
8237
    v.extend(bg_both(t, |p| p.chrome_bg));
890
8237
    push_bottom_border_both(&mut v, t, |p| p.border);
891
    // Hover text, light and dark. The tab strip is page-neutral chrome and a
892
    // hovered tab's text takes the accent, so the dark twin is the theme's
893
    // `DARK_ACC` — the accent is the one state colour with a genuine per-mode
894
    // value in both palettes.
895
8237
    v.extend(flat::hover_text_color_both(t.accent, flat::DARK_ACC));
896
    // A tab header is ONE line. Without this "PAGE LAYOUT" wrapped, and its
897
    // second line was drawn below the 26px tab strip, over the ribbon content
898
    // - invisible only because the content band was opaque and painted over
899
    // it. It stops being invisible the moment an app makes that band
900
    // translucent, which is what `content_bg` is for.
901
8237
    v.push(Cond::simple(P::WhiteSpace(
902
8237
        props::property::StyleWhiteSpaceValue::Exact(StyleWhiteSpace::Nowrap),
903
8237
    )));
904
8237
    CssPropertyWithConditionsVec::from_vec(v)
905
8237
}
906

            
907
1347
fn theme_tab_active(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
908
1347
    let mut v: Vec<Cond> = vec![
909
1347
        cond_border_box(),
910
1347
        Cond::simple(P::const_display(LayoutDisplay::Flex)),
911
1347
        Cond::simple(P::const_flex_direction(LayoutFlexDirection::Row)),
912
1347
        Cond::simple(P::const_align_items(LayoutAlignItems::Center)),
913
1347
        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(0))),
914
    ];
915
1347
    v.push(Cond::simple(P::const_flex_shrink(LayoutFlexShrink {
916
1347
        inner: FloatValue::const_new(0),
917
1347
    })));
918
1347
    push_padding(&mut v, 6, 12, 6, 12);
919
1347
    v.push(Cond::simple(P::user_select(StyleUserSelect::None)));
920
1347
    v.extend(accent_text_both(t));
921
1347
    v.extend(bg_both(t, |p| p.chrome_bg));
922
1347
    push_box_border_both(&mut v, t, |p| p.border);
923
    // Erase the underline below the active tab: the bottom border matches
924
    // the chrome so the tab visually merges with the ribbon content — in
925
    // both modes, so the pair follows the box border's pair (last wins).
926
1347
    push_edge_color_both(&mut v, Edge::Bottom, t, |p| p.content_bg);
927
    // One line, like every other tab - see `theme_tab`.
928
1347
    v.push(Cond::simple(P::WhiteSpace(
929
1347
        props::property::StyleWhiteSpaceValue::Exact(StyleWhiteSpace::Nowrap),
930
1347
    )));
931
1347
    CssPropertyWithConditionsVec::from_vec(v)
932
1347
}
933

            
934
1347
fn theme_tab_filler(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
935
1347
    let mut v = vec![Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(
936
        1,
937
    )))];
938
1347
    push_bottom_border_both(&mut v, t, |p| p.border);
939
1347
    CssPropertyWithConditionsVec::from_vec(v)
940
1347
}
941

            
942
1347
fn theme_content(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
943
1347
    let mut v = vec![
944
1347
        cond_border_box(),
945
1347
        Cond::simple(P::const_display(LayoutDisplay::Flex)),
946
1347
        Cond::simple(P::const_flex_direction(LayoutFlexDirection::Row)),
947
1347
        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(0))),
948
1347
        Cond::simple(P::const_flex_shrink(LayoutFlexShrink {
949
1347
            inner: FloatValue::const_new(0),
950
1347
        })),
951
1347
        Cond::simple(P::const_height(LayoutHeight::const_px(92))),
952
    ];
953
1347
    v.extend(bg_both(t, |p| p.content_bg));
954
1347
    CssPropertyWithConditionsVec::from_vec(v)
955
1347
}
956

            
957
5302
fn theme_group(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
958
5302
    let mut v = vec![
959
5302
        Cond::simple(P::const_display(LayoutDisplay::Flex)),
960
5302
        Cond::simple(P::const_flex_direction(LayoutFlexDirection::Column)),
961
5302
        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(0))),
962
5302
        Cond::simple(P::const_flex_shrink(LayoutFlexShrink {
963
5302
            inner: FloatValue::const_new(0),
964
5302
        })),
965
5302
        Cond::simple(P::const_padding_top(LayoutPaddingTop::const_px(3))),
966
5302
        Cond::simple(P::const_padding_left(LayoutPaddingLeft::const_px(2))),
967
5302
        Cond::simple(P::const_padding_right(LayoutPaddingRight::const_px(2))),
968
5302
        Cond::simple(P::const_border_right_width(
969
5302
            LayoutBorderRightWidth::const_px(1),
970
        )),
971
5302
        Cond::simple(P::const_border_right_style(StyleBorderRightStyle {
972
5302
            inner: BorderStyle::Solid,
973
5302
        })),
974
    ];
975
5302
    push_edge_color_both(&mut v, Edge::Right, t, |p| p.separator);
976
5302
    CssPropertyWithConditionsVec::from_vec(v)
977
5302
}
978

            
979
5302
fn theme_group_label(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
980
5302
    let mut v = vec![
981
5302
        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(1))),
982
5302
        Cond::simple(P::const_text_align(StyleTextAlign::Center)),
983
5302
        Cond::simple(P::const_font_size(StyleFontSize::const_px(11))),
984
    ];
985
5302
    v.extend(text_both(t, |p| p.label));
986
5302
    v.push(Cond::simple(P::user_select(StyleUserSelect::None)));
987
5302
    CssPropertyWithConditionsVec::from_vec(v)
988
5302
}
989

            
990
3
fn theme_launcher_button(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
991
3
    let mut v = vec![
992
3
        cond_border_box(),
993
3
        Cond::simple(P::const_display(LayoutDisplay::Flex)),
994
3
        Cond::simple(P::const_flex_direction(LayoutFlexDirection::Row)),
995
3
        Cond::simple(P::const_align_items(LayoutAlignItems::Center)),
996
3
        Cond::simple(P::const_justify_content(LayoutJustifyContent::Center)),
997
3
        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(0))),
998
3
        Cond::simple(P::const_flex_shrink(LayoutFlexShrink {
999
3
            inner: FloatValue::const_new(0),
3
        })),
3
        Cond::simple(P::const_width(LayoutWidth::const_px(16))),
3
        Cond::simple(P::const_height(LayoutHeight::const_px(14))),
    ];
3
    push_padding(&mut v, 0, 0, 0, 0);
3
    v.push(Cond::simple(P::const_cursor(StyleCursor::Default)));
3
    v.push(cond_bg(TRANSPARENT));
3
    push_box_border(&mut v, TRANSPARENT);
3
    push_chrome_hover_fill(&mut v, t);
3
    push_chrome_hover_border(&mut v, t);
3
    CssPropertyWithConditionsVec::from_vec(v)
3
}
3
fn theme_launcher_icon(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
3
    let mut v = vec![Cond::simple(P::const_font_size(StyleFontSize::const_px(
        11,
    )))];
3
    v.extend(text_both(t, |p| p.label));
3
    v.push(Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(
        0,
    ))));
3
    v.push(Cond::simple(P::user_select(StyleUserSelect::None)));
3
    CssPropertyWithConditionsVec::from_vec(v)
3
}
2
fn theme_separator(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
2
    let mut v = vec![
2
        Cond::simple(P::const_width(LayoutWidth::const_px(1))),
2
        Cond::simple(P::const_height(LayoutHeight::const_px(22))),
2
        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(0))),
2
        Cond::simple(P::const_flex_shrink(LayoutFlexShrink {
2
            inner: FloatValue::const_new(0),
2
        })),
2
        Cond::simple(P::const_margin_left(LayoutMarginLeft::const_px(3))),
2
        Cond::simple(P::const_margin_right(LayoutMarginRight::const_px(3))),
    ];
2
    v.extend(bg_both(t, |p| p.separator));
2
    CssPropertyWithConditionsVec::from_vec(v)
2
}
1220
fn theme_large_button(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
1220
    let mut v = vec![
1220
        Cond::simple(P::const_display(LayoutDisplay::Flex)),
1220
        Cond::simple(P::const_flex_direction(LayoutFlexDirection::Column)),
1220
        Cond::simple(P::const_align_items(LayoutAlignItems::Center)),
1220
        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(0))),
1220
        Cond::simple(P::const_flex_shrink(LayoutFlexShrink {
1220
            inner: FloatValue::const_new(0),
1220
        })),
1220
        Cond::simple(P::const_height(LayoutHeight::const_px(66))),
1220
        Cond::simple(P::const_min_width(LayoutMinWidth::const_px(44))),
    ];
1220
    push_padding(&mut v, 3, 7, 3, 7);
1220
    v.push(Cond::simple(P::const_margin_right(
1220
        LayoutMarginRight::const_px(1),
    )));
1220
    push_button_chassis(&mut v, t);
1220
    CssPropertyWithConditionsVec::from_vec(v)
1220
}
1220
fn theme_large_icon(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
1220
    let mut v = vec![Cond::simple(P::const_font_size(StyleFontSize::const_px(
        32,
    )))];
1220
    v.extend(text_both(t, |p| p.icon));
1220
    v.push(Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(
        0,
    ))));
1220
    v.push(Cond::simple(P::user_select(StyleUserSelect::None)));
1220
    CssPropertyWithConditionsVec::from_vec(v)
1220
}
1220
fn theme_large_label(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
1220
    let mut v = vec![Cond::simple(P::const_font_size(StyleFontSize::const_px(
        12,
    )))];
1220
    v.extend(text_both(t, |p| p.text));
1220
    v.push(Cond::simple(P::const_text_align(StyleTextAlign::Center)));
1220
    v.push(Cond::simple(P::const_margin_top(
1220
        LayoutMarginTop::const_px(3),
    )));
1220
    v.push(Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(
        0,
    ))));
1220
    v.push(Cond::simple(P::user_select(StyleUserSelect::None)));
1220
    CssPropertyWithConditionsVec::from_vec(v)
1220
}
10710
fn theme_small_button(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
10710
    let mut v = vec![
10710
        Cond::simple(P::const_display(LayoutDisplay::Flex)),
10710
        Cond::simple(P::const_flex_direction(LayoutFlexDirection::Row)),
10710
        Cond::simple(P::const_align_items(LayoutAlignItems::Center)),
10710
        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(0))),
10710
        Cond::simple(P::const_flex_shrink(LayoutFlexShrink {
10710
            inner: FloatValue::const_new(0),
10710
        })),
10710
        Cond::simple(P::const_height(LayoutHeight::const_px(22))),
    ];
10710
    push_padding(&mut v, 1, 3, 1, 3);
10710
    push_button_chassis(&mut v, t);
10710
    CssPropertyWithConditionsVec::from_vec(v)
10710
}
10710
fn theme_small_icon(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
10710
    let mut v = vec![Cond::simple(P::const_font_size(StyleFontSize::const_px(
        16,
    )))];
10710
    v.extend(text_both(t, |p| p.icon));
10710
    v.push(Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(
        0,
    ))));
10710
    v.push(Cond::simple(P::user_select(StyleUserSelect::None)));
10710
    CssPropertyWithConditionsVec::from_vec(v)
10710
}
14639
fn theme_small_label(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
14639
    let mut v = vec![Cond::simple(P::const_font_size(StyleFontSize::const_px(
        12,
    )))];
14639
    v.extend(text_both(t, |p| p.text));
14639
    v.push(Cond::simple(P::const_margin_left(
14639
        LayoutMarginLeft::const_px(5),
    )));
14639
    v.push(Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(
        0,
    ))));
14639
    v.push(Cond::simple(P::user_select(StyleUserSelect::None)));
14639
    CssPropertyWithConditionsVec::from_vec(v)
14639
}
15858
fn theme_arrow_icon(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
15858
    let mut v = vec![Cond::simple(P::const_font_size(StyleFontSize::const_px(
        14,
    )))];
15858
    v.extend(text_both(t, |p| p.label));
15858
    v.push(Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(
        0,
    ))));
15858
    v.push(Cond::simple(P::user_select(StyleUserSelect::None)));
15858
    CssPropertyWithConditionsVec::from_vec(v)
15858
}
/// Appended to a button's container style when [`RibbonButton::toggled`] is
/// set. Inline properties resolve last-wins, so these override the base.
3
fn theme_checked(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
3
    let mut v: Vec<Cond> = bg_both(t, |p| p.checked_bg).to_vec();
3
    push_border_colors_both(&mut v, t, |p| p.hover_border);
3
    CssPropertyWithConditionsVec::from_vec(v)
3
}
1310
fn theme_gallery_frame(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
1310
    let mut v = vec![
1310
        cond_border_box(),
1310
        Cond::simple(P::const_min_width(LayoutMinWidth::const_px(137))),
1310
        Cond::simple(P::const_display(LayoutDisplay::Flex)),
1310
        Cond::simple(P::const_flex_direction(LayoutFlexDirection::Row)),
1310
        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(1))),
1310
        Cond::simple(P::const_height(LayoutHeight::const_px(68))),
        // The frame IS the gallery viewport (like classic office suites): overflow hidden
        // both clips partially-visible cells and zeroes the frame's
        // automatic minimum size so it yields space to rigid groups.
        // (taffy 0.10 only collapses the minimum for DIRECT scroll
        // containers — see layout/tests/flex_intrinsic_text.rs.)
1310
        Cond::simple(P::const_overflow_x(LayoutOverflow::Hidden)),
1310
        Cond::simple(P::const_overflow_y(LayoutOverflow::Hidden)),
    ];
1310
    v.extend(bg_both(t, |p| p.chrome_bg));
1310
    push_box_border_both(&mut v, t, |p| p.border);
1310
    CssPropertyWithConditionsVec::from_vec(v)
1310
}
22084
fn theme_gallery_cell(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
22084
    let mut v = vec![
22084
        cond_border_box(),
22084
        Cond::simple(P::const_display(LayoutDisplay::Flex)),
22084
        Cond::simple(P::const_flex_direction(LayoutFlexDirection::Column)),
22084
        Cond::simple(P::const_align_items(LayoutAlignItems::Center)),
22084
        Cond::simple(P::const_justify_content(LayoutJustifyContent::Center)),
22084
        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(0))),
22084
        Cond::simple(P::const_flex_shrink(LayoutFlexShrink {
22084
            inner: FloatValue::const_new(0),
22084
        })),
22084
        Cond::simple(P::const_width(LayoutWidth::const_px(120))),
    ];
22084
    push_padding(&mut v, 2, 6, 2, 6);
22084
    v.push(Cond::simple(P::const_cursor(StyleCursor::Default)));
22084
    v.push(Cond::simple(P::user_select(StyleUserSelect::None)));
22084
    push_box_border(&mut v, TRANSPARENT);
    // Cells are divided by a thin rule on their right edge.
22084
    push_edge_color_both(&mut v, Edge::Right, t, |p| p.separator);
22084
    push_chrome_hover_fill(&mut v, t);
22084
    push_chrome_hover_border(&mut v, t);
22084
    CssPropertyWithConditionsVec::from_vec(v)
22084
}
/// Appended to [`RibbonStyle::gallery_cell_style`] for the selected cell.
13658
fn theme_gallery_cell_selected(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
13658
    let mut v: Vec<Cond> = bg_both(t, |p| p.selected_bg).to_vec();
13658
    push_border_colors_both(&mut v, t, |p| p.hover_border);
13658
    CssPropertyWithConditionsVec::from_vec(v)
13658
}
11043
fn theme_gallery_cell_label(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
11043
    let mut v = vec![Cond::simple(P::const_font_size(StyleFontSize::const_px(
        11,
    )))];
11043
    v.extend(text_both(t, |p| p.text));
11043
    v.push(Cond::simple(P::const_margin_top(
11043
        LayoutMarginTop::const_px(2),
    )));
11043
    v.push(Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(
        0,
    ))));
11043
    v.push(Cond::simple(P::user_select(StyleUserSelect::None)));
11043
    CssPropertyWithConditionsVec::from_vec(v)
11043
}
1310
fn theme_gallery_spinner(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
1310
    let mut v = vec![
1310
        Cond::simple(P::const_display(LayoutDisplay::Flex)),
1310
        Cond::simple(P::const_flex_direction(LayoutFlexDirection::Column)),
1310
        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(0))),
1310
        Cond::simple(P::const_flex_shrink(LayoutFlexShrink {
1310
            inner: FloatValue::const_new(0),
1310
        })),
1310
        Cond::simple(P::const_width(LayoutWidth::const_px(15))),
1310
        Cond::simple(P::const_border_left_width(LayoutBorderLeftWidth::const_px(
            1,
        ))),
1310
        Cond::simple(P::const_border_left_style(StyleBorderLeftStyle {
1310
            inner: BorderStyle::Solid,
1310
        })),
    ];
1310
    push_edge_color_both(&mut v, Edge::Left, t, |p| p.separator);
1310
    CssPropertyWithConditionsVec::from_vec(v)
1310
}
/// The gallery wrapper is the positioning context for the expansion panel;
/// it is otherwise transparent and behaves exactly like the bare frame.
static GALLERY_WRAPPER_STYLE: &[Cond] = &[
    Cond::simple(P::const_display(LayoutDisplay::Flex)),
    Cond::simple(P::const_flex_direction(LayoutFlexDirection::Row)),
    Cond::simple(P::const_position(LayoutPosition::Relative)),
    Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(1))),
    Cond::simple(P::const_min_width(LayoutMinWidth::const_px(137))),
];
/// The "More" expansion panel: an absolutely-positioned wrapped grid of every
/// gallery cell, hidden until the More button toggles its `display`.
1308
fn theme_gallery_panel(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
1308
    let mut v = vec![
1308
        Cond::simple(P::const_display(LayoutDisplay::None)),
1308
        Cond::simple(P::const_position(LayoutPosition::Absolute)),
        // Same reason as the mobile overlay: absolute is not "on top".
1308
        Cond::simple(P::const_z_index(LayoutZIndex::Integer(100))),
1308
        Cond::simple(P::const_top(LayoutTop::const_px(68))),
1308
        Cond::simple(P::const_left(LayoutLeft::const_px(0))),
1308
        Cond::simple(P::const_width(LayoutWidth::const_px(612))),
1308
        Cond::simple(P::const_flex_direction(LayoutFlexDirection::Row)),
1308
        Cond::simple(P::const_flex_wrap(LayoutFlexWrap::Wrap)),
    ];
1308
    v.extend(bg_both(t, |p| p.chrome_bg));
1308
    push_box_border_both(&mut v, t, |p| p.border);
1308
    CssPropertyWithConditionsVec::from_vec(v)
1308
}
3928
fn theme_gallery_spinner_button(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
3928
    let mut v = vec![
3928
        cond_border_box(),
3928
        Cond::simple(P::const_display(LayoutDisplay::Flex)),
3928
        Cond::simple(P::const_flex_direction(LayoutFlexDirection::Row)),
3928
        Cond::simple(P::const_align_items(LayoutAlignItems::Center)),
3928
        Cond::simple(P::const_justify_content(LayoutJustifyContent::Center)),
3928
        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(1))),
3928
        Cond::simple(P::const_width(LayoutWidth::const_px(14))),
    ];
3928
    push_padding(&mut v, 0, 0, 0, 0);
3928
    v.push(Cond::simple(P::const_cursor(StyleCursor::Default)));
3928
    v.push(cond_bg(TRANSPARENT));
3928
    v.push(Cond::simple(P::const_border_top_width(
3928
        LayoutBorderTopWidth::const_px(0),
    )));
3928
    v.push(Cond::simple(P::const_border_left_width(
3928
        LayoutBorderLeftWidth::const_px(0),
    )));
3928
    v.push(Cond::simple(P::const_border_right_width(
3928
        LayoutBorderRightWidth::const_px(0),
    )));
3928
    v.push(Cond::simple(P::const_border_bottom_width(
3928
        LayoutBorderBottomWidth::const_px(0),
    )));
3928
    push_chrome_hover_fill(&mut v, t);
3928
    CssPropertyWithConditionsVec::from_vec(v)
3928
}
3928
fn theme_gallery_spinner_icon(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
3928
    let mut v = vec![Cond::simple(P::const_font_size(StyleFontSize::const_px(
        12,
    )))];
3928
    v.extend(text_both(t, |p| p.label));
3928
    v.push(Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(
        0,
    ))));
3928
    v.push(Cond::simple(P::user_select(StyleUserSelect::None)));
3928
    CssPropertyWithConditionsVec::from_vec(v)
3928
}
/// Office-2013-look combobox parts, injected by [`RibbonStyle::styled_combo_box`].
4
fn theme_combo_wrapper_base(_t: &RibbonTheme) -> Vec<Cond> {
4
    vec![
4
        Cond::simple(P::const_display(LayoutDisplay::InlineBlock)),
4
        Cond::simple(P::const_position(LayoutPosition::Relative)),
4
        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(0))),
4
        Cond::simple(P::const_flex_shrink(LayoutFlexShrink {
4
            inner: FloatValue::const_new(0),
4
        })),
4
        Cond::simple(P::const_margin_right(LayoutMarginRight::const_px(2))),
4
        Cond::simple(P::const_font_size(StyleFontSize::const_px(12))),
4
        Cond::simple(P::const_font_family(SYSTEM_UI_FAMILY)),
    ]
4
}
4
fn theme_combo_field(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
4
    let mut v = vec![
4
        cond_border_box(),
4
        Cond::simple(P::const_display(LayoutDisplay::Flex)),
4
        Cond::simple(P::const_flex_direction(LayoutFlexDirection::Row)),
4
        Cond::simple(P::const_align_items(LayoutAlignItems::Center)),
4
        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(0))),
4
        Cond::simple(P::const_height(LayoutHeight::const_px(22))),
    ];
4
    push_padding(&mut v, 0, 2, 0, 5);
4
    v.push(Cond::simple(P::const_cursor(StyleCursor::Text)));
4
    v.extend(bg_both(t, |p| p.chrome_bg));
4
    v.extend(text_both(t, |p| p.text));
4
    push_box_border_both(&mut v, t, |p| p.field_border);
    // Focus ring, light and dark. The field sits on the neutral chrome and its
    // ring is the accent, so the dark twin is the theme's `DARK_ACC`. All four
    // edges: a ring that sets only some leaves the rest at their resting
    // colour.
4
    v.extend(flat::focus_border_both(t.accent, flat::DARK_ACC));
4
    CssPropertyWithConditionsVec::from_vec(v)
4
}
4
fn theme_combo_arrow(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
4
    let mut v = vec![Cond::simple(P::const_font_size(StyleFontSize::const_px(
        14,
    )))];
4
    v.extend(text_both(t, |p| p.label));
4
    v.push(Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(
        0,
    ))));
4
    v.push(Cond::simple(P::user_select(StyleUserSelect::None)));
4
    CssPropertyWithConditionsVec::from_vec(v)
4
}
// -- Mobile part styles --
//
// Touch targets follow the platform minimum (44px). The desktop tab strip
// and the mobile tab button are mutually exclusive via the viewport
// condition, so exactly one is ever visible.
/// The full-width tab button that replaces the tab strip on phones. Shows the
/// ACTIVE tab's label plus a chevron that opens the tab overlay; double
/// tapping it collapses the ribbon exactly like double clicking a desktop tab.
1348
fn theme_mobile_tab_button(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
1348
    let mut v: Vec<Cond> = mobile_only_visibility(LayoutDisplay::Flex).to_vec();
1348
    v.push(cond_border_box());
1348
    v.push(Cond::simple(P::const_flex_direction(
1348
        LayoutFlexDirection::Row,
    )));
1348
    v.push(Cond::simple(P::const_align_items(LayoutAlignItems::Center)));
1348
    v.push(Cond::simple(P::const_height(LayoutHeight::const_px(48))));
1348
    v.push(Cond::simple(P::const_width(LayoutWidth::Px(
1348
        PixelValue::const_percent(100),
1348
    ))));
1348
    push_padding(&mut v, 0, 12, 0, 16);
1348
    v.push(Cond::simple(P::const_font_size(StyleFontSize::const_px(
        17,
    ))));
1348
    v.extend(accent_text_both(t));
1348
    v.extend(bg_both(t, |p| p.chrome_bg));
1348
    push_bottom_border_both(&mut v, t, |p| p.border);
1348
    v.push(Cond::simple(P::const_cursor(StyleCursor::Pointer)));
1348
    v.push(Cond::simple(P::user_select(StyleUserSelect::None)));
1348
    CssPropertyWithConditionsVec::from_vec(v)
1348
}
/// The active tab's label inside the mobile tab button.
1347
fn theme_mobile_tab_label(_t: &RibbonTheme) -> CssPropertyWithConditionsVec {
1347
    CssPropertyWithConditionsVec::from_vec(vec![
1347
        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(1))),
1347
        Cond::simple(P::user_select(StyleUserSelect::None)),
    ])
1347
}
/// Chevron on the mobile tab button.
1347
fn theme_mobile_tab_arrow(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
1347
    let mut v = vec![Cond::simple(P::const_font_size(StyleFontSize::const_px(
        24,
    )))];
1347
    v.extend(accent_text_both(t));
1347
    v.push(Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(
        0,
    ))));
1347
    v.push(Cond::simple(P::user_select(StyleUserSelect::None)));
1347
    CssPropertyWithConditionsVec::from_vec(v)
1347
}
/// Full-screen overlay listing every tab; opened by the mobile tab button.
1347
fn theme_mobile_tab_overlay(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
1347
    let mut v = vec![
        // Hidden until the button opens it (on ANY viewport: the overlay is
        // only reachable through the mobile button).
1347
        Cond::simple(P::const_display(LayoutDisplay::None)),
1347
        cond_border_box(),
1347
        Cond::simple(P::const_position(LayoutPosition::Absolute)),
        // ABOVE its siblings. `position: absolute` only takes a node out of
        // flow — it does not lift it in paint order, so with no z-index the
        // overlay was painted and then covered by the mobile band, which is a
        // LATER sibling in the same container. Nothing in the widget set
        // rendered above anything, because no widget set z-index at all.
1347
        Cond::simple(P::const_z_index(LayoutZIndex::Integer(100))),
1347
        Cond::simple(P::const_top(LayoutTop::const_px(0))),
1347
        Cond::simple(P::const_left(LayoutLeft::const_px(0))),
1347
        Cond::simple(P::const_width(LayoutWidth::Px(PixelValue::const_percent(
1347
            100,
1347
        )))),
1347
        Cond::simple(P::const_flex_direction(LayoutFlexDirection::Column)),
    ];
1347
    v.extend(bg_both(t, |p| p.chrome_bg));
1347
    push_box_border_both(&mut v, t, |p| p.border);
1347
    CssPropertyWithConditionsVec::from_vec(v)
1347
}
/// One row of the mobile tab overlay - a full-width 48px touch target.
9580
fn theme_mobile_tab_overlay_item(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
9580
    let mut v = vec![
9580
        cond_border_box(),
9580
        Cond::simple(P::const_display(LayoutDisplay::Flex)),
9580
        Cond::simple(P::const_flex_direction(LayoutFlexDirection::Row)),
9580
        Cond::simple(P::const_align_items(LayoutAlignItems::Center)),
9580
        Cond::simple(P::const_height(LayoutHeight::const_px(48))),
9580
        Cond::simple(P::const_font_size(StyleFontSize::const_px(17))),
    ];
9580
    v.extend(text_both(t, |p| p.text));
9580
    v.push(Cond::simple(P::const_cursor(StyleCursor::Pointer)));
9580
    v.push(Cond::simple(P::user_select(StyleUserSelect::None)));
9580
    push_padding(&mut v, 0, 16, 0, 16);
9580
    push_bottom_border_both(&mut v, t, |p| p.separator);
9580
    push_chrome_hover_fill(&mut v, t);
9580
    CssPropertyWithConditionsVec::from_vec(v)
9580
}
/// The scrollable list of GROUP names shown beside the visible group on
/// phones. Sits on the user's dominant-hand side (see [`Handedness`]).
1352
fn theme_mobile_group_list(t: &RibbonTheme, left_handed: bool) -> CssPropertyWithConditionsVec {
1352
    let mut v: Vec<Cond> = mobile_only_visibility(LayoutDisplay::Flex).to_vec();
1352
    v.push(cond_border_box());
1352
    v.push(Cond::simple(P::const_flex_direction(
1352
        LayoutFlexDirection::Column,
    )));
1352
    v.push(Cond::simple(P::const_width(LayoutWidth::const_px(116))));
1352
    v.push(Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(
        0,
    ))));
1352
    v.push(Cond::simple(P::const_flex_shrink(LayoutFlexShrink {
1352
        inner: FloatValue::const_new(0),
1352
    })));
1352
    v.push(Cond::simple(P::const_overflow_y(LayoutOverflow::Scroll)));
1352
    v.push(Cond::simple(P::const_overflow_x(LayoutOverflow::Hidden)));
1352
    v.extend(bg_both(t, |p| p.chrome_bg));
    // The list hugs the dominant hand: a border on the side that faces the
    // content, so the divider reads correctly whichever side it is on.
1352
    if left_handed {
3
        v.push(Cond::simple(P::const_border_right_width(
3
            LayoutBorderRightWidth::const_px(1),
        )));
3
        v.push(Cond::simple(P::const_border_right_style(
3
            StyleBorderRightStyle {
3
                inner: BorderStyle::Solid,
3
            },
        )));
3
        push_edge_color_both(&mut v, Edge::Right, t, |p| p.separator);
    } else {
1349
        v.push(Cond::simple(P::const_border_left_width(
1349
            LayoutBorderLeftWidth::const_px(1),
        )));
1349
        v.push(Cond::simple(P::const_border_left_style(
1349
            StyleBorderLeftStyle {
1349
                inner: BorderStyle::Solid,
1349
            },
        )));
1349
        push_edge_color_both(&mut v, Edge::Left, t, |p| p.separator);
    }
1352
    CssPropertyWithConditionsVec::from_vec(v)
1352
}
/// One entry of the mobile group list.
5305
fn theme_mobile_group_list_item(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
5305
    let mut v = vec![
5305
        cond_border_box(),
5305
        Cond::simple(P::const_display(LayoutDisplay::Flex)),
5305
        Cond::simple(P::const_align_items(LayoutAlignItems::Center)),
5305
        Cond::simple(P::const_height(LayoutHeight::const_px(44))),
5305
        Cond::simple(P::const_font_size(StyleFontSize::const_px(15))),
    ];
5305
    v.extend(text_both(t, |p| p.text));
5305
    v.push(Cond::simple(P::const_cursor(StyleCursor::Pointer)));
5305
    v.push(Cond::simple(P::user_select(StyleUserSelect::None)));
5305
    push_padding(&mut v, 0, 10, 0, 12);
5305
    push_bottom_border_both(&mut v, t, |p| p.separator);
5305
    push_chrome_hover_fill(&mut v, t);
5305
    CssPropertyWithConditionsVec::from_vec(v)
5305
}
/// The selected entry of the mobile group list (appended, last-wins).
1331
fn theme_mobile_group_list_item_selected(t: &RibbonTheme) -> CssPropertyWithConditionsVec {
1331
    let mut v: Vec<Cond> = bg_both(t, |p| p.selected_bg).to_vec();
1331
    v.extend(accent_text_both(t));
1331
    CssPropertyWithConditionsVec::from_vec(v)
1331
}
// -- Classes --
static CLS_RIBBON: &[IdOrClass] = &[Class(AzString::from_const_str("__azul-native-ribbon"))];
static CLS_TAB_BAR: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-ribbon-tabbar",
))];
static CLS_APP_BUTTON: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-ribbon-appbutton",
))];
static CLS_TAB: &[IdOrClass] = &[Class(AzString::from_const_str("__azul-native-ribbon-tab"))];
static CLS_TAB_ACTIVE: &[IdOrClass] = &[
    Class(AzString::from_const_str("__azul-native-ribbon-tab")),
    Class(AzString::from_const_str("__azul-native-ribbon-tab-active")),
];
static CLS_TAB_FILLER: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-ribbon-tab-filler",
))];
static CLS_CONTENT: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-ribbon-content",
))];
static CLS_GROUP: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-ribbon-group",
))];
static CLS_GROUP_ITEMS: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-ribbon-group-items",
))];
static CLS_GROUP_FOOTER: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-ribbon-group-footer",
))];
static CLS_GROUP_LABEL: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-ribbon-group-label",
))];
static CLS_FOOTER_SPACER: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-ribbon-footer-spacer",
))];
static CLS_COLUMN: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-ribbon-column",
))];
static CLS_ROW: &[IdOrClass] = &[Class(AzString::from_const_str("__azul-native-ribbon-row"))];
static CLS_SEPARATOR: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-ribbon-separator",
))];
static CLS_GALLERY: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-ribbon-gallery",
))];
static CLS_GALLERY_STRIP: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-ribbon-gallery-strip",
))];
static CLS_GALLERY_CELL: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-ribbon-gallery-cell",
))];
static CLS_GALLERY_CELL_SELECTED: &[IdOrClass] = &[
    Class(AzString::from_const_str(
        "__azul-native-ribbon-gallery-cell",
    )),
    Class(AzString::from_const_str(
        "__azul-native-ribbon-gallery-cell-selected",
    )),
];
/// Class names the handlers resolve their targets by (see
/// `ancestor_with_class`), kept next to the `IdOrClass` tables that emit them.
const GALLERY_WRAPPER_CLASS: &str = "__azul-native-ribbon-gallery-wrapper";
const GALLERY_CELL_CLASS: &str = "__azul-native-ribbon-gallery-cell";
const RIBBON_TAB_CLASS: &str = "__azul-native-ribbon-tab";
const MOBILE_TAB_BUTTON_CLASS: &str = "__azul-native-ribbon-mobile-tab";
const RIBBON_CONTAINER_CLASS: &str = "__azul-native-ribbon";
const MOBILE_GROUP_LIST_ITEM_CLASS: &str = "__azul-native-ribbon-mobile-group-list-item";
const RIBBON_CONTENT_CLASS: &str = "__azul-native-ribbon-content";
/// The mobile band: the group list AND the one visible group, side by side.
/// Collapsing on mobile has to hide THIS, not just the content — hiding the
/// content alone leaves the group list behind as a floating strip with nothing
/// beside it.
const MOBILE_BAND_CLASS: &str = "__azul-native-ribbon-mobile-band";
static CLS_MOBILE_TAB_BUTTON: &[IdOrClass] =
    &[Class(AzString::from_const_str(MOBILE_TAB_BUTTON_CLASS))];
static CLS_MOBILE_TAB_OVERLAY: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-ribbon-mobile-tab-overlay",
))];
static CLS_MOBILE_TAB_OVERLAY_ITEM: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-ribbon-mobile-tab-overlay-item",
))];
static CLS_MOBILE_GROUP_LIST: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-ribbon-mobile-group-list",
))];
static CLS_MOBILE_BAND: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-ribbon-mobile-band",
))];
static CLS_MOBILE_GROUP_LIST_ITEM: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-ribbon-mobile-group-list-item",
))];
static CLS_GALLERY_MORE: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-ribbon-gallery-more",
))];
static CLS_GALLERY_WRAPPER: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-ribbon-gallery-wrapper",
))];
static CLS_GALLERY_PANEL: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-ribbon-gallery-panel",
))];
static CLS_GALLERY_SPINNER: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-ribbon-gallery-spinner",
))];
// -- Style bundle --
/// Every visual part of the ribbon chrome as a replaceable property list.
///
/// The default ([`RibbonStyle::office_2013`]) reproduces the the Office-2013-era look look:
/// white chrome, #2B579A accents, #CDE6F7 hover fills. Each field is applied
/// to exactly one DOM part; replace any of them to re-theme that part.
/// Fields named `*_style` fully replace the part's style; [`Self::checked_style`]
/// and [`Self::gallery_cell_selected_style`] are *appended* to the base button /
/// cell style (inline CSS resolves last-wins, so appended properties override).
#[derive(Debug, Clone, PartialEq, Eq)]
#[repr(C)]
pub struct RibbonStyle {
    /// The palette this style bundle was derived from. Kept for
    /// [`Self::styled_combo_box`] and for consumers deriving matching
    /// custom parts.
    pub theme: RibbonTheme,
    /// The handedness the mobile parts were derived for.
    ///
    /// Stored for the same reason as [`Self::theme`]: it is an INPUT to one of
    /// the parts (`mobile_group_list_style` puts the divider on the far side for
    /// a left-handed layout), and `from_theme_handed` used to bake it into that
    /// vec and then throw the flag away — so the bundle could not re-derive the
    /// part, and nothing downstream could tell which hand it had been built for.
    pub handedness: Handedness,
    /// Root container (vertical: tab bar over content).
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub container_style: OptionCssPropertyWithConditionsVec,
    /// The horizontal tab strip.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub tab_bar_style: OptionCssPropertyWithConditionsVec,
    /// The blue application button ("FILE").
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub app_button_style: OptionCssPropertyWithConditionsVec,
    /// An inactive tab header.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub tab_style: OptionCssPropertyWithConditionsVec,
    /// The active tab header.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub tab_active_style: OptionCssPropertyWithConditionsVec,
    /// The filler segment after the last tab (carries the underline).
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub tab_filler_style: OptionCssPropertyWithConditionsVec,
    /// The content band below the tab strip (horizontal group list).
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub content_style: OptionCssPropertyWithConditionsVec,
    /// One group (vertical: items over footer), incl. the right separator.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub group_style: OptionCssPropertyWithConditionsVec,
    /// The item area of a group.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub group_items_style: OptionCssPropertyWithConditionsVec,
    /// The footer row of a group (label + dialog launcher).
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub group_footer_style: OptionCssPropertyWithConditionsVec,
    /// The centered group caption.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub group_label_style: OptionCssPropertyWithConditionsVec,
    /// Invisible spacer balancing the launcher so the caption stays centered.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub footer_spacer_style: OptionCssPropertyWithConditionsVec,
    /// Container style injected into the dialog-launcher [`Button`].
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub launcher_button_style: OptionCssPropertyWithConditionsVec,
    /// Icon style injected into the dialog-launcher [`Button`].
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub launcher_icon_style: OptionCssPropertyWithConditionsVec,
    /// A [`RibbonColumn`] packing box.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub column_style: OptionCssPropertyWithConditionsVec,
    /// A [`RibbonRow`] packing box.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub row_style: OptionCssPropertyWithConditionsVec,
    /// A [`RibbonItem::Separator`] rule.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub separator_style: OptionCssPropertyWithConditionsVec,
    /// Container style injected into large-button [`Button`]s.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub large_button_style: OptionCssPropertyWithConditionsVec,
    /// Icon style injected into large-button [`Button`]s.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub large_icon_style: OptionCssPropertyWithConditionsVec,
    /// Label style injected into large-button [`Button`]s.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub large_label_style: OptionCssPropertyWithConditionsVec,
    /// Container style injected into small-button [`Button`]s.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub small_button_style: OptionCssPropertyWithConditionsVec,
    /// Icon style injected into small-button [`Button`]s.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub small_icon_style: OptionCssPropertyWithConditionsVec,
    /// Label style injected into small-button [`Button`]s.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub small_label_style: OptionCssPropertyWithConditionsVec,
    /// Style of the drop-down arrow glyph on Menu/Split buttons.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub arrow_icon_style: OptionCssPropertyWithConditionsVec,
    /// APPENDED to the button container when [`RibbonButton::toggled`] is set.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub checked_style: OptionCssPropertyWithConditionsVec,
    /// The gallery outer frame.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub gallery_frame_style: OptionCssPropertyWithConditionsVec,
    /// The horizontal cell strip inside the gallery frame.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub gallery_strip_style: OptionCssPropertyWithConditionsVec,
    /// One gallery cell.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub gallery_cell_style: OptionCssPropertyWithConditionsVec,
    /// APPENDED to the selected gallery cell.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub gallery_cell_selected_style: OptionCssPropertyWithConditionsVec,
    /// The name label under a gallery cell preview.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub gallery_cell_label_style: OptionCssPropertyWithConditionsVec,
    /// The vertical spinner column on the gallery's right edge.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub gallery_spinner_style: OptionCssPropertyWithConditionsVec,
    /// Positioning context wrapping the gallery frame + expansion panel.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub gallery_wrapper_style: OptionCssPropertyWithConditionsVec,
    /// The expansion panel shown by the gallery's "More" button.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub gallery_panel_style: OptionCssPropertyWithConditionsVec,
    /// Full-width tab button shown INSTEAD of the tab strip on phones.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub mobile_tab_button_style: OptionCssPropertyWithConditionsVec,
    /// Active-tab label inside the mobile tab button.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub mobile_tab_label_style: OptionCssPropertyWithConditionsVec,
    /// Chevron on the mobile tab button.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub mobile_tab_arrow_style: OptionCssPropertyWithConditionsVec,
    /// Full-screen tab picker opened by the mobile tab button.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub mobile_tab_overlay_style: OptionCssPropertyWithConditionsVec,
    /// One row of the mobile tab picker.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub mobile_tab_overlay_item_style: OptionCssPropertyWithConditionsVec,
    /// Scrollable group list shown beside the visible group on phones.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub mobile_group_list_style: OptionCssPropertyWithConditionsVec,
    /// One entry of the mobile group list.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub mobile_group_list_item_style: OptionCssPropertyWithConditionsVec,
    /// APPENDED to the selected mobile group-list entry.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub mobile_group_list_item_selected_style: OptionCssPropertyWithConditionsVec,
    /// Container style injected into the three spinner [`Button`]s.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub gallery_spinner_button_style: OptionCssPropertyWithConditionsVec,
    /// Icon style injected into the three spinner [`Button`]s.
    ///
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
    /// a real answer — "no properties at all" — which the pre-filled field could
    /// not express.
    pub gallery_spinner_icon_style: OptionCssPropertyWithConditionsVec,
}
impl RibbonStyle {
    /// The the Office-2013-era look look (white chrome, #2B579A accents) - the default.
    #[must_use]
199
    pub const fn office_2013() -> Self {
199
        Self::from_theme(RibbonTheme::office_2013())
199
    }
    /// Derives every part style from the given palette. This is the styling
    /// override API: build a [`RibbonTheme`] (or start from a preset), then
    /// replace individual `*_style` fields for finer control.
    #[must_use]
202
    pub const fn from_theme(theme: RibbonTheme) -> Self {
202
        Self::from_theme_handed(theme, Handedness::RightHanded)
202
    }
    /// [`Self::from_theme`] with an explicit hand: the mobile group list sits
    /// on the dominant-hand side so the thumb reaches it. Independent of text
    /// direction - see [`Handedness`].
    #[must_use]
1377
    pub const fn from_theme_handed(theme: RibbonTheme, handedness: Handedness) -> Self {
1377
        Self {
1377
            theme,
1377
            handedness,
1377
            container_style: OptionCssPropertyWithConditionsVec::None,
1377
            tab_bar_style: OptionCssPropertyWithConditionsVec::None,
1377
            app_button_style: OptionCssPropertyWithConditionsVec::None,
1377
            tab_style: OptionCssPropertyWithConditionsVec::None,
1377
            tab_active_style: OptionCssPropertyWithConditionsVec::None,
1377
            tab_filler_style: OptionCssPropertyWithConditionsVec::None,
1377
            content_style: OptionCssPropertyWithConditionsVec::None,
1377
            group_style: OptionCssPropertyWithConditionsVec::None,
1377
            group_items_style: OptionCssPropertyWithConditionsVec::None,
1377
            group_footer_style: OptionCssPropertyWithConditionsVec::None,
1377
            group_label_style: OptionCssPropertyWithConditionsVec::None,
1377
            footer_spacer_style: OptionCssPropertyWithConditionsVec::None,
1377
            launcher_button_style: OptionCssPropertyWithConditionsVec::None,
1377
            launcher_icon_style: OptionCssPropertyWithConditionsVec::None,
1377
            column_style: OptionCssPropertyWithConditionsVec::None,
1377
            row_style: OptionCssPropertyWithConditionsVec::None,
1377
            separator_style: OptionCssPropertyWithConditionsVec::None,
1377
            large_button_style: OptionCssPropertyWithConditionsVec::None,
1377
            large_icon_style: OptionCssPropertyWithConditionsVec::None,
1377
            large_label_style: OptionCssPropertyWithConditionsVec::None,
1377
            small_button_style: OptionCssPropertyWithConditionsVec::None,
1377
            small_icon_style: OptionCssPropertyWithConditionsVec::None,
1377
            small_label_style: OptionCssPropertyWithConditionsVec::None,
1377
            arrow_icon_style: OptionCssPropertyWithConditionsVec::None,
1377
            checked_style: OptionCssPropertyWithConditionsVec::None,
1377
            gallery_frame_style: OptionCssPropertyWithConditionsVec::None,
1377
            gallery_strip_style: OptionCssPropertyWithConditionsVec::None,
1377
            gallery_cell_style: OptionCssPropertyWithConditionsVec::None,
1377
            gallery_cell_selected_style: OptionCssPropertyWithConditionsVec::None,
1377
            gallery_cell_label_style: OptionCssPropertyWithConditionsVec::None,
1377
            gallery_spinner_style: OptionCssPropertyWithConditionsVec::None,
1377
            gallery_wrapper_style: OptionCssPropertyWithConditionsVec::None,
1377
            gallery_panel_style: OptionCssPropertyWithConditionsVec::None,
1377
            mobile_tab_button_style: OptionCssPropertyWithConditionsVec::None,
1377
            mobile_tab_label_style: OptionCssPropertyWithConditionsVec::None,
1377
            mobile_tab_arrow_style: OptionCssPropertyWithConditionsVec::None,
1377
            mobile_tab_overlay_style: OptionCssPropertyWithConditionsVec::None,
1377
            mobile_tab_overlay_item_style: OptionCssPropertyWithConditionsVec::None,
1377
            mobile_group_list_style: OptionCssPropertyWithConditionsVec::None,
1377
            mobile_group_list_item_style: OptionCssPropertyWithConditionsVec::None,
1377
            mobile_group_list_item_selected_style: OptionCssPropertyWithConditionsVec::None,
1377
            gallery_spinner_button_style: OptionCssPropertyWithConditionsVec::None,
1377
            gallery_spinner_icon_style: OptionCssPropertyWithConditionsVec::None,
1377
        }
1377
    }
    /// Whether the mobile parts are laid out for a left-handed grip.
    #[must_use]
1350
    pub const fn is_left_handed(&self) -> bool {
1350
        matches!(self.handedness, Handedness::LeftHanded)
1350
    }
    /// The `container_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
2506
    pub fn resolved_container_style(&self) -> CssPropertyWithConditionsVec {
2506
        self.container_style
2506
            .clone()
2506
            .into_option()
2506
            .unwrap_or_else(|| theme_container(&self.theme))
2506
    }
    /// The `tab_bar_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
1347
    pub fn resolved_tab_bar_style(&self) -> CssPropertyWithConditionsVec {
1347
        self.tab_bar_style
1347
            .clone()
1347
            .into_option()
1347
            .unwrap_or_else(|| theme_tab_bar(&self.theme))
1347
    }
    /// The `app_button_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
1184
    pub fn resolved_app_button_style(&self) -> CssPropertyWithConditionsVec {
1184
        self.app_button_style
1184
            .clone()
1184
            .into_option()
1184
            .unwrap_or_else(|| theme_app_button(&self.theme))
1184
    }
    /// The `tab_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
8236
    pub fn resolved_tab_style(&self) -> CssPropertyWithConditionsVec {
8236
        self.tab_style
8236
            .clone()
8236
            .into_option()
8236
            .unwrap_or_else(|| theme_tab(&self.theme))
8236
    }
    /// The `tab_active_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
1346
    pub fn resolved_tab_active_style(&self) -> CssPropertyWithConditionsVec {
1346
        self.tab_active_style
1346
            .clone()
1346
            .into_option()
1346
            .unwrap_or_else(|| theme_tab_active(&self.theme))
1346
    }
    /// The `tab_filler_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
1346
    pub fn resolved_tab_filler_style(&self) -> CssPropertyWithConditionsVec {
1346
        self.tab_filler_style
1346
            .clone()
1346
            .into_option()
1346
            .unwrap_or_else(|| theme_tab_filler(&self.theme))
1346
    }
    /// The `content_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
1346
    pub fn resolved_content_style(&self) -> CssPropertyWithConditionsVec {
1346
        self.content_style
1346
            .clone()
1346
            .into_option()
1346
            .unwrap_or_else(|| theme_content(&self.theme))
1346
    }
    /// The `group_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
5301
    pub fn resolved_group_style(&self) -> CssPropertyWithConditionsVec {
5301
        self.group_style
5301
            .clone()
5301
            .into_option()
5301
            .unwrap_or_else(|| theme_group(&self.theme))
5301
    }
    /// The `group_items_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
5301
    pub fn resolved_group_items_style(&self) -> CssPropertyWithConditionsVec {
5301
        self.group_items_style
5301
            .clone()
5301
            .into_option()
5301
            .unwrap_or_else(|| CssPropertyWithConditionsVec::from_const_slice(GROUP_ITEMS_STYLE))
5301
    }
    /// The `group_footer_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
5301
    pub fn resolved_group_footer_style(&self) -> CssPropertyWithConditionsVec {
5301
        self.group_footer_style
5301
            .clone()
5301
            .into_option()
5301
            .unwrap_or_else(|| CssPropertyWithConditionsVec::from_const_slice(GROUP_FOOTER_STYLE))
5301
    }
    /// The `group_label_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
5301
    pub fn resolved_group_label_style(&self) -> CssPropertyWithConditionsVec {
5301
        self.group_label_style
5301
            .clone()
5301
            .into_option()
5301
            .unwrap_or_else(|| theme_group_label(&self.theme))
5301
    }
    /// The `footer_spacer_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
2
    pub fn resolved_footer_spacer_style(&self) -> CssPropertyWithConditionsVec {
2
        self.footer_spacer_style
2
            .clone()
2
            .into_option()
2
            .unwrap_or_else(|| CssPropertyWithConditionsVec::from_const_slice(FOOTER_SPACER_STYLE))
2
    }
    /// The `launcher_button_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
2
    pub fn resolved_launcher_button_style(&self) -> CssPropertyWithConditionsVec {
2
        self.launcher_button_style
2
            .clone()
2
            .into_option()
2
            .unwrap_or_else(|| theme_launcher_button(&self.theme))
2
    }
    /// The `launcher_icon_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
2
    pub fn resolved_launcher_icon_style(&self) -> CssPropertyWithConditionsVec {
2
        self.launcher_icon_style
2
            .clone()
2
            .into_option()
2
            .unwrap_or_else(|| theme_launcher_icon(&self.theme))
2
    }
    /// The `column_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
3572
    pub fn resolved_column_style(&self) -> CssPropertyWithConditionsVec {
3572
        self.column_style
3572
            .clone()
3572
            .into_option()
3572
            .unwrap_or_else(|| CssPropertyWithConditionsVec::from_const_slice(COLUMN_STYLE))
3572
    }
    /// The `row_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
1
    pub fn resolved_row_style(&self) -> CssPropertyWithConditionsVec {
1
        self.row_style
1
            .clone()
1
            .into_option()
1
            .unwrap_or_else(|| CssPropertyWithConditionsVec::from_const_slice(ROW_STYLE))
1
    }
    /// The `separator_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
1
    pub fn resolved_separator_style(&self) -> CssPropertyWithConditionsVec {
1
        self.separator_style
1
            .clone()
1
            .into_option()
1
            .unwrap_or_else(|| theme_separator(&self.theme))
1
    }
    /// The `large_button_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
1219
    pub fn resolved_large_button_style(&self) -> CssPropertyWithConditionsVec {
1219
        self.large_button_style
1219
            .clone()
1219
            .into_option()
1219
            .unwrap_or_else(|| theme_large_button(&self.theme))
1219
    }
    /// The `large_icon_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
1219
    pub fn resolved_large_icon_style(&self) -> CssPropertyWithConditionsVec {
1219
        self.large_icon_style
1219
            .clone()
1219
            .into_option()
1219
            .unwrap_or_else(|| theme_large_icon(&self.theme))
1219
    }
    /// The `large_label_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
1219
    pub fn resolved_large_label_style(&self) -> CssPropertyWithConditionsVec {
1219
        self.large_label_style
1219
            .clone()
1219
            .into_option()
1219
            .unwrap_or_else(|| theme_large_label(&self.theme))
1219
    }
    /// The `small_button_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
10710
    pub fn resolved_small_button_style(&self) -> CssPropertyWithConditionsVec {
10710
        self.small_button_style
10710
            .clone()
10710
            .into_option()
10710
            .unwrap_or_else(|| theme_small_button(&self.theme))
10710
    }
    /// The `small_icon_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
10709
    pub fn resolved_small_icon_style(&self) -> CssPropertyWithConditionsVec {
10709
        self.small_icon_style
10709
            .clone()
10709
            .into_option()
10709
            .unwrap_or_else(|| theme_small_icon(&self.theme))
10709
    }
    /// The `small_label_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
14638
    pub fn resolved_small_label_style(&self) -> CssPropertyWithConditionsVec {
14638
        self.small_label_style
14638
            .clone()
14638
            .into_option()
14638
            .unwrap_or_else(|| theme_small_label(&self.theme))
14638
    }
    /// The `arrow_icon_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
15857
    pub fn resolved_arrow_icon_style(&self) -> CssPropertyWithConditionsVec {
15857
        self.arrow_icon_style
15857
            .clone()
15857
            .into_option()
15857
            .unwrap_or_else(|| theme_arrow_icon(&self.theme))
15857
    }
    /// The `checked_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
2
    pub fn resolved_checked_style(&self) -> CssPropertyWithConditionsVec {
2
        self.checked_style
2
            .clone()
2
            .into_option()
2
            .unwrap_or_else(|| theme_checked(&self.theme))
2
    }
    /// The `gallery_frame_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
1309
    pub fn resolved_gallery_frame_style(&self) -> CssPropertyWithConditionsVec {
1309
        self.gallery_frame_style
1309
            .clone()
1309
            .into_option()
1309
            .unwrap_or_else(|| theme_gallery_frame(&self.theme))
1309
    }
    /// The `gallery_strip_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
1309
    pub fn resolved_gallery_strip_style(&self) -> CssPropertyWithConditionsVec {
1309
        self.gallery_strip_style
1309
            .clone()
1309
            .into_option()
1309
            .unwrap_or_else(|| CssPropertyWithConditionsVec::from_const_slice(GALLERY_STRIP_STYLE))
1309
    }
    /// The `gallery_cell_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
22083
    pub fn resolved_gallery_cell_style(&self) -> CssPropertyWithConditionsVec {
22083
        self.gallery_cell_style
22083
            .clone()
22083
            .into_option()
22083
            .unwrap_or_else(|| theme_gallery_cell(&self.theme))
22083
    }
    /// The `gallery_cell_selected_style` this bundle renders with: the caller's override if there
    /// is one, else derived from [`Self::theme`].
    #[must_use]
13657
    pub fn resolved_gallery_cell_selected_style(&self) -> CssPropertyWithConditionsVec {
13657
        self.gallery_cell_selected_style
13657
            .clone()
13657
            .into_option()
13657
            .unwrap_or_else(|| theme_gallery_cell_selected(&self.theme))
13657
    }
    /// The `gallery_cell_label_style` this bundle renders with: the caller's override if there is
    /// one, else derived from [`Self::theme`].
    #[must_use]
11042
    pub fn resolved_gallery_cell_label_style(&self) -> CssPropertyWithConditionsVec {
11042
        self.gallery_cell_label_style
11042
            .clone()
11042
            .into_option()
11042
            .unwrap_or_else(|| theme_gallery_cell_label(&self.theme))
11042
    }
    /// The `gallery_spinner_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
1309
    pub fn resolved_gallery_spinner_style(&self) -> CssPropertyWithConditionsVec {
1309
        self.gallery_spinner_style
1309
            .clone()
1309
            .into_option()
1309
            .unwrap_or_else(|| theme_gallery_spinner(&self.theme))
1309
    }
    /// The `gallery_wrapper_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
1307
    pub fn resolved_gallery_wrapper_style(&self) -> CssPropertyWithConditionsVec {
1307
        self.gallery_wrapper_style
1307
            .clone()
1307
            .into_option()
1307
            .unwrap_or_else(|| {
1307
                CssPropertyWithConditionsVec::from_const_slice(GALLERY_WRAPPER_STYLE)
1307
            })
1307
    }
    /// The `gallery_panel_style` this bundle renders with: the caller's override if there is one,
    /// else derived from [`Self::theme`].
    #[must_use]
1307
    pub fn resolved_gallery_panel_style(&self) -> CssPropertyWithConditionsVec {
1307
        self.gallery_panel_style
1307
            .clone()
1307
            .into_option()
1307
            .unwrap_or_else(|| theme_gallery_panel(&self.theme))
1307
    }
    /// The `mobile_tab_button_style` this bundle renders with: the caller's override if there is
    /// one, else derived from [`Self::theme`].
    #[must_use]
1347
    pub fn resolved_mobile_tab_button_style(&self) -> CssPropertyWithConditionsVec {
1347
        self.mobile_tab_button_style
1347
            .clone()
1347
            .into_option()
1347
            .unwrap_or_else(|| theme_mobile_tab_button(&self.theme))
1347
    }
    /// The `mobile_tab_label_style` this bundle renders with: the caller's override if there is
    /// one, else derived from [`Self::theme`].
    #[must_use]
1346
    pub fn resolved_mobile_tab_label_style(&self) -> CssPropertyWithConditionsVec {
1346
        self.mobile_tab_label_style
1346
            .clone()
1346
            .into_option()
1346
            .unwrap_or_else(|| theme_mobile_tab_label(&self.theme))
1346
    }
    /// The `mobile_tab_arrow_style` this bundle renders with: the caller's override if there is
    /// one, else derived from [`Self::theme`].
    #[must_use]
1346
    pub fn resolved_mobile_tab_arrow_style(&self) -> CssPropertyWithConditionsVec {
1346
        self.mobile_tab_arrow_style
1346
            .clone()
1346
            .into_option()
1346
            .unwrap_or_else(|| theme_mobile_tab_arrow(&self.theme))
1346
    }
    /// The `mobile_tab_overlay_style` this bundle renders with: the caller's override if there is
    /// one, else derived from [`Self::theme`].
    #[must_use]
1346
    pub fn resolved_mobile_tab_overlay_style(&self) -> CssPropertyWithConditionsVec {
1346
        self.mobile_tab_overlay_style
1346
            .clone()
1346
            .into_option()
1346
            .unwrap_or_else(|| theme_mobile_tab_overlay(&self.theme))
1346
    }
    /// The `mobile_tab_overlay_item_style` this bundle renders with: the caller's override if there
    /// is one, else derived from [`Self::theme`].
    #[must_use]
9579
    pub fn resolved_mobile_tab_overlay_item_style(&self) -> CssPropertyWithConditionsVec {
9579
        self.mobile_tab_overlay_item_style
9579
            .clone()
9579
            .into_option()
9579
            .unwrap_or_else(|| theme_mobile_tab_overlay_item(&self.theme))
9579
    }
    /// The `mobile_group_list_style` this bundle renders with: the caller's override if there is
    /// one, else derived from [`Self::theme`].
    #[must_use]
1350
    pub fn resolved_mobile_group_list_style(&self) -> CssPropertyWithConditionsVec {
1350
        self.mobile_group_list_style
1350
            .clone()
1350
            .into_option()
1350
            .unwrap_or_else(|| theme_mobile_group_list(&self.theme, self.is_left_handed()))
1350
    }
    /// The `mobile_group_list_item_style` this bundle renders with: the caller's override if there
    /// is one, else derived from [`Self::theme`].
    #[must_use]
5304
    pub fn resolved_mobile_group_list_item_style(&self) -> CssPropertyWithConditionsVec {
5304
        self.mobile_group_list_item_style
5304
            .clone()
5304
            .into_option()
5304
            .unwrap_or_else(|| theme_mobile_group_list_item(&self.theme))
5304
    }
    /// The `mobile_group_list_item_selected_style` this bundle renders with: the caller's override
    /// if there is one, else derived from [`Self::theme`].
    #[must_use]
1330
    pub fn resolved_mobile_group_list_item_selected_style(&self) -> CssPropertyWithConditionsVec {
1330
        self.mobile_group_list_item_selected_style
1330
            .clone()
1330
            .into_option()
1330
            .unwrap_or_else(|| theme_mobile_group_list_item_selected(&self.theme))
1330
    }
    /// The `gallery_spinner_button_style` this bundle renders with: the caller's override if there
    /// is one, else derived from [`Self::theme`].
    #[must_use]
3927
    pub fn resolved_gallery_spinner_button_style(&self) -> CssPropertyWithConditionsVec {
3927
        self.gallery_spinner_button_style
3927
            .clone()
3927
            .into_option()
3927
            .unwrap_or_else(|| theme_gallery_spinner_button(&self.theme))
3927
    }
    /// The `gallery_spinner_icon_style` this bundle renders with: the caller's override if there is
    /// one, else derived from [`Self::theme`].
    #[must_use]
3927
    pub fn resolved_gallery_spinner_icon_style(&self) -> CssPropertyWithConditionsVec {
3927
        self.gallery_spinner_icon_style
3927
            .clone()
3927
            .into_option()
3927
            .unwrap_or_else(|| theme_gallery_spinner_icon(&self.theme))
3927
    }
    /// Derives the ribbon style from the OS theme (see
    /// [`RibbonTheme::from_system`]). Pass `SystemStyle::detect()` for the
    /// live system look, e.g. to render a "system native" ribbon.
    #[must_use]
2
    pub fn from_system(style: SystemStyle) -> Self {
2
        let handedness = style.handedness;
2
        Self::from_theme_handed(RibbonTheme::from_system(style), handedness)
2
    }
    /// Returns a [`ComboBox`] with this ribbon's field look injected through
    /// the combobox's public style fields (flat 1px border, 22px field, 12px
    /// text - the the Office-2013-era look font-name/font-size pickers). `width` is the
    /// total field width in px. Demonstrates (and exercises) the widget
    /// style-injection API; tweak the returned combobox further by replacing
    /// any of its `*_style` fields.
    #[must_use]
3
    pub fn styled_combo_box(&self, items: StringVec, text: AzString, width: isize) -> ComboBox {
3
        let mut combo = ComboBox::new(items).with_text(text);
3
        let mut wrapper: Vec<Cond> = theme_combo_wrapper_base(&self.theme);
3
        wrapper.push(Cond::simple(P::const_width(LayoutWidth::const_px(width))));
3
        combo.wrapper_style = OptionCssPropertyWithConditionsVec::Some(
3
            CssPropertyWithConditionsVec::from_vec(wrapper),
3
        );
3
        combo.field_style =
3
            OptionCssPropertyWithConditionsVec::Some(theme_combo_field(&self.theme));
3
        combo.text_style = OptionCssPropertyWithConditionsVec::Some(
3
            CssPropertyWithConditionsVec::from_const_slice(RIBBON_COMBO_TEXT_STYLE),
3
        );
3
        combo.arrow_style =
3
            OptionCssPropertyWithConditionsVec::Some(theme_combo_arrow(&self.theme));
3
        combo
3
    }
}
impl Default for RibbonStyle {
1
    fn default() -> Self {
1
        Self::office_2013()
1
    }
}
// -- Data model --
/// The interactive behaviors the ribbon performs BY ITSELF, without any
/// application state. Each is the classic default and each can be turned off,
/// in which case the corresponding event is still forwarded to the app
/// callback (if any) but the ribbon does not touch its own chrome.
///
/// The state these behaviors need (collapsed / peeked / selected cell) lives
/// in a private `RefAny` minted inside [`Ribbon::dom`] — the application's
/// own data model is never involved.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(C)]
pub struct RibbonBehavior {
    /// Double-clicking a tab header collapses the content band; double
    /// clicking again restores it (office-2013: "Collapse the Ribbon").
    pub collapsible: bool,
    /// While collapsed, hovering a tab header peeks the content band and
    /// leaving it hides the band again.
    pub peek_on_hover: bool,
    /// Clicking a gallery cell moves the selection highlight without waiting
    /// for the app to re-render.
    pub auto_select_gallery: bool,
    /// The gallery's third spinner button ("More") toggles an expansion
    /// panel showing every cell.
    pub expandable_gallery: bool,
    /// On phones, tapping the tab button opens the full-screen tab picker.
    /// With this off the button is inert and the application drives tab
    /// switching itself.
    pub mobile_tab_overlay: bool,
}
impl RibbonBehavior {
    /// All classic office-suite behaviors enabled - the default.
    #[must_use]
189
    pub const fn office_2013() -> Self {
189
        Self {
189
            collapsible: true,
189
            peek_on_hover: true,
189
            auto_select_gallery: true,
189
            expandable_gallery: true,
189
            mobile_tab_overlay: true,
189
        }
189
    }
    /// Every self-driven behavior off: the ribbon only forwards events to
    /// the application callbacks and never patches its own chrome.
    #[must_use]
6
    pub const fn inert() -> Self {
6
        Self {
6
            collapsible: false,
6
            peek_on_hover: false,
6
            auto_select_gallery: false,
6
            expandable_gallery: false,
6
            mobile_tab_overlay: false,
6
        }
6
    }
}
impl Default for RibbonBehavior {
1
    fn default() -> Self {
1
        Self::office_2013()
1
    }
}
/// Top-level ribbon widget: an optional application button, a tab strip and
/// the active tab's groups.
#[derive(Debug, Clone)]
#[repr(C)]
pub struct Ribbon {
    /// Optional application button rendered before the first tab ("FILE").
    pub app_button: OptionRibbonAppButton,
    /// Tabs displayed in the ribbon tab bar.
    pub tabs: RibbonTabVec,
    /// Index of the currently active tab.
    pub active_tab: usize,
    /// Optional callback fired when a tab is clicked (receives the tab index).
    pub on_tab_click: OptionRibbonOnTabClick,
    /// All part styles (defaults to the the Office-2013-era look look).
    pub style: RibbonStyle,
    /// Which interactions the ribbon handles by itself (defaults to the classic behavior).
    pub behavior: RibbonBehavior,
}
/// The application button at the far left of the tab strip ("FILE").
#[derive(Debug, Clone)]
#[repr(C)]
pub struct RibbonAppButton {
    /// Display label of the application button.
    pub label: AzString,
    /// Optional click callback.
    pub on_click: OptionButtonOnClick,
}
/// A single tab within a [`Ribbon`], containing a label and groups.
#[derive(Debug, Clone)]
#[repr(C)]
pub struct RibbonTab {
    /// Display label shown in the tab bar.
    pub label: AzString,
    /// Groups rendered when this tab is active.
    pub groups: RibbonGroupVec,
    /// Extra properties APPENDED to this tab header's style, after the
    /// shared [`RibbonStyle::tab_style`] / [`RibbonStyle::tab_active_style`]
    /// — so they win, and they apply in BOTH states.
    ///
    /// `None` (the default) leaves the tab looking like every other one; `Some`
    /// APPENDS, so a caller cannot drop the shared tab style the strip depends
    /// on. An empty vec used to be the sentinel for "no extras", which is the
    /// confusion this option removes.
    /// This is the only per-tab hook: `RibbonStyle` describes the tab
    /// STRIP, so without it a single tab could not be tinted, badged or
    /// given its own border, and telling two tabs apart in a screenshot
    /// meant reading their labels.
    pub style: OptionCssPropertyWithConditionsVec,
}
/// A captioned group of controls within a [`RibbonTab`].
#[derive(Debug, Clone)]
#[repr(C)]
pub struct RibbonGroup {
    /// Caption shown centered under the group content.
    pub label: AzString,
    /// The controls of this group, laid out left-to-right.
    pub items: RibbonItemVec,
    /// Optional dialog-box-launcher callback; when set, a small launcher
    /// button is rendered at the right end of the caption row.
    pub launcher: OptionButtonOnClick,
    /// When set, this group absorbs the remaining ribbon width (the classic office-suite
    /// Styles gallery group stretches; the other groups are content-sized).
    pub fills_space: bool,
}
/// One control slot inside a [`RibbonGroup`].
// `#[repr(C, u8)]` — this enum crosses the C ABI and is mirrored in api.json.
// Boxing the large variant to equalise sizes would change the generated
// bindings for every language, so the size spread is deliberate.
#[allow(clippy::large_enum_variant)]
#[derive(Debug, Clone)]
#[repr(C, u8)]
pub enum RibbonItem {
    /// Full-height button: icon over label (`RibbonX` `button[size=large]`).
    LargeButton(RibbonButton),
    /// One-row button: icon beside optional label (`RibbonX` `button`).
    SmallButton(RibbonButton),
    /// Vertical packing box (`RibbonX` `box[boxStyle=vertical]`).
    Column(RibbonColumn),
    /// Horizontal packing box (`RibbonX` `box`/`buttonGroup`).
    Row(RibbonRow),
    /// Embeds the existing [`ComboBox`] widget (`RibbonX` `comboBox`).
    Combo(ComboBox),
    /// Embeds the existing [`DropDown`] widget (`RibbonX` `dropDown`).
    Drop(DropDown),
    /// Embeds the existing [`CheckBox`] widget (`RibbonX` `checkBox`).
    Check(CheckBox),
    /// In-ribbon gallery with spinner column (`RibbonX` `gallery`).
    Gallery(RibbonGallery),
    /// Thin vertical rule (`RibbonX` `separator`).
    Separator,
    /// Arbitrary user content.
    Custom(Dom),
}
/// Vertical stack of items (e.g. the Cut/Copy/Format-Painter column).
#[derive(Debug, Clone)]
#[repr(C)]
pub struct RibbonColumn {
    /// Items stacked top-to-bottom.
    pub items: RibbonItemVec,
}
/// Horizontal cluster of items (e.g. the Bold/Italic/Underline row).
#[derive(Debug, Clone)]
#[repr(C)]
pub struct RibbonRow {
    /// Items packed left-to-right.
    pub items: RibbonItemVec,
}
/// Declarative description of one ribbon button; expands to the existing
/// [`Button`] widget with ribbon styles injected.
#[derive(Debug, Clone)]
#[repr(C)]
pub struct RibbonButton {
    /// Icon name resolved via the icon provider (Material Icons ships
    /// builtin, e.g. "`content_paste`"). Empty string = no icon.
    pub icon: AzString,
    /// Button label. Empty string = icon-only button.
    pub label: AzString,
    /// Drop-down decoration: none, menu arrow or split-button arrow.
    pub arrow: RibbonArrow,
    /// Renders the button in the toggled-on state (`RibbonX` `toggleButton`).
    pub toggled: bool,
    /// Optional click callback (same family as [`Button::on_click`]).
    pub on_click: OptionButtonOnClick,
}
/// Drop-down decoration of a [`RibbonButton`].
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
#[repr(C)]
pub enum RibbonArrow {
    /// Plain button without an arrow.
    #[default]
    None,
    /// The whole button opens a menu (`RibbonX` `menu`).
    Menu,
    /// Primary action + separate arrow region (`RibbonX` `splitButton`).
    /// Rendered identically to `Menu`; the split behavior is the caller's.
    Split,
}
/// In-ribbon gallery: a strip of preview cells plus a 3-button spinner column.
#[derive(Debug, Clone)]
#[repr(C)]
pub struct RibbonGallery {
    /// The visible cells.
    pub cells: RibbonGalleryCellVec,
    /// Index of the selected cell.
    pub selected: usize,
    /// Optional callback fired when a cell is clicked (receives cell index).
    pub on_select: OptionRibbonGalleryOnSelect,
}
/// One gallery cell: an arbitrary preview [`Dom`] over a name label.
#[derive(Debug, Clone)]
#[repr(C)]
pub struct RibbonGalleryCell {
    /// Preview content rendered above the label (e.g. styled sample text).
    pub preview: Dom,
    /// Name label rendered under the preview.
    pub label: AzString,
}
impl_option!(
    RibbonAppButton,
    OptionRibbonAppButton,
    copy = false,
    [Debug, Clone]
);
impl_option!(RibbonTab, OptionRibbonTab, copy = false, [Debug, Clone]);
impl_option!(RibbonGroup, OptionRibbonGroup, copy = false, [Debug, Clone]);
impl_option!(RibbonItem, OptionRibbonItem, copy = false, [Debug, Clone]);
impl_option!(
    RibbonGalleryCell,
    OptionRibbonGalleryCell,
    copy = false,
    [Debug, Clone]
);
impl_vec!(
    RibbonTab,
    RibbonTabVec,
    RibbonTabVecDestructor,
    RibbonTabVecDestructorType,
    RibbonTabVecSlice,
    OptionRibbonTab
);
impl_vec_clone!(RibbonTab, RibbonTabVec, RibbonTabVecDestructor);
impl_vec_debug!(RibbonTab, RibbonTabVec);
impl_vec_mut!(RibbonTab, RibbonTabVec);
impl_vec!(
    RibbonGroup,
    RibbonGroupVec,
    RibbonGroupVecDestructor,
    RibbonGroupVecDestructorType,
    RibbonGroupVecSlice,
    OptionRibbonGroup
);
impl_vec_clone!(RibbonGroup, RibbonGroupVec, RibbonGroupVecDestructor);
impl_vec_debug!(RibbonGroup, RibbonGroupVec);
impl_vec_mut!(RibbonGroup, RibbonGroupVec);
impl_vec!(
    RibbonItem,
    RibbonItemVec,
    RibbonItemVecDestructor,
    RibbonItemVecDestructorType,
    RibbonItemVecSlice,
    OptionRibbonItem
);
impl_vec_clone!(RibbonItem, RibbonItemVec, RibbonItemVecDestructor);
impl_vec_debug!(RibbonItem, RibbonItemVec);
impl_vec_mut!(RibbonItem, RibbonItemVec);
impl_vec!(
    RibbonGalleryCell,
    RibbonGalleryCellVec,
    RibbonGalleryCellVecDestructor,
    RibbonGalleryCellVecDestructorType,
    RibbonGalleryCellVecSlice,
    OptionRibbonGalleryCell
);
impl_vec_clone!(
    RibbonGalleryCell,
    RibbonGalleryCellVec,
    RibbonGalleryCellVecDestructor
);
impl_vec_debug!(RibbonGalleryCell, RibbonGalleryCellVec);
impl_vec_mut!(RibbonGalleryCell, RibbonGalleryCellVec);
// -- Constructors / builders --
impl RibbonAppButton {
    /// Creates an application button with the given label and no callback.
    #[must_use]
130
    pub fn new(label: AzString) -> Self {
130
        Self {
130
            label,
130
            on_click: None.into(),
130
        }
130
    }
    /// Sets the click callback.
1
    pub fn set_on_click<C: Into<super::button::ButtonOnClickCallback>>(
1
        &mut self,
1
        data: RefAny,
1
        on_click: C,
1
    ) {
1
        self.on_click = Some(super::button::ButtonOnClick {
1
            refany: data,
1
            callback: on_click.into(),
1
        })
1
        .into();
1
    }
    /// Builder method: sets the click callback and returns `self`.
    #[must_use]
1
    pub fn with_on_click<C: Into<super::button::ButtonOnClickCallback>>(
1
        mut self,
1
        data: RefAny,
1
        on_click: C,
1
    ) -> Self {
1
        self.set_on_click(data, on_click);
1
        self
1
    }
}
impl RibbonTab {
    /// Creates a new tab with the given label and no groups.
    #[must_use]
1047
    pub const fn new(label: AzString) -> Self {
1047
        Self {
1047
            label,
1047
            groups: RibbonGroupVec::from_const_slice(&[]),
1047
            style: OptionCssPropertyWithConditionsVec::None,
1047
        }
1047
    }
    /// Appends per-tab style properties to this tab's header (see
    /// [`RibbonTab::style`]).
    pub fn set_style(&mut self, style: CssPropertyWithConditionsVec) {
        self.style = OptionCssPropertyWithConditionsVec::Some(style);
    }
    /// Builder method: sets the per-tab header style and returns `self`.
    #[must_use]
    pub fn with_style(mut self, style: CssPropertyWithConditionsVec) -> Self {
        self.set_style(style);
        self
    }
    /// Appends a group to this tab.
13503
    pub fn add_group(&mut self, group: RibbonGroup) {
13503
        self.groups.push(group);
13503
    }
    /// Builder method: appends a group and returns `self`.
    #[must_use]
13503
    pub fn with_group(mut self, group: RibbonGroup) -> Self {
13503
        self.add_group(group);
13503
        self
13503
    }
}
impl RibbonGroup {
    /// Creates a new group with the given caption and no items.
    #[must_use]
1380
    pub const fn new(label: AzString) -> Self {
1380
        Self {
1380
            label,
1380
            items: RibbonItemVec::from_const_slice(&[]),
1380
            launcher: OptionButtonOnClick::None,
1380
            fills_space: false,
1380
        }
1380
    }
    /// Builder method: makes this group absorb the remaining ribbon width.
    #[must_use]
120
    pub const fn with_fills_space(mut self, fills_space: bool) -> Self {
120
        self.fills_space = fills_space;
120
        self
120
    }
    /// Appends an item to this group.
14310
    pub fn add_item(&mut self, item: RibbonItem) {
14310
        self.items.push(item);
14310
    }
    /// Builder method: appends an item and returns `self`.
    #[must_use]
14310
    pub fn with_item(mut self, item: RibbonItem) -> Self {
14310
        self.add_item(item);
14310
        self
14310
    }
    /// Sets the dialog-box-launcher callback (renders the launcher button).
2
    pub fn set_launcher<C: Into<super::button::ButtonOnClickCallback>>(
2
        &mut self,
2
        data: RefAny,
2
        on_click: C,
2
    ) {
2
        self.launcher = Some(super::button::ButtonOnClick {
2
            refany: data,
2
            callback: on_click.into(),
2
        })
2
        .into();
2
    }
    /// Builder method: sets the launcher callback and returns `self`.
    #[must_use]
2
    pub fn with_launcher<C: Into<super::button::ButtonOnClickCallback>>(
2
        mut self,
2
        data: RefAny,
2
        on_click: C,
2
    ) -> Self {
2
        self.set_launcher(data, on_click);
2
        self
2
    }
}
impl RibbonColumn {
    /// Creates an empty column.
    #[must_use]
359
    pub const fn new() -> Self {
359
        Self {
359
            items: RibbonItemVec::from_const_slice(&[]),
359
        }
359
    }
    /// Appends an item to this column.
10704
    pub fn add_item(&mut self, item: RibbonItem) {
10704
        self.items.push(item);
10704
    }
    /// Builder method: appends an item and returns `self`.
    #[must_use]
10704
    pub fn with_item(mut self, item: RibbonItem) -> Self {
10704
        self.add_item(item);
10704
        self
10704
    }
}
impl Default for RibbonColumn {
    fn default() -> Self {
        Self::new()
    }
}
impl RibbonRow {
    /// Creates an empty row.
    #[must_use]
1
    pub const fn new() -> Self {
1
        Self {
1
            items: RibbonItemVec::from_const_slice(&[]),
1
        }
1
    }
    /// Appends an item to this row.
2
    pub fn add_item(&mut self, item: RibbonItem) {
2
        self.items.push(item);
2
    }
    /// Builder method: appends an item and returns `self`.
    #[must_use]
2
    pub fn with_item(mut self, item: RibbonItem) -> Self {
2
        self.add_item(item);
2
        self
2
    }
}
impl Default for RibbonRow {
    fn default() -> Self {
        Self::new()
    }
}
impl RibbonButton {
    /// Creates a plain button with an icon and a label (both may be empty).
    #[must_use]
2029
    pub const fn new(icon: AzString, label: AzString) -> Self {
2029
        Self {
2029
            icon,
2029
            label,
2029
            arrow: RibbonArrow::None,
2029
            toggled: false,
2029
            on_click: OptionButtonOnClick::None,
2029
        }
2029
    }
    /// Builder method: sets the arrow decoration and returns `self`.
    #[must_use]
2
    pub const fn with_arrow(mut self, arrow: RibbonArrow) -> Self {
2
        self.arrow = arrow;
2
        self
2
    }
    /// Builder method: sets the toggled state and returns `self`.
    #[must_use]
1
    pub const fn with_toggled(mut self, toggled: bool) -> Self {
1
        self.toggled = toggled;
1
        self
1
    }
    /// Sets the click callback.
    pub fn set_on_click<C: Into<super::button::ButtonOnClickCallback>>(
        &mut self,
        data: RefAny,
        on_click: C,
    ) {
        self.on_click = Some(super::button::ButtonOnClick {
            refany: data,
            callback: on_click.into(),
        })
        .into();
    }
    /// Builder method: sets the click callback and returns `self`.
    #[must_use]
    pub fn with_on_click<C: Into<super::button::ButtonOnClickCallback>>(
        mut self,
        data: RefAny,
        on_click: C,
    ) -> Self {
        self.set_on_click(data, on_click);
        self
    }
}
impl RibbonGallery {
    /// Creates a gallery from its cells; cell 0 is selected.
    #[must_use]
139
    pub fn new(cells: RibbonGalleryCellVec) -> Self {
139
        Self {
139
            cells,
139
            selected: 0,
139
            on_select: None.into(),
139
        }
139
    }
    /// Builder method: sets the selected cell index and returns `self`.
    #[must_use]
1
    pub const fn with_selected(mut self, selected: usize) -> Self {
1
        self.selected = selected;
1
        self
1
    }
    /// Sets the cell-click callback.
1
    pub fn set_on_select<C: Into<RibbonGalleryOnSelectCallback>>(
1
        &mut self,
1
        data: RefAny,
1
        on_select: C,
1
    ) {
1
        self.on_select = Some(RibbonGalleryOnSelect {
1
            refany: data,
1
            callback: on_select.into(),
1
        })
1
        .into();
1
    }
    /// Builder method: sets the cell-click callback and returns `self`.
    #[must_use]
1
    pub fn with_on_select<C: Into<RibbonGalleryOnSelectCallback>>(
1
        mut self,
1
        data: RefAny,
1
        on_select: C,
1
    ) -> Self {
1
        self.set_on_select(data, on_select);
1
        self
1
    }
}
impl RibbonGalleryCell {
    /// Creates a cell from a preview subtree and a name label.
    #[must_use]
573
    pub const fn new(preview: Dom, label: AzString) -> Self {
573
        Self { preview, label }
573
    }
}
impl Ribbon {
    /// Creates a new ribbon with the given tabs, the first tab active and the
    /// the Office-2013-era look default style.
    #[must_use]
183
    pub fn new(tabs: RibbonTabVec) -> Self {
183
        Self {
183
            app_button: None.into(),
183
            tabs,
183
            active_tab: 0,
183
            on_tab_click: None.into(),
183
            style: RibbonStyle::office_2013(),
183
            behavior: RibbonBehavior::office_2013(),
183
        }
183
    }
    /// Sets the application button ("FILE").
1183
    pub fn set_app_button(&mut self, app_button: RibbonAppButton) {
1183
        self.app_button = Some(app_button).into();
1183
    }
    /// Builder method: sets the application button and returns `self`.
    #[must_use]
1183
    pub fn with_app_button(mut self, app_button: RibbonAppButton) -> Self {
1183
        self.set_app_button(app_button);
1183
        self
1183
    }
    /// Replaces the whole style bundle.
    pub fn set_style(&mut self, style: RibbonStyle) {
        self.style = style;
    }
    /// Builder method: replaces the style bundle and returns `self`.
    #[must_use]
    pub fn with_style(mut self, style: RibbonStyle) -> Self {
        self.set_style(style);
        self
    }
    /// Replaces the self-driven behavior set (collapse, peek, gallery).
7
    pub const fn set_behavior(&mut self, behavior: RibbonBehavior) {
7
        self.behavior = behavior;
7
    }
    /// Builder method: replaces the behavior set and returns `self`.
    #[must_use]
7
    pub const fn with_behavior(mut self, behavior: RibbonBehavior) -> Self {
7
        self.set_behavior(behavior);
7
        self
7
    }
    /// Sets the active tab by index, clamping to the last valid tab.
14
    pub const fn set_active_tab(&mut self, index: usize) {
14
        let max = self.tabs.len().saturating_sub(1);
14
        self.active_tab = if index > max { max } else { index };
14
    }
    /// Builder method: sets the active tab (clamped) and returns `self`.
    #[must_use]
2
    pub const fn with_active_tab(mut self, index: usize) -> Self {
2
        self.set_active_tab(index);
2
        self
2
    }
    /// Registers a callback invoked when a tab is clicked.
1
    pub fn set_on_tab_click<C: Into<RibbonOnTabClickCallback>>(&mut self, data: RefAny, cb: C) {
1
        self.on_tab_click = Some(RibbonOnTabClick {
1
            callback: cb.into(),
1
            refany: data,
1
        })
1
        .into();
1
    }
    /// Builder method: registers a tab-click callback and returns `self`.
    #[must_use]
1
    pub fn with_on_tab_click<C: Into<RibbonOnTabClickCallback>>(
1
        mut self,
1
        data: RefAny,
1
        cb: C,
1
    ) -> Self {
1
        self.set_on_tab_click(data, cb);
1
        self
1
    }
    /// Builds the ADAPTIVE ribbon DOM: both the desktop chrome (tab strip)
    /// and the touch chrome (full-width tab button, group list) live in the
    /// tree, and inline viewport conditions decide which is visible. Use
    /// this when one tree must serve every window size without re-running
    /// `layout()` logic.
    #[must_use]
184
    pub fn dom(self) -> Dom {
184
        self.build_chrome(RibbonChromeMode::Adaptive)
184
    }
    /// Builds ONLY the desktop chrome (tab strip + content band), with no
    /// mobile nodes and no viewport conditions. Pair with
    /// [`Self::dom_mobile`] by branching on
    /// `LayoutCallbackInfo::viewport_bigger_than` in `layout()` - the
    /// framework re-invokes `layout()` on every resize, so crossing the
    /// breakpoint swaps the structure.
    #[must_use]
1161
    pub fn dom_desktop(self) -> Dom {
1161
        self.build_chrome(RibbonChromeMode::Desktop)
1161
    }
    /// Builds ONLY the touch chrome: the full-width active-tab button (tap
    /// opens the fullscreen tab picker, double-tap collapses the band), the
    /// scrollable group list on the dominant-hand side, and ONE visible
    /// group at a time (tapping a list entry swaps it in with no app
    /// relayout). See [`Self::dom_desktop`] for the pairing contract.
    #[must_use]
1
    pub fn dom_mobile(self) -> Dom {
1
        self.build_chrome(RibbonChromeMode::Mobile)
1
    }
1346
    fn build_chrome(self, mode: RibbonChromeMode) -> Dom {
        let Self {
1346
            app_button,
1346
            tabs,
1346
            active_tab,
1346
            on_tab_click,
1346
            style,
1346
            behavior,
1346
        } = self;
1346
        let has_callback = on_tab_click.is_some();
        // Labels are needed by both chromes; `tabs` is consumed below.
9579
        let tab_labels: Vec<AzString> = tabs.as_slice().iter().map(|t| t.label.clone()).collect();
1346
        let group_labels: Vec<AzString> = tabs
1346
            .as_slice()
1346
            .get(active_tab)
1346
            .map(|t| {
1344
                t.groups
1344
                    .as_slice()
1344
                    .iter()
5314
                    .map(|g| g.label.clone())
1344
                    .collect()
1344
            })
1346
            .unwrap_or_default();
1346
        let mut bar_children: Vec<Dom> = Vec::with_capacity(tabs.len() + 2);
1346
        if let Some(ab) = app_button.into_option() {
1183
            let mut d = Dom::create_div()
1183
                .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_APP_BUTTON))
1183
                .with_css_props(style.resolved_app_button_style())
1183
                .with_children(DomVec::from_vec(vec![crate::widgets::widget_p_with_text(
1183
                    ab.label,
                )]));
1183
            if let Some(oc) = ab.on_click.into_option() {
1
                d = d.with_callbacks(
1
                    vec![CoreCallbackData {
1
                        event: EventFilter::Hover(HoverEventFilter::Click),
1
                        callback: CoreCallback {
1
                            cb: oc.callback.cb as *const () as usize,
1
                            ctx: oc.callback.ctx,
1
                        },
1
                        refany: oc.refany,
1
                    }]
1
                    .into(),
1
                );
1182
            }
1183
            bar_children.push(d);
163
        }
        // Private chrome state shared by every tab header: the collapse and
        // hover-peek behaviors are driven from here, so the application's own
        // data model never has to model ribbon chrome.
        // Mobile starts COLLAPSED. On a phone the content band eats most of the
        // viewport and the document is what the user came for; the classic
        // office suites do the same thing at this size. The seed has to agree
        // with the initial DOM below — `set_content_visible` only ever runs
        // from a callback, so a state that says "collapsed" over a band that
        // renders expanded would make the first double-tap a no-op.
1346
        let chrome = RefAny::new(RibbonChromeState {
1346
            collapsed: matches!(mode, RibbonChromeMode::Mobile),
        });
9579
        for (idx, tab) in tabs.as_slice().iter().enumerate() {
9579
            let (classes, part_style) = if idx == active_tab {
1344
                (CLS_TAB_ACTIVE, style.resolved_tab_active_style())
            } else {
8235
                (CLS_TAB, style.resolved_tab_style())
            };
            // Per-tab properties go AFTER the shared ones so they win, and
            // they are applied in both the active and inactive state.
9579
            let part_style = match tab.style.as_ref() {
9579
                None => part_style,
                Some(extra) => {
                    let mut merged = part_style.into_library_owned_vec();
                    merged.extend(extra.as_ref().iter().cloned());
                    CssPropertyWithConditionsVec::from_vec(merged)
                }
            };
9579
            let mut d = Dom::create_div()
9579
                .with_ids_and_classes(IdOrClassVec::from_const_slice(classes))
9579
                .with_css_props(part_style)
9579
                .with_children(DomVec::from_vec(vec![crate::widgets::widget_p_with_text(
9579
                    tab.label.clone(),
                )]));
9579
            let mut cbs: Vec<CoreCallbackData> = Vec::with_capacity(4);
9579
            if has_callback {
5
                cbs.push(CoreCallbackData {
5
                    event: EventFilter::Hover(HoverEventFilter::Click),
5
                    callback: CoreCallback {
5
                        cb: on_ribbon_tab_click as usize,
5
                        ctx: azul_core::refany::OptionRefAny::None,
5
                    },
5
                    refany: RefAny::new(TabClickData {
5
                        tab_idx: idx,
5
                        on_tab_click: on_tab_click.clone(),
5
                    }),
5
                });
9574
            }
9579
            if behavior.collapsible {
9568
                cbs.push(CoreCallbackData {
9568
                    event: EventFilter::Hover(HoverEventFilter::DoubleClick),
9568
                    callback: CoreCallback {
9568
                        cb: on_ribbon_tab_double_click as usize,
9568
                        ctx: azul_core::refany::OptionRefAny::None,
9568
                    },
9568
                    refany: chrome.clone(),
9568
                });
9568
                if behavior.peek_on_hover {
9567
                    cbs.push(CoreCallbackData {
9567
                        event: EventFilter::Hover(HoverEventFilter::MouseEnter),
9567
                        callback: CoreCallback {
9567
                            cb: on_ribbon_tab_peek_enter as usize,
9567
                            ctx: azul_core::refany::OptionRefAny::None,
9567
                        },
9567
                        refany: chrome.clone(),
9567
                    });
9567
                    cbs.push(CoreCallbackData {
9567
                        event: EventFilter::Hover(HoverEventFilter::MouseLeave),
9567
                        callback: CoreCallback {
9567
                            cb: on_ribbon_tab_peek_leave as usize,
9567
                            ctx: azul_core::refany::OptionRefAny::None,
9567
                        },
9567
                        refany: chrome.clone(),
9567
                    });
9567
                }
11
            }
9579
            if !cbs.is_empty() {
9568
                d = d.with_callbacks(cbs.into());
9568
            }
9579
            bar_children.push(d);
        }
1346
        bar_children.push(
1346
            Dom::create_div()
1346
                .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_TAB_FILLER))
1346
                .with_css_props(style.resolved_tab_filler_style()),
        );
1346
        let tab_bar = Dom::create_div()
1346
            .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_TAB_BAR))
1346
            .with_css_props(style.resolved_tab_bar_style())
1346
            .with_children(DomVec::from_vec(bar_children));
1346
        let mut group_doms: Vec<Dom> =
1346
            match tabs.into_library_owned_vec().into_iter().nth(active_tab) {
1344
                Some(active) => active
1344
                    .groups
1344
                    .into_library_owned_vec()
1344
                    .into_iter()
5314
                    .map(|g| group_dom(g, &style, behavior))
1344
                    .collect(),
2
                None => Vec::new(),
            };
        // Structural mobile chrome shows ONE group at a time; the group list
        // beside the content swaps them in (a runtime display patch - no app
        // relayout, same mechanism as the gallery panel).
1346
        if matches!(mode, RibbonChromeMode::Mobile) {
3
            for (idx, g) in group_doms.iter_mut().enumerate() {
3
                if idx != 0 {
2
                    g.root
2
                        .upsert_inline_css_property(P::const_display(LayoutDisplay::None));
2
                }
            }
1345
        }
        // ---- mobile chrome -------------------------------------------
        // Same tabs and groups, touch presentation. Both chromes live in the
        // tree and the viewport condition decides which is visible, so there
        // is no second widget tree and no state to keep in sync.
1346
        let active_label = tab_labels
1346
            .get(active_tab)
1346
            .cloned()
1346
            .unwrap_or_else(|| AzString::from_const_str(""));
1346
        let mut mobile_tab_button = Dom::create_div()
1346
            .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_MOBILE_TAB_BUTTON))
1346
            .with_css_props(style.resolved_mobile_tab_button_style())
1346
            .with_children(DomVec::from_vec(vec![
1346
                crate::widgets::widget_p()
1346
                    .with_css_props(style.resolved_mobile_tab_label_style())
1346
                    .with_children(DomVec::from_vec(vec![
1346
                        Dom::create_text_do_not_use_without_block_level_wrapper(active_label),
                    ])),
1346
                Dom::create_icon(AzString::from_const_str("expand_more"))
1346
                    .with_css_props(style.resolved_mobile_tab_arrow_style()),
            ]));
1346
        let mut mobile_cbs: Vec<CoreCallbackData> = Vec::with_capacity(2);
1346
        if behavior.mobile_tab_overlay {
1341
            mobile_cbs.push(CoreCallbackData {
1341
                event: EventFilter::Hover(HoverEventFilter::Click),
1341
                callback: CoreCallback {
1341
                    cb: on_ribbon_mobile_tab_click as usize,
1341
                    ctx: azul_core::refany::OptionRefAny::None,
1341
                },
1341
                refany: RefAny::new(MobileTabData { open: false }),
1341
            });
1341
        }
        // Double tap collapses the band, exactly like a desktop double click.
1346
        if behavior.collapsible {
1341
            mobile_cbs.push(CoreCallbackData {
1341
                event: EventFilter::Hover(HoverEventFilter::DoubleClick),
1341
                callback: CoreCallback {
1341
                    cb: on_ribbon_tab_double_click as usize,
1341
                    ctx: azul_core::refany::OptionRefAny::None,
1341
                },
1341
                refany: chrome.clone(),
1341
            });
1341
        }
1346
        if !mobile_cbs.is_empty() {
1341
            mobile_tab_button = mobile_tab_button.with_callbacks(mobile_cbs.into());
1341
        }
        // Full-screen tab picker, hidden until the button opens it.
1346
        let overlay_items: Vec<Dom> = tab_labels
1346
            .iter()
1346
            .enumerate()
9579
            .map(|(idx, label)| {
9579
                let mut item = Dom::create_div()
9579
                    .with_ids_and_classes(IdOrClassVec::from_const_slice(
9579
                        CLS_MOBILE_TAB_OVERLAY_ITEM,
                    ))
9579
                    .with_css_props(style.resolved_mobile_tab_overlay_item_style())
9579
                    .with_children(DomVec::from_vec(vec![crate::widgets::widget_p_with_text(
9579
                        label.clone(),
                    )]));
9579
                if has_callback {
5
                    item = item.with_callbacks(
5
                        vec![CoreCallbackData {
5
                            event: EventFilter::Hover(HoverEventFilter::Click),
5
                            callback: CoreCallback {
5
                                cb: on_ribbon_tab_click as usize,
5
                                ctx: azul_core::refany::OptionRefAny::None,
5
                            },
5
                            refany: RefAny::new(TabClickData {
5
                                tab_idx: idx,
5
                                on_tab_click: on_tab_click.clone(),
5
                            }),
5
                        }]
5
                        .into(),
5
                    );
9574
                }
9579
                item
9579
            })
1346
            .collect();
1346
        let mobile_tab_overlay = Dom::create_div()
1346
            .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_MOBILE_TAB_OVERLAY))
1346
            .with_css_props(style.resolved_mobile_tab_overlay_style())
1346
            .with_children(DomVec::from_vec(overlay_items));
        // Group list: on phones ONE group is visible and the rest are a
        // scrollable list on the dominant-hand side.
1346
        let group_list_items: Vec<Dom> = group_labels
1346
            .iter()
1346
            .enumerate()
5316
            .map(|(idx, label)| {
5301
                let item_style = if idx == 0 {
1327
                    merged_style(
1327
                        &style.resolved_mobile_group_list_item_style(),
1327
                        &style.resolved_mobile_group_list_item_selected_style(),
                    )
                } else {
3974
                    style.resolved_mobile_group_list_item_style()
                };
5301
                let mut item = Dom::create_div()
5301
                    .with_ids_and_classes(IdOrClassVec::from_const_slice(
5301
                        CLS_MOBILE_GROUP_LIST_ITEM,
                    ))
5301
                    .with_css_props(item_style)
5301
                    .with_children(DomVec::from_vec(vec![crate::widgets::widget_p_with_text(
5301
                        label.clone(),
                    )]));
5301
                if matches!(mode, RibbonChromeMode::Mobile) {
3
                    item = item.with_callbacks(
3
                        vec![CoreCallbackData {
3
                            event: EventFilter::Hover(HoverEventFilter::Click),
3
                            callback: CoreCallback {
3
                                cb: on_ribbon_mobile_group_click as usize,
3
                                ctx: azul_core::refany::OptionRefAny::None,
3
                            },
3
                            refany: RefAny::new(GroupListClickData {
3
                                group_idx: idx,
3
                                selected_style: style
3
                                    .resolved_mobile_group_list_item_selected_style(),
3
                                base_style: style.resolved_mobile_group_list_item_style(),
3
                            }),
3
                        }]
3
                        .into(),
3
                    );
5298
                }
5301
                item
5301
            })
1346
            .collect();
1346
        let mobile_group_list = Dom::create_div()
1346
            .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_MOBILE_GROUP_LIST))
1346
            .with_css_props(style.resolved_mobile_group_list_style())
1346
            .with_children(DomVec::from_vec(group_list_items));
1346
        let content = Dom::create_div()
1346
            .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_CONTENT))
1346
            .with_css_props(style.resolved_content_style())
1346
            .with_children(DomVec::from_vec(group_doms));
        // Structural modes pin the chrome's visibility unconditionally
        // (inline resolution is last-wins, so the appended value overrides
        // the baked viewport condition): the STRUCTURE is the breakpoint
        // switch, not the stylesheet.
1346
        let children = match mode {
184
            RibbonChromeMode::Adaptive => vec![
184
                tab_bar,
184
                mobile_tab_button,
184
                mobile_tab_overlay,
184
                mobile_group_list,
184
                content,
            ],
            RibbonChromeMode::Desktop => {
1161
                let mut tab_bar = tab_bar;
1161
                tab_bar
1161
                    .root
1161
                    .upsert_inline_css_property(P::const_display(LayoutDisplay::Flex));
1161
                vec![tab_bar, content]
            }
            RibbonChromeMode::Mobile => {
1
                let mut mobile_tab_button = mobile_tab_button;
1
                let mut mobile_group_list = mobile_group_list;
1
                mobile_tab_button
1
                    .root
1
                    .upsert_inline_css_property(P::const_display(LayoutDisplay::Flex));
1
                mobile_group_list
1
                    .root
1
                    .upsert_inline_css_property(P::const_display(LayoutDisplay::Flex));
                // The group list and the ONE visible group share a ROW band
                // ("scrollable list beside the content", the touch spec) -
                // structurally, because the container is a column. List side
                // = leading (right-handed default); a Handedness-driven
                // row-reverse via a future mobile_band_style field can flip
                // it without changing this structure.
1
                let band = Dom::create_div()
1
                    .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_MOBILE_BAND))
1
                    .with_css_props(CssPropertyWithConditionsVec::from_vec(vec![
1
                        Cond::simple(P::const_display(LayoutDisplay::Flex)),
1
                        Cond::simple(P::const_flex_direction(LayoutFlexDirection::Row)),
1
                        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(1))),
1
                        cond_border_box(),
                    ]))
1
                    .with_children(DomVec::from_vec(vec![mobile_group_list, content]));
                // Collapsed to start — the other half of the `chrome` seed
                // above. Only the tab button shows; tapping it expands.
1
                let mut band = band;
1
                band.root
1
                    .upsert_inline_css_property(P::const_display(LayoutDisplay::None));
1
                vec![mobile_tab_button, mobile_tab_overlay, band]
            }
        };
1346
        let mut container = Dom::create_div()
1346
            .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_RIBBON))
1346
            .with_css_props(style.resolved_container_style())
1346
            .with_children(DomVec::from_vec(children));
        // The chrome state (collapse flag) lives on the container as a
        // DATASET so it follows node identity across RefreshDom rebuilds
        // (see keep_old_ribbon_chrome). Without this, every rebuild reset
        // collapsed=false: double-clicking a tab collapsed the band and the
        // tab-click's own RefreshDom immediately forgot it. Only attached
        // when a chrome behavior is active - an inert ribbon has no chrome
        // state to persist (and `Dom` equality stays meaningful for it).
1346
        if behavior.collapsible || behavior.peek_on_hover {
1341
            container
1341
                .root
1341
                .set_dataset(azul_core::refany::OptionRefAny::Some(chrome));
1341
            // The `as` is NOT trivial: it coerces the fn ITEM to a fn POINTER,
1341
            // which is what `DatasetMergeCallback: From<...>` is implemented for.
1341
            // Dropping it fails to satisfy the bound.
1341
            #[allow(trivial_casts)]
1341
            container.root.set_merge_callback(
1341
                keep_old_ribbon_chrome as azul_core::dom::DatasetMergeCallbackType,
1341
            );
1341
        }
1346
        container
1346
    }
}
// -- DOM assembly helpers --
/// `base` with `extra` appended (inline CSS resolves last-wins, so `extra`
/// overrides `base` where they collide).
5244
fn merged_style(
5244
    base: &CssPropertyWithConditionsVec,
5244
    extra: &CssPropertyWithConditionsVec,
5244
) -> CssPropertyWithConditionsVec {
5244
    if extra.as_ref().is_empty() {
        return base.clone();
5244
    }
5244
    let mut v: Vec<Cond> = base.as_ref().to_vec();
5244
    v.extend_from_slice(extra.as_ref());
5244
    CssPropertyWithConditionsVec::from_vec(v)
5244
}
/// Expands ribbon button config to the existing [`Button`] widget with the
/// given part styles injected through `Button`'s public style fields.
15856
fn styled_button(
15856
    icon: AzString,
15856
    label: AzString,
15856
    trailing_icon: AzString,
15856
    container_style: CssPropertyWithConditionsVec,
15856
    icon_style: CssPropertyWithConditionsVec,
15856
    label_style: CssPropertyWithConditionsVec,
15856
    trailing_icon_style: CssPropertyWithConditionsVec,
15856
    on_click: OptionButtonOnClick,
15856
) -> Dom {
15856
    let mut b = Button::create(label);
15856
    b.icon = icon;
15856
    b.trailing_icon = trailing_icon;
15856
    b.container_style = OptionCssPropertyWithConditionsVec::Some(container_style);
15856
    b.icon_style = OptionCssPropertyWithConditionsVec::Some(icon_style);
15856
    b.label_style = OptionCssPropertyWithConditionsVec::Some(label_style);
15856
    b.trailing_icon_style = OptionCssPropertyWithConditionsVec::Some(trailing_icon_style);
15856
    b.on_click = on_click;
15856
    b.dom()
15856
}
11927
fn expand_ribbon_button(rb: RibbonButton, large: bool, s: &RibbonStyle) -> Dom {
11927
    let base = if large {
1218
        &s.resolved_large_button_style()
    } else {
10709
        &s.resolved_small_button_style()
    };
11927
    let container = if rb.toggled {
1
        merged_style(base, &s.resolved_checked_style())
    } else {
11926
        base.clone()
    };
11927
    let trailing = match rb.arrow {
11925
        RibbonArrow::None => AzString::from_const_str(""),
2
        RibbonArrow::Menu | RibbonArrow::Split => AzString::from_const_str("arrow_drop_down"),
    };
11927
    let (icon_style, label_style) = if large {
1218
        (
1218
            s.resolved_large_icon_style(),
1218
            s.resolved_large_label_style(),
1218
        )
    } else {
10709
        (
10709
            s.resolved_small_icon_style(),
10709
            s.resolved_small_label_style(),
10709
        )
    };
11927
    styled_button(
11927
        rb.icon,
11927
        rb.label,
11927
        trailing,
11927
        container,
11927
        icon_style,
11927
        label_style,
11927
        s.resolved_arrow_icon_style(),
11927
        rb.on_click,
    )
11927
}
16814
fn item_dom(item: RibbonItem, s: &RibbonStyle, b: RibbonBehavior) -> Dom {
16814
    match item {
1218
        RibbonItem::LargeButton(rb) => expand_ribbon_button(rb, true, s),
10709
        RibbonItem::SmallButton(rb) => expand_ribbon_button(rb, false, s),
3572
        RibbonItem::Column(col) => Dom::create_div()
3572
            .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_COLUMN))
3572
            .with_css_props(s.resolved_column_style())
3572
            .with_children(DomVec::from_vec(
3572
                col.items
3572
                    .into_library_owned_vec()
3572
                    .into_iter()
10704
                    .map(|it| item_dom(it, s, b))
3572
                    .collect(),
            )),
1
        RibbonItem::Row(row) => Dom::create_div()
1
            .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_ROW))
1
            .with_css_props(s.resolved_row_style())
1
            .with_children(DomVec::from_vec(
1
                row.items
1
                    .into_library_owned_vec()
1
                    .into_iter()
2
                    .map(|it| item_dom(it, s, b))
1
                    .collect(),
            )),
1
        RibbonItem::Combo(combo) => combo.dom(),
1
        RibbonItem::Drop(drop) => drop.dom(),
1
        RibbonItem::Check(check) => check.dom(),
1309
        RibbonItem::Gallery(gallery) => gallery_dom(gallery, s, b),
1
        RibbonItem::Separator => Dom::create_div()
1
            .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_SEPARATOR))
1
            .with_css_props(s.resolved_separator_style()),
1
        RibbonItem::Custom(dom) => dom,
    }
16814
}
/// Appended to the group style when [`RibbonGroup::fills_space`] is set:
/// the group absorbs leftover width AND yields it under pressure, down to
/// an explicit floor. The explicit `min-width` is load-bearing — it
/// replaces the flex automatic minimum size, which taffy 0.10 does not
/// collapse across the nested group > items > gallery-frame chain (see
/// `layout/tests/flex_intrinsic_text.rs`).
static GROUP_FILL_STYLE: &[Cond] = &[
    Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(1))),
    Cond::simple(P::const_flex_shrink(LayoutFlexShrink {
        inner: FloatValue::const_new(1),
    })),
    Cond::simple(P::const_min_width(LayoutMinWidth::const_px(160))),
];
5301
fn group_dom(group: RibbonGroup, s: &RibbonStyle, b: RibbonBehavior) -> Dom {
    let RibbonGroup {
5301
        label,
5301
        items,
5301
        launcher,
5301
        fills_space,
5301
    } = group;
5301
    let item_doms: Vec<Dom> = items
5301
        .into_library_owned_vec()
5301
        .into_iter()
6111
        .map(|it| item_dom(it, s, b))
5301
        .collect();
5301
    let items_row = Dom::create_div()
5301
        .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_GROUP_ITEMS))
5301
        .with_css_props(s.resolved_group_items_style())
5301
        .with_children(DomVec::from_vec(item_doms));
5301
    let has_launcher = launcher.is_some();
5301
    let mut footer_children: Vec<Dom> = Vec::with_capacity(3);
5301
    if has_launcher {
2
        // Balances the launcher's width so the caption stays centered.
2
        footer_children.push(
2
            Dom::create_div()
2
                .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_FOOTER_SPACER))
2
                .with_css_props(s.resolved_footer_spacer_style()),
2
        );
5299
    }
5301
    footer_children.push(
5301
        crate::widgets::widget_p()
5301
            .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_GROUP_LABEL))
5301
            .with_css_props(s.resolved_group_label_style())
5301
            .with_children(DomVec::from_vec(vec![
5301
                Dom::create_text_do_not_use_without_block_level_wrapper(label),
            ])),
    );
5301
    if let Some(l) = launcher.into_option() {
2
        footer_children.push(styled_button(
2
            AzString::from_const_str("south_east"),
2
            AzString::from_const_str(""),
2
            AzString::from_const_str(""),
2
            s.resolved_launcher_button_style(),
2
            s.resolved_launcher_icon_style(),
2
            s.resolved_small_label_style(),
2
            s.resolved_arrow_icon_style(),
2
            Some(l).into(),
2
        ));
5299
    }
5301
    let footer = Dom::create_div()
5301
        .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_GROUP_FOOTER))
5301
        .with_css_props(s.resolved_group_footer_style())
5301
        .with_children(DomVec::from_vec(footer_children));
5301
    let group_style = if fills_space {
1300
        merged_style(
1300
            &s.resolved_group_style(),
1300
            &CssPropertyWithConditionsVec::from_const_slice(GROUP_FILL_STYLE),
        )
    } else {
4001
        s.resolved_group_style()
    };
5301
    Dom::create_div()
5301
        .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_GROUP))
5301
        .with_css_props(group_style)
5301
        .with_children(DomVec::from_vec(vec![items_row, footer]))
5301
}
1309
fn gallery_dom(gallery: RibbonGallery, s: &RibbonStyle, b: RibbonBehavior) -> Dom {
    let RibbonGallery {
1309
        cells,
1309
        selected,
1309
        on_select,
1309
    } = gallery;
1309
    let has_callback = on_select.is_some();
1309
    let cells = cells.into_library_owned_vec();
    // The cells are built twice: once for the in-ribbon strip and once for
    // the expansion panel, so "More" can show every cell without a relayout.
2616
    let build_cells = |in_panel: bool| -> Vec<Dom> {
2616
        let mut out: Vec<Dom> = Vec::with_capacity(cells.len());
11042
        for (idx, cell) in cells.iter().enumerate() {
11042
            let (classes, cell_style) = if idx == selected {
2616
                (
2616
                    CLS_GALLERY_CELL_SELECTED,
2616
                    merged_style(
2616
                        &s.resolved_gallery_cell_style(),
2616
                        &s.resolved_gallery_cell_selected_style(),
2616
                    ),
2616
                )
            } else {
8426
                (CLS_GALLERY_CELL, s.resolved_gallery_cell_style())
            };
11042
            let label = crate::widgets::widget_p()
11042
                .with_css_props(s.resolved_gallery_cell_label_style())
11042
                .with_children(DomVec::from_vec(vec![
11042
                    Dom::create_text_do_not_use_without_block_level_wrapper(cell.label.clone()),
                ]));
11042
            let mut d = Dom::create_div()
11042
                .with_ids_and_classes(IdOrClassVec::from_const_slice(classes))
11042
                .with_css_props(cell_style)
11042
                .with_children(DomVec::from_vec(vec![cell.preview.clone(), label]));
11042
            if has_callback || b.auto_select_gallery {
11040
                d = d.with_callbacks(
11040
                    vec![CoreCallbackData {
11040
                        event: EventFilter::Hover(HoverEventFilter::Click),
11040
                        callback: CoreCallback {
11040
                            cb: on_ribbon_gallery_cell_click as usize,
11040
                            ctx: azul_core::refany::OptionRefAny::None,
11040
                        },
11040
                        refany: RefAny::new(GalleryCellClickData {
11040
                            cell_idx: idx,
11040
                            on_select: on_select.clone(),
11040
                            auto_select: b.auto_select_gallery,
11040
                            in_panel,
11040
                            selected_style: s.resolved_gallery_cell_selected_style(),
11040
                            base_style: s.resolved_gallery_cell_style(),
11040
                        }),
11040
                    }]
11040
                    .into(),
11040
                );
11040
            }
11042
            out.push(d);
        }
2616
        out
2616
    };
1309
    let strip = Dom::create_div()
1309
        .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_GALLERY_STRIP))
1309
        .with_css_props(s.resolved_gallery_strip_style())
1309
        .with_children(DomVec::from_vec(build_cells(false)));
    // Spinner column: scroll-up, scroll-down, and the "More" button that
    // toggles the expansion panel (the classic office-suite "More" chevron-over-bar).
1309
    let spinner_icons = ["expand_less", "expand_more", "arrow_drop_down"];
1309
    let spinner_buttons: Vec<Dom> = spinner_icons
1309
        .iter()
1309
        .enumerate()
3927
        .map(|(i, icon)| {
3927
            let mut btn = styled_button(
3927
                AzString::from(*icon),
3927
                AzString::from_const_str(""),
3927
                AzString::from_const_str(""),
3927
                s.resolved_gallery_spinner_button_style(),
3927
                s.resolved_gallery_spinner_icon_style(),
3927
                s.resolved_small_label_style(),
3927
                s.resolved_arrow_icon_style(),
3927
                OptionButtonOnClick::None,
            );
            // The third button is "More": it expands the panel.
3927
            if i == 2 && b.expandable_gallery {
1307
                btn = btn.with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_GALLERY_MORE));
1307
                btn = btn.with_callbacks(
1307
                    vec![CoreCallbackData {
1307
                        event: EventFilter::Hover(HoverEventFilter::Click),
1307
                        callback: CoreCallback {
1307
                            cb: on_ribbon_gallery_more_click as usize,
1307
                            ctx: azul_core::refany::OptionRefAny::None,
1307
                        },
1307
                        refany: RefAny::new(GalleryMoreData { open: false }),
1307
                    }]
1307
                    .into(),
1307
                );
2620
            }
3927
            btn
3927
        })
1309
        .collect();
1309
    let spinner = Dom::create_div()
1309
        .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_GALLERY_SPINNER))
1309
        .with_css_props(s.resolved_gallery_spinner_style())
1309
        .with_children(DomVec::from_vec(spinner_buttons));
1309
    let frame = Dom::create_div()
1309
        .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_GALLERY))
1309
        .with_css_props(s.resolved_gallery_frame_style())
1309
        .with_children(DomVec::from_vec(vec![strip, spinner]));
1309
    if !b.expandable_gallery {
2
        return frame;
1307
    }
    // The expansion panel is an absolutely-positioned wrapped grid of every
    // cell, hidden until "More" is clicked (the popover/combobox pattern).
1307
    let panel = Dom::create_div()
1307
        .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_GALLERY_PANEL))
1307
        .with_css_props(s.resolved_gallery_panel_style())
1307
        .with_children(DomVec::from_vec(build_cells(true)));
1307
    Dom::create_div()
1307
        .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_GALLERY_WRAPPER))
1307
        .with_css_props(s.resolved_gallery_wrapper_style())
1307
        .with_children(DomVec::from_vec(vec![frame, panel]))
1309
}
// -- Trampolines --
/// Which chrome [`Ribbon::dom`]-family builder emits.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum RibbonChromeMode {
    /// Both chromes in one tree; inline viewport conditions pick one.
    Adaptive,
    /// Desktop chrome only (tab strip + content).
    Desktop,
    /// Touch chrome only (tab button + overlay + group list + one group).
    Mobile,
}
/// Per-list-entry payload for the mobile group switcher.
struct GroupListClickData {
    group_idx: usize,
    selected_style: CssPropertyWithConditionsVec,
    base_style: CssPropertyWithConditionsVec,
}
/// Tapping a group-list entry shows THAT group in the content band and moves
/// the highlight - a runtime display patch, no app relayout (the same
/// chokepoint mechanism the gallery panel uses). Targets resolve BY CLASS
/// from the ribbon container, per the widget convention.
extern "C" fn on_ribbon_mobile_group_click(mut refany: RefAny, mut info: CallbackInfo) -> Update {
    let hit = info.get_hit_node();
    let Some(mut data) = refany.downcast_mut::<GroupListClickData>() else {
        return Update::DoNothing;
    };
    let group_idx = data.group_idx;
    let selected_style = data.selected_style.clone();
    let base_style = data.base_style.clone();
    drop(data);
    let Some(ribbon) = ancestor_with_class(&info, hit, RIBBON_CONTAINER_CLASS) else {
        return Update::DoNothing;
    };
    // Swap the visible group inside the content band (the content sits
    // INSIDE the mobile band wrapper, so resolve by descendant search).
    if let Some(content) = descendant_with_class(&info, ribbon, RIBBON_CONTENT_CLASS) {
        let mut group = info.get_first_child(content);
        let mut idx = 0_usize;
        while let Some(g) = group {
            let display = if idx == group_idx {
                LayoutDisplay::Flex
            } else {
                LayoutDisplay::None
            };
            info.set_css_property(g, P::const_display(display));
            group = info.get_next_sibling(g);
            idx += 1;
        }
    }
    // Move the highlight along the list (unconditional props only, like the
    // gallery cell highlight). For a DE-selected entry, property types the
    // selected style sets but the base style does not are reset to Initial -
    // set_css_property(Initial) REMOVES the runtime override, so the entry
    // falls back to its inline style instead of keeping the stale highlight.
    let item = ancestor_with_class(&info, hit, MOBILE_GROUP_LIST_ITEM_CLASS).unwrap_or(hit);
    if let Some(list) = info.get_parent(item) {
        let mut sibling = info.get_first_child(list);
        while let Some(entry) = sibling {
            if entry == item {
                for prop in selected_style.as_ref() {
                    if prop.apply_if.as_ref().is_empty() {
                        info.set_css_property(entry, prop.property.clone());
                    }
                }
            } else {
                for prop in base_style.as_ref() {
                    if prop.apply_if.as_ref().is_empty() {
                        info.set_css_property(entry, prop.property.clone());
                    }
                }
                for prop in selected_style.as_ref() {
                    if !prop.apply_if.as_ref().is_empty() {
                        continue;
                    }
                    let ty = prop.property.get_type();
                    let in_base = base_style
                        .as_ref()
                        .iter()
                        .any(|b| b.apply_if.as_ref().is_empty() && b.property.get_type() == ty);
                    if !in_base {
                        info.set_css_property(entry, props::property::CssProperty::initial(ty));
                    }
                }
            }
            sibling = info.get_next_sibling(entry);
        }
    }
    Update::DoNothing
}
/// Dataset merge for the ribbon container: chrome state (collapse) must
/// survive app-driven rebuilds (any callback returning `RefreshDom` - the
/// ribbon's own tab switch does), so keep the OLD allocation wholesale.
/// `diff::transfer_states` then re-points every tab callback refany (they
/// are clones of this dataset) onto the kept allocation, so the handlers
/// keep reading the persistent state with no further wiring.
extern "C" fn keep_old_ribbon_chrome(_new: RefAny, old: RefAny) -> RefAny {
    old
}
struct TabClickData {
    tab_idx: usize,
    on_tab_click: OptionRibbonOnTabClick,
}
4
extern "C" fn on_ribbon_tab_click(mut refany: RefAny, info: CallbackInfo) -> Update {
4
    let Some(mut data) = refany.downcast_mut::<TabClickData>() else {
1
        return Update::DoNothing;
    };
3
    let idx = data.tab_idx;
3
    match data.on_tab_click.as_mut() {
3
        Some(RibbonOnTabClick { refany, callback }) => (callback.cb)(refany.clone(), info, idx),
        None => Update::DoNothing,
    }
4
}
/// Private chrome state for the collapse / hover-peek behaviors. Lives in a
/// `RefAny` minted inside [`Ribbon::dom`] and shared by every tab header, so
/// the ribbon can drive its own chrome without any application state.
struct RibbonChromeState {
    collapsed: bool,
}
/// The content band is the tab bar's next sibling; from a tab header that is
/// `parent(tab) -> next_sibling`.
/// The content band of the ribbon that owns `hit`'s tab header, resolved BY
/// CLASS: walk up to the ribbon container, then scan its children for the
/// content class. Positional navigation (`next_sibling(parent(tab))`) broke
/// the moment the container grew more children — the mobile chrome sits
/// between the tab bar and the content band, so a double-click "collapsed"
/// the (already hidden) mobile tab button while the content stayed visible.
fn content_node_of_tab(info: &CallbackInfo, hit: DomNodeId) -> Option<DomNodeId> {
    let tab = ancestor_with_class(info, hit, RIBBON_TAB_CLASS)
        .or_else(|| ancestor_with_class(info, hit, MOBILE_TAB_BUTTON_CLASS))?;
    let ribbon = ancestor_with_class(info, tab, RIBBON_CONTAINER_CLASS)?;
    // Mobile first: the band is what "collapsed" means there. Desktop has no
    // band, so it falls through to the content div as before.
    descendant_with_class(info, ribbon, MOBILE_BAND_CLASS)
        .or_else(|| descendant_with_class(info, ribbon, RIBBON_CONTENT_CLASS))
}
fn set_content_visible(info: &mut CallbackInfo, content: DomNodeId, visible: bool) {
    let display = if visible {
        LayoutDisplay::Flex
    } else {
        LayoutDisplay::None
    };
    info.set_css_property(content, P::const_display(display));
}
/// Double-click on a tab header toggles the collapsed state of the content
/// band (the classic office-suite "Collapse the Ribbon").
extern "C" fn on_ribbon_tab_double_click(mut refany: RefAny, mut info: CallbackInfo) -> Update {
    let hit = info.get_hit_node();
    let Some(content) = content_node_of_tab(&info, hit) else {
        return Update::DoNothing;
    };
    let Some(mut state) = refany.downcast_mut::<RibbonChromeState>() else {
        return Update::DoNothing;
    };
    state.collapsed = !state.collapsed;
    let collapsed = state.collapsed;
    drop(state);
    set_content_visible(&mut info, content, !collapsed);
    Update::DoNothing
}
/// While collapsed, hovering a tab header peeks the content band.
extern "C" fn on_ribbon_tab_peek_enter(mut refany: RefAny, mut info: CallbackInfo) -> Update {
    let hit = info.get_hit_node();
    let Some(content) = content_node_of_tab(&info, hit) else {
        return Update::DoNothing;
    };
    let Some(state) = refany.downcast_ref::<RibbonChromeState>() else {
        return Update::DoNothing;
    };
    let collapsed = state.collapsed;
    drop(state);
    if collapsed {
        set_content_visible(&mut info, content, true);
    }
    Update::DoNothing
}
/// Leaving the tab header hides the peeked band again.
extern "C" fn on_ribbon_tab_peek_leave(mut refany: RefAny, mut info: CallbackInfo) -> Update {
    let hit = info.get_hit_node();
    let Some(content) = content_node_of_tab(&info, hit) else {
        return Update::DoNothing;
    };
    let Some(state) = refany.downcast_ref::<RibbonChromeState>() else {
        return Update::DoNothing;
    };
    let collapsed = state.collapsed;
    drop(state);
    if collapsed {
        set_content_visible(&mut info, content, false);
    }
    Update::DoNothing
}
/// Per-mobile-tab-button state: whether the tab overlay is open.
struct MobileTabData {
    open: bool,
}
/// The mobile tab button opens/closes the full-screen tab picker, which is
/// its next sibling in the ribbon container.
extern "C" fn on_ribbon_mobile_tab_click(mut refany: RefAny, mut info: CallbackInfo) -> Update {
    let hit = info.get_hit_node();
    let Some(button) = ancestor_with_class(&info, hit, MOBILE_TAB_BUTTON_CLASS) else {
        return Update::DoNothing;
    };
    let Some(overlay) = info.get_next_sibling(button) else {
        return Update::DoNothing;
    };
    let Some(mut data) = refany.downcast_mut::<MobileTabData>() else {
        return Update::DoNothing;
    };
    data.open = !data.open;
    let open = data.open;
    drop(data);
    info.set_css_property(
        overlay,
        P::const_display(if open {
            LayoutDisplay::Flex
        } else {
            LayoutDisplay::None
        }),
    );
    Update::DoNothing
}
/// Per-"More"-button state: whether the expansion panel is open.
struct GalleryMoreData {
    open: bool,
}
/// Walks up from `start` (inclusive) to the first ancestor carrying `class`.
///
/// Hit nodes are not stable: a click on a button can report the button or
/// the icon/label node inside it, and widgets may gain wrapper levels. So
/// the ribbon's handlers locate their targets by CLASS rather than by
/// counting `get_parent` hops - the same identifiers the public CSS API is
/// built on. The walk is bounded so a malformed tree cannot spin.
2
fn ancestor_with_class(info: &CallbackInfo, start: DomNodeId, class: &str) -> Option<DomNodeId> {
2
    let mut current = Some(start);
4
    for _ in 0..16 {
4
        let node = current?;
2
        if info
2
            .get_node_classes(node)
2
            .as_ref()
2
            .iter()
2
            .any(|c| c.as_str() == class)
        {
            return Some(node);
2
        }
2
        current = info.get_parent(node);
    }
    None
2
}
/// Breadth-first search for the first descendant of `root` carrying `class`,
/// bounded to 64 visited nodes. The ribbon's structural chromes nest parts
/// at different depths (the mobile band wraps group list + content), so
/// class resolution must not assume direct children.
fn descendant_with_class(info: &CallbackInfo, root: DomNodeId, class: &str) -> Option<DomNodeId> {
    let mut queue: Vec<DomNodeId> = Vec::with_capacity(8);
    let mut child = info.get_first_child(root);
    while let Some(n) = child {
        queue.push(n);
        child = info.get_next_sibling(n);
    }
    let mut visited = 0_usize;
    let mut i = 0_usize;
    while i < queue.len() && visited < 64 {
        let node = queue[i];
        i += 1;
        visited += 1;
        if info
            .get_node_classes(node)
            .as_ref()
            .iter()
            .any(|cl| cl.as_str() == class)
        {
            return Some(node);
        }
        let mut child = info.get_first_child(node);
        while let Some(n) = child {
            queue.push(n);
            child = info.get_next_sibling(n);
        }
    }
    None
}
/// The "More" button toggles the expansion panel (the gallery wrapper's
/// last child).
extern "C" fn on_ribbon_gallery_more_click(mut refany: RefAny, mut info: CallbackInfo) -> Update {
    let hit = info.get_hit_node();
    let Some(wrapper) = ancestor_with_class(&info, hit, GALLERY_WRAPPER_CLASS) else {
        return Update::DoNothing;
    };
    let Some(panel) = info.get_last_child(wrapper) else {
        return Update::DoNothing;
    };
    let Some(mut data) = refany.downcast_mut::<GalleryMoreData>() else {
        return Update::DoNothing;
    };
    data.open = !data.open;
    let open = data.open;
    drop(data);
    let display = if open {
        LayoutDisplay::Flex
    } else {
        LayoutDisplay::None
    };
    info.set_css_property(panel, P::const_display(display));
    Update::DoNothing
}
struct GalleryCellClickData {
    cell_idx: usize,
    on_select: OptionRibbonGalleryOnSelect,
    /// Move the selection highlight without an app relayout.
    auto_select: bool,
    /// Cells in the expansion panel also close the panel when picked.
    in_panel: bool,
    selected_style: CssPropertyWithConditionsVec,
    base_style: CssPropertyWithConditionsVec,
}
2
extern "C" fn on_ribbon_gallery_cell_click(mut refany: RefAny, mut info: CallbackInfo) -> Update {
2
    let hit = info.get_hit_node();
2
    let Some(mut data) = refany.downcast_mut::<GalleryCellClickData>() else {
        return Update::DoNothing;
    };
2
    let idx = data.cell_idx;
2
    let auto_select = data.auto_select;
2
    let in_panel = data.in_panel;
2
    let selected_style = data.selected_style.clone();
2
    let base_style = data.base_style.clone();
2
    let user = data.on_select.clone();
2
    drop(data);
    // Default behavior: move the highlight to the clicked cell immediately,
    // so the gallery feels live even if the app does not re-render. The hit
    // node may be the cell's preview or label, so resolve the cell by class.
2
    let cell = ancestor_with_class(&info, hit, GALLERY_CELL_CLASS).unwrap_or(hit);
2
    if auto_select {
        if let Some(strip) = info.get_parent(cell) {
            let mut sibling = info.get_first_child(strip);
            while let Some(cell_node) = sibling {
                let style = if cell_node == cell {
                    &selected_style
                } else {
                    &base_style
                };
                for prop in style.as_ref() {
                    if prop.apply_if.as_ref().is_empty() {
                        info.set_css_property(cell_node, prop.property.clone());
                    }
                }
                sibling = info.get_next_sibling(cell_node);
            }
        }
        // Picking from the expansion panel closes it.
        if in_panel {
            if let Some(panel) = info.get_parent(cell) {
                info.set_css_property(panel, P::const_display(LayoutDisplay::None));
            }
        }
2
    }
2
    match user.into_option() {
1
        Some(RibbonGalleryOnSelect { refany, callback }) => (callback.cb)(refany, info, idx),
1
        None => Update::DoNothing,
    }
2
}
impl From<Ribbon> for Dom {
1
    fn from(r: Ribbon) -> Self {
1
        r.dom()
1
    }
}
#[cfg(test)]
mod tests {
    use std::{
        collections::BTreeMap,
        sync::{Arc, Mutex},
    };
    use azul_core::{
        dom::{DomId, DomNodeId, NodeId, NodeType},
        geom::OptionLogicalPosition,
        gl::OptionGlContextPtr,
        hit_test::ScrollPosition,
        refany::OptionRefAny,
        resources::RendererResources,
        styled_dom::NodeHierarchyItemId,
        window::{MonitorVec, RawWindowHandle},
    };
    use azul_css::{
        dynamic_selector::{DynamicSelector, DynamicSelectorVec, PseudoStateType, ThemeCondition},
        props::property::{CssProperty, CssPropertyType},
        system::SystemStyle,
    };
    use rust_fontconfig::FcFontCache;
    use super::*;
    #[cfg(feature = "icu")]
    use crate::icu::IcuLocalizerHandle;
    use crate::{
        callbacks::{CallbackChange, CallbackInfoRefData, ExternalSystemCallbacks},
        window::LayoutWindow,
        window_state::FullWindowState,
    };
    // ------------------------------------------------------------------
    // Helpers
    // ------------------------------------------------------------------
269
    fn has_class(node: &Dom, name: &str) -> bool {
269
        node.root
269
            .get_ids_and_classes()
269
            .as_ref()
269
            .iter()
271
            .any(|c| matches!(c, Class(s) if s.as_str() == name))
269
    }
    /// Text of a label node, looking through the `<p>` block wrapper the
    /// label convention mandates (`p > text`).
16
    fn text_of(node: &Dom) -> Option<&str> {
16
        match node.root.get_node_type() {
4
            NodeType::Text(s) => Some(s.as_ref().as_str()),
12
            NodeType::P => match node.children.as_ref() {
12
                [only] => match only.root.get_node_type() {
12
                    NodeType::Text(s) => Some(s.as_ref().as_str()),
                    _ => None,
                },
                _ => None,
            },
            _ => None,
        }
16
    }
    /// USER convention (2026-08-12): widget-emitted text is never a raw
    /// `create_text` child — every label is `<p>` wrapping exactly one text
    /// node. Raw text as a direct flex child takes the anonymous-box path
    /// that made "PAGE LAYOUT" wrap and the group captions de-center live.
    /// Walks the full desktop + mobile chrome (tabs, captions, buttons,
    /// gallery, launcher) and flags every Text node under a non-P parent.
    #[test]
1
    fn every_ribbon_label_is_block_formatted_no_raw_text_children() {
        extern "C" fn noop_launcher_click(_data: RefAny, _info: CallbackInfo) -> Update {
            Update::DoNothing
        }
73
        fn walk(node: &Dom, parent_is_p: bool, bad: &mut Vec<String>) {
73
            if let NodeType::Text(t) = node.root.get_node_type() {
19
                if !parent_is_p {
                    bad.push(t.as_ref().as_str().to_string());
19
                }
54
            }
            // An icon's text leaf is the glyph slot icon resolution fills
            // (the icon becomes an inline <span> around it): by convention.
73
            let is_p = matches!(node.root.get_node_type(), NodeType::P | NodeType::Icon(_));
73
            for c in node.children.as_ref() {
72
                walk(c, is_p, bad);
72
            }
73
        }
1
        let cells = vec![RibbonGalleryCell::new(
1
            Dom::create_div(), // user preview content — exempt from the convention
1
            "Style 0".into(),
        )];
1
        let tab = RibbonTab::new("HOME".into())
1
            .with_group(
1
                RibbonGroup::new("Clipboard".into())
1
                    .with_item(RibbonItem::LargeButton(RibbonButton::new(
1
                        "content_paste".into(),
1
                        "Paste".into(),
1
                    )))
1
                    .with_launcher(
1
                        RefAny::new(0usize),
1
                        noop_launcher_click as crate::widgets::button::ButtonOnClickCallbackType,
                    ),
            )
1
            .with_group(
1
                RibbonGroup::new("Styles".into())
1
                    .with_item(RibbonItem::Gallery(RibbonGallery::new(cells.into()))),
            );
1
        let dom = Ribbon::new(RibbonTabVec::from_vec(vec![
1
            tab,
1
            RibbonTab::new("PAGE LAYOUT".into()),
        ]))
1
        .with_app_button(RibbonAppButton::new("FILE".into()))
1
        .dom();
1
        let mut bad = Vec::new();
1
        walk(&dom, false, &mut bad);
1
        assert!(
1
            bad.is_empty(),
            "raw text nodes outside a <p> wrapper: {bad:?}"
        );
1
    }
    /// The text of a box's single label child (tabs / app button).
5
    fn label_text(node: &Dom) -> Option<&str> {
5
        node.children.as_ref().first().and_then(text_of)
5
    }
8
    fn icon_name_of(node: &Dom) -> Option<&str> {
8
        match node.root.get_node_type() {
8
            NodeType::Icon(s) => Some(s.as_ref().as_str()),
            _ => None,
        }
8
    }
10
    fn inline_props(node: &Dom) -> Vec<CssProperty> {
10
        node.root
10
            .style
10
            .iter_inline_properties()
235
            .map(|(p, _)| p.clone())
10
            .collect()
10
    }
11
    fn style_props(style: &CssPropertyWithConditionsVec) -> Vec<CssProperty> {
209
        style.as_ref().iter().map(|c| c.property.clone()).collect()
11
    }
116
    fn recursive_descendants(node: &Dom) -> usize {
116
        node.children
116
            .as_ref()
116
            .iter()
116
            .map(|c| 1 + recursive_descendants(c))
116
            .sum()
116
    }
    /// `(tab bar, content)` of a rendered ribbon DOM.
    ///
    /// The root also carries the mobile chrome (tab button, tab overlay,
    /// group list), which the viewport conditions hide on desktop - so the
    /// parts are located by CLASS, not by index.
33
    fn parts(dom: &Dom) -> (&Dom, &Dom) {
66
        let by_class = |name: &str| {
66
            dom.children
66
                .as_ref()
66
                .iter()
198
                .find(|c| has_class(c, name))
66
                .unwrap_or_else(|| panic!("a ribbon DOM has a {name} child"))
66
        };
33
        (
33
            by_class("__azul-native-ribbon-tabbar"),
33
            by_class("__azul-native-ribbon-content"),
33
        )
33
    }
    /// `(items row, footer)` of the `n`-th rendered group.
19
    fn group_parts(content: &Dom, n: usize) -> (&Dom, &Dom) {
19
        let group = &content.children.as_ref()[n];
19
        let ch = group.children.as_ref();
19
        assert_eq!(ch.len(), 2, "a group is exactly [items, footer]");
19
        (&ch[0], &ch[1])
19
    }
24
    fn tabs(n: usize) -> RibbonTabVec {
24
        let mut v = Vec::with_capacity(n);
63
        for i in 0..n {
63
            v.push(RibbonTab::new(AzString::from(format!("t{i}"))));
63
        }
24
        RibbonTabVec::from_vec(v)
24
    }
10
    fn small_btn(icon: &str, label: &str) -> RibbonButton {
10
        RibbonButton::new(AzString::from(icon), AzString::from(label))
10
    }
    struct IndexLog {
        seen: Vec<usize>,
    }
4
    extern "C" fn record_index(mut data: RefAny, _: CallbackInfo, index: usize) -> Update {
4
        if let Some(mut log) = data.downcast_mut::<IndexLog>() {
4
            log.seen.push(index);
4
        }
4
        Update::RefreshDom
4
    }
2
    fn log_indices(data: &mut RefAny) -> Vec<usize> {
2
        data.downcast_ref::<IndexLog>()
2
            .expect("payload must still be an IndexLog")
2
            .seen
2
            .clone()
2
    }
    /// Invokes `cb` (a ribbon trampoline) with a minimal `CallbackInfo`. The
    /// trampolines never read the DOM, so the `LayoutWindow` holds no layout
    /// results - if they ever start touching them, these tests notice.
6
    fn run_trampoline(
6
        cb: extern "C" fn(RefAny, CallbackInfo) -> Update,
6
        data: RefAny,
6
    ) -> (Update, Vec<CallbackChange>) {
6
        let layout_window =
6
            LayoutWindow::new(FcFontCache::default()).expect("LayoutWindow::new failed");
6
        let renderer_resources = RendererResources::default();
6
        let previous_window_state: Option<FullWindowState> = None;
6
        let current_window_state = FullWindowState::default();
6
        let gl_context = OptionGlContextPtr::None;
6
        let scroll_states: BTreeMap<DomId, BTreeMap<NodeHierarchyItemId, ScrollPosition>> =
6
            BTreeMap::new();
6
        let window_handle = RawWindowHandle::Unsupported;
6
        let system_callbacks = ExternalSystemCallbacks::rust_internal();
6
        let ref_data = CallbackInfoRefData {
6
            layout_window: &layout_window,
6
            renderer_resources: &renderer_resources,
6
            previous_window_state: &previous_window_state,
6
            current_window_state: &current_window_state,
6
            gl_context: &gl_context,
6
            current_scroll_manager: &scroll_states,
6
            current_window_handle: &window_handle,
6
            system_callbacks: &system_callbacks,
6
            system_style: Arc::new(SystemStyle::default()),
6
            monitors: Arc::new(Mutex::new(MonitorVec::from_const_slice(&[]))),
6
            #[cfg(feature = "icu")]
6
            icu_localizer: IcuLocalizerHandle::default(),
6
            ctx: OptionRefAny::None,
6
        };
6
        let changes: Arc<Mutex<Vec<CallbackChange>>> = Arc::new(Mutex::new(Vec::new()));
6
        let info = CallbackInfo::new(
6
            &ref_data,
6
            &changes,
6
            DomNodeId {
6
                dom: DomId::ROOT_ID,
6
                node: NodeHierarchyItemId::from_crate_internal(Some(NodeId::new(0))),
6
            },
6
            OptionLogicalPosition::None,
6
            OptionLogicalPosition::None,
        );
6
        let update = cb(data, info);
6
        let recorded = core::mem::take(&mut *changes.lock().expect("change log poisoned"));
6
        (update, recorded)
6
    }
    // ------------------------------------------------------------------
    // Constructors and invariants
    // ------------------------------------------------------------------
    #[test]
1
    fn ribbon_new_defaults_to_office_2013_with_tab_zero_active() {
5
        for count in [0usize, 1, 2, 9] {
4
            let r = Ribbon::new(tabs(count));
4
            assert_eq!(r.tabs.len(), count);
4
            assert_eq!(r.active_tab, 0);
4
            assert!(r.on_tab_click.is_none());
4
            assert!(r.app_button.is_none());
4
            assert_eq!(r.style, RibbonStyle::office_2013());
        }
1
    }
    #[test]
1
    fn ribbon_style_default_is_office_2013() {
1
        assert_eq!(RibbonStyle::default(), RibbonStyle::office_2013());
1
    }
    #[test]
1
    fn set_active_tab_clamps_to_the_last_valid_index() {
1
        let mut r = Ribbon::new(RibbonTabVec::from_vec(Vec::new()));
4
        for index in [0usize, 1, usize::MAX / 2, usize::MAX] {
4
            r.set_active_tab(index);
4
            assert_eq!(r.active_tab, 0, "empty ribbon must clamp {index} to 0");
        }
1
        let mut r = Ribbon::new(tabs(4));
5
        for index in 0..4 {
4
            r.set_active_tab(index);
4
            assert_eq!(r.active_tab, index);
        }
4
        for index in [4usize, 5, usize::MAX - 1, usize::MAX] {
4
            r.set_active_tab(index);
4
            assert_eq!(r.active_tab, 3, "{index} must clamp to the last tab");
        }
1
    }
    #[test]
1
    fn group_and_tab_builders_append_in_order() {
1
        let group = RibbonGroup::new(AzString::from("Font"))
1
            .with_item(RibbonItem::SmallButton(small_btn("format_bold", "")))
1
            .with_item(RibbonItem::Separator);
1
        assert_eq!(group.items.len(), 2);
1
        assert!(group.launcher.is_none());
1
        let tab = RibbonTab::new(AzString::from("HOME"))
1
            .with_group(group.clone())
1
            .with_group(RibbonGroup::new(AzString::from("Editing")));
1
        assert_eq!(tab.groups.len(), 2);
1
        assert_eq!(tab.groups.as_ref()[0].label.as_str(), "Font");
1
        assert_eq!(tab.groups.as_ref()[1].label.as_str(), "Editing");
1
    }
    // ------------------------------------------------------------------
    // Tab bar
    // ------------------------------------------------------------------
    #[test]
1
    fn dom_of_an_empty_ribbon_has_only_the_filler_in_the_bar() {
1
        let dom = Ribbon::new(RibbonTabVec::from_vec(Vec::new())).dom();
1
        assert!(has_class(&dom, "__azul-native-ribbon"));
1
        let (bar, content) = parts(&dom);
1
        assert!(has_class(bar, "__azul-native-ribbon-tabbar"));
1
        assert_eq!(
1
            bar.children.as_ref().len(),
            1,
            "empty ribbon bar = filler only"
        );
1
        assert!(has_class(
1
            &bar.children.as_ref()[0],
1
            "__azul-native-ribbon-tab-filler"
        ));
1
        assert!(content.children.as_ref().is_empty());
1
    }
    #[test]
1
    fn dom_desktop_emits_only_the_desktop_chrome() {
1
        let r = Ribbon::new(tabs(3));
1
        let dom = r.dom_desktop();
1
        let ch = dom.children.as_ref();
1
        assert_eq!(ch.len(), 2, "desktop chrome = [tab bar, content]");
1
        assert!(has_class(&ch[0], "__azul-native-ribbon-tabbar"));
1
        assert!(has_class(&ch[1], "__azul-native-ribbon-content"));
1
    }
    #[test]
1
    fn dom_mobile_emits_only_the_touch_chrome_with_one_visible_group() {
        use azul_css::props::property::CssPropertyType;
1
        let mut tab = RibbonTab::new(AzString::from_const_str("HOME"));
3
        for label in ["Clipboard", "Font", "Paragraph"] {
3
            tab = tab.with_group(RibbonGroup::new(AzString::from(label)));
3
        }
1
        let r = Ribbon::new(RibbonTabVec::from_vec(vec![tab]));
1
        let dom = r.dom_mobile();
1
        let ch = dom.children.as_ref();
1
        assert_eq!(ch.len(), 3, "mobile chrome = [tab button, overlay, band]");
1
        assert!(has_class(&ch[0], "__azul-native-ribbon-mobile-tab"));
1
        assert!(has_class(&ch[1], "__azul-native-ribbon-mobile-tab-overlay"));
1
        assert!(has_class(&ch[2], "__azul-native-ribbon-mobile-band"));
1
        let band = ch[2].children.as_ref();
1
        assert_eq!(band.len(), 2, "band = [group list, content] side by side");
1
        assert!(has_class(
1
            &band[0],
1
            "__azul-native-ribbon-mobile-group-list"
        ));
1
        assert!(has_class(&band[1], "__azul-native-ribbon-content"));
        // Exactly the FIRST group is visible; the others carry an appended
        // unconditional display:none (the group list swaps them at runtime).
3
        let last_uncond_display = |d: &Dom| {
3
            d.root
3
                .style
3
                .iter_inline_properties()
33
                .filter(|(p, conds)| {
33
                    conds.as_ref().is_empty() && p.get_type() == CssPropertyType::Display
33
                })
3
                .last()
3
                .map(|(p, _)| p.clone())
3
        };
1
        let groups = ch[2].children.as_ref()[1].children.as_ref();
1
        assert_eq!(groups.len(), 3);
1
        assert_ne!(
1
            last_uncond_display(&groups[0]),
1
            Some(P::const_display(LayoutDisplay::None)),
            "first group stays visible"
        );
2
        for g in &groups[1..] {
2
            assert_eq!(
2
                last_uncond_display(g),
2
                Some(P::const_display(LayoutDisplay::None)),
                "non-initial groups start hidden in the mobile chrome"
            );
        }
        // Every group-list entry carries the swap callback.
3
        for item in ch[2].children.as_ref()[0].children.as_ref() {
3
            assert_eq!(
3
                item.root.callbacks.as_ref().len(),
                1,
                "group-list entry has the swap callback"
            );
        }
1
    }
    #[test]
1
    fn dom_renders_app_button_tabs_and_filler_in_order() {
1
        let r = Ribbon::new(tabs(3))
1
            .with_app_button(RibbonAppButton::new(AzString::from("FILE")))
1
            .with_active_tab(1);
1
        let dom = r.dom();
1
        let (bar, _) = parts(&dom);
1
        let ch = bar.children.as_ref();
1
        assert_eq!(ch.len(), 5, "[app, t0, t1, t2, filler]");
1
        assert!(has_class(&ch[0], "__azul-native-ribbon-appbutton"));
        // The app button and the tabs are BOXES holding a label text child
        // (a raw text node is an inline box, whose border paints around the
        // text run instead of the padded tab).
1
        assert_eq!(label_text(&ch[0]), Some("FILE"));
4
        for i in 0..3 {
3
            assert_eq!(label_text(&ch[1 + i]), Some(format!("t{i}").as_str()));
3
            assert!(has_class(&ch[1 + i], "__azul-native-ribbon-tab"));
3
            assert_eq!(
3
                has_class(&ch[1 + i], "__azul-native-ribbon-tab-active"),
3
                i == 1,
                "only tab 1 is active"
            );
        }
1
        assert!(has_class(&ch[4], "__azul-native-ribbon-tab-filler"));
        // the active tab carries the active style, the others the plain style
1
        let s = RibbonStyle::office_2013();
1
        assert_eq!(inline_props(&ch[1]), style_props(&s.resolved_tab_style()));
1
        assert_eq!(
1
            inline_props(&ch[2]),
1
            style_props(&s.resolved_tab_active_style())
        );
1
    }
    #[test]
1
    fn dom_with_an_out_of_range_active_tab_highlights_nothing_and_renders_no_groups() {
1
        let mut r = Ribbon::new(tabs(3));
1
        r.active_tab = usize::MAX; // public field bypasses the clamp
1
        let dom = r.dom();
1
        let (bar, content) = parts(&dom);
3
        for tab in &bar.children.as_ref()[..3] {
3
            assert!(!has_class(tab, "__azul-native-ribbon-tab-active"));
        }
1
        assert!(content.children.as_ref().is_empty());
1
    }
    #[test]
1
    fn dom_without_a_callback_attaches_no_user_tab_handler() {
1
        let dom = Ribbon::new(tabs(4)).dom();
1
        let (bar, _) = parts(&dom);
5
        for tab in bar.children.as_ref() {
5
            assert!(
5
                !tab.root
5
                    .get_callbacks()
5
                    .as_ref()
5
                    .iter()
12
                    .any(|c| c.event == EventFilter::Hover(HoverEventFilter::Click)),
                "no user callback -> no MouseUp handler (chrome handlers may still be present)"
            );
        }
1
    }
    #[test]
1
    fn dom_gives_every_tab_a_mouseup_callback_with_its_own_index() {
1
        let dom = Ribbon::new(tabs(5))
1
            .with_on_tab_click(
1
                RefAny::new(IndexLog { seen: Vec::new() }),
1
                record_index as RibbonOnTabClickCallbackType,
            )
1
            .dom();
1
        let (bar, _) = parts(&dom);
5
        for (i, tab) in bar.children.as_ref()[..5].iter().enumerate() {
5
            let cbs = tab.root.get_callbacks();
            // Default behavior also attaches the collapse/peek chrome
            // handlers; the USER callback is the MouseUp one.
5
            let click = cbs
5
                .as_ref()
5
                .iter()
5
                .find(|c| c.event == EventFilter::Hover(HoverEventFilter::Click))
5
                .expect("every tab has a MouseUp user handler");
5
            let mut payload = click.refany.clone();
5
            let data = payload
5
                .downcast_ref::<TabClickData>()
5
                .expect("tab payload is a TabClickData");
5
            assert_eq!(data.tab_idx, i);
        }
        // the filler has no callback
1
        assert!(bar.children.as_ref()[5]
1
            .root
1
            .get_callbacks()
1
            .as_ref()
1
            .is_empty());
1
    }
    #[test]
1
    fn app_button_callback_is_attached_directly() {
        extern "C" fn noop(_: RefAny, _: CallbackInfo) -> Update {
            Update::DoNothing
        }
1
        let ab = RibbonAppButton::new(AzString::from("FILE")).with_on_click(
1
            RefAny::new(0u8),
1
            noop as super::super::button::ButtonOnClickCallbackType,
        );
1
        let dom = Ribbon::new(tabs(1)).with_app_button(ab).dom();
1
        let (bar, _) = parts(&dom);
1
        let cbs = bar.children.as_ref()[0].root.get_callbacks();
1
        assert_eq!(cbs.as_ref().len(), 1);
1
        assert_eq!(cbs.as_ref()[0].callback.cb, noop as usize);
1
    }
    // ------------------------------------------------------------------
    // Trampolines
    // ------------------------------------------------------------------
    #[test]
1
    fn tab_click_forwards_the_index_and_propagates_the_update() {
1
        let mut log = RefAny::new(IndexLog { seen: Vec::new() });
4
        for idx in [0usize, 7, usize::MAX] {
3
            let data = RefAny::new(TabClickData {
3
                tab_idx: idx,
3
                on_tab_click: Some(RibbonOnTabClick {
3
                    callback: (record_index as RibbonOnTabClickCallbackType).into(),
3
                    refany: log.clone(),
3
                })
3
                .into(),
3
            });
3
            let (update, changes) = run_trampoline(on_ribbon_tab_click, data);
3
            assert_eq!(update, Update::RefreshDom);
3
            assert!(changes.is_empty());
        }
1
        assert_eq!(log_indices(&mut log), vec![0, 7, usize::MAX]);
1
    }
    #[test]
1
    fn gallery_click_forwards_the_index_and_propagates_the_update() {
1
        let mut log = RefAny::new(IndexLog { seen: Vec::new() });
1
        let data = RefAny::new(GalleryCellClickData {
1
            cell_idx: 3,
1
            on_select: Some(RibbonGalleryOnSelect {
1
                callback: (record_index as RibbonGalleryOnSelectCallbackType).into(),
1
                refany: log.clone(),
1
            })
1
            .into(),
1
            // The auto-select branch needs live layout results; this test
1
            // drives the forwarding path only.
1
            auto_select: false,
1
            in_panel: false,
1
            selected_style: CssPropertyWithConditionsVec::from_const_slice(&[]),
1
            base_style: CssPropertyWithConditionsVec::from_const_slice(&[]),
1
        });
1
        let (update, changes) = run_trampoline(on_ribbon_gallery_cell_click, data);
1
        assert_eq!(update, Update::RefreshDom);
1
        assert!(changes.is_empty());
1
        assert_eq!(log_indices(&mut log), vec![3]);
1
    }
    #[test]
1
    fn trampolines_with_foreign_or_empty_payloads_are_noops() {
1
        let (update, changes) = run_trampoline(on_ribbon_tab_click, RefAny::new(0xdead_u64));
1
        assert_eq!(update, Update::DoNothing);
1
        assert!(changes.is_empty());
1
        let data = RefAny::new(GalleryCellClickData {
1
            cell_idx: 0,
1
            on_select: None.into(),
1
            auto_select: false,
1
            in_panel: false,
1
            selected_style: CssPropertyWithConditionsVec::from_const_slice(&[]),
1
            base_style: CssPropertyWithConditionsVec::from_const_slice(&[]),
1
        });
1
        let (update, _) = run_trampoline(on_ribbon_gallery_cell_click, data);
1
        assert_eq!(update, Update::DoNothing);
1
    }
    // ------------------------------------------------------------------
    // Groups
    // ------------------------------------------------------------------
    #[test]
1
    fn group_renders_items_over_a_footer_with_the_caption() {
1
        let tab = RibbonTab::new(AzString::from("HOME")).with_group(
1
            RibbonGroup::new(AzString::from("Clipboard"))
1
                .with_item(RibbonItem::SmallButton(small_btn("content_cut", "Cut"))),
        );
1
        let dom = Ribbon::new(RibbonTabVec::from_vec(vec![tab])).dom();
1
        let (_, content) = parts(&dom);
1
        assert_eq!(content.children.as_ref().len(), 1);
1
        assert!(has_class(
1
            &content.children.as_ref()[0],
1
            "__azul-native-ribbon-group"
        ));
1
        let (items, footer) = group_parts(content, 0);
1
        assert!(has_class(items, "__azul-native-ribbon-group-items"));
1
        assert_eq!(items.children.as_ref().len(), 1);
1
        assert!(has_class(footer, "__azul-native-ribbon-group-footer"));
        // no launcher: the footer is exactly [caption]
1
        assert_eq!(footer.children.as_ref().len(), 1);
1
        assert_eq!(text_of(&footer.children.as_ref()[0]), Some("Clipboard"));
1
    }
    #[test]
1
    fn group_with_launcher_renders_spacer_caption_launcher() {
        extern "C" fn noop(_: RefAny, _: CallbackInfo) -> Update {
            Update::DoNothing
        }
1
        let group = RibbonGroup::new(AzString::from("Font")).with_launcher(
1
            RefAny::new(0u8),
1
            noop as super::super::button::ButtonOnClickCallbackType,
        );
1
        let tab = RibbonTab::new(AzString::from("HOME")).with_group(group);
1
        let dom = Ribbon::new(RibbonTabVec::from_vec(vec![tab])).dom();
1
        let (_, content) = parts(&dom);
1
        let (_, footer) = group_parts(content, 0);
1
        let ch = footer.children.as_ref();
1
        assert_eq!(ch.len(), 3, "[spacer, caption, launcher]");
1
        assert!(has_class(&ch[0], "__azul-native-ribbon-footer-spacer"));
1
        assert_eq!(text_of(&ch[1]), Some("Font"));
        // the launcher is a real Button widget with the south_east icon
1
        assert!(matches!(ch[2].root.get_node_type(), NodeType::Button));
1
        assert_eq!(
1
            icon_name_of(&ch[2].children.as_ref()[0]),
            Some("south_east")
        );
1
        assert_eq!(ch[2].root.get_callbacks().as_ref().len(), 1);
1
    }
    // ------------------------------------------------------------------
    // Items
    // ------------------------------------------------------------------
    /// Renders one item into a throwaway single-group ribbon and returns the
    /// rendered item node.
14
    fn render_item(item: RibbonItem) -> Dom {
14
        let tab = RibbonTab::new(AzString::from("t"))
14
            .with_group(RibbonGroup::new(AzString::from("g")).with_item(item));
14
        let dom = Ribbon::new(RibbonTabVec::from_vec(vec![tab])).dom();
14
        let (_, content) = parts(&dom);
14
        let (items, _) = group_parts(content, 0);
14
        assert_eq!(items.children.as_ref().len(), 1);
14
        items.children.as_ref()[0].clone()
14
    }
    #[test]
1
    fn large_button_expands_to_a_button_widget_with_icon_label_and_arrow() {
1
        let rb = RibbonButton::new(AzString::from("content_paste"), AzString::from("Paste"))
1
            .with_arrow(RibbonArrow::Split);
1
        let node = render_item(RibbonItem::LargeButton(rb));
1
        assert!(matches!(node.root.get_node_type(), NodeType::Button));
1
        assert!(
1
            has_class(&node, "__azul-native-button"),
            "reuses the Button widget"
        );
1
        let ch = node.children.as_ref();
1
        assert_eq!(ch.len(), 3, "[icon, label, arrow]");
1
        assert_eq!(icon_name_of(&ch[0]), Some("content_paste"));
1
        assert_eq!(text_of(&ch[1]), Some("Paste"));
1
        assert_eq!(icon_name_of(&ch[2]), Some("arrow_drop_down"));
1
        let s = RibbonStyle::office_2013();
        // Verbatim, states included: the ribbon injects a complete part style
        // (its hover/pressed pairs now come from `flat::hover_bg_both` etc.),
        // and `Button::dom` appends nothing over an injected container style —
        // a caller who supplied one chose every property in it.
1
        assert_eq!(
1
            inline_props(&node),
1
            style_props(&s.resolved_large_button_style())
        );
1
        assert_eq!(
1
            inline_props(&ch[0]),
1
            style_props(&s.resolved_large_icon_style())
        );
1
        assert_eq!(
1
            inline_props(&ch[1]),
1
            style_props(&s.resolved_large_label_style())
        );
1
        assert_eq!(
1
            inline_props(&ch[2]),
1
            style_props(&s.resolved_arrow_icon_style())
        );
1
    }
    #[test]
1
    fn icon_only_small_button_skips_the_empty_label() {
1
        let node = render_item(RibbonItem::SmallButton(small_btn("format_bold", "")));
1
        let ch = node.children.as_ref();
1
        assert_eq!(ch.len(), 1, "icon only — no empty text node");
1
        assert_eq!(icon_name_of(&ch[0]), Some("format_bold"));
1
    }
    #[test]
1
    fn toggled_button_appends_the_checked_style_last() {
1
        let rb = small_btn("format_align_left", "").with_toggled(true);
1
        let node = render_item(RibbonItem::SmallButton(rb));
1
        let s = RibbonStyle::office_2013();
1
        let mut expected = style_props(&s.resolved_small_button_style());
1
        expected.extend(style_props(&s.resolved_checked_style()));
        // Verbatim: the injected style is the whole inline style (see
        // `large_button_expands_to_a_button_widget_with_icon_label_and_arrow`).
1
        assert_eq!(
1
            inline_props(&node),
            expected,
            "checked props must come last so they win (inline CSS is last-wins)"
        );
1
    }
    // ------------------------------------------------------------------
    // Interactive states (declared by the theme module, with dark twins)
    // ------------------------------------------------------------------
    /// Every hover / pressed / focus declaration in `decls` has a twin gated
    /// on `Theme(Dark)` for the same property — and there is at least one.
    ///
    /// The states moved OUT of this file into `themes::flat` (phase 2 of the
    /// widget theme migration), which is a move nothing else in this suite
    /// would notice: it compiles either way, and every other assertion here
    /// passes if the theme silently drops them or ships the light half alone.
5
    fn assert_every_state_rule_has_a_dark_twin<'a>(
5
        what: &str,
5
        decls: impl Iterator<Item = (&'a CssProperty, &'a DynamicSelectorVec)>,
5
    ) {
5
        let mut light: Vec<(CssPropertyType, PseudoStateType)> = Vec::new();
5
        let mut dark: Vec<(CssPropertyType, PseudoStateType)> = Vec::new();
169
        for (p, conds) in decls {
164
            let conds = conds.as_ref();
164
            let state = conds.iter().find_map(|c| match c {
                DynamicSelector::PseudoState(
34
                    s @ (PseudoStateType::Hover | PseudoStateType::Active | PseudoStateType::Focus),
34
                ) => Some(*s),
32
                _ => None,
66
            });
164
            let Some(state) = state else { continue };
34
            let is_dark = conds
34
                .iter()
34
                .any(|c| matches!(c, DynamicSelector::Theme(ThemeCondition::Dark)));
34
            if is_dark {
17
                dark.push((p.get_type(), state));
17
            } else {
17
                light.push((p.get_type(), state));
17
            }
        }
5
        assert!(
5
            !light.is_empty(),
            "{what}: carries no hover/pressed/focus rule at all — the theme forgot to append them"
        );
22
        for (ty, state) in &light {
17
            assert!(
17
                dark.contains(&(*ty, *state)),
                "{what}: `{ty:?}` on {state:?} has no dark twin, so its light-mode value is \
                 painted on a dark surface"
            );
        }
5
    }
    /// The first background fill on `node` gated on `state`, in the light or
    /// the dark half.
4
    fn state_fill(node: &Dom, state: PseudoStateType, want_dark: bool) -> CssProperty {
4
        node.root
4
            .style
4
            .iter_inline_properties()
92
            .find(|(p, conds)| {
92
                let conds = conds.as_ref();
92
                let gated_on_state = conds
92
                    .iter()
92
                    .any(|c| matches!(c, DynamicSelector::PseudoState(s) if *s == state));
92
                let is_dark = conds
92
                    .iter()
92
                    .any(|c| matches!(c, DynamicSelector::Theme(ThemeCondition::Dark)));
92
                matches!(p, CssProperty::BackgroundContent(_))
8
                    && gated_on_state
6
                    && is_dark == want_dark
92
            })
4
            .map(|(p, _)| p.clone())
4
            .unwrap_or_else(|| panic!("no {state:?} fill on the node (dark: {want_dark})"))
4
    }
    #[test]
1
    fn every_ribbon_state_rule_has_a_dark_twin_chosen_for_its_surface() {
        use azul_css::StringVec;
1
        let dom = Ribbon::new(tabs(2))
1
            .with_app_button(RibbonAppButton::new(AzString::from("FILE")))
1
            .dom();
1
        let (bar, _) = parts(&dom);
1
        let ch = bar.children.as_ref();
        // [app, t0 (active), t1, filler]
1
        let (app, tab) = (&ch[0], &ch[2]);
        // The application button is an ACCENT fill in either mode, so its
        // hover keeps the palette's `accent_hover` in dark mode too.
1
        assert_every_state_rule_has_a_dark_twin(
1
            "application button",
1
            app.root.style.iter_inline_properties(),
        );
1
        assert_eq!(
1
            state_fill(app, PseudoStateType::Hover, true),
1
            state_fill(app, PseudoStateType::Hover, false),
            "the application button does not go grey in dark mode, so neither may its hover"
        );
        // An inactive tab's text takes the accent on hover; the dark twin is
        // the theme's accent, not the palette's light-mode blue. (The HOVER
        // twin: the tab's resting text has a dark twin of its own now.)
1
        assert_every_state_rule_has_a_dark_twin("tab", tab.root.style.iter_inline_properties());
1
        let dark_hover_text = tab
1
            .root
1
            .style
1
            .iter_inline_properties()
22
            .find(|(p, conds)| {
22
                let conds = conds.as_ref();
22
                matches!(p, CssProperty::TextColor(_))
4
                    && conds
4
                        .iter()
4
                        .any(|c| matches!(c, DynamicSelector::Theme(ThemeCondition::Dark)))
2
                    && conds
2
                        .iter()
2
                        .any(|c| matches!(c, DynamicSelector::PseudoState(PseudoStateType::Hover)))
22
            })
1
            .map(|(p, _)| p.clone());
1
        assert_eq!(
            dark_hover_text,
1
            Some(P::const_text_color(StyleTextColor {
1
                inner: flat::DARK_ACC
1
            })),
            "a hovered tab's text is the accent, so its dark twin is the theme's accent"
        );
        // A small button (the chassis: hover fill, hover border, pressed fill)
        // and a gallery cell sit on the page-neutral chrome, so their dark
        // twins are the theme's tokens.
1
        let button = render_item(RibbonItem::SmallButton(small_btn("format_bold", "Bold")));
1
        assert_every_state_rule_has_a_dark_twin(
1
            "small button",
1
            button.root.style.iter_inline_properties(),
        );
1
        let wrapper = render_item(RibbonItem::Gallery(gallery(1)));
1
        let cell = &wrapper.children.as_ref()[0].children.as_ref()[0]
1
            .children
1
            .as_ref()[0];
1
        assert_every_state_rule_has_a_dark_twin(
1
            "gallery cell",
1
            cell.root.style.iter_inline_properties(),
        );
1
        assert_eq!(
1
            state_fill(cell, PseudoStateType::Hover, false),
1
            P::const_background_content(bg_vec(RibbonTheme::office_2013().hover_bg)),
            "the light half is the palette's own value, unchanged by the move"
        );
1
        assert_eq!(
1
            state_fill(cell, PseudoStateType::Hover, true),
1
            P::const_background_content(bg_vec(flat::DARK_HT)),
            "a cell sits on the neutral chrome, so its dark hover is the theme's hover face"
        );
        // The combo field's focus ring, from the style the ribbon injects.
1
        let combo = RibbonStyle::office_2013().styled_combo_box(
1
            StringVec::from_vec(vec![AzString::from("Calibri")]),
1
            AzString::from("Calibri"),
            120,
        );
1
        let field = combo
1
            .field_style
1
            .into_option()
1
            .expect("the ribbon injects a field style");
1
        assert_every_state_rule_has_a_dark_twin(
1
            "combo field",
39
            field.as_ref().iter().map(|c| (&c.property, &c.apply_if)),
        );
1
    }
    #[test]
1
    fn columns_and_rows_nest_items_recursively() {
1
        let column = RibbonColumn::new()
1
            .with_item(RibbonItem::SmallButton(small_btn("content_cut", "Cut")))
1
            .with_item(RibbonItem::Row(
1
                RibbonRow::new()
1
                    .with_item(RibbonItem::SmallButton(small_btn("format_bold", "")))
1
                    .with_item(RibbonItem::Separator),
1
            ));
1
        let node = render_item(RibbonItem::Column(column));
1
        assert!(has_class(&node, "__azul-native-ribbon-column"));
1
        let ch = node.children.as_ref();
1
        assert_eq!(ch.len(), 2);
1
        assert!(matches!(ch[0].root.get_node_type(), NodeType::Button));
1
        assert!(has_class(&ch[1], "__azul-native-ribbon-row"));
1
        let row_ch = ch[1].children.as_ref();
1
        assert_eq!(row_ch.len(), 2);
1
        assert!(has_class(&row_ch[1], "__azul-native-ribbon-separator"));
1
    }
    #[test]
1
    fn embedded_widgets_render_with_their_own_classes() {
        use azul_css::StringVec;
1
        let combo = ComboBox::new(StringVec::from_vec(vec![AzString::from("Calibri")]));
1
        let node = render_item(RibbonItem::Combo(combo));
1
        assert!(has_class(&node, "__azul-native-combobox"));
1
        let drop = DropDown::new(StringVec::from_vec(vec![AzString::from("11")]));
1
        let node = render_item(RibbonItem::Drop(drop));
1
        assert!(has_class(&node, "__azul-native-dropdown"));
1
        let check = CheckBox::create(true);
1
        let node = render_item(RibbonItem::Check(check));
1
        assert!(has_class(&node, "__azul-native-checkbox-container"));
1
    }
    #[test]
1
    fn custom_items_pass_through_verbatim() {
1
        let custom = Dom::create_text_do_not_use_without_block_level_wrapper("¶");
1
        let node = render_item(RibbonItem::Custom(custom.clone()));
1
        assert_eq!(node, custom);
1
    }
    // ------------------------------------------------------------------
    // Gallery
    // ------------------------------------------------------------------
8
    fn gallery(cells: usize) -> RibbonGallery {
8
        let v: Vec<RibbonGalleryCell> = (0..cells)
22
            .map(|i| {
22
                RibbonGalleryCell::new(
22
                    Dom::create_text_do_not_use_without_block_level_wrapper(format!("AaBbCc{i}")),
22
                    AzString::from(format!("Style {i}")),
                )
22
            })
8
            .collect();
8
        RibbonGallery::new(RibbonGalleryCellVec::from_vec(v))
8
    }
    #[test]
1
    fn gallery_renders_strip_cells_and_three_spinner_buttons() {
1
        let wrapper = render_item(RibbonItem::Gallery(gallery(4).with_selected(2)));
1
        assert!(has_class(&wrapper, "__azul-native-ribbon-gallery-wrapper"));
1
        let node = &wrapper.children.as_ref()[0];
1
        assert!(has_class(node, "__azul-native-ribbon-gallery"));
1
        let ch = node.children.as_ref();
1
        assert_eq!(ch.len(), 2, "[strip, spinner]");
1
        let (strip, spinner) = (&ch[0], &ch[1]);
1
        assert!(has_class(strip, "__azul-native-ribbon-gallery-strip"));
1
        let cells = strip.children.as_ref();
1
        assert_eq!(cells.len(), 4);
4
        for (i, cell) in cells.iter().enumerate() {
4
            assert!(has_class(cell, "__azul-native-ribbon-gallery-cell"));
4
            assert_eq!(
4
                has_class(cell, "__azul-native-ribbon-gallery-cell-selected"),
4
                i == 2,
                "only cell 2 is selected"
            );
            // [preview, label]
4
            let cc = cell.children.as_ref();
4
            assert_eq!(cc.len(), 2);
4
            assert_eq!(text_of(&cc[0]), Some(format!("AaBbCc{i}").as_str()));
4
            assert_eq!(text_of(&cc[1]), Some(format!("Style {i}").as_str()));
        }
        // selected cell style = base + selected extras appended
1
        let s = RibbonStyle::office_2013();
1
        let mut expected = style_props(&s.resolved_gallery_cell_style());
1
        expected.extend(style_props(&s.resolved_gallery_cell_selected_style()));
1
        assert_eq!(inline_props(&cells[2]), expected);
1
        assert!(has_class(spinner, "__azul-native-ribbon-gallery-spinner"));
1
        let buttons = spinner.children.as_ref();
1
        assert_eq!(buttons.len(), 3);
1
        let expected_icons = ["expand_less", "expand_more", "arrow_drop_down"];
3
        for (b, expected_icon) in buttons.iter().zip(expected_icons) {
3
            assert!(matches!(b.root.get_node_type(), NodeType::Button));
3
            assert_eq!(icon_name_of(&b.children.as_ref()[0]), Some(expected_icon));
        }
1
    }
    #[test]
1
    fn gallery_cells_carry_their_own_index_in_the_click_payload() {
1
        let g = gallery(2).with_on_select(
1
            RefAny::new(IndexLog { seen: Vec::new() }),
1
            record_index as RibbonGalleryOnSelectCallbackType,
        );
1
        let wrapper = render_item(RibbonItem::Gallery(g));
1
        let frame = &wrapper.children.as_ref()[0];
2
        for (i, cell) in frame.children.as_ref()[0]
1
            .children
1
            .as_ref()
1
            .iter()
1
            .enumerate()
        {
2
            let cbs = cell.root.get_callbacks();
2
            assert_eq!(cbs.as_ref().len(), 1);
2
            let mut payload = cbs.as_ref()[0].refany.clone();
2
            let data = payload
2
                .downcast_ref::<GalleryCellClickData>()
2
                .expect("cell payload is a GalleryCellClickData");
2
            assert_eq!(data.cell_idx, i);
        }
1
    }
    // ------------------------------------------------------------------
    // Style injection
    // ------------------------------------------------------------------
    #[test]
1
    fn replacing_a_part_style_restyles_the_expanded_buttons() {
1
        let injected = CssPropertyWithConditionsVec::from_vec(vec![Cond::simple(
1
            P::const_font_size(StyleFontSize::const_px(99)),
        )]);
1
        let tab = RibbonTab::new(AzString::from("t")).with_group(
1
            RibbonGroup::new(AzString::from("g"))
1
                .with_item(RibbonItem::SmallButton(small_btn("format_bold", ""))),
        );
1
        let mut r = Ribbon::new(RibbonTabVec::from_vec(vec![tab]));
1
        r.style.small_button_style = OptionCssPropertyWithConditionsVec::Some(injected.clone());
1
        let dom = r.dom();
1
        let (_, content) = parts(&dom);
1
        let (items, _) = group_parts(content, 0);
1
        assert_eq!(
1
            inline_props(&items.children.as_ref()[0]),
1
            style_props(&injected),
            "the injected style must reach the expanded Button verbatim"
        );
1
    }
    // ------------------------------------------------------------------
    // Whole-tree invariants
    // ------------------------------------------------------------------
    #[test]
1
    fn estimated_child_count_cache_stays_consistent_for_a_full_ribbon() {
1
        let tab = RibbonTab::new(AzString::from("HOME"))
1
            .with_group(
1
                RibbonGroup::new(AzString::from("Clipboard"))
1
                    .with_item(RibbonItem::LargeButton(
1
                        RibbonButton::new(AzString::from("content_paste"), AzString::from("Paste"))
1
                            .with_arrow(RibbonArrow::Split),
1
                    ))
1
                    .with_item(RibbonItem::Column(
1
                        RibbonColumn::new()
1
                            .with_item(RibbonItem::SmallButton(small_btn("content_cut", "Cut")))
1
                            .with_item(RibbonItem::SmallButton(small_btn("content_copy", "Copy"))),
1
                    )),
            )
1
            .with_group(
1
                RibbonGroup::new(AzString::from("Styles"))
1
                    .with_item(RibbonItem::Gallery(gallery(6))),
            );
1
        let dom = Ribbon::new(RibbonTabVec::from_vec(vec![tab]))
1
            .with_app_button(RibbonAppButton::new(AzString::from("FILE")))
1
            .dom();
1
        assert_eq!(
            dom.estimated_total_children,
1
            recursive_descendants(&dom),
            "cached descendant count desynced from the real tree"
        );
1
    }
    #[test]
1
    fn from_ribbon_for_dom_matches_dom() {
        // Only meaningful without callbacks: every `dom()` call mints fresh
        // per-tab RefAny payloads and two RefAnys never compare equal.
        // Inert: the default behaviors mint a fresh chrome `RefAny` per call
        // and two RefAnys never compare equal.
2
        let inert = || Ribbon::new(tabs(3)).with_behavior(RibbonBehavior::inert());
1
        assert_eq!(Dom::from(inert()), inert().dom());
1
    }
    #[test]
1
    fn styled_combo_box_injects_the_ribbon_field_look() {
        use azul_css::StringVec;
1
        let s = RibbonStyle::office_2013();
1
        let combo = s.styled_combo_box(
1
            StringVec::from_vec(vec![AzString::from("Calibri")]),
1
            AzString::from("Calibri (Body)"),
            133,
        );
1
        let default = ComboBox::create();
1
        assert_ne!(
            combo.wrapper_style, default.wrapper_style,
            "wrapper restyled"
        );
1
        assert_ne!(
1
            combo.resolved_field_style(),
1
            default.resolved_field_style(),
            "field restyled"
        );
1
        assert_eq!(combo.combo_state.inner.text.as_str(), "Calibri (Body)");
        // the width is the LAST wrapper property, so it wins over any base width
1
        let wrapper = combo.resolved_wrapper_style();
1
        let last = wrapper.as_ref().last().expect("wrapper style is non-empty");
1
        assert!(
1
            matches!(&last.property, CssProperty::Width(_)),
            "styled_combo_box must append the width last, got {:?}",
            last.property
        );
1
    }
    // ------------------------------------------------------------------
    // Theming
    // ------------------------------------------------------------------
    #[test]
1
    fn from_theme_recolors_the_accent_carrying_parts() {
1
        let neon = ColorU {
1
            r: 255,
1
            g: 0,
1
            b: 128,
1
            a: 255,
1
        };
1
        let mut theme = RibbonTheme::office_2013();
1
        theme.accent = neon;
1
        let s = RibbonStyle::from_theme(theme);
1
        assert_eq!(s.theme, theme, "the style bundle records its palette");
1
        assert_ne!(s, RibbonStyle::office_2013());
        // The app button's fill is the accent color.
1
        let app_bg = s
1
            .resolved_app_button_style()
1
            .as_ref()
1
            .iter()
11
            .find_map(|c| match &c.property {
1
                CssProperty::BackgroundContent(b) => b.get_property().cloned(),
10
                _ => None,
11
            })
1
            .expect("app button declares a background");
1
        assert_eq!(
1
            app_bg.as_ref(),
1
            &[StyleBackgroundContent::Color(neon)],
            "the app button fill must follow the theme accent"
        );
        // The active tab's text is the accent color.
1
        let active_text = s
1
            .resolved_tab_active_style()
1
            .as_ref()
1
            .iter()
12
            .find_map(|c| match &c.property {
1
                CssProperty::TextColor(t) => t.get_property().copied(),
11
                _ => None,
12
            })
1
            .expect("active tab declares a text color");
1
        assert_eq!(active_text.inner, neon);
1
    }
    #[test]
1
    fn office_2013_is_exactly_from_theme_of_the_office_2013_palette() {
1
        assert_eq!(
1
            RibbonStyle::office_2013(),
1
            RibbonStyle::from_theme(RibbonTheme::office_2013()),
            "one source of truth: the named preset is just from_theme"
        );
1
    }
    #[test]
1
    fn from_system_with_no_reported_colors_falls_back_to_office_2013() {
        // SystemStyle::default() may pre-fill platform colors; the fallback
        // contract is about a system that reports NO colors at all.
1
        let mut sys = SystemStyle::default();
1
        sys.colors = system::SystemColors::default();
1
        assert_eq!(
1
            RibbonTheme::from_system(sys.clone()),
1
            RibbonTheme::office_2013()
        );
1
        assert_eq!(RibbonStyle::from_system(sys), RibbonStyle::office_2013());
1
    }
    #[test]
1
    fn from_system_extracts_reported_colors_and_falls_back_for_the_rest() {
1
        let reported = ColorU {
1
            r: 9,
1
            g: 99,
1
            b: 199,
1
            a: 255,
1
        };
1
        let mut sys = SystemStyle::default();
1
        sys.colors.accent = Some(reported).into();
1
        let t = RibbonTheme::from_system(sys);
1
        assert_eq!(t.accent, reported, "reported accent must be extracted");
1
        assert_eq!(t.hover_border, reported, "hover border follows the accent");
1
        assert_eq!(
            t.text,
1
            RibbonTheme::office_2013().text,
            "unreported colors fall back to the the Office-2013-era look palette"
        );
1
    }
    // ------------------------------------------------------------------
    // Behaviors
    // ------------------------------------------------------------------
    #[test]
1
    fn default_behavior_is_office_2013_and_inert_disables_everything() {
1
        assert_eq!(RibbonBehavior::default(), RibbonBehavior::office_2013());
1
        let w = RibbonBehavior::office_2013();
1
        assert!(w.collapsible && w.peek_on_hover && w.auto_select_gallery && w.expandable_gallery);
1
        assert!(w.mobile_tab_overlay);
1
        let i = RibbonBehavior::inert();
1
        assert!(
1
            !i.collapsible && !i.peek_on_hover && !i.auto_select_gallery && !i.expandable_gallery
        );
1
        assert!(!i.mobile_tab_overlay);
1
        assert_eq!(Ribbon::new(tabs(1)).behavior, RibbonBehavior::office_2013());
1
    }
    #[test]
1
    fn collapsible_tabs_carry_double_click_and_peek_handlers() {
1
        let dom = Ribbon::new(tabs(3)).dom();
1
        let (bar, _) = parts(&dom);
3
        for tab in &bar.children.as_ref()[..3] {
3
            let events: Vec<EventFilter> = tab
3
                .root
3
                .get_callbacks()
3
                .as_ref()
3
                .iter()
3
                .map(|c| c.event)
3
                .collect();
3
            assert!(
3
                events.contains(&EventFilter::Hover(HoverEventFilter::DoubleClick)),
                "a collapsible ribbon must listen for DoubleClick, got {events:?}"
            );
3
            assert!(events.contains(&EventFilter::Hover(HoverEventFilter::MouseEnter)));
3
            assert!(events.contains(&EventFilter::Hover(HoverEventFilter::MouseLeave)));
        }
1
    }
    #[test]
1
    fn inert_behavior_attaches_no_chrome_handlers() {
1
        let dom = Ribbon::new(tabs(2))
1
            .with_behavior(RibbonBehavior::inert())
1
            .dom();
1
        let (bar, _) = parts(&dom);
2
        for tab in &bar.children.as_ref()[..2] {
2
            assert!(
2
                tab.root.get_callbacks().as_ref().is_empty(),
                "an inert ribbon with no user callback must attach nothing"
            );
        }
1
    }
    #[test]
1
    fn peek_can_be_disabled_while_collapse_stays_on() {
1
        let behavior = RibbonBehavior {
1
            peek_on_hover: false,
1
            ..RibbonBehavior::office_2013()
1
        };
1
        let dom = Ribbon::new(tabs(1)).with_behavior(behavior).dom();
1
        let (bar, _) = parts(&dom);
1
        let events: Vec<EventFilter> = bar.children.as_ref()[0]
1
            .root
1
            .get_callbacks()
1
            .as_ref()
1
            .iter()
1
            .map(|c| c.event)
1
            .collect();
1
        assert_eq!(
            events,
1
            vec![EventFilter::Hover(HoverEventFilter::DoubleClick)]
        );
1
    }
    #[test]
1
    fn expandable_gallery_wraps_the_frame_and_adds_a_hidden_panel() {
1
        let node = render_item(RibbonItem::Gallery(gallery(3)));
1
        assert!(has_class(&node, "__azul-native-ribbon-gallery-wrapper"));
1
        let ch = node.children.as_ref();
1
        assert_eq!(ch.len(), 2, "[frame, panel]");
1
        assert!(has_class(&ch[0], "__azul-native-ribbon-gallery"));
1
        assert!(has_class(&ch[1], "__azul-native-ribbon-gallery-panel"));
        // The panel holds EVERY cell and starts hidden.
1
        assert_eq!(ch[1].children.as_ref().len(), 3);
1
        let display = inline_props(&ch[1]).into_iter().find_map(|p| match p {
1
            CssProperty::Display(d) => d.get_property().copied(),
            _ => None,
1
        });
1
        assert_eq!(
            display,
            Some(LayoutDisplay::None),
            "the panel starts hidden"
        );
        // The third spinner button is the "More" toggle.
1
        let spinner = &ch[0].children.as_ref()[1];
1
        let more = &spinner.children.as_ref()[2];
1
        assert_eq!(more.root.get_callbacks().as_ref().len(), 1);
1
        assert_eq!(
1
            more.root.get_callbacks().as_ref()[0].event,
            EventFilter::Hover(HoverEventFilter::Click)
        );
1
    }
    #[test]
1
    fn non_expandable_gallery_is_the_bare_frame() {
1
        let tab = RibbonTab::new(AzString::from("t")).with_group(
1
            RibbonGroup::new(AzString::from("g")).with_item(RibbonItem::Gallery(gallery(2))),
        );
1
        let behavior = RibbonBehavior {
1
            expandable_gallery: false,
1
            ..RibbonBehavior::office_2013()
1
        };
1
        let dom = Ribbon::new(RibbonTabVec::from_vec(vec![tab]))
1
            .with_behavior(behavior)
1
            .dom();
1
        let (_, content) = parts(&dom);
1
        let (items, _) = group_parts(content, 0);
1
        let node = &items.children.as_ref()[0];
1
        assert!(has_class(node, "__azul-native-ribbon-gallery"));
1
        assert!(!has_class(node, "__azul-native-ribbon-gallery-wrapper"));
1
    }
    #[test]
1
    fn auto_select_attaches_cell_handlers_even_without_a_user_callback() {
        // The classic behavior moves the highlight on click regardless of the app; with
        // auto_select off and no user callback, nothing is attached.
1
        let node = render_item(RibbonItem::Gallery(gallery(2)));
1
        let strip = &node.children.as_ref()[0].children.as_ref()[0];
2
        for cell in strip.children.as_ref() {
2
            assert_eq!(cell.root.get_callbacks().as_ref().len(), 1);
        }
1
        let tab = RibbonTab::new(AzString::from("t")).with_group(
1
            RibbonGroup::new(AzString::from("g")).with_item(RibbonItem::Gallery(gallery(2))),
        );
1
        let dom = Ribbon::new(RibbonTabVec::from_vec(vec![tab]))
1
            .with_behavior(RibbonBehavior::inert())
1
            .dom();
1
        let (_, content) = parts(&dom);
1
        let (items, _) = group_parts(content, 0);
1
        let strip = &items.children.as_ref()[0].children.as_ref()[0];
2
        for cell in strip.children.as_ref() {
2
            assert!(cell.root.get_callbacks().as_ref().is_empty());
        }
1
    }
    // ------------------------------------------------------------------
    // Responsive / mobile
    // ------------------------------------------------------------------
    /// Both chromes are emitted once and the VIEWPORT decides which shows,
    /// so the mobile ribbon keeps the desktop semantics (same tabs, same
    /// groups) without a second widget tree.
    #[test]
1
    fn mobile_chrome_is_emitted_alongside_the_desktop_chrome() {
1
        let dom = Ribbon::new(tabs(3)).with_active_tab(1).dom();
1
        let ch = dom.children.as_ref();
5
        for class in [
            "__azul-native-ribbon-tabbar",
1
            "__azul-native-ribbon-mobile-tab",
1
            "__azul-native-ribbon-mobile-tab-overlay",
1
            "__azul-native-ribbon-mobile-group-list",
1
            "__azul-native-ribbon-content",
        ] {
5
            assert!(
15
                ch.iter().any(|c| has_class(c, class)),
                "the ribbon must emit a {class} child"
            );
        }
        // The mobile button shows the ACTIVE tab's label.
1
        let btn = ch
1
            .iter()
2
            .find(|c| has_class(c, "__azul-native-ribbon-mobile-tab"))
1
            .expect("mobile tab button");
1
        assert_eq!(label_text(btn), Some("t1"));
1
        assert_eq!(
1
            icon_name_of(&btn.children.as_ref()[1]),
            Some("expand_more"),
            "the mobile tab button carries the picker chevron"
        );
        // The overlay lists every tab.
1
        let overlay = ch
1
            .iter()
3
            .find(|c| has_class(c, "__azul-native-ribbon-mobile-tab-overlay"))
1
            .expect("tab overlay");
1
        assert_eq!(overlay.children.as_ref().len(), 3);
1
    }
    /// The breakpoint is expressed as a real viewport condition, and the
    /// conditional value comes LAST so it wins (inline CSS is last-match).
    #[test]
1
    fn the_desktop_tab_strip_is_hidden_under_the_mobile_breakpoint() {
1
        let s = RibbonStyle::office_2013();
1
        let tab_bar = s.resolved_tab_bar_style();
1
        let displays: Vec<(&LayoutDisplay, bool)> = tab_bar
1
            .as_ref()
1
            .iter()
8
            .filter_map(|c| match &c.property {
2
                CssProperty::Display(d) => d
2
                    .get_property()
2
                    .map(|d| (d, !c.apply_if.as_ref().is_empty())),
6
                _ => None,
8
            })
1
            .collect();
1
        assert_eq!(
1
            displays.len(),
            2,
            "the tab strip declares an unconditional and a mobile display"
        );
1
        assert_eq!(*displays[0].0, LayoutDisplay::Flex);
1
        assert!(!displays[0].1, "the desktop value is unconditional");
1
        assert_eq!(*displays[1].0, LayoutDisplay::None);
1
        assert!(
1
            displays[1].1,
            "the mobile value is conditional and comes last"
        );
        // ...and the mobile button is the mirror image.
1
        let mobile_tab = s.resolved_mobile_tab_button_style();
1
        let mobile: Vec<(&LayoutDisplay, bool)> = mobile_tab
1
            .as_ref()
1
            .iter()
22
            .filter_map(|c| match &c.property {
2
                CssProperty::Display(d) => d
2
                    .get_property()
2
                    .map(|d| (d, !c.apply_if.as_ref().is_empty())),
20
                _ => None,
22
            })
1
            .collect();
1
        assert_eq!(*mobile[0].0, LayoutDisplay::None);
1
        assert_eq!(*mobile[1].0, LayoutDisplay::Flex);
1
        assert!(mobile[1].1);
1
    }
    /// Handedness moves the mobile group list to the reachable side. It is
    /// independent of text direction, so it is its own system setting.
    #[test]
1
    fn handedness_flips_the_mobile_group_list_divider() {
1
        let right =
1
            RibbonStyle::from_theme_handed(RibbonTheme::office_2013(), Handedness::RightHanded);
1
        let left =
1
            RibbonStyle::from_theme_handed(RibbonTheme::office_2013(), Handedness::LeftHanded);
        // The bundle stores the HANDEDNESS now and derives the part from it, so
        // comparing the fields would compare two `None`s. Both facts are worth
        // pinning: the input differs, and so does what it resolves to.
1
        assert_ne!(right.handedness, left.handedness);
1
        assert_ne!(
1
            right.resolved_mobile_group_list_style(),
1
            left.resolved_mobile_group_list_style()
        );
2
        let has = |s: &CssPropertyWithConditionsVec, want_left: bool| {
24
            s.as_ref().iter().any(|c| {
24
                if want_left {
12
                    matches!(c.property, CssProperty::BorderLeftWidth(_))
                } else {
12
                    matches!(c.property, CssProperty::BorderRightWidth(_))
                }
24
            })
2
        };
1
        assert!(
1
            has(&right.resolved_mobile_group_list_style(), true),
            "a right-handed list sits at the right edge, so its divider is on its LEFT"
        );
1
        assert!(
1
            has(&left.resolved_mobile_group_list_style(), false),
            "a left-handed list sits at the left edge, so its divider is on its RIGHT"
        );
1
    }
    #[test]
1
    fn from_system_picks_up_the_system_handedness() {
1
        let mut sys = SystemStyle::default();
1
        sys.handedness = Handedness::LeftHanded;
1
        let from_sys = RibbonStyle::from_system(sys.clone());
1
        let expected =
1
            RibbonStyle::from_theme_handed(RibbonTheme::from_system(sys), Handedness::LeftHanded);
1
        assert_eq!(
            from_sys.mobile_group_list_style,
            expected.mobile_group_list_style
        );
1
    }
    #[test]
1
    fn inert_behavior_leaves_the_mobile_tab_button_without_a_toggle() {
1
        let dom = Ribbon::new(tabs(2))
1
            .with_behavior(RibbonBehavior::inert())
1
            .dom();
1
        let btn = dom
1
            .children
1
            .as_ref()
1
            .iter()
2
            .find(|c| has_class(c, "__azul-native-ribbon-mobile-tab"))
1
            .expect("mobile tab button");
1
        assert!(btn.root.get_callbacks().as_ref().is_empty());
1
    }
    #[test]
1
    fn styled_combo_box_follows_the_style_bundles_theme() {
1
        let neon = ColorU {
1
            r: 1,
1
            g: 2,
1
            b: 3,
1
            a: 255,
1
        };
1
        let mut theme = RibbonTheme::office_2013();
1
        theme.field_border = neon;
1
        let combo = RibbonStyle::from_theme(theme).styled_combo_box(
1
            StringVec::from_vec(vec![]),
1
            AzString::from("x"),
            50,
        );
1
        let border_color = combo
1
            .resolved_field_style()
1
            .as_ref()
1
            .iter()
24
            .find_map(|c| match &c.property {
1
                CssProperty::BorderTopColor(b) => b.get_property().copied(),
23
                _ => None,
24
            })
1
            .expect("combo field declares a border color");
1
        assert_eq!(
            border_color.inner, neon,
            "combo field border follows the theme"
        );
1
    }
    // ------------------------------------------------------------------
    // Resting colours, light and dark
    // ------------------------------------------------------------------
    //
    // The ribbon's resting surfaces are declared from `RibbonTheme`, whose
    // fields are LIGHT values; the dark twins come from `dark_counterpart`.
    // These pins say two things: the light look is byte-for-byte what it was
    // before the twins existed, and every twin is where last-match-wins can
    // see it.
    /// The colour a declaration carries, if it is a colour property. A
    /// gradient or image background is not a colour (none in the ribbon).
676
    fn colour_of(p: &CssProperty) -> Option<ColorU> {
676
        match p {
65
            CssProperty::BackgroundContent(b) => b
65
                .get_property()
65
                .and_then(|v| v.as_ref().first())
65
                .and_then(|c| match c {
65
                    StyleBackgroundContent::Color(c) => Some(*c),
                    _ => None,
65
                }),
43
            CssProperty::TextColor(t) => t.get_property().map(|t| t.inner),
29
            CssProperty::BorderTopColor(c) => c.get_property().map(|c| c.inner),
33
            CssProperty::BorderLeftColor(c) => c.get_property().map(|c| c.inner),
35
            CssProperty::BorderRightColor(c) => c.get_property().map(|c| c.inner),
47
            CssProperty::BorderBottomColor(c) => c.get_property().map(|c| c.inner),
424
            _ => None,
        }
676
    }
    /// `(type, colour)` of every unconditional colour declaration on `node`,
    /// in declaration order — the light look of the node.
4
    fn light_colours(node: &Dom) -> Vec<(CssPropertyType, ColorU)> {
4
        crate::widgets::theme_probe::unconditional(node)
4
            .iter()
64
            .filter_map(|p| colour_of(p).map(|c| (p.get_type(), c)))
4
            .collect()
4
    }
    #[test]
1
    fn the_light_look_of_the_chrome_is_unchanged_by_the_dark_twins() {
        use crate::widgets::theme_probe::unconditional;
1
        let dom = Ribbon::new(tabs(2))
1
            .with_app_button(RibbonAppButton::new(AzString::from("FILE")))
1
            .dom();
1
        let (bar, content) = parts(&dom);
        // The root: white chrome over a #D4D4D4 bottom rule, exactly as the
        // Office palette declares it.
1
        assert_eq!(
1
            unconditional(&dom),
1
            vec![
1
                P::const_display(LayoutDisplay::Flex),
1
                P::const_flex_direction(LayoutFlexDirection::Column),
1
                P::const_flex_grow(LayoutFlexGrow::const_new(0)),
1
                P::const_font_family(SYSTEM_UI_FAMILY),
1
                P::const_font_size(StyleFontSize::const_px(12)),
1
                P::const_background_content(bg_vec(WHITE)),
1
                P::const_border_bottom_width(LayoutBorderBottomWidth::const_px(1)),
1
                P::const_border_bottom_style(StyleBorderBottomStyle {
1
                    inner: BorderStyle::Solid,
1
                }),
1
                P::const_border_bottom_color(StyleBorderBottomColor { inner: W13_BORDER }),
            ],
            "root: the unconditional declarations are the light look, in order"
        );
1
        assert_eq!(
1
            unconditional(bar),
1
            vec![
1
                P::const_box_sizing(LayoutBoxSizing::BorderBox),
1
                P::const_display(LayoutDisplay::Flex),
1
                P::const_flex_direction(LayoutFlexDirection::Row),
1
                P::const_flex_grow(LayoutFlexGrow::const_new(0)),
1
                P::const_height(LayoutHeight::const_px(26)),
1
                P::const_background_content(bg_vec(WHITE)),
            ],
            "tab bar"
        );
1
        assert_eq!(
1
            unconditional(content),
1
            vec![
1
                P::const_box_sizing(LayoutBoxSizing::BorderBox),
1
                P::const_display(LayoutDisplay::Flex),
1
                P::const_flex_direction(LayoutFlexDirection::Row),
1
                P::const_flex_grow(LayoutFlexGrow::const_new(0)),
1
                P::const_flex_shrink(LayoutFlexShrink {
1
                    inner: FloatValue::const_new(0),
1
                }),
1
                P::const_height(LayoutHeight::const_px(92)),
1
                P::const_background_content(bg_vec(WHITE)),
            ],
            "content band"
        );
1
    }
    #[test]
1
    fn the_light_colours_of_the_tab_strip_are_unchanged_by_the_dark_twins() {
        use CssPropertyType as T;
1
        let dom = Ribbon::new(tabs(2))
1
            .with_app_button(RibbonAppButton::new(AzString::from("FILE")))
1
            .dom();
1
        let (bar, _) = parts(&dom);
1
        let ch = bar.children.as_ref();
        // [app, t0 (active), t1, filler]
1
        let (app, active, tab, filler) = (&ch[0], &ch[1], &ch[2], &ch[3]);
1
        assert_eq!(
1
            light_colours(app),
1
            vec![(T::BackgroundContent, W13_BLUE), (T::TextColor, WHITE)],
            "application button: accent fill, white label"
        );
1
        assert_eq!(
1
            light_colours(tab),
1
            vec![
1
                (T::TextColor, W13_TEXT),
1
                (T::BackgroundContent, WHITE),
1
                (T::BorderBottomColor, W13_BORDER),
            ],
            "inactive tab"
        );
1
        assert_eq!(
1
            light_colours(active),
1
            vec![
1
                (T::TextColor, W13_BLUE),
1
                (T::BackgroundContent, WHITE),
1
                (T::BorderTopColor, W13_BORDER),
1
                (T::BorderLeftColor, W13_BORDER),
1
                (T::BorderRightColor, W13_BORDER),
1
                (T::BorderBottomColor, W13_BORDER),
                // The underline erased: the bottom edge matches the content band.
1
                (T::BorderBottomColor, WHITE),
            ],
            "active tab"
        );
1
        assert_eq!(
1
            light_colours(filler),
1
            vec![(T::BorderBottomColor, W13_BORDER)],
            "tab filler"
        );
1
    }
    /// Every part builder, by name, over one palette (and the left-handed
    /// group list, which is the one part that takes a second input).
1
    fn every_builder(t: &RibbonTheme) -> Vec<(&'static str, CssPropertyWithConditionsVec)> {
1
        vec![
1
            ("container", theme_container(t)),
1
            ("tab_bar", theme_tab_bar(t)),
1
            ("app_button", theme_app_button(t)),
1
            ("tab", theme_tab(t)),
1
            ("tab_active", theme_tab_active(t)),
1
            ("tab_filler", theme_tab_filler(t)),
1
            ("content", theme_content(t)),
1
            ("group", theme_group(t)),
1
            ("group_label", theme_group_label(t)),
1
            ("launcher_button", theme_launcher_button(t)),
1
            ("launcher_icon", theme_launcher_icon(t)),
1
            ("separator", theme_separator(t)),
1
            ("large_button", theme_large_button(t)),
1
            ("large_icon", theme_large_icon(t)),
1
            ("large_label", theme_large_label(t)),
1
            ("small_button", theme_small_button(t)),
1
            ("small_icon", theme_small_icon(t)),
1
            ("small_label", theme_small_label(t)),
1
            ("arrow_icon", theme_arrow_icon(t)),
1
            ("checked", theme_checked(t)),
1
            ("gallery_frame", theme_gallery_frame(t)),
1
            ("gallery_cell", theme_gallery_cell(t)),
1
            ("gallery_cell_selected", theme_gallery_cell_selected(t)),
1
            ("gallery_cell_label", theme_gallery_cell_label(t)),
1
            ("gallery_spinner", theme_gallery_spinner(t)),
1
            ("gallery_panel", theme_gallery_panel(t)),
1
            ("gallery_spinner_button", theme_gallery_spinner_button(t)),
1
            ("gallery_spinner_icon", theme_gallery_spinner_icon(t)),
1
            (
1
                "combo_wrapper",
1
                CssPropertyWithConditionsVec::from_vec(theme_combo_wrapper_base(t)),
1
            ),
1
            ("combo_field", theme_combo_field(t)),
1
            ("combo_arrow", theme_combo_arrow(t)),
1
            ("mobile_tab_button", theme_mobile_tab_button(t)),
1
            ("mobile_tab_label", theme_mobile_tab_label(t)),
1
            ("mobile_tab_arrow", theme_mobile_tab_arrow(t)),
1
            ("mobile_tab_overlay", theme_mobile_tab_overlay(t)),
1
            ("mobile_tab_overlay_item", theme_mobile_tab_overlay_item(t)),
1
            (
1
                "mobile_group_list (right)",
1
                theme_mobile_group_list(t, false),
1
            ),
1
            ("mobile_group_list (left)", theme_mobile_group_list(t, true)),
1
            ("mobile_group_list_item", theme_mobile_group_list_item(t)),
1
            (
1
                "mobile_group_list_item_selected",
1
                theme_mobile_group_list_item_selected(t),
1
            ),
        ]
1
    }
212
    fn is_state_gated(conds: &DynamicSelectorVec) -> bool {
212
        conds
212
            .as_ref()
212
            .iter()
212
            .any(|c| matches!(c, DynamicSelector::PseudoState(_)))
212
    }
74
    fn is_dark_gated(conds: &DynamicSelectorVec) -> bool {
74
        conds
74
            .as_ref()
74
            .iter()
74
            .any(|c| matches!(c, DynamicSelector::Theme(ThemeCondition::Dark)))
74
    }
    /// Invariant I8 for the ribbon's RESTING colours: every opaque colour a
    /// builder declares unconditionally has a dark twin of the same property,
    /// declared AFTER it (last-match-wins), and no builder declares a resting
    /// dark twin for a property it does not declare in light. The one
    /// exception is the application button — an accent fill and the label on
    /// it are their own colour in both modes. States are the other test's
    /// business (`every_ribbon_state_rule_has_a_dark_twin_chosen_for_its_surface`).
    #[test]
1
    fn every_resting_colour_of_every_builder_has_a_dark_twin_after_it_and_nothing_else_does() {
        use std::collections::BTreeSet;
1
        let mut twins_seen = 0usize;
40
        for (name, part) in every_builder(&RibbonTheme::office_2013()) {
40
            let mut light: Vec<(CssPropertyType, usize)> = Vec::new();
40
            let mut dark: Vec<(CssPropertyType, usize)> = Vec::new();
605
            for (i, c) in part.as_ref().iter().enumerate() {
605
                let Some(colour) = colour_of(&c.property) else {
373
                    continue;
                };
                // Transparent fills/borders (a hover paints over them) have no
                // dark value to take; states have their own twins.
232
                if colour.a == 0 || is_state_gated(&c.apply_if) {
82
                    continue;
150
                }
150
                if c.apply_if.as_ref().is_empty() {
76
                    light.push((c.property.get_type(), i));
76
                } else if is_dark_gated(&c.apply_if) {
74
                    dark.push((c.property.get_type(), i));
74
                }
            }
40
            let own_colour = name == "app_button";
40
            let expect: BTreeSet<CssPropertyType> = if own_colour {
1
                BTreeSet::new()
            } else {
39
                light.iter().map(|(t, _)| *t).collect()
            };
40
            let got: BTreeSet<CssPropertyType> = dark.iter().map(|(t, _)| *t).collect();
40
            assert_eq!(
                got, expect,
                "{name}: the resting dark twins must cover exactly the resting light colours \
                 (light: {light:?}, dark: {dark:?})"
            );
114
            for (ty, dark_at) in &dark {
74
                let light_at = light
74
                    .iter()
171
                    .find(|(t, _)| t == ty)
74
                    .map(|(_, i)| *i)
74
                    .expect("covered by the set comparison above");
74
                assert!(
74
                    light_at < *dark_at,
                    "{name}: the dark twin of {ty:?} (#{dark_at}) precedes its light value \
                     (#{light_at}), so the light value wins in dark mode"
                );
            }
40
            twins_seen += dark.len();
        }
1
        assert!(
1
            twins_seen > 40,
            "only {twins_seen} resting twins: the walk found nothing"
        );
1
    }
    /// The dark half of the palette is the flat theme's tokens for every
    /// page-neutral field, and the light value for every own-colour field.
    #[test]
1
    fn the_dark_palette_is_the_flat_themes_tokens_and_keeps_the_accent() {
1
        let t = RibbonTheme::office_2013();
1
        let d = t.dark_counterpart();
1
        assert_eq!(d.chrome_bg, flat::DARK_SUR, "chrome");
1
        assert_eq!(d.content_bg, flat::DARK_SUR, "content band");
1
        assert_eq!(d.text, flat::DARK_INK, "control text");
1
        assert_eq!(d.label, flat::DARK_INK2, "captions and secondary glyphs");
1
        assert_eq!(d.icon, flat::DARK_ICON, "icon glyphs");
1
        assert_eq!(d.border, flat::DARK_BD, "chrome borders");
1
        assert_eq!(d.separator, flat::DARK_SEP, "separators");
1
        assert_eq!(d.hover_bg, flat::DARK_HT, "hover fill");
1
        assert_eq!(d.hover_border, flat::DARK_BD, "hover / toggled border");
1
        assert_eq!(d.pressed_bg, flat::DARK_PT, "pressed fill");
1
        assert_eq!(d.checked_bg, flat::DARK_PT, "toggled-on fill");
1
        assert_eq!(d.selected_bg, flat::DARK_HT, "selected cell fill");
1
        assert_eq!(d.field_border, flat::DARK_BD3, "field border");
        // Own colour: the accent, its hover and the label on it.
1
        assert_eq!(
1
            (d.accent, d.accent_hover, d.accent_text),
1
            (t.accent, t.accent_hover, t.accent_text),
            "an accent fill does not change with the mode"
        );
        // The resting hover/pressed tokens are the ones the state twins use,
        // so a hovered control and the surface under it come from one palette.
1
        assert_eq!(
1
            (d.hover_bg, d.hover_border, d.pressed_bg),
            (flat::DARK_HT, flat::DARK_BD, flat::DARK_PT)
        );
        // A palette that reports its own accent keeps it in the dark too.
1
        let mut sys = SystemStyle::default();
1
        sys.colors.accent = Some(ColorU {
1
            r: 9,
1
            g: 99,
1
            b: 199,
1
            a: 255,
1
        })
1
        .into();
1
        let os = RibbonTheme::from_system(sys);
1
        assert_eq!(os.dark_counterpart().accent, os.accent);
        // A transparent light value (see-through chrome over a window
        // gradient) stays transparent instead of becoming an opaque slab.
1
        let mut see_through = t;
1
        see_through.chrome_bg = TRANSPARENT;
1
        see_through.content_bg = TRANSPARENT;
1
        let d = see_through.dark_counterpart();
1
        assert_eq!(d.chrome_bg, TRANSPARENT);
1
        assert_eq!(d.content_bg, TRANSPARENT);
1
        assert_eq!(d.text, flat::DARK_INK, "the other fields still go dark");
1
    }
    /// The accent stays blue in dark mode: the application button keeps its
    /// fill and label untouched (no resting twin at all), and the active
    /// tab's label — the accent as TEXT on the neutral chrome — takes the
    /// flat theme's accent, the same blue its hover text already took.
    #[test]
1
    fn the_accent_keeps_its_blue_in_dark_mode() {
        use crate::widgets::theme_probe::dark;
1
        let dom = Ribbon::new(tabs(2))
1
            .with_app_button(RibbonAppButton::new(AzString::from("FILE")))
1
            .dom();
1
        let (bar, _) = parts(&dom);
1
        let ch = bar.children.as_ref();
        // [app, t0 (active), t1, filler]
1
        let (app, active) = (&ch[0], &ch[1]);
1
        let app_dark: Vec<CssProperty> = dark(app);
1
        assert_eq!(
1
            app_dark.iter().filter_map(colour_of).collect::<Vec<_>>(),
1
            vec![W13_BLUE_HOVER],
            "the application button's only dark declaration is its hover fill, and that is the \
             palette's own accent_hover: {app_dark:?}"
        );
1
        assert!(
1
            !app_dark
1
                .iter()
1
                .any(|p| matches!(p, CssProperty::TextColor(_))),
            "the white label on the accent fill has no dark twin"
        );
1
        let active_dark_text: Vec<ColorU> = dark(active)
1
            .iter()
7
            .filter(|p| matches!(p, CssProperty::TextColor(_)))
1
            .filter_map(colour_of)
1
            .collect();
1
        assert_eq!(
            active_dark_text,
1
            vec![flat::DARK_ACC],
            "the active tab's label takes the theme's accent in dark mode"
        );
        // (`DARK_ACC` is #3b82f6 — still a blue.)
1
        let active_dark_bg: Vec<ColorU> = dark(active)
1
            .iter()
7
            .filter(|p| matches!(p, CssProperty::BackgroundContent(_)))
1
            .filter_map(colour_of)
1
            .collect();
1
        assert_eq!(
            active_dark_bg,
1
            vec![flat::DARK_SUR],
            "and the chrome under it went dark"
        );
1
    }
    /// The chrome itself — root, tab bar, content band — goes dark with the
    /// window: this is the bar that stayed a white Office-2013 strip on a dark
    /// window before the resting surfaces had twins.
    #[test]
1
    fn the_chrome_goes_dark_with_the_window() {
        use crate::widgets::theme_probe::dark;
1
        let dom = Ribbon::new(tabs(2)).dom();
1
        let (bar, content) = parts(&dom);
3
        let colours = |node: &Dom| dark(node).iter().filter_map(colour_of).collect::<Vec<_>>();
1
        assert_eq!(
1
            colours(&dom),
1
            vec![flat::DARK_SUR, flat::DARK_BD],
            "root: dark chrome over a dark bottom rule"
        );
1
        assert_eq!(colours(bar), vec![flat::DARK_SUR], "tab bar");
1
        assert_eq!(colours(content), vec![flat::DARK_SUR], "content band");
        // And every one of those twins is a dark-mode-only declaration; the
        // light look is pinned separately
        // (`the_light_look_of_the_chrome_is_unchanged_by_the_dark_twins`).
3
        for node in [&dom, bar, content] {
4
            for p in dark(node) {
4
                assert!(
4
                    !crate::widgets::theme_probe::unconditional(node).contains(&p),
                    "a dark value leaked into the unconditional style: {p:?}"
                );
            }
        }
1
    }
}