1
//! Microsoft Office-style title band with a Quick Access Toolbar
2
//! (the Office-2013-era look look by default).
3
//!
4
//! Models the top chrome band of an Office document window:
5
//!
6
//! ```text
7
//! QuickAccessBar ─ leading slot            (app logo, any user Dom)
8
//!                ─ quick-access actions    QuickAccessAction (save / undo / redo)
9
//!                ─ customize arrow         ("▾" menu glyph, optional)
10
//!                ─ window title            (centered, "Document1 - AzWriter")
11
//!                ─ trailing actions        QuickAccessAction (help, ribbon options)
12
//!                ─ window buttons          minimize / maximize / close
13
//! ```
14
//!
15
//! Buttons are not re-implemented: every action and window button expands
16
//! to the existing [`super::button::Button`] widget with title-band part
17
//! styles injected through `Button`'s public style fields (the same
18
//! composition rule the ribbon uses). Icons resolve through the registered
19
//! icon provider (Material Icons by default): "save", "undo", "redo",
20
//! "help_outline", "minimize", "crop_square", "close".
21
//!
22
//! This widget draws WINDOW CHROME AS DOM - pair it with borderless window
23
//! decorations, or use [`super::titlebar::Titlebar`] when the OS should
24
//! draw its native caption instead. Window-button clicks are forwarded to
25
//! application callbacks; the band never calls `modify_window_state`
26
//! itself, so it stays inert in mockups and screenshot harnesses.
27
//!
28
//! All visual parts are exposed on [`QuickAccessStyle`] (defaults =
29
//! the Office-2013-era look look, [`QuickAccessStyle::office_2013`]); replace any field to
30
//! re-theme without touching widget code. There is no behavior struct: the
31
//! band has no self-driven chrome interactions.
32

            
33
use azul_core::{
34
    dom::{Dom, DomVec, IdOrClass, IdOrClass::Class, IdOrClassVec, OptionDom},
35
    refany::RefAny,
36
};
37
#[allow(clippy::wildcard_imports)]
38
// widget/render module pulls in the css property/value types it builds with
39
use azul_css::{
40
    dynamic_selector::{
41
        CssPropertyWithConditions as Cond, CssPropertyWithConditionsVec,
42
        OptionCssPropertyWithConditionsVec,
43
    },
44
    props::{
45
        basic::{
46
            color::ColorU,
47
            font::{StyleFontFamily, StyleFontFamilyVec},
48
            *,
49
        },
50
        layout::*,
51
        property::CssProperty as P,
52
        style::*,
53
    },
54
    *,
55
};
56
use azul_css::{
57
    impl_option, impl_vec, impl_vec_clone, impl_vec_debug, impl_vec_mut, system::SystemStyle,
58
};
59

            
60
use super::{
61
    button::{Button, OptionButtonOnClick},
62
    themes::flat,
63
    titlebar,
64
};
65

            
66
// -- Font --
67

            
68
const SYSTEM_UI_STR: AzString = AzString::from_const_str("system:ui");
69
const SYSTEM_UI_FAMILIES: &[StyleFontFamily] = &[StyleFontFamily::System(SYSTEM_UI_STR)];
70
const SYSTEM_UI_FAMILY: StyleFontFamilyVec =
71
    StyleFontFamilyVec::from_const_slice(SYSTEM_UI_FAMILIES);
72

            
73
// -- the Office-2013-era look palette (seeds QuickAccessTheme::office_2013) --
74

            
75
const WHITE: ColorU = ColorU {
76
    r: 255,
77
    g: 255,
78
    b: 255,
79
    a: 255,
80
};
81
const TRANSPARENT: ColorU = ColorU {
82
    r: 0,
83
    g: 0,
84
    b: 0,
85
    a: 0,
86
};
87
/// Title text gray (#5D5D5D).
88
const W13_TITLE_TEXT: ColorU = ColorU {
89
    r: 93,
90
    g: 93,
91
    b: 93,
92
    a: 255,
93
};
94
/// Action glyph gray (#6A6A6A).
95
const W13_ICON_GRAY: ColorU = ColorU {
96
    r: 106,
97
    g: 106,
98
    b: 106,
99
    a: 255,
100
};
101
/// Hover fill on band controls (#E5E5E5).
102
const W13_HOVER_BG: ColorU = ColorU {
103
    r: 229,
104
    g: 229,
105
    b: 229,
106
    a: 255,
107
};
108
/// Pressed fill (#CCCCCC).
109
const W13_PRESSED_BG: ColorU = ColorU {
110
    r: 204,
111
    g: 204,
112
    b: 204,
113
    a: 255,
114
};
115
/// Close button hover fill (#E81123, the Windows caption red).
116
const W13_CLOSE_HOVER: ColorU = ColorU {
117
    r: 232,
118
    g: 17,
119
    b: 35,
120
    a: 255,
121
};
122

            
123
// -- Metrics (the Office-2013-era look, logical px) --
124

            
125
/// Band height.
126
const BAR_HEIGHT: isize = 28;
127
/// Quick-access glyph size.
128
const QAT_ICON_PX: isize = 15;
129
/// Window-button glyph size.
130
const WIN_ICON_PX: isize = 14;
131
/// Width of one quick-access button.
132
const QAT_BUTTON_W: isize = 26;
133
/// Width of one window button (office-2013: wide flat caption buttons).
134
const WIN_BUTTON_W: isize = 34;
135
/// Title text size.
136
const TITLE_PX: isize = 12;
137

            
138
// -- Theme --
139

            
140
/// Color palette from which a full [`QuickAccessStyle`] is derived via
141
/// [`QuickAccessStyle::from_theme`]. All fields are plain colors, so themes
142
/// are trivially constructible over FFI. Preset:
143
/// [`QuickAccessTheme::office_2013`] (the default).
144
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
145
#[repr(C)]
146
pub struct QuickAccessTheme {
147
    /// Band fill (office-2013: white).
148
    pub bg: ColorU,
149
    /// Title text color.
150
    pub text: ColorU,
151
    /// Action and window-button glyph color.
152
    pub icon: ColorU,
153
    /// Hover fill on band controls.
154
    pub hover_bg: ColorU,
155
    /// Pressed fill on band controls.
156
    pub pressed_bg: ColorU,
157
    /// Close button hover fill (caption red).
158
    pub close_hover_bg: ColorU,
159
    /// Close button glyph color while hovered.
160
    pub close_hover_icon: ColorU,
161
}
162

            
163
impl QuickAccessTheme {
164
    /// The the Office-2013-era look palette: white band, gray glyphs, red close hover.
165
    #[must_use]
166
50
    pub const fn office_2013() -> Self {
167
50
        Self {
168
50
            bg: WHITE,
169
50
            text: W13_TITLE_TEXT,
170
50
            icon: W13_ICON_GRAY,
171
50
            hover_bg: W13_HOVER_BG,
172
50
            pressed_bg: W13_PRESSED_BG,
173
50
            close_hover_bg: W13_CLOSE_HOVER,
174
50
            close_hover_icon: WHITE,
175
50
        }
176
50
    }
177

            
178
    /// Extracts a band palette from the OS theme.
179
    ///
180
    /// The quick-access band IS the window's titlebar in an app that draws its
181
    /// own chrome, so it reads the OS TITLEBAR colours first
182
    /// (`SystemMetrics::titlebar`, which every desktop keeps separately from
183
    /// the window background and which is what the user compares against the
184
    /// native window next to it) and falls back to the general palette, then
185
    /// to this field's own Office-2013 value. Same discipline as
186
    /// [`super::ribbon::RibbonTheme::from_system`]: one system colour per
187
    /// field, no colour arithmetic, so the FFI-observable behaviour stays
188
    /// trivial to reason about.
189
    ///
190
    /// Takes the style by value (FFI constructor convention).
191
    #[must_use]
192
5
    pub fn from_system(style: SystemStyle) -> Self {
193
5
        let d = Self::office_2013();
194
5
        let c = &style.colors;
195
5
        let tb = &style.metrics.titlebar;
196
5
        let secondary = c.secondary_text.into_option();
197
5
        let title_text = tb
198
5
            .text_active
199
5
            .into_option()
200
5
            .or_else(|| c.text.into_option());
201
        Self {
202
5
            bg: tb
203
5
                .background_active
204
5
                .into_option()
205
5
                .or_else(|| c.window_background.into_option())
206
5
                .unwrap_or(d.bg),
207
5
            text: title_text.unwrap_or(d.text),
208
5
            icon: secondary.or(title_text).unwrap_or(d.icon),
209
5
            hover_bg: tb
210
5
                .button_hover_background
211
5
                .into_option()
212
5
                .or_else(|| c.selection_background_inactive.into_option())
213
5
                .unwrap_or(d.hover_bg),
214
5
            pressed_bg: c.selection_background.into_option().unwrap_or(d.pressed_bg),
215
            // The close button keeps its own colour on every platform (Breeze
216
            // and Windows both go red), which is why it is a separate metric
217
            // and never falls back to the ordinary hover fill.
218
5
            close_hover_bg: tb
219
5
                .close_button_hover_background
220
5
                .into_option()
221
5
                .unwrap_or(d.close_hover_bg),
222
5
            close_hover_icon: c.accent_text.into_option().unwrap_or(d.close_hover_icon),
223
        }
224
5
    }
225
}
226

            
227
impl Default for QuickAccessTheme {
228
    fn default() -> Self {
229
        Self::office_2013()
230
    }
231
}
232

            
233
// -- Theme -> property-list builders --
234

            
235
102
fn bg_vec(c: ColorU) -> StyleBackgroundContentVec {
236
102
    StyleBackgroundContentVec::from_vec(vec![StyleBackgroundContent::Color(c)])
237
102
}
238

            
239
102
fn cond_bg(c: ColorU) -> Cond {
240
102
    Cond::simple(P::const_background_content(bg_vec(c)))
241
102
}
242

            
243
204
const fn cond_text_color(c: ColorU) -> Cond {
244
204
    Cond::simple(P::const_text_color(StyleTextColor { inner: c }))
245
204
}
246

            
247
102
const fn cond_border_box() -> Cond {
248
102
    Cond::simple(P::const_box_sizing(LayoutBoxSizing::BorderBox))
249
102
}
250

            
251
136
fn push_row_center(v: &mut Vec<Cond>) {
252
136
    v.push(Cond::simple(P::const_display(LayoutDisplay::Flex)));
253
136
    v.push(Cond::simple(P::const_flex_direction(
254
136
        LayoutFlexDirection::Row,
255
    )));
256
136
    v.push(Cond::simple(P::const_align_items(LayoutAlignItems::Center)));
257
136
    v.push(Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(
258
        0,
259
    ))));
260
136
    v.push(Cond::simple(P::const_flex_shrink(LayoutFlexShrink {
261
136
        inner: FloatValue::const_new(0),
262
136
    })));
263
136
}
264

            
265
/// Flat, hover-highlighted button chassis shared by every band control.
266
/// The explicit TRANSPARENT border overrides the [`Button`] widget's
267
/// default frame (the classic office-suite band controls are frameless until hovered).
268
68
fn push_flat_button(v: &mut Vec<Cond>, t: &QuickAccessTheme) {
269
68
    v.push(cond_border_box());
270
68
    v.push(Cond::simple(P::const_cursor(StyleCursor::Default)));
271
68
    v.push(Cond::simple(P::user_select(StyleUserSelect::None)));
272
68
    v.push(cond_bg(TRANSPARENT));
273
68
    push_box_border(v, TRANSPARENT);
274
    // Hover and pressed, light AND dark, built by the theme module so the pair
275
    // cannot be split: the dark half needs a palette this file cannot see, and
276
    // a rule written here could only ever name the light colour — which is how
277
    // every band control kept its light grey highlight on a dark surface.
278
    //
279
    // The band is PAGE-NEUTRAL — white in the Office look, the desktop's
280
    // titlebar colour from `from_system` — so the dark twins are the theme's
281
    // own hover and pressed faces, `DARK_HT` / `DARK_PT`, exactly what
282
    // `flat::button_states` gives the neutral button. See
283
    // `themes::flat::hover_bg_both` for the rule.
284
68
    v.extend(flat::hover_bg_both(t.hover_bg, flat::DARK_HT));
285
68
    v.extend(flat::active_bg_both(t.pressed_bg, flat::DARK_PT));
286
68
}
287

            
288
/// 1px solid border on all four sides in the given color.
289
68
fn push_box_border(v: &mut Vec<Cond>, c: ColorU) {
290
68
    v.push(Cond::simple(P::const_border_top_width(
291
68
        LayoutBorderTopWidth::const_px(1),
292
    )));
293
68
    v.push(Cond::simple(P::const_border_left_width(
294
68
        LayoutBorderLeftWidth::const_px(1),
295
    )));
296
68
    v.push(Cond::simple(P::const_border_right_width(
297
68
        LayoutBorderRightWidth::const_px(1),
298
    )));
299
68
    v.push(Cond::simple(P::const_border_bottom_width(
300
68
        LayoutBorderBottomWidth::const_px(1),
301
    )));
302
68
    v.push(Cond::simple(P::const_border_top_style(
303
68
        StyleBorderTopStyle {
304
68
            inner: BorderStyle::Solid,
305
68
        },
306
    )));
307
68
    v.push(Cond::simple(P::const_border_left_style(
308
68
        StyleBorderLeftStyle {
309
68
            inner: BorderStyle::Solid,
310
68
        },
311
    )));
312
68
    v.push(Cond::simple(P::const_border_right_style(
313
68
        StyleBorderRightStyle {
314
68
            inner: BorderStyle::Solid,
315
68
        },
316
    )));
317
68
    v.push(Cond::simple(P::const_border_bottom_style(
318
68
        StyleBorderBottomStyle {
319
68
            inner: BorderStyle::Solid,
320
68
        },
321
    )));
322
68
    v.push(Cond::simple(P::const_border_top_color(
323
68
        StyleBorderTopColor { inner: c },
324
    )));
325
68
    v.push(Cond::simple(P::const_border_left_color(
326
68
        StyleBorderLeftColor { inner: c },
327
    )));
328
68
    v.push(Cond::simple(P::const_border_right_color(
329
68
        StyleBorderRightColor { inner: c },
330
    )));
331
68
    v.push(Cond::simple(P::const_border_bottom_color(
332
68
        StyleBorderBottomColor { inner: c },
333
    )));
334
68
}
335

            
336
34
fn theme_bar(t: &QuickAccessTheme) -> CssPropertyWithConditionsVec {
337
34
    let mut v = Vec::new();
338
34
    push_row_center(&mut v);
339
34
    v.push(cond_border_box());
340
34
    v.push(Cond::simple(P::const_height(LayoutHeight::const_px(
341
        BAR_HEIGHT,
342
    ))));
343
34
    v.push(Cond::simple(P::const_font_family(SYSTEM_UI_FAMILY)));
344
34
    v.push(Cond::simple(P::const_font_size(StyleFontSize::const_px(
345
        TITLE_PX,
346
    ))));
347
34
    v.push(cond_bg(t.bg));
348
34
    v.push(Cond::simple(P::const_padding_left(
349
34
        LayoutPaddingLeft::const_px(8),
350
    )));
351
34
    CssPropertyWithConditionsVec::from_vec(v)
352
34
}
353

            
354
34
fn theme_leading(_t: &QuickAccessTheme) -> CssPropertyWithConditionsVec {
355
34
    let mut v = Vec::new();
356
34
    push_row_center(&mut v);
357
34
    v.push(Cond::simple(P::const_margin_right(
358
34
        LayoutMarginRight::const_px(4),
359
    )));
360
34
    CssPropertyWithConditionsVec::from_vec(v)
361
34
}
362

            
363
34
fn theme_action_button(t: &QuickAccessTheme) -> CssPropertyWithConditionsVec {
364
34
    let mut v = Vec::new();
365
34
    push_row_center(&mut v);
366
34
    push_flat_button(&mut v, t);
367
34
    v.push(Cond::simple(P::const_justify_content(
368
34
        LayoutJustifyContent::Center,
369
    )));
370
34
    v.push(Cond::simple(P::const_width(LayoutWidth::const_px(
371
        QAT_BUTTON_W,
372
    ))));
373
34
    v.push(Cond::simple(P::const_height(LayoutHeight::const_px(
374
34
        BAR_HEIGHT - 4,
375
    ))));
376
34
    CssPropertyWithConditionsVec::from_vec(v)
377
34
}
378

            
379
4
fn theme_action_icon(t: &QuickAccessTheme) -> CssPropertyWithConditionsVec {
380
4
    CssPropertyWithConditionsVec::from_vec(vec![
381
4
        Cond::simple(P::const_font_size(StyleFontSize::const_px(QAT_ICON_PX))),
382
4
        cond_text_color(t.icon),
383
    ])
384
4
}
385

            
386
/// The small "customize quick access toolbar" chevron after the actions.
387
34
fn theme_menu_arrow(t: &QuickAccessTheme) -> CssPropertyWithConditionsVec {
388
34
    CssPropertyWithConditionsVec::from_vec(vec![
389
34
        Cond::simple(P::const_font_size(StyleFontSize::const_px(12))),
390
34
        cond_text_color(t.icon),
391
34
        Cond::simple(P::const_margin_left(LayoutMarginLeft::const_px(1))),
392
34
        Cond::simple(P::const_margin_right(LayoutMarginRight::const_px(4))),
393
    ])
394
34
}
395

            
396
34
fn theme_title(t: &QuickAccessTheme) -> CssPropertyWithConditionsVec {
397
34
    CssPropertyWithConditionsVec::from_vec(vec![
398
34
        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(1))),
399
34
        Cond::simple(P::const_text_align(StyleTextAlign::Center)),
400
34
        Cond::simple(P::const_font_size(StyleFontSize::const_px(TITLE_PX))),
401
34
        cond_text_color(t.text),
402
34
        Cond::simple(P::user_select(StyleUserSelect::None)),
403
    ])
404
34
}
405

            
406
34
fn theme_window_button(t: &QuickAccessTheme) -> CssPropertyWithConditionsVec {
407
34
    let mut v = Vec::new();
408
34
    push_row_center(&mut v);
409
34
    push_flat_button(&mut v, t);
410
34
    v.push(Cond::simple(P::const_justify_content(
411
34
        LayoutJustifyContent::Center,
412
    )));
413
34
    v.push(Cond::simple(P::const_width(LayoutWidth::const_px(
414
        WIN_BUTTON_W,
415
    ))));
416
34
    v.push(Cond::simple(P::const_height(LayoutHeight::const_px(
417
        BAR_HEIGHT,
418
    ))));
419
34
    CssPropertyWithConditionsVec::from_vec(v)
420
34
}
421

            
422
132
fn theme_window_icon(t: &QuickAccessTheme) -> CssPropertyWithConditionsVec {
423
132
    CssPropertyWithConditionsVec::from_vec(vec![
424
132
        Cond::simple(P::const_font_size(StyleFontSize::const_px(WIN_ICON_PX))),
425
132
        cond_text_color(t.icon),
426
    ])
427
132
}
428

            
429
/// APPENDED to the close button: the caption-red hover.
430
34
fn theme_close_button(t: &QuickAccessTheme) -> CssPropertyWithConditionsVec {
431
    // ROUND, because that is what the desktop draws. A close button's red is a
432
    // hover FILL behind a neutral glyph, and every current desktop draws that
433
    // fill as a circle - a full-height red rectangle in the corner of the
434
    // titlebar is the one detail that gives a hand-drawn titlebar away.
435
    // Half the bar height makes the fill as round as the button allows.
436
34
    let radius = PixelValue::px(BAR_HEIGHT as f32 / 2.0);
437
34
    let mut v: Vec<Cond> = Vec::new();
438
    // Hover, light AND dark, built by the theme module so the pair cannot be
439
    // split. The dark twin is the SAME colour, on purpose: the caption red is
440
    // the desktop's own colour for this one button and it stays red on a dark
441
    // desktop (Breeze and Windows alike), which is why it is a separate palette
442
    // field and never the ordinary hover fill. It is the one control on the
443
    // band whose hover is not page-neutral — see `themes::flat::hover_bg_both`
444
    // for the rule.
445
34
    v.extend(flat::hover_bg_both(t.close_hover_bg, t.close_hover_bg));
446
    // The round shape has no colour; its twin repeats the radius so that every
447
    // state rule on the band has a dark half.
448
34
    v.extend(flat::hover_radius_pair(radius));
449
34
    CssPropertyWithConditionsVec::from_vec(v)
450
34
}
451

            
452
// -- Style --
453

            
454
/// All part styles of the title band. Every part defaults to the the Office-2013-era look
455
/// look; replace any field for finer control (the same override API as
456
/// [`super::ribbon::RibbonStyle`]).
457
#[derive(Debug, Clone, PartialEq, Eq)]
458
#[repr(C)]
459
pub struct QuickAccessStyle {
460
    /// The palette this style bundle was derived from. Kept for consumers
461
    /// deriving matching custom parts.
462
    pub theme: QuickAccessTheme,
463
    /// The band itself (horizontal row).
464
    ///
465
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
466
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
467
    /// a real answer — "no properties at all" — which the pre-filled field could
468
    /// not express.
469
    pub bar_style: OptionCssPropertyWithConditionsVec,
470
    /// Wrapper around the leading slot.
471
    ///
472
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
473
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
474
    /// a real answer — "no properties at all" — which the pre-filled field could
475
    /// not express.
476
    pub leading_style: OptionCssPropertyWithConditionsVec,
477
    /// Container style injected into one quick-access [`Button`].
478
    ///
479
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
480
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
481
    /// a real answer — "no properties at all" — which the pre-filled field could
482
    /// not express.
483
    pub action_button_style: OptionCssPropertyWithConditionsVec,
484
    /// Icon style injected into the quick-access [`Button`]s.
485
    ///
486
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
487
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
488
    /// a real answer — "no properties at all" — which the pre-filled field could
489
    /// not express.
490
    pub action_icon_style: OptionCssPropertyWithConditionsVec,
491
    /// The customize chevron after the quick-access actions.
492
    ///
493
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
494
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
495
    /// a real answer — "no properties at all" — which the pre-filled field could
496
    /// not express.
497
    pub menu_arrow_style: OptionCssPropertyWithConditionsVec,
498
    /// The centered window title.
499
    ///
500
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
501
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
502
    /// a real answer — "no properties at all" — which the pre-filled field could
503
    /// not express.
504
    pub title_style: OptionCssPropertyWithConditionsVec,
505
    /// Container style injected into the window [`Button`]s.
506
    ///
507
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
508
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
509
    /// a real answer — "no properties at all" — which the pre-filled field could
510
    /// not express.
511
    pub window_button_style: OptionCssPropertyWithConditionsVec,
512
    /// Icon style injected into the window [`Button`]s.
513
    ///
514
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
515
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
516
    /// a real answer — "no properties at all" — which the pre-filled field could
517
    /// not express.
518
    pub window_icon_style: OptionCssPropertyWithConditionsVec,
519
    /// APPENDED to the close [`Button`] (caption-red hover).
520
    ///
521
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
522
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
523
    /// a real answer — "no properties at all" — which the pre-filled field could
524
    /// not express.
525
    pub close_button_style: OptionCssPropertyWithConditionsVec,
526
}
527

            
528
impl QuickAccessStyle {
529
    /// The the Office-2013-era look look (white band, gray glyphs) - the default.
530
    #[must_use]
531
43
    pub const fn office_2013() -> Self {
532
43
        Self::from_theme(QuickAccessTheme::office_2013())
533
43
    }
534

            
535
    /// Every part style, derived from the OS theme - see
536
    /// [`QuickAccessTheme::from_system`]. Takes the style by value (FFI
537
    /// constructor convention).
538
    #[must_use]
539
1
    pub fn from_system(style: SystemStyle) -> Self {
540
1
        Self::from_theme(QuickAccessTheme::from_system(style))
541
1
    }
542

            
543
    /// Derives every part style from the given palette.
544
    #[must_use]
545
44
    pub const fn from_theme(theme: QuickAccessTheme) -> Self {
546
44
        Self {
547
44
            theme,
548
44
            bar_style: OptionCssPropertyWithConditionsVec::None,
549
44
            leading_style: OptionCssPropertyWithConditionsVec::None,
550
44
            action_button_style: OptionCssPropertyWithConditionsVec::None,
551
44
            action_icon_style: OptionCssPropertyWithConditionsVec::None,
552
44
            menu_arrow_style: OptionCssPropertyWithConditionsVec::None,
553
44
            title_style: OptionCssPropertyWithConditionsVec::None,
554
44
            window_button_style: OptionCssPropertyWithConditionsVec::None,
555
44
            window_icon_style: OptionCssPropertyWithConditionsVec::None,
556
44
            close_button_style: OptionCssPropertyWithConditionsVec::None,
557
44
        }
558
44
    }
559

            
560
    /// The `bar_style` this bundle renders with: the caller's override if there is
561
    /// one, else derived from [`Self::theme`].
562
    #[must_use]
563
34
    pub fn resolved_bar_style(&self) -> CssPropertyWithConditionsVec {
564
34
        self.bar_style
565
34
            .clone()
566
34
            .into_option()
567
34
            .unwrap_or_else(|| theme_bar(&self.theme))
568
34
    }
569

            
570
    /// The `leading_style` this bundle renders with: the caller's override if there is
571
    /// one, else derived from [`Self::theme`].
572
    #[must_use]
573
34
    pub fn resolved_leading_style(&self) -> CssPropertyWithConditionsVec {
574
34
        self.leading_style
575
34
            .clone()
576
34
            .into_option()
577
34
            .unwrap_or_else(|| theme_leading(&self.theme))
578
34
    }
579

            
580
    /// The `action_button_style` this bundle renders with: the caller's override if there is
581
    /// one, else derived from [`Self::theme`].
582
    #[must_use]
583
34
    pub fn resolved_action_button_style(&self) -> CssPropertyWithConditionsVec {
584
34
        self.action_button_style
585
34
            .clone()
586
34
            .into_option()
587
34
            .unwrap_or_else(|| theme_action_button(&self.theme))
588
34
    }
589

            
590
    /// The `action_icon_style` this bundle renders with: the caller's override if there is
591
    /// one, else derived from [`Self::theme`].
592
    #[must_use]
593
4
    pub fn resolved_action_icon_style(&self) -> CssPropertyWithConditionsVec {
594
4
        self.action_icon_style
595
4
            .clone()
596
4
            .into_option()
597
4
            .unwrap_or_else(|| theme_action_icon(&self.theme))
598
4
    }
599

            
600
    /// The `menu_arrow_style` this bundle renders with: the caller's override if there is
601
    /// one, else derived from [`Self::theme`].
602
    #[must_use]
603
34
    pub fn resolved_menu_arrow_style(&self) -> CssPropertyWithConditionsVec {
604
34
        self.menu_arrow_style
605
34
            .clone()
606
34
            .into_option()
607
34
            .unwrap_or_else(|| theme_menu_arrow(&self.theme))
608
34
    }
609

            
610
    /// The `title_style` this bundle renders with: the caller's override if there is
611
    /// one, else derived from [`Self::theme`].
612
    #[must_use]
613
34
    pub fn resolved_title_style(&self) -> CssPropertyWithConditionsVec {
614
34
        self.title_style
615
34
            .clone()
616
34
            .into_option()
617
34
            .unwrap_or_else(|| theme_title(&self.theme))
618
34
    }
619

            
620
    /// The `window_button_style` this bundle renders with: the caller's override if there is
621
    /// one, else derived from [`Self::theme`].
622
    #[must_use]
623
34
    pub fn resolved_window_button_style(&self) -> CssPropertyWithConditionsVec {
624
34
        self.window_button_style
625
34
            .clone()
626
34
            .into_option()
627
34
            .unwrap_or_else(|| theme_window_button(&self.theme))
628
34
    }
629

            
630
    /// The `window_icon_style` this bundle renders with: the caller's override if there is
631
    /// one, else derived from [`Self::theme`].
632
    #[must_use]
633
132
    pub fn resolved_window_icon_style(&self) -> CssPropertyWithConditionsVec {
634
132
        self.window_icon_style
635
132
            .clone()
636
132
            .into_option()
637
132
            .unwrap_or_else(|| theme_window_icon(&self.theme))
638
132
    }
639

            
640
    /// The `close_button_style` this bundle renders with: the caller's override if there is
641
    /// one, else derived from [`Self::theme`].
642
    #[must_use]
643
34
    pub fn resolved_close_button_style(&self) -> CssPropertyWithConditionsVec {
644
34
        self.close_button_style
645
34
            .clone()
646
34
            .into_option()
647
34
            .unwrap_or_else(|| theme_close_button(&self.theme))
648
34
    }
649
}
650

            
651
impl Default for QuickAccessStyle {
652
1
    fn default() -> Self {
653
1
        Self::office_2013()
654
1
    }
655
}
656

            
657
// -- Data model --
658

            
659
/// One icon action on the band (quick-access or trailing).
660
#[derive(Debug, Clone)]
661
#[repr(C)]
662
pub struct QuickAccessAction {
663
    /// Icon name, resolved through the registered icon provider.
664
    pub icon: AzString,
665
    /// Optional click handler; without one the action is inert.
666
    pub on_click: OptionButtonOnClick,
667
}
668

            
669
impl QuickAccessAction {
670
    /// Creates an inert action with the given icon name.
671
    #[must_use]
672
12
    pub fn new(icon: AzString) -> Self {
673
12
        Self {
674
12
            icon,
675
12
            on_click: None.into(),
676
12
        }
677
12
    }
678

            
679
    /// Sets the click callback.
680
    pub fn set_on_click<C: Into<super::button::ButtonOnClickCallback>>(
681
        &mut self,
682
        data: RefAny,
683
        on_click: C,
684
    ) {
685
        self.on_click = Some(super::button::ButtonOnClick {
686
            refany: data,
687
            callback: on_click.into(),
688
        })
689
        .into();
690
    }
691

            
692
    /// Builder method: sets the click callback and returns `self`.
693
    #[must_use]
694
    pub fn with_on_click<C: Into<super::button::ButtonOnClickCallback>>(
695
        mut self,
696
        data: RefAny,
697
        on_click: C,
698
    ) -> Self {
699
        self.set_on_click(data, on_click);
700
        self
701
    }
702
}
703

            
704
impl_option!(
705
    QuickAccessAction,
706
    OptionQuickAccessAction,
707
    copy = false,
708
    [Debug, Clone]
709
);
710
impl_vec!(
711
    QuickAccessAction,
712
    QuickAccessActionVec,
713
    QuickAccessActionVecDestructor,
714
    QuickAccessActionVecDestructorType,
715
    QuickAccessActionVecSlice,
716
    OptionQuickAccessAction
717
);
718
impl_vec_clone!(
719
    QuickAccessAction,
720
    QuickAccessActionVec,
721
    QuickAccessActionVecDestructor
722
);
723
impl_vec_debug!(QuickAccessAction, QuickAccessActionVec);
724
impl_vec_mut!(QuickAccessAction, QuickAccessActionVec);
725

            
726
/// Top-level title band: leading slot, quick-access actions, customize
727
/// arrow, centered title, trailing actions and the window buttons.
728
#[derive(Debug, Clone)]
729
#[repr(C)]
730
pub struct QuickAccessBar {
731
    /// All part styles (defaults to the the Office-2013-era look look).
732
    pub style: QuickAccessStyle,
733

            
734
    /// Optional leading content (office-2013: the app logo square).
735
    pub leading: OptionDom,
736

            
737
    /// Optional minimize handler.
738
    pub on_minimize: OptionButtonOnClick,
739

            
740
    /// Optional maximize/restore handler.
741
    pub on_maximize: OptionButtonOnClick,
742

            
743
    /// Optional close handler.
744
    pub on_close: OptionButtonOnClick,
745

            
746
    /// The centered window title ("Document1 - `AzWriter`").
747
    pub title: AzString,
748

            
749
    /// Quick-access actions (office-2013: save / undo / redo).
750
    pub actions: QuickAccessActionVec,
751

            
752
    /// Actions between the title and the window buttons (office-2013: help,
753
    /// ribbon display options).
754
    pub trailing_actions: QuickAccessActionVec,
755

            
756
    /// Renders the "customize quick access toolbar" chevron.
757
    pub show_menu_arrow: bool,
758

            
759
    /// Renders the minimize window button.
760
    pub show_minimize: bool,
761

            
762
    /// Renders the maximize/restore window button.
763
    pub show_maximize: bool,
764

            
765
    /// Renders the close window button.
766
    pub show_close: bool,
767

            
768
    /// Safe-area inset above the band, in logical px.
769
    ///
770
    /// On a phone the status bar (or a notch) occupies the top of the window,
771
    /// and a band drawn at y=0 renders UNDER the clock. Padding alone cannot
772
    /// fix that: the band root carries a FIXED `height: BAR_HEIGHT`, so
773
    /// `padding-top` squashes 28px of content into what is left rather than
774
    /// moving it down. That was measured - a padding-only attempt left first
775
    /// content on the same pixel row.
776
    ///
777
    /// So the inset ADDS to the band height and pads by the same amount: the
778
    /// content box stays exactly `BAR_HEIGHT` tall and the band grows upward
779
    /// into the status bar, which is also what makes the band's own background
780
    /// colour fill the notch area instead of leaving a gap.
781
    ///
782
    /// Feed it from `CallbackInfo::get_safe_area_insets().top`, via
783
    /// `PixelValue::to_pixels_absolute()`. `0.0` (the default) is exactly the
784
    /// old behaviour, so desktop callers need change nothing.
785
    pub top_inset: f32,
786
}
787

            
788
// -- CSS classes --
789

            
790
static CLS_QAB: &[IdOrClass] = &[Class(AzString::from_const_str(
791
    "__azul-native-quick-access",
792
))];
793
static CLS_LEADING: &[IdOrClass] = &[Class(AzString::from_const_str(
794
    "__azul-native-quick-access-leading",
795
))];
796
static CLS_TITLE: &[IdOrClass] = &[Class(AzString::from_const_str(
797
    "__azul-native-quick-access-title",
798
))];
799

            
800
// -- Constructors / builders --
801

            
802
impl QuickAccessBar {
803
    /// Creates a band with the given title, no actions and all three
804
    /// window buttons, in the the Office-2013-era look style.
805
    #[must_use]
806
39
    pub fn new(title: AzString) -> Self {
807
39
        Self {
808
39
            leading: None.into(),
809
39
            actions: QuickAccessActionVec::from_vec(Vec::new()),
810
39
            show_menu_arrow: false,
811
39
            title,
812
39
            trailing_actions: QuickAccessActionVec::from_vec(Vec::new()),
813
39
            show_minimize: true,
814
39
            show_maximize: true,
815
39
            show_close: true,
816
39
            on_minimize: None.into(),
817
39
            on_maximize: None.into(),
818
39
            on_close: None.into(),
819
39
            style: QuickAccessStyle::office_2013(),
820
39
            top_inset: 0.0,
821
39
        }
822
39
    }
823

            
824
    /// Sets the safe-area inset above the band - see [`Self::top_inset`].
825
    #[must_use]
826
2
    pub const fn with_top_inset(mut self, top_inset: f32) -> Self {
827
2
        self.top_inset = top_inset;
828
2
        self
829
2
    }
830

            
831
    /// The the Office-2013-era look band: save / undo / redo quick-access actions (inert
832
    /// until callbacks are set), the customize chevron, and help before the
833
    /// window buttons.
834
    #[must_use]
835
3
    pub fn office_2013(title: AzString) -> Self {
836
3
        let mut band = Self::new(title);
837
3
        band.actions = QuickAccessActionVec::from_vec(vec![
838
3
            QuickAccessAction::new(AzString::from_const_str("save")),
839
3
            QuickAccessAction::new(AzString::from_const_str("undo")),
840
3
            QuickAccessAction::new(AzString::from_const_str("redo")),
841
        ]);
842
3
        band.show_menu_arrow = true;
843
3
        band.trailing_actions = QuickAccessActionVec::from_vec(vec![QuickAccessAction::new(
844
3
            AzString::from_const_str("help_outline"),
845
        )]);
846
3
        band
847
3
    }
848

            
849
    /// Builder method: sets the leading content.
850
    #[must_use]
851
1
    pub fn with_leading(mut self, leading: Dom) -> Self {
852
1
        self.leading = Some(leading).into();
853
1
        self
854
1
    }
855

            
856
    /// Builder method: replaces the quick-access actions.
857
    #[must_use]
858
    pub fn with_actions(mut self, actions: QuickAccessActionVec) -> Self {
859
        self.actions = actions;
860
        self
861
    }
862

            
863
    /// Builder method: replaces the trailing actions.
864
    #[must_use]
865
    pub fn with_trailing_actions(mut self, trailing_actions: QuickAccessActionVec) -> Self {
866
        self.trailing_actions = trailing_actions;
867
        self
868
    }
869

            
870
    /// Builder method: replaces the style bundle.
871
    #[must_use]
872
    pub fn with_style(mut self, style: QuickAccessStyle) -> Self {
873
        self.style = style;
874
        self
875
    }
876

            
877
    /// Renders the band.
878
    #[must_use]
879
34
    pub fn dom(self) -> Dom {
880
        let Self {
881
34
            leading,
882
34
            actions,
883
34
            show_menu_arrow,
884
34
            title,
885
34
            trailing_actions,
886
34
            show_minimize,
887
34
            show_maximize,
888
34
            show_close,
889
34
            on_minimize,
890
34
            on_maximize,
891
34
            on_close,
892
34
            style,
893
34
            top_inset,
894
34
        } = self;
895

            
896
        // Every part resolved up front: the resolvers borrow `&style`, and
897
        // `bar_style` is moved out of it at the end of this function.
898
34
        let part_bar = style.resolved_bar_style();
899
34
        let part_leading = style.resolved_leading_style();
900
34
        let part_action_button = style.resolved_action_button_style();
901
34
        let part_menu_arrow = style.resolved_menu_arrow_style();
902
34
        let part_title = style.resolved_title_style();
903
34
        let part_window_button = style.resolved_window_button_style();
904
34
        let part_close_button = style.resolved_close_button_style();
905

            
906
34
        let mut children: Vec<Dom> = Vec::with_capacity(actions.len() + 8);
907

            
908
34
        if let Some(lead) = leading.into_option() {
909
1
            children.push(
910
1
                Dom::create_div()
911
1
                    .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_LEADING))
912
1
                    .with_css_props(part_leading)
913
1
                    .with_children(DomVec::from_vec(vec![lead])),
914
1
            );
915
33
        }
916

            
917
34
        for action in actions.into_library_owned_vec() {
918
3
            children.push(action_button(action, &part_action_button, &style));
919
3
        }
920

            
921
34
        if show_menu_arrow {
922
1
            children.push(
923
1
                Dom::create_icon(AzString::from_const_str("arrow_drop_down"))
924
1
                    .with_css_props(part_menu_arrow),
925
1
            );
926
33
        }
927

            
928
34
        children.push(
929
34
            crate::widgets::widget_p_with_text(title)
930
34
                .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_TITLE))
931
34
                .with_css_props(part_title),
932
        );
933

            
934
34
        for action in trailing_actions.into_library_owned_vec() {
935
1
            children.push(action_button(action, &part_window_button, &style));
936
1
        }
937

            
938
        // The window controls come from the DESKTOP's icon theme first
939
        // (`system:` = the pack the shell fills from the user's icon theme -
940
        // Breeze, Adwaita, whatever is installed), with the bundled Material
941
        // glyph as the fallback for a desktop that provides none. A bar that
942
        // draws its own titlebar and then paints Material chevrons next to
943
        // the session's real windows is the one detail that gives client-side
944
        // decoration away; the same chain the CSD titlebar widget uses
945
        // (`super::titlebar`) keeps them identical.
946
        // A control with no app callback still has to WORK. These three do one
947
        // window-state thing each, identically in every app, and a bar that
948
        // draws them and then does nothing when they are clicked is worse than
949
        // one that draws none - which is what this band was: `on_minimize` and
950
        // friends default to `None`, so AzWriter's window buttons were
951
        // decorative. The default is the titlebar widget's own callback, so
952
        // the two bars behave identically as well as looking identical.
953
34
        if show_minimize {
954
33
            children.push(window_button(
955
33
                AzString::from_const_str("system:window-minimize,minimize"),
956
33
                OptionDom::None,
957
33
                part_window_button.clone(),
958
33
                &style,
959
33
                or_default(on_minimize, titlebar::callbacks::csd_minimize),
960
33
            ));
961
33
        }
962
34
        if show_maximize {
963
33
            children.push(window_button(
964
33
                AzString::from_const_str("system:window-maximize,crop_square"),
965
33
                // The glyph depends on the LIVE window frame, so it is a view
966
33
                // that re-renders in place rather than a fixed picture - see
967
33
                // `titlebar::maximize_icon_view`. The `icon` above stays as the
968
33
                // accessible name; the click stays on the BUTTON, which is the
969
33
                // only box that covers the whole control (the view cannot be
970
33
                // made to - see the sizing note in `maximize_icon_view`).
971
33
                OptionDom::Some(titlebar::maximize_icon_view(
972
33
                    AzString::from_const_str("system:window-maximize,crop_square"),
973
33
                    AzString::from_const_str("system:window-restore,filter_none"),
974
33
                    style.resolved_window_icon_style(),
975
33
                )),
976
33
                part_window_button.clone(),
977
33
                &style,
978
33
                or_default(on_maximize, titlebar::callbacks::csd_maximize),
979
33
            ));
980
33
        }
981
34
        if show_close {
982
33
            children.push(window_button(
983
33
                AzString::from_const_str("system:titlebar-close,system:window-close,close"),
984
33
                OptionDom::None,
985
33
                merged_style(&part_window_button, &part_close_button),
986
33
                &style,
987
33
                or_default(on_close, titlebar::callbacks::csd_close),
988
33
            ));
989
33
        }
990

            
991
        // The safe-area inset is applied HERE, not in `theme_bar`, because it
992
        // is a property of the WINDOW (which notch, which orientation) and not
993
        // of the theme - two bands with the same look can need different
994
        // insets, and `QuickAccessStyle` is shared and cached.
995
        //
996
        // Appending overrides the height `theme_bar` already pushed: later
997
        // declarations win, which is the same mechanism `merged_style` relies
998
        // on to let the close button restyle the window button above it.
999
34
        let bar_style = if top_inset > 0.0 {
1
            let mut props = part_bar.as_ref().to_vec();
1
            props.push(Cond::simple(P::const_height(LayoutHeight::px(
1
                BAR_HEIGHT as f32 + top_inset,
            ))));
1
            props.push(Cond::simple(P::const_padding_top(LayoutPaddingTop {
1
                inner: PixelValue::px(top_inset),
1
            })));
1
            CssPropertyWithConditionsVec::from_vec(props)
        } else {
33
            part_bar
        };
34
        Dom::create_div()
34
            .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_QAB))
34
            .with_css_props(bar_style)
34
            .with_children(DomVec::from_vec(children))
34
    }
}
impl Default for QuickAccessBar {
1
    fn default() -> Self {
1
        Self::new(AzString::from_const_str(""))
1
    }
}
impl From<QuickAccessBar> for Dom {
    fn from(q: QuickAccessBar) -> Self {
        q.dom()
    }
}
// -- DOM builders --
33
fn merged_style(
33
    base: &CssPropertyWithConditionsVec,
33
    extra: &CssPropertyWithConditionsVec,
33
) -> CssPropertyWithConditionsVec {
33
    if extra.as_ref().is_empty() {
        return base.clone();
33
    }
33
    let mut v: Vec<Cond> = base.as_ref().to_vec();
33
    v.extend_from_slice(extra.as_ref());
33
    CssPropertyWithConditionsVec::from_vec(v)
33
}
/// Expands one action to the existing [`Button`] widget with the given
/// container style injected.
4
fn action_button(
4
    action: QuickAccessAction,
4
    container: &CssPropertyWithConditionsVec,
4
    style: &QuickAccessStyle,
4
) -> Dom {
4
    let mut b = Button::create(AzString::from_const_str(""));
4
    b.icon = action.icon;
4
    b.container_style = OptionCssPropertyWithConditionsVec::Some(container.clone());
4
    b.icon_style = OptionCssPropertyWithConditionsVec::Some(style.resolved_action_icon_style());
4
    b.on_click = action.on_click;
4
    b.dom()
4
}
99
fn window_button(
99
    icon: AzString,
99
    icon_dom: OptionDom,
99
    container: CssPropertyWithConditionsVec,
99
    style: &QuickAccessStyle,
99
    on_click: OptionButtonOnClick,
99
) -> Dom {
99
    let mut b = Button::create(AzString::from_const_str(""));
99
    b.icon = icon;
99
    b.icon_dom = icon_dom;
99
    b.container_style = OptionCssPropertyWithConditionsVec::Some(container);
99
    b.icon_style = OptionCssPropertyWithConditionsVec::Some(style.resolved_window_icon_style());
99
    b.on_click = on_click;
99
    b.dom()
99
}
/// The app's callback if it set one, otherwise the shared window-control
/// default. Takes the default as a plain `fn` so a control needs no `RefAny`
/// of its own: these callbacks read the window state and write it back.
99
fn or_default(
99
    supplied: OptionButtonOnClick,
99
    fallback: super::button::ButtonOnClickCallbackType,
99
) -> OptionButtonOnClick {
99
    if supplied.is_some() {
        return supplied;
99
    }
99
    OptionButtonOnClick::Some(super::button::ButtonOnClick {
99
        refany: RefAny::new(()),
99
        callback: fallback.into(),
99
    })
99
}
#[cfg(test)]
mod tests {
    use super::*;
    // ------------------------------------------------------------------
    // Constructors and invariants
    // ------------------------------------------------------------------
    /// The window controls must ask the DESKTOP first and fall back to the
    /// bundled glyph - the same chain the CSD titlebar uses. Asserted as a
    /// CHAIN, not as a literal name: pinning one icon name is how this last
    /// broke, and an unresolved icon renders as an empty div rather than
    /// failing loudly.
    #[test]
1
    fn the_window_controls_ask_the_desktop_icon_theme_first() {
1
        let dom = QuickAccessBar::new(AzString::from("t")).dom();
1
        let mut icons: Vec<String> = collect_icon_names(&dom);
        // The maximize control's glyph is a VIEW, because it depends on the
        // live window frame - so its chain is what the view DRAWS, not what
        // the tree contains. Both states are asserted in
        // `the_maximize_control_draws_restore_when_the_window_is_maximized`;
        // here it joins the chain check like the other two.
1
        icons.push(
1
            super::super::titlebar::glyph_drawn_by_view(
1
                maximize_view(&dom),
1
                azul_core::window::WindowFrame::Normal,
            )
1
            .expect("the maximize control draws an icon"),
        );
3
        for (system, fallback) in [
1
            ("system:window-minimize", "minimize"),
1
            ("system:window-maximize", "crop_square"),
1
            ("system:titlebar-close", "close"),
        ] {
3
            let chain = icons
3
                .iter()
6
                .find(|i| i.starts_with(system))
3
                .unwrap_or_else(|| panic!("no window button asks for {system}; got {icons:?}"));
3
            let mut parts = chain.split(',');
3
            assert_eq!(
3
                parts.next(),
3
                Some(system),
                "the desktop's icon must come FIRST in the chain"
            );
3
            assert!(
4
                parts.any(|p| p == fallback),
                "{chain} must fall back to the bundled {fallback} glyph"
            );
        }
1
    }
    /// The maximize control's icon view inside a rendered band.
2
    fn maximize_view(dom: &Dom) -> &Dom {
22
        fn walk<'a>(node: &'a Dom, out: &mut Option<&'a Dom>) {
20
            if matches!(
22
                node.root.get_node_type(),
                azul_core::dom::NodeType::VirtualView
2
            ) && out.is_none()
2
            {
2
                *out = Some(node);
20
            }
22
            for c in node.children.as_ref() {
20
                walk(c, out);
20
            }
22
        }
2
        let mut found = None;
2
        walk(dom, &mut found);
2
        found.expect("the band renders a maximize icon view")
2
    }
    #[test]
1
    fn the_maximize_control_draws_restore_when_the_window_is_maximized() {
        use azul_core::window::WindowFrame;
1
        let dom = QuickAccessBar::new(AzString::from("t")).dom();
1
        let view = maximize_view(&dom);
1
        assert_eq!(
1
            super::super::titlebar::glyph_drawn_by_view(view, WindowFrame::Normal).as_deref(),
            Some("system:window-maximize,crop_square")
        );
1
        assert_eq!(
1
            super::super::titlebar::glyph_drawn_by_view(view, WindowFrame::Maximized).as_deref(),
            Some("system:window-restore,filter_none")
        );
1
    }
    #[test]
1
    fn the_window_controls_work_without_the_app_wiring_them() {
        // They did nothing at all before: `on_minimize`/`on_maximize`/
        // `on_close` default to None, and AzWriter never set them, so the
        // band's window buttons were decorative. Each now falls back to the
        // titlebar widget's own callback, which is the same behaviour the
        // auto-injected bar has.
1
        let dom = QuickAccessBar::new(AzString::from("t")).dom();
1
        let mut with_callbacks = 0usize;
11
        fn walk(node: &Dom, n: &mut usize) {
11
            if !node.root.get_callbacks().as_ref().is_empty() {
3
                *n += 1;
8
            }
11
            for c in node.children.as_ref() {
10
                walk(c, n);
10
            }
11
        }
1
        walk(&dom, &mut with_callbacks);
1
        assert!(
1
            with_callbacks >= 3,
            "minimize, maximize and close must each carry a callback, found {with_callbacks}"
        );
1
    }
    /// Every icon name in a DOM tree, in document order.
1
    fn collect_icon_names(dom: &Dom) -> Vec<String> {
11
        fn walk(node: &Dom, out: &mut Vec<String>) {
11
            if let azul_core::dom::NodeType::Icon(icon) = node.root.get_node_type() {
2
                out.push(icon.as_str().to_string());
9
            }
11
            for child in node.children.as_ref() {
10
                walk(child, out);
10
            }
11
        }
1
        let mut out = Vec::new();
1
        walk(dom, &mut out);
1
        out
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 = azul_css::system::SystemStyle::default();
1
        sys.colors = azul_css::system::SystemColors::default();
1
        sys.metrics.titlebar = azul_css::system::TitlebarMetrics::default();
1
        assert_eq!(
1
            QuickAccessTheme::from_system(sys.clone()),
1
            QuickAccessTheme::office_2013()
        );
1
        assert_eq!(
1
            QuickAccessStyle::from_system(sys),
1
            QuickAccessStyle::office_2013()
        );
1
    }
    #[test]
1
    fn from_system_prefers_the_os_titlebar_colours_over_the_window_palette() {
1
        let header = ColorU {
1
            r: 61,
1
            g: 174,
1
            b: 233,
1
            a: 255,
1
        };
1
        let window_bg = ColorU {
1
            r: 239,
1
            g: 240,
1
            b: 241,
1
            a: 255,
1
        };
1
        let mut sys = azul_css::system::SystemStyle::default();
1
        sys.colors = azul_css::system::SystemColors::default();
1
        sys.metrics.titlebar = azul_css::system::TitlebarMetrics::default();
1
        sys.colors.window_background = Some(window_bg).into();
        // Window background only: the band takes it.
1
        assert_eq!(QuickAccessTheme::from_system(sys.clone()).bg, window_bg);
        // A reported HEADER colour outranks it — the band is the titlebar.
1
        sys.metrics.titlebar.background_active = Some(header).into();
1
        assert_eq!(QuickAccessTheme::from_system(sys).bg, header);
1
    }
    #[test]
1
    fn from_system_keeps_the_close_hover_out_of_the_ordinary_hover_fill() {
1
        let hover = ColorU {
1
            r: 1,
1
            g: 2,
1
            b: 3,
1
            a: 255,
1
        };
1
        let mut sys = azul_css::system::SystemStyle::default();
1
        sys.colors = azul_css::system::SystemColors::default();
1
        sys.metrics.titlebar = azul_css::system::TitlebarMetrics::default();
1
        sys.metrics.titlebar.button_hover_background = Some(hover).into();
1
        let t = QuickAccessTheme::from_system(sys);
1
        assert_eq!(t.hover_bg, hover);
1
        assert_eq!(
            t.close_hover_bg,
1
            QuickAccessTheme::office_2013().close_hover_bg,
            "the close button keeps its own colour: a desktop that reports a button hover but no \
             close hover must NOT paint the close button in the ordinary fill"
        );
1
    }
    #[test]
1
    fn quick_access_new_has_no_actions_and_all_window_buttons() {
1
        let q = QuickAccessBar::new(AzString::from("t"));
1
        assert_eq!(q.actions.len(), 0);
1
        assert_eq!(q.trailing_actions.len(), 0);
1
        assert!(!q.show_menu_arrow);
1
        assert!(q.show_minimize && q.show_maximize && q.show_close);
1
        assert_eq!(q.style, QuickAccessStyle::office_2013());
1
    }
    #[test]
1
    fn quick_access_office_2013_has_save_undo_redo_and_help() {
1
        let q = QuickAccessBar::office_2013(AzString::from("Document1 - AzWriter"));
1
        let icons: Vec<&str> = q
1
            .actions
1
            .as_slice()
1
            .iter()
3
            .map(|a| a.icon.as_str())
1
            .collect();
1
        assert_eq!(icons, ["save", "undo", "redo"]);
1
        assert!(q.show_menu_arrow);
1
        assert_eq!(q.trailing_actions.len(), 1);
1
    }
    #[test]
1
    fn quick_access_style_default_is_office_2013() {
1
        assert_eq!(QuickAccessStyle::default(), QuickAccessStyle::office_2013());
1
    }
    // ------------------------------------------------------------------
    // DOM shape
    // ------------------------------------------------------------------
    #[test]
1
    fn dom_renders_actions_arrow_title_trailing_and_window_buttons_in_order() {
1
        let dom = QuickAccessBar::office_2013(AzString::from("t")).dom();
        // 3 actions + arrow + title + 1 trailing + min + max + close
1
        assert_eq!(dom.children.as_ref().len(), 9);
1
    }
    #[test]
1
    fn dom_without_window_buttons_renders_title_only() {
1
        let mut q = QuickAccessBar::new(AzString::from("t"));
1
        q.show_minimize = false;
1
        q.show_maximize = false;
1
        q.show_close = false;
1
        let dom = q.dom();
1
        assert_eq!(dom.children.as_ref().len(), 1);
1
    }
    // ------------------------------------------------------------------
    // Safe-area inset (10c-v-a)
    // ------------------------------------------------------------------
    /// Pulls the last `height` and `padding-top` the bar root declares, which
    /// is what the cascade resolves to: later declarations win, the mechanism
    /// `merged_style` already relies on.
2
    fn bar_height_and_padding_top(dom: &Dom) -> (Option<f32>, Option<f32>) {
2
        let mut height = None;
2
        let mut padding = None;
24
        for (p, _) in dom.root.style.iter_inline_properties() {
24
            match p {
3
                P::Height(v) => {
3
                    if let Some(LayoutHeight::Px(px)) = v.get_property() {
3
                        height = Some(px.number.get());
3
                    }
                }
1
                P::PaddingTop(v) => {
1
                    if let Some(pt) = v.get_property() {
1
                        padding = Some(pt.inner.number.get());
1
                    }
                }
20
                _ => {}
            }
        }
2
        (height, padding)
2
    }
    /// THE regression this closes. A padding-only fix was tried and measured:
    /// it moved nothing, because the band root carries a fixed
    /// `height: BAR_HEIGHT`, so padding squashes the content instead of
    /// displacing it. The inset must ADD to the height by the same amount it
    /// pads, leaving the content box exactly `BAR_HEIGHT` tall.
    #[test]
1
    fn the_top_inset_grows_the_band_so_the_content_box_stays_bar_height() {
1
        let inset = 24.0_f32;
1
        let dom = QuickAccessBar::new(AzString::from("t"))
1
            .with_top_inset(inset)
1
            .dom();
1
        let (height, padding) = bar_height_and_padding_top(&dom);
1
        let height = height.expect("the band must declare a height");
1
        let padding = padding.expect("the band must declare a top padding");
1
        assert!(
1
            (height - (BAR_HEIGHT as f32 + inset)).abs() < 0.001,
            "height {height} should be BAR_HEIGHT + inset"
        );
1
        assert!(
1
            (padding - inset).abs() < 0.001,
            "padding-top {padding} should equal the inset"
        );
1
        assert!(
1
            ((height - padding) - BAR_HEIGHT as f32).abs() < 0.001,
            "content box is {} tall, must stay BAR_HEIGHT ({BAR_HEIGHT}) - this is exactly the \
             padding-only attempt that squashed the band",
            height - padding
        );
1
    }
    /// Desktop has no notch and must be byte-identical to before the field
    /// existed - no extra declarations, no changed height.
    #[test]
1
    fn a_zero_inset_changes_nothing() {
1
        let plain = QuickAccessBar::new(AzString::from("t")).dom();
1
        let zeroed = QuickAccessBar::new(AzString::from("t"))
1
            .with_top_inset(0.0)
1
            .dom();
1
        assert_eq!(
1
            plain.root.style.iter_inline_properties().count(),
1
            zeroed.root.style.iter_inline_properties().count(),
            "a zero inset must not append declarations"
        );
1
        let (h, _) = bar_height_and_padding_top(&plain);
1
        assert_eq!(h, Some(BAR_HEIGHT as f32));
1
    }
    /// The default has to be the desktop behaviour, or every existing caller
    /// silently gains a band that is taller than it asked for.
    #[test]
1
    fn the_default_inset_is_zero() {
1
        assert_eq!(QuickAccessBar::default().top_inset, 0.0);
1
        assert_eq!(QuickAccessBar::new(AzString::from("t")).top_inset, 0.0);
1
        assert_eq!(
1
            QuickAccessBar::office_2013(AzString::from("t")).top_inset,
            0.0
        );
1
    }
    #[test]
1
    fn dom_wraps_the_leading_slot_first() {
1
        let q = QuickAccessBar::new(AzString::from("t")).with_leading(Dom::create_div());
1
        let dom = q.dom();
1
        let first = &dom.children.as_ref()[0];
1
        let classes = first.root.get_ids_and_classes();
1
        assert!(classes.as_ref().iter().any(|c| match c {
1
            Class(s) => s.as_str().contains("quick-access-leading"),
            IdOrClass::Id(_) => false,
1
        }));
1
    }
}