1
//! Microsoft Office-style backstage view widget (the full-window "FILE"
2
//! screen, the Office-2013-era look look by default).
3
//!
4
//! Models the component hierarchy of the Office backstage:
5
//!
6
//! ```text
7
//! Backstage ─ nav column (dark accent, full height)
8
//!           │    ├─ back button (white ring + left arrow)
9
//!           │    └─ nav items ("Info", "New", "Open", …, "Account", "Options")
10
//!           └─ right side
11
//!                ├─ title strip (optional, app-provided: window title/buttons)
12
//!                └─ content pane (app-provided Dom for the active item)
13
//! ```
14
//!
15
//! The widget owns the CHROME: nav column, back button, item highlight and
16
//! the content host. The per-item pane content ("Open" recent list, "Info"
17
//! properties, …) is application composition, injected through
18
//! [`Backstage::content`] - the backstage does not model document state.
19
//!
20
//! The back button expands to the existing [`super::button::Button`] widget
21
//! with backstage part styles injected (the ribbon's composition rule), and
22
//! its arrow uses `Dom::create_icon("arrow_back")` so glyphs resolve through
23
//! the registered icon provider (Material Icons by default).
24
//!
25
//! All visual parts are exposed on [`BackstageStyle`] (defaults = the Office-2013-era look
26
//! look, [`BackstageStyle::office_2013`]); replace any field to re-theme
27
//! without touching widget code. [`BackstageBehavior`] holds the
28
//! interactions the backstage performs by itself (currently: Escape invokes
29
//! the back callback, like classic office suites).
30

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

            
63
use super::{
64
    button::{Button, ButtonOnClick, OptionButtonOnClick},
65
    themes::flat,
66
};
67
use crate::callbacks::CallbackInfo;
68

            
69
// -- Callbacks --
70

            
71
/// Callback signature invoked when a nav item is clicked (receives the item
72
/// index).
73
pub type BackstageOnNavSelectCallbackType = extern "C" fn(RefAny, CallbackInfo, usize) -> Update;
74
impl_widget_callback!(
75
    BackstageOnNavSelect,
76
    OptionBackstageOnNavSelect,
77
    BackstageOnNavSelectCallback,
78
    BackstageOnNavSelectCallbackType
79
);
80

            
81
azul_core::impl_managed_callback! {
82
    wrapper:        BackstageOnNavSelectCallback,
83
    info_ty:        CallbackInfo,
84
    return_ty:      Update,
85
    default_ret:    Update::DoNothing,
86
    invoker_static: BACKSTAGE_ON_NAV_SELECT_INVOKER,
87
    invoker_ty:     AzBackstageOnNavSelectCallbackInvoker,
88
    thunk_fn:       az_backstage_on_nav_select_callback_thunk,
89
    setter_fn:      AzApp_setBackstageOnNavSelectCallbackInvoker,
90
    from_handle_fn: AzBackstageOnNavSelectCallback_createFromHostHandle,
91
    extra_args:     [ item_index: usize ],
92
}
93

            
94
// -- Font --
95

            
96
const SYSTEM_UI_STR: AzString = AzString::from_const_str("system:ui");
97
const SYSTEM_UI_FAMILIES: &[StyleFontFamily] = &[StyleFontFamily::System(SYSTEM_UI_STR)];
98
const SYSTEM_UI_FAMILY: StyleFontFamilyVec =
99
    StyleFontFamilyVec::from_const_slice(SYSTEM_UI_FAMILIES);
100

            
101
// -- the Office-2013-era look palette (seeds BackstageTheme::office_2013) --
102

            
103
const WHITE: ColorU = ColorU {
104
    r: 255,
105
    g: 255,
106
    b: 255,
107
    a: 255,
108
};
109
const TRANSPARENT: ColorU = ColorU {
110
    r: 0,
111
    g: 0,
112
    b: 0,
113
    a: 0,
114
};
115
/// Office 2013 accent blue (#2B579A): the nav column fill.
116
const W13_BLUE: ColorU = ColorU {
117
    r: 43,
118
    g: 87,
119
    b: 154,
120
    a: 255,
121
};
122
/// Hover fill on nav items (#3465AC).
123
const W13_NAV_HOVER: ColorU = ColorU {
124
    r: 52,
125
    g: 101,
126
    b: 172,
127
    a: 255,
128
};
129
/// Active nav item fill (#3E6DB5).
130
const W13_NAV_ACTIVE: ColorU = ColorU {
131
    r: 62,
132
    g: 109,
133
    b: 181,
134
    a: 255,
135
};
136

            
137
// -- Metrics (the Office-2013-era look, logical px) --
138

            
139
/// Nav column width.
140
const NAV_WIDTH: isize = 126;
141
/// Height of one nav item.
142
const NAV_ITEM_H: isize = 38;
143
/// Nav item text size.
144
const NAV_TEXT_PX: isize = 13;
145
/// Extra gap above a `gap_before` item (office-2013: before "Account").
146
const NAV_GAP_H: isize = 22;
147
/// Back button ring diameter.
148
const BACK_D: isize = 38;
149

            
150
// -- Theme --
151

            
152
/// Color palette from which a full [`BackstageStyle`] is derived via
153
/// [`BackstageStyle::from_theme`]. All fields are plain colors, so themes
154
/// are trivially constructible over FFI. Preset:
155
/// [`BackstageTheme::office_2013`] (the default).
156
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
157
#[repr(C)]
158
pub struct BackstageTheme {
159
    /// Nav column fill (office-2013: accent blue).
160
    pub nav_bg: ColorU,
161
    /// Nav item text and back-arrow color.
162
    pub nav_text: ColorU,
163
    /// Hover fill on nav items.
164
    pub nav_hover_bg: ColorU,
165
    /// Fill of the active nav item.
166
    pub nav_active_bg: ColorU,
167
    /// Content pane fill.
168
    pub content_bg: ColorU,
169
    /// Back button ring color.
170
    pub back_ring: ColorU,
171
}
172

            
173
impl BackstageTheme {
174
    /// The the Office-2013-era look palette: #2B579A nav, white text, lighter-blue
175
    /// highlights, white content.
176
    #[must_use]
177
22
    pub const fn office_2013() -> Self {
178
22
        Self {
179
22
            nav_bg: W13_BLUE,
180
22
            nav_text: WHITE,
181
22
            nav_hover_bg: W13_NAV_HOVER,
182
22
            nav_active_bg: W13_NAV_ACTIVE,
183
22
            content_bg: WHITE,
184
22
            back_ring: WHITE,
185
22
        }
186
22
    }
187

            
188
    /// Extracts a backstage palette from the OS theme.
189
    ///
190
    /// The nav column is an ACCENT-FILLED band and the pane behind it is the
191
    /// window surface, so those two system colours carry the whole screen. A
192
    /// colour the platform does not report falls back to that field's own
193
    /// Office-2013 value, never to another derived value; same discipline as
194
    /// [`super::ribbon::RibbonTheme::from_system`], no colour arithmetic.
195
    ///
196
    /// Takes the style by value (FFI constructor convention).
197
    #[must_use]
198
3
    pub fn from_system(style: SystemStyle) -> Self {
199
3
        let d = Self::office_2013();
200
3
        let c = &style.colors;
201
3
        let on_accent = c.accent_text.into_option();
202
3
        Self {
203
3
            nav_bg: c.accent.into_option().unwrap_or(d.nav_bg),
204
3
            nav_text: on_accent.unwrap_or(d.nav_text),
205
3
            nav_hover_bg: c
206
3
                .selection_background
207
3
                .into_option()
208
3
                .unwrap_or(d.nav_hover_bg),
209
3
            nav_active_bg: c
210
3
                .selection_background_inactive
211
3
                .into_option()
212
3
                .unwrap_or(d.nav_active_bg),
213
3
            content_bg: c.window_background.into_option().unwrap_or(d.content_bg),
214
3
            back_ring: on_accent.unwrap_or(d.back_ring),
215
3
        }
216
3
    }
217
}
218

            
219
impl Default for BackstageTheme {
220
    fn default() -> Self {
221
        Self::office_2013()
222
    }
223
}
224

            
225
// -- Theme -> property-list builders --
226

            
227
91
fn bg_vec(c: ColorU) -> StyleBackgroundContentVec {
228
91
    StyleBackgroundContentVec::from_vec(vec![StyleBackgroundContent::Color(c)])
229
91
}
230

            
231
91
fn cond_bg(c: ColorU) -> Cond {
232
91
    Cond::simple(P::const_background_content(bg_vec(c)))
233
91
}
234

            
235
26
const fn cond_text_color(c: ColorU) -> Cond {
236
26
    Cond::simple(P::const_text_color(StyleTextColor { inner: c }))
237
26
}
238

            
239
78
const fn cond_border_box() -> Cond {
240
78
    Cond::simple(P::const_box_sizing(LayoutBoxSizing::BorderBox))
241
78
}
242

            
243
13
fn push_ring_border(v: &mut Vec<Cond>, c: ColorU, width: isize, radius: isize) {
244
13
    v.push(Cond::simple(P::const_border_top_width(
245
13
        LayoutBorderTopWidth::const_px(width),
246
    )));
247
13
    v.push(Cond::simple(P::const_border_left_width(
248
13
        LayoutBorderLeftWidth::const_px(width),
249
    )));
250
13
    v.push(Cond::simple(P::const_border_right_width(
251
13
        LayoutBorderRightWidth::const_px(width),
252
    )));
253
13
    v.push(Cond::simple(P::const_border_bottom_width(
254
13
        LayoutBorderBottomWidth::const_px(width),
255
    )));
256
13
    v.push(Cond::simple(P::const_border_top_style(
257
13
        StyleBorderTopStyle {
258
13
            inner: BorderStyle::Solid,
259
13
        },
260
    )));
261
13
    v.push(Cond::simple(P::const_border_left_style(
262
13
        StyleBorderLeftStyle {
263
13
            inner: BorderStyle::Solid,
264
13
        },
265
    )));
266
13
    v.push(Cond::simple(P::const_border_right_style(
267
13
        StyleBorderRightStyle {
268
13
            inner: BorderStyle::Solid,
269
13
        },
270
    )));
271
13
    v.push(Cond::simple(P::const_border_bottom_style(
272
13
        StyleBorderBottomStyle {
273
13
            inner: BorderStyle::Solid,
274
13
        },
275
    )));
276
13
    v.push(Cond::simple(P::const_border_top_color(
277
13
        StyleBorderTopColor { inner: c },
278
    )));
279
13
    v.push(Cond::simple(P::const_border_left_color(
280
13
        StyleBorderLeftColor { inner: c },
281
    )));
282
13
    v.push(Cond::simple(P::const_border_right_color(
283
13
        StyleBorderRightColor { inner: c },
284
    )));
285
13
    v.push(Cond::simple(P::const_border_bottom_color(
286
13
        StyleBorderBottomColor { inner: c },
287
    )));
288
13
    v.push(Cond::simple(P::const_border_top_left_radius(
289
13
        StyleBorderTopLeftRadius::const_px(radius),
290
    )));
291
13
    v.push(Cond::simple(P::const_border_top_right_radius(
292
13
        StyleBorderTopRightRadius::const_px(radius),
293
    )));
294
13
    v.push(Cond::simple(P::const_border_bottom_left_radius(
295
13
        StyleBorderBottomLeftRadius::const_px(radius),
296
    )));
297
13
    v.push(Cond::simple(P::const_border_bottom_right_radius(
298
13
        StyleBorderBottomRightRadius::const_px(radius),
299
    )));
300
13
}
301

            
302
/// The hover fill of the two controls on the nav column (back button, nav
303
/// item), light AND dark.
304
///
305
/// Built by the theme module rather than declared here, so the pair cannot be
306
/// split: the dark half needs a palette this file cannot see, and a rule
307
/// written here could only ever name the light colour — which is how every
308
/// interactive state in this toolkit came to paint its light fill onto a dark
309
/// surface.
310
///
311
/// The dark twin is the SAME colour, on purpose. The nav column is an ACCENT
312
/// fill in either mode (`theme_nav` paints `nav_bg` with no dark variant;
313
/// `from_system` reads it from the desktop's accent), and `nav_hover_bg` is a
314
/// shade of that accent. The theme's neutral `DARK_HT` on a blue band would be
315
/// worse than today's light-only rule — see `themes::flat::hover_bg_both` for
316
/// the rule, and `flat::button_states` for the same call on a Primary button.
317
26
fn push_nav_hover(v: &mut Vec<Cond>, t: &BackstageTheme) {
318
26
    v.extend(flat::hover_bg_both(t.nav_hover_bg, t.nav_hover_bg));
319
26
}
320

            
321
13
fn theme_root(t: &BackstageTheme) -> CssPropertyWithConditionsVec {
322
13
    CssPropertyWithConditionsVec::from_vec(vec![
323
13
        cond_border_box(),
324
13
        Cond::simple(P::const_display(LayoutDisplay::Flex)),
325
13
        Cond::simple(P::const_flex_direction(LayoutFlexDirection::Row)),
326
13
        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(1))),
327
13
        Cond::simple(P::const_font_family(SYSTEM_UI_FAMILY)),
328
13
        Cond::simple(P::const_font_size(StyleFontSize::const_px(NAV_TEXT_PX))),
329
13
        cond_bg(t.content_bg),
330
    ])
331
13
}
332

            
333
13
fn theme_nav(t: &BackstageTheme) -> CssPropertyWithConditionsVec {
334
13
    CssPropertyWithConditionsVec::from_vec(vec![
335
13
        cond_border_box(),
336
13
        Cond::simple(P::const_display(LayoutDisplay::Flex)),
337
13
        Cond::simple(P::const_flex_direction(LayoutFlexDirection::Column)),
338
13
        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(0))),
339
13
        Cond::simple(P::const_flex_shrink(LayoutFlexShrink {
340
13
            inner: FloatValue::const_new(0),
341
13
        })),
342
13
        Cond::simple(P::const_width(LayoutWidth::const_px(NAV_WIDTH))),
343
13
        cond_bg(t.nav_bg),
344
    ])
345
13
}
346

            
347
/// The circled back arrow. office-2013: a 2px white ring, transparent fill,
348
/// hover fills like a nav item.
349
13
fn theme_back_button(t: &BackstageTheme) -> CssPropertyWithConditionsVec {
350
13
    let mut v = vec![
351
13
        cond_border_box(),
352
13
        Cond::simple(P::const_display(LayoutDisplay::Flex)),
353
13
        Cond::simple(P::const_flex_direction(LayoutFlexDirection::Row)),
354
13
        Cond::simple(P::const_align_items(LayoutAlignItems::Center)),
355
13
        Cond::simple(P::const_justify_content(LayoutJustifyContent::Center)),
356
13
        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(0))),
357
13
        Cond::simple(P::const_flex_shrink(LayoutFlexShrink {
358
13
            inner: FloatValue::const_new(0),
359
13
        })),
360
13
        Cond::simple(P::const_width(LayoutWidth::const_px(BACK_D))),
361
13
        Cond::simple(P::const_height(LayoutHeight::const_px(BACK_D))),
362
13
        Cond::simple(P::const_margin_top(LayoutMarginTop::const_px(16))),
363
13
        Cond::simple(P::const_margin_left(LayoutMarginLeft::const_px(20))),
364
13
        Cond::simple(P::const_margin_bottom(LayoutMarginBottom::const_px(18))),
365
13
        Cond::simple(P::const_cursor(StyleCursor::Pointer)),
366
13
        Cond::simple(P::user_select(StyleUserSelect::None)),
367
13
        cond_bg(TRANSPARENT),
368
    ];
369
13
    push_nav_hover(&mut v, t);
370
13
    push_ring_border(&mut v, t.back_ring, 2, BACK_D / 2);
371
13
    CssPropertyWithConditionsVec::from_vec(v)
372
13
}
373

            
374
13
fn theme_back_icon(t: &BackstageTheme) -> CssPropertyWithConditionsVec {
375
13
    CssPropertyWithConditionsVec::from_vec(vec![
376
13
        Cond::simple(P::const_font_size(StyleFontSize::const_px(20))),
377
13
        cond_text_color(t.nav_text),
378
    ])
379
13
}
380

            
381
13
fn theme_nav_item(t: &BackstageTheme) -> CssPropertyWithConditionsVec {
382
13
    let mut v = vec![
383
13
        cond_border_box(),
384
13
        Cond::simple(P::const_display(LayoutDisplay::Flex)),
385
13
        Cond::simple(P::const_flex_direction(LayoutFlexDirection::Row)),
386
13
        Cond::simple(P::const_align_items(LayoutAlignItems::Center)),
387
13
        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(0))),
388
13
        Cond::simple(P::const_flex_shrink(LayoutFlexShrink {
389
13
            inner: FloatValue::const_new(0),
390
13
        })),
391
13
        Cond::simple(P::const_height(LayoutHeight::const_px(NAV_ITEM_H))),
392
13
        Cond::simple(P::const_padding_left(LayoutPaddingLeft::const_px(24))),
393
13
        Cond::simple(P::const_font_size(StyleFontSize::const_px(NAV_TEXT_PX))),
394
13
        Cond::simple(P::const_cursor(StyleCursor::Pointer)),
395
13
        Cond::simple(P::user_select(StyleUserSelect::None)),
396
13
        cond_text_color(t.nav_text),
397
13
        cond_bg(TRANSPARENT),
398
    ];
399
13
    push_nav_hover(&mut v, t);
400
13
    CssPropertyWithConditionsVec::from_vec(v)
401
13
}
402

            
403
/// APPENDED to the active nav item.
404
13
fn theme_nav_item_active(t: &BackstageTheme) -> CssPropertyWithConditionsVec {
405
13
    CssPropertyWithConditionsVec::from_vec(vec![cond_bg(t.nav_active_bg)])
406
13
}
407

            
408
/// APPENDED to a `gap_before` nav item (office-2013: the gap before "Account").
409
13
fn theme_nav_item_gap(_t: &BackstageTheme) -> CssPropertyWithConditionsVec {
410
13
    CssPropertyWithConditionsVec::from_vec(vec![Cond::simple(P::const_margin_top(
411
13
        LayoutMarginTop::const_px(NAV_GAP_H),
412
    ))])
413
13
}
414

            
415
13
fn theme_right(t: &BackstageTheme) -> CssPropertyWithConditionsVec {
416
13
    CssPropertyWithConditionsVec::from_vec(vec![
417
13
        cond_border_box(),
418
13
        Cond::simple(P::const_display(LayoutDisplay::Flex)),
419
13
        Cond::simple(P::const_flex_direction(LayoutFlexDirection::Column)),
420
13
        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(1))),
421
13
        cond_bg(t.content_bg),
422
    ])
423
13
}
424

            
425
13
fn theme_content(t: &BackstageTheme) -> CssPropertyWithConditionsVec {
426
13
    CssPropertyWithConditionsVec::from_vec(vec![
427
13
        cond_border_box(),
428
13
        Cond::simple(P::const_display(LayoutDisplay::Flex)),
429
13
        Cond::simple(P::const_flex_direction(LayoutFlexDirection::Column)),
430
13
        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(1))),
431
13
        cond_bg(t.content_bg),
432
    ])
433
13
}
434

            
435
// -- Style --
436

            
437
/// All part styles of the backstage. Every part defaults to the the Office-2013-era look
438
/// look; replace any field for finer control (the same override API as
439
/// [`super::ribbon::RibbonStyle`]).
440
#[derive(Debug, Clone, PartialEq, Eq)]
441
#[repr(C)]
442
pub struct BackstageStyle {
443
    /// The palette this style bundle was derived from. Kept for consumers
444
    /// deriving matching custom parts.
445
    pub theme: BackstageTheme,
446
    /// Root container (horizontal: nav column beside the right side).
447
    ///
448
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
449
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
450
    /// a real answer — "no properties at all" — which the pre-filled field could
451
    /// not express.
452
    pub root_style: OptionCssPropertyWithConditionsVec,
453
    /// The nav column.
454
    ///
455
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
456
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
457
    /// a real answer — "no properties at all" — which the pre-filled field could
458
    /// not express.
459
    pub nav_style: OptionCssPropertyWithConditionsVec,
460
    /// Container style injected into the back [`Button`] (the ring).
461
    ///
462
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
463
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
464
    /// a real answer — "no properties at all" — which the pre-filled field could
465
    /// not express.
466
    pub back_button_style: OptionCssPropertyWithConditionsVec,
467
    /// Icon style injected into the back [`Button`] (the arrow).
468
    ///
469
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
470
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
471
    /// a real answer — "no properties at all" — which the pre-filled field could
472
    /// not express.
473
    pub back_icon_style: OptionCssPropertyWithConditionsVec,
474
    /// One nav item.
475
    ///
476
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
477
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
478
    /// a real answer — "no properties at all" — which the pre-filled field could
479
    /// not express.
480
    pub nav_item_style: OptionCssPropertyWithConditionsVec,
481
    /// APPENDED to the active nav item.
482
    ///
483
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
484
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
485
    /// a real answer — "no properties at all" — which the pre-filled field could
486
    /// not express.
487
    pub nav_item_active_style: OptionCssPropertyWithConditionsVec,
488
    /// APPENDED to a `gap_before` nav item.
489
    ///
490
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
491
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
492
    /// a real answer — "no properties at all" — which the pre-filled field could
493
    /// not express.
494
    pub nav_item_gap_style: OptionCssPropertyWithConditionsVec,
495
    /// The right side (title strip over content).
496
    ///
497
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
498
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
499
    /// a real answer — "no properties at all" — which the pre-filled field could
500
    /// not express.
501
    pub right_style: OptionCssPropertyWithConditionsVec,
502
    /// The content host for the active pane.
503
    ///
504
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
505
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
506
    /// a real answer — "no properties at all" — which the pre-filled field could
507
    /// not express.
508
    pub content_style: OptionCssPropertyWithConditionsVec,
509
}
510

            
511
impl BackstageStyle {
512
    /// The the Office-2013-era look look (#2B579A nav, white content) - the default.
513
    #[must_use]
514
17
    pub const fn office_2013() -> Self {
515
17
        Self::from_theme(BackstageTheme::office_2013())
516
17
    }
517

            
518
    /// Every part style, derived from the OS theme - see
519
    /// [`BackstageTheme::from_system`]. Takes the style by value (FFI
520
    /// constructor convention).
521
    #[must_use]
522
1
    pub fn from_system(style: SystemStyle) -> Self {
523
1
        Self::from_theme(BackstageTheme::from_system(style))
524
1
    }
525

            
526
    /// Derives every part style from the given palette.
527
    #[must_use]
528
18
    pub const fn from_theme(theme: BackstageTheme) -> Self {
529
18
        Self {
530
18
            theme,
531
18
            root_style: OptionCssPropertyWithConditionsVec::None,
532
18
            nav_style: OptionCssPropertyWithConditionsVec::None,
533
18
            back_button_style: OptionCssPropertyWithConditionsVec::None,
534
18
            back_icon_style: OptionCssPropertyWithConditionsVec::None,
535
18
            nav_item_style: OptionCssPropertyWithConditionsVec::None,
536
18
            nav_item_active_style: OptionCssPropertyWithConditionsVec::None,
537
18
            nav_item_gap_style: OptionCssPropertyWithConditionsVec::None,
538
18
            right_style: OptionCssPropertyWithConditionsVec::None,
539
18
            content_style: OptionCssPropertyWithConditionsVec::None,
540
18
        }
541
18
    }
542

            
543
    /// The `root_style` this bundle renders with: the caller's override if there is
544
    /// one, else derived from [`Self::theme`].
545
    #[must_use]
546
13
    pub fn resolved_root_style(&self) -> CssPropertyWithConditionsVec {
547
13
        self.root_style
548
13
            .clone()
549
13
            .into_option()
550
13
            .unwrap_or_else(|| theme_root(&self.theme))
551
13
    }
552

            
553
    /// The `nav_style` this bundle renders with: the caller's override if there is
554
    /// one, else derived from [`Self::theme`].
555
    #[must_use]
556
13
    pub fn resolved_nav_style(&self) -> CssPropertyWithConditionsVec {
557
13
        self.nav_style
558
13
            .clone()
559
13
            .into_option()
560
13
            .unwrap_or_else(|| theme_nav(&self.theme))
561
13
    }
562

            
563
    /// The `back_button_style` this bundle renders with: the caller's override if there is
564
    /// one, else derived from [`Self::theme`].
565
    #[must_use]
566
13
    pub fn resolved_back_button_style(&self) -> CssPropertyWithConditionsVec {
567
13
        self.back_button_style
568
13
            .clone()
569
13
            .into_option()
570
13
            .unwrap_or_else(|| theme_back_button(&self.theme))
571
13
    }
572

            
573
    /// The `back_icon_style` this bundle renders with: the caller's override if there is
574
    /// one, else derived from [`Self::theme`].
575
    #[must_use]
576
13
    pub fn resolved_back_icon_style(&self) -> CssPropertyWithConditionsVec {
577
13
        self.back_icon_style
578
13
            .clone()
579
13
            .into_option()
580
13
            .unwrap_or_else(|| theme_back_icon(&self.theme))
581
13
    }
582

            
583
    /// The `nav_item_style` this bundle renders with: the caller's override if there is
584
    /// one, else derived from [`Self::theme`].
585
    #[must_use]
586
13
    pub fn resolved_nav_item_style(&self) -> CssPropertyWithConditionsVec {
587
13
        self.nav_item_style
588
13
            .clone()
589
13
            .into_option()
590
13
            .unwrap_or_else(|| theme_nav_item(&self.theme))
591
13
    }
592

            
593
    /// The `nav_item_active_style` this bundle renders with: the caller's override if there is
594
    /// one, else derived from [`Self::theme`].
595
    #[must_use]
596
13
    pub fn resolved_nav_item_active_style(&self) -> CssPropertyWithConditionsVec {
597
13
        self.nav_item_active_style
598
13
            .clone()
599
13
            .into_option()
600
13
            .unwrap_or_else(|| theme_nav_item_active(&self.theme))
601
13
    }
602

            
603
    /// The `nav_item_gap_style` this bundle renders with: the caller's override if there is
604
    /// one, else derived from [`Self::theme`].
605
    #[must_use]
606
13
    pub fn resolved_nav_item_gap_style(&self) -> CssPropertyWithConditionsVec {
607
13
        self.nav_item_gap_style
608
13
            .clone()
609
13
            .into_option()
610
13
            .unwrap_or_else(|| theme_nav_item_gap(&self.theme))
611
13
    }
612

            
613
    /// The `right_style` this bundle renders with: the caller's override if there is
614
    /// one, else derived from [`Self::theme`].
615
    #[must_use]
616
13
    pub fn resolved_right_style(&self) -> CssPropertyWithConditionsVec {
617
13
        self.right_style
618
13
            .clone()
619
13
            .into_option()
620
13
            .unwrap_or_else(|| theme_right(&self.theme))
621
13
    }
622

            
623
    /// The `content_style` this bundle renders with: the caller's override if there is
624
    /// one, else derived from [`Self::theme`].
625
    #[must_use]
626
13
    pub fn resolved_content_style(&self) -> CssPropertyWithConditionsVec {
627
13
        self.content_style
628
13
            .clone()
629
13
            .into_option()
630
13
            .unwrap_or_else(|| theme_content(&self.theme))
631
13
    }
632
}
633

            
634
impl Default for BackstageStyle {
635
1
    fn default() -> Self {
636
1
        Self::office_2013()
637
1
    }
638
}
639

            
640
// -- Behavior --
641

            
642
/// The interactions the backstage performs BY ITSELF. Each is the classic
643
/// default and each can be turned off.
644
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
645
#[repr(C)]
646
pub struct BackstageBehavior {
647
    /// Pressing Escape invokes the back callback (office-2013: Esc leaves the
648
    /// backstage). Attached as a window-level key handler on the root, so
649
    /// it fires regardless of focus. Requires [`Backstage::on_back`].
650
    pub close_on_escape: bool,
651
}
652

            
653
impl BackstageBehavior {
654
    /// All classic office-suite behaviors enabled - the default.
655
    #[must_use]
656
17
    pub const fn office_2013() -> Self {
657
17
        Self {
658
17
            close_on_escape: true,
659
17
        }
660
17
    }
661

            
662
    /// Every self-driven behavior off.
663
    #[must_use]
664
2
    pub const fn inert() -> Self {
665
2
        Self {
666
2
            close_on_escape: false,
667
2
        }
668
2
    }
669
}
670

            
671
impl Default for BackstageBehavior {
672
1
    fn default() -> Self {
673
1
        Self::office_2013()
674
1
    }
675
}
676

            
677
// -- Data model --
678

            
679
/// One backstage nav item ("Info", "Open", …).
680
#[derive(Debug, Clone, PartialEq, Eq)]
681
#[repr(C)]
682
pub struct BackstageNavItem {
683
    /// The item label.
684
    pub label: AzString,
685
    /// Renders an extra gap above this item (office-2013: before "Account").
686
    pub gap_before: bool,
687
}
688

            
689
impl BackstageNavItem {
690
    /// Creates a nav item without a gap.
691
    #[must_use]
692
109
    pub const fn new(label: AzString) -> Self {
693
109
        Self {
694
109
            label,
695
109
            gap_before: false,
696
109
        }
697
109
    }
698

            
699
    /// Builder method: marks this item as starting a new group.
700
    #[must_use]
701
9
    pub const fn with_gap_before(mut self) -> Self {
702
9
        self.gap_before = true;
703
9
        self
704
9
    }
705
}
706

            
707
impl_option!(
708
    BackstageNavItem,
709
    OptionBackstageNavItem,
710
    copy = false,
711
    [Debug, Clone, PartialEq]
712
);
713
impl_vec!(
714
    BackstageNavItem,
715
    BackstageNavItemVec,
716
    BackstageNavItemVecDestructor,
717
    BackstageNavItemVecDestructorType,
718
    BackstageNavItemVecSlice,
719
    OptionBackstageNavItem
720
);
721
impl_vec_clone!(
722
    BackstageNavItem,
723
    BackstageNavItemVec,
724
    BackstageNavItemVecDestructor
725
);
726
impl_vec_debug!(BackstageNavItem, BackstageNavItemVec);
727
impl_vec_mut!(BackstageNavItem, BackstageNavItemVec);
728

            
729
/// Top-level backstage widget: nav column + app-provided content pane.
730
#[derive(Debug, Clone)]
731
#[repr(C)]
732
pub struct Backstage {
733
    /// Nav items, top to bottom.
734
    pub nav_items: BackstageNavItemVec,
735
    /// Index of the active (highlighted) nav item.
736
    pub active_item: usize,
737
    /// Optional callback fired when a nav item is clicked (receives the
738
    /// item index).
739
    pub on_nav_select: OptionBackstageOnNavSelect,
740
    /// Optional callback fired by the back button (and by Escape, if
741
    /// [`BackstageBehavior::close_on_escape`] is set).
742
    pub on_back: OptionButtonOnClick,
743
    /// Optional strip rendered above the content, right of the nav column
744
    /// (office-2013: the white title bar area with the window buttons).
745
    pub title_strip: azul_core::dom::OptionDom,
746
    /// The active item's pane content (application composition).
747
    pub content: azul_core::dom::OptionDom,
748
    /// Which interactions the backstage handles by itself (defaults to
749
    /// Word).
750
    pub behavior: BackstageBehavior,
751
    /// All part styles (defaults to the the Office-2013-era look look).
752
    pub style: BackstageStyle,
753
}
754

            
755
// -- CSS classes --
756

            
757
static CLS_BACKSTAGE: &[IdOrClass] = &[Class(AzString::from_const_str("__azul-native-backstage"))];
758
static CLS_NAV: &[IdOrClass] = &[Class(AzString::from_const_str(
759
    "__azul-native-backstage-nav",
760
))];
761
static CLS_NAV_ITEM: &[IdOrClass] = &[Class(AzString::from_const_str(
762
    "__azul-native-backstage-nav-item",
763
))];
764
static CLS_NAV_ITEM_ACTIVE: &[IdOrClass] = &[
765
    Class(AzString::from_const_str("__azul-native-backstage-nav-item")),
766
    Class(AzString::from_const_str(
767
        "__azul-native-backstage-nav-item-active",
768
    )),
769
];
770
static CLS_RIGHT: &[IdOrClass] = &[Class(AzString::from_const_str(
771
    "__azul-native-backstage-right",
772
))];
773
static CLS_CONTENT: &[IdOrClass] = &[Class(AzString::from_const_str(
774
    "__azul-native-backstage-content",
775
))];
776

            
777
/// The default the Office-2013-era look nav labels, in order.
778
pub const OFFICE_2013_NAV_LABELS: &[&str] = &[
779
    "Info", "New", "Open", "Save", "Save As", "Print", "Share", "Export", "Close",
780
];
781

            
782
// -- Constructors / builders --
783

            
784
impl Backstage {
785
    /// Creates a backstage with the given nav items, item 0 active, no
786
    /// callbacks and no content, in the the Office-2013-era look style.
787
    #[must_use]
788
14
    pub fn new(nav_items: BackstageNavItemVec) -> Self {
789
14
        Self {
790
14
            nav_items,
791
14
            active_item: 0,
792
14
            on_nav_select: None.into(),
793
14
            on_back: None.into(),
794
14
            title_strip: None.into(),
795
14
            content: None.into(),
796
14
            behavior: BackstageBehavior::office_2013(),
797
14
            style: BackstageStyle::office_2013(),
798
14
        }
799
14
    }
800

            
801
    /// The the Office-2013-era look nav: Info / New / Open / Save / Save As / Print /
802
    /// Share / Export / Close, then a gap, then Account / Options.
803
    #[must_use]
804
9
    pub fn office_2013() -> Self {
805
9
        let mut items: Vec<BackstageNavItem> = OFFICE_2013_NAV_LABELS
806
9
            .iter()
807
81
            .map(|l| BackstageNavItem::new(AzString::from(*l)))
808
9
            .collect();
809
9
        items.push(BackstageNavItem::new(AzString::from_const_str("Account")).with_gap_before());
810
9
        items.push(BackstageNavItem::new(AzString::from_const_str("Options")));
811
9
        Self::new(BackstageNavItemVec::from_vec(items))
812
9
    }
813

            
814
    /// Sets the active nav item.
815
1
    pub const fn set_active_item(&mut self, active_item: usize) {
816
1
        self.active_item = active_item;
817
1
    }
818

            
819
    /// Builder method: sets the active nav item and returns `self`.
820
    #[must_use]
821
1
    pub const fn with_active_item(mut self, active_item: usize) -> Self {
822
1
        self.set_active_item(active_item);
823
1
        self
824
1
    }
825

            
826
    /// Sets the pane content for the active item.
827
    pub fn set_content(&mut self, content: Dom) {
828
        self.content = Some(content).into();
829
    }
830

            
831
    /// Builder method: sets the pane content and returns `self`.
832
    #[must_use]
833
    pub fn with_content(mut self, content: Dom) -> Self {
834
        self.set_content(content);
835
        self
836
    }
837

            
838
    /// Sets the title strip rendered above the content.
839
1
    pub fn set_title_strip(&mut self, title_strip: Dom) {
840
1
        self.title_strip = Some(title_strip).into();
841
1
    }
842

            
843
    /// Builder method: sets the title strip and returns `self`.
844
    #[must_use]
845
1
    pub fn with_title_strip(mut self, title_strip: Dom) -> Self {
846
1
        self.set_title_strip(title_strip);
847
1
        self
848
1
    }
849

            
850
    /// Sets the nav-select callback.
851
1
    pub fn set_on_nav_select<C: Into<BackstageOnNavSelectCallback>>(
852
1
        &mut self,
853
1
        data: RefAny,
854
1
        on_nav_select: C,
855
1
    ) {
856
1
        self.on_nav_select = Some(BackstageOnNavSelect {
857
1
            refany: data,
858
1
            callback: on_nav_select.into(),
859
1
        })
860
1
        .into();
861
1
    }
862

            
863
    /// Builder method: sets the nav-select callback and returns `self`.
864
    #[must_use]
865
1
    pub fn with_on_nav_select<C: Into<BackstageOnNavSelectCallback>>(
866
1
        mut self,
867
1
        data: RefAny,
868
1
        on_nav_select: C,
869
1
    ) -> Self {
870
1
        self.set_on_nav_select(data, on_nav_select);
871
1
        self
872
1
    }
873

            
874
    /// Sets the back callback (back button + Escape).
875
2
    pub fn set_on_back<C: Into<super::button::ButtonOnClickCallback>>(
876
2
        &mut self,
877
2
        data: RefAny,
878
2
        on_back: C,
879
2
    ) {
880
2
        self.on_back = Some(ButtonOnClick {
881
2
            refany: data,
882
2
            callback: on_back.into(),
883
2
        })
884
2
        .into();
885
2
    }
886

            
887
    /// Builder method: sets the back callback and returns `self`.
888
    #[must_use]
889
2
    pub fn with_on_back<C: Into<super::button::ButtonOnClickCallback>>(
890
2
        mut self,
891
2
        data: RefAny,
892
2
        on_back: C,
893
2
    ) -> Self {
894
2
        self.set_on_back(data, on_back);
895
2
        self
896
2
    }
897

            
898
    /// Builder method: replaces the behavior set.
899
    #[must_use]
900
1
    pub const fn with_behavior(mut self, behavior: BackstageBehavior) -> Self {
901
1
        self.behavior = behavior;
902
1
        self
903
1
    }
904

            
905
    /// Builder method: replaces the style bundle.
906
    #[must_use]
907
    pub fn with_style(mut self, style: BackstageStyle) -> Self {
908
        self.style = style;
909
        self
910
    }
911

            
912
    /// Renders the backstage.
913
    #[must_use]
914
13
    pub fn dom(self) -> Dom {
915
        let Self {
916
13
            nav_items,
917
13
            active_item,
918
13
            on_nav_select,
919
13
            on_back,
920
13
            title_strip,
921
13
            content,
922
13
            behavior,
923
13
            style,
924
13
        } = self;
925

            
926
        // Every part resolved up front: the resolvers borrow `&style`, and
927
        // `root_style` is moved out of it at the end of this function.
928
13
        let part_root = style.resolved_root_style();
929
13
        let part_nav = style.resolved_nav_style();
930
13
        let part_back_button = style.resolved_back_button_style();
931
13
        let part_back_icon = style.resolved_back_icon_style();
932
13
        let part_nav_item = style.resolved_nav_item_style();
933
13
        let part_nav_item_active = style.resolved_nav_item_active_style();
934
13
        let part_nav_item_gap = style.resolved_nav_item_gap_style();
935
13
        let part_right = style.resolved_right_style();
936
13
        let part_content = style.resolved_content_style();
937

            
938
        // -- nav column --
939
13
        let mut nav_children: Vec<Dom> = Vec::with_capacity(nav_items.len() + 1);
940

            
941
13
        {
942
13
            let mut b = Button::create(AzString::from_const_str(""));
943
13
            b.icon = AzString::from_const_str("arrow_back");
944
13
            b.container_style = OptionCssPropertyWithConditionsVec::Some(part_back_button);
945
13
            b.icon_style = OptionCssPropertyWithConditionsVec::Some(part_back_icon);
946
13
            b.on_click = on_back.clone();
947
13
            nav_children.push(b.dom());
948
13
        }
949

            
950
98
        for (idx, item) in nav_items.into_library_owned_vec().into_iter().enumerate() {
951
98
            let (classes, mut part_style) = if idx == active_item {
952
13
                (
953
13
                    CLS_NAV_ITEM_ACTIVE,
954
13
                    merged_style(&part_nav_item, &part_nav_item_active),
955
13
                )
956
            } else {
957
85
                (CLS_NAV_ITEM, part_nav_item.clone())
958
            };
959
98
            if item.gap_before {
960
8
                part_style = merged_style(&part_style, &part_nav_item_gap);
961
90
            }
962
            // The nav item div is display:flex — a raw text run cannot be a
963
            // flex item (no anonymous-block wrapping in azul), so the label
964
            // gets its `<p>` per the label convention. Caught by `dom_lint`
965
            // on its very first run.
966
98
            let mut d = Dom::create_div()
967
98
                .with_ids_and_classes(IdOrClassVec::from_const_slice(classes))
968
98
                .with_css_props(part_style)
969
98
                .with_children(DomVec::from_vec(vec![crate::widgets::widget_p_with_text(
970
98
                    item.label,
971
                )]));
972
98
            if let Some(cb) = on_nav_select.as_ref() {
973
11
                d = d.with_callbacks(
974
11
                    vec![CoreCallbackData {
975
11
                        event: EventFilter::Hover(HoverEventFilter::Click),
976
11
                        callback: CoreCallback {
977
11
                            cb: on_backstage_nav_click as usize,
978
11
                            ctx: azul_core::refany::OptionRefAny::None,
979
11
                        },
980
11
                        refany: RefAny::new(NavClickData {
981
11
                            item_idx: idx,
982
11
                            on_nav_select: cb.clone(),
983
11
                        }),
984
11
                    }]
985
11
                    .into(),
986
11
                );
987
87
            }
988
98
            nav_children.push(d);
989
        }
990

            
991
13
        let nav = Dom::create_div()
992
13
            .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_NAV))
993
13
            .with_css_props(part_nav)
994
13
            .with_children(DomVec::from_vec(nav_children));
995

            
996
        // -- right side --
997
13
        let mut right_children: Vec<Dom> = Vec::with_capacity(2);
998
13
        if let Some(strip) = title_strip.into_option() {
999
1
            right_children.push(strip);
12
        }
13
        let pane = match content.into_option() {
            Some(c) => c,
13
            None => Dom::create_div(),
        };
13
        right_children.push(
13
            Dom::create_div()
13
                .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_CONTENT))
13
                .with_css_props(part_content)
13
                .with_children(DomVec::from_vec(vec![pane])),
        );
13
        let right = Dom::create_div()
13
            .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_RIGHT))
13
            .with_css_props(part_right)
13
            .with_children(DomVec::from_vec(right_children));
13
        let mut root = Dom::create_div()
13
            .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_BACKSTAGE))
13
            .with_css_props(part_root)
13
            .with_children(DomVec::from_vec(vec![nav, right]));
        // Escape leaves the backstage (window-level, focus-independent).
13
        if behavior.close_on_escape {
12
            if let Some(back) = on_back.into_option() {
1
                root = root.with_callbacks(
1
                    vec![CoreCallbackData {
1
                        event: EventFilter::Window(WindowEventFilter::VirtualKeyDown),
1
                        callback: CoreCallback {
1
                            cb: on_backstage_key_down as usize,
1
                            ctx: azul_core::refany::OptionRefAny::None,
1
                        },
1
                        refany: RefAny::new(EscCloseData { on_back: back }),
1
                    }]
1
                    .into(),
1
                );
11
            }
1
        }
13
        root
13
    }
}
impl Default for Backstage {
    fn default() -> Self {
        Self::office_2013()
    }
}
impl From<Backstage> for Dom {
    fn from(b: Backstage) -> Self {
        b.dom()
    }
}
21
fn merged_style(
21
    base: &CssPropertyWithConditionsVec,
21
    extra: &CssPropertyWithConditionsVec,
21
) -> CssPropertyWithConditionsVec {
21
    if extra.as_ref().is_empty() {
        return base.clone();
21
    }
21
    let mut v: Vec<Cond> = base.as_ref().to_vec();
21
    v.extend_from_slice(extra.as_ref());
21
    CssPropertyWithConditionsVec::from_vec(v)
21
}
// -- Nav-click / Escape plumbing --
/// Payload of one nav item: the item index plus the user's nav callback.
struct NavClickData {
    item_idx: usize,
    on_nav_select: BackstageOnNavSelect,
}
extern "C" fn on_backstage_nav_click(mut data: RefAny, info: CallbackInfo) -> Update {
    let Some(payload) = data.downcast_ref::<NavClickData>() else {
        return Update::DoNothing;
    };
    let idx = payload.item_idx;
    let cb = payload.on_nav_select.callback.cb;
    let refany = payload.on_nav_select.refany.clone();
    drop(payload);
    (cb)(refany, info, idx)
}
/// Payload of the window-level Escape handler: the user's back callback.
struct EscCloseData {
    on_back: ButtonOnClick,
}
extern "C" fn on_backstage_key_down(mut data: RefAny, info: CallbackInfo) -> Update {
    let Some(payload) = data.downcast_ref::<EscCloseData>() else {
        return Update::DoNothing;
    };
    let is_escape = matches!(
        info.get_current_keyboard_state()
            .current_virtual_keycode
            .into_option(),
        Some(VirtualKeyCode::Escape)
    );
    if !is_escape {
        return Update::DoNothing;
    }
    let cb = payload.on_back.callback.cb;
    let refany = payload.on_back.refany.clone();
    drop(payload);
    (cb)(refany, info)
}
#[cfg(test)]
mod tests {
    use super::*;
    extern "C" fn nav_cb(_: RefAny, _: CallbackInfo, _: usize) -> Update {
        Update::DoNothing
    }
    extern "C" fn back_cb(_: RefAny, _: CallbackInfo) -> Update {
        Update::DoNothing
    }
    #[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
        assert_eq!(
1
            BackstageTheme::from_system(sys.clone()),
1
            BackstageTheme::office_2013()
        );
1
        assert_eq!(
1
            BackstageStyle::from_system(sys),
1
            BackstageStyle::office_2013()
        );
1
    }
    #[test]
1
    fn from_system_separates_the_accent_nav_band_from_the_window_surface() {
1
        let accent = ColorU {
1
            r: 61,
1
            g: 174,
1
            b: 233,
1
            a: 255,
1
        };
1
        let surface = ColorU {
1
            r: 35,
1
            g: 38,
1
            b: 41,
1
            a: 255,
1
        };
1
        let mut sys = azul_css::system::SystemStyle::default();
1
        sys.colors = azul_css::system::SystemColors::default();
1
        sys.colors.accent = Some(accent).into();
1
        sys.colors.window_background = Some(surface).into();
1
        let t = BackstageTheme::from_system(sys);
1
        assert_eq!(t.nav_bg, accent, "the nav column is the accent band");
1
        assert_eq!(t.content_bg, surface, "the pane is the window surface");
1
        assert_ne!(
            t.nav_bg, t.content_bg,
            "a dark surface must not swallow the nav column"
        );
1
        assert_eq!(
            t.nav_text,
1
            BackstageTheme::office_2013().nav_text,
            "an unreported colour falls back to its OWN office value"
        );
1
    }
    // ------------------------------------------------------------------
    // Constructors and invariants
    // ------------------------------------------------------------------
    #[test]
1
    fn backstage_office_2013_has_eleven_items_with_account_gapped() {
1
        let b = Backstage::office_2013();
1
        assert_eq!(b.nav_items.len(), 11);
1
        assert_eq!(b.active_item, 0);
1
        let items = b.nav_items.as_slice();
1
        assert_eq!(items[0].label.as_str(), "Info");
1
        assert_eq!(items[8].label.as_str(), "Close");
1
        assert_eq!(items[9].label.as_str(), "Account");
1
        assert!(items[9].gap_before);
1
        assert_eq!(items[10].label.as_str(), "Options");
1
        assert!(!items[10].gap_before);
1
    }
    #[test]
1
    fn backstage_style_default_is_office_2013() {
1
        assert_eq!(BackstageStyle::default(), BackstageStyle::office_2013());
1
    }
    #[test]
1
    fn backstage_behavior_default_closes_on_escape() {
1
        assert_eq!(
1
            BackstageBehavior::default(),
1
            BackstageBehavior::office_2013()
        );
1
        assert!(BackstageBehavior::office_2013().close_on_escape);
1
        assert!(!BackstageBehavior::inert().close_on_escape);
1
    }
    // ------------------------------------------------------------------
    // DOM shape
    // ------------------------------------------------------------------
    #[test]
1
    fn dom_renders_nav_and_right_side() {
1
        let dom = Backstage::office_2013().dom();
1
        assert_eq!(dom.children.as_ref().len(), 2);
        // Nav: back button + 11 items.
1
        let nav = &dom.children.as_ref()[0];
1
        assert_eq!(nav.children.as_ref().len(), 12);
1
    }
    #[test]
1
    fn dom_places_the_title_strip_above_the_content() {
1
        let strip = Dom::create_div();
1
        let dom = Backstage::office_2013().with_title_strip(strip).dom();
1
        let right = &dom.children.as_ref()[1];
1
        assert_eq!(right.children.as_ref().len(), 2);
1
    }
    #[test]
1
    fn nav_items_get_click_callbacks_only_with_a_select_handler() {
        // Without a handler: inert items.
1
        let dom = Backstage::office_2013().dom();
1
        let nav = &dom.children.as_ref()[0];
11
        for item in nav.children.as_ref().iter().skip(1) {
11
            assert!(item.root.callbacks.as_ref().is_empty());
        }
        // With a handler: every item carries one.
1
        let dom = Backstage::office_2013()
1
            .with_on_nav_select(RefAny::new(()), nav_cb as BackstageOnNavSelectCallbackType)
1
            .dom();
1
        let nav = &dom.children.as_ref()[0];
11
        for item in nav.children.as_ref().iter().skip(1) {
11
            assert_eq!(item.root.callbacks.as_ref().len(), 1);
        }
1
    }
    #[test]
1
    fn escape_handler_is_attached_only_with_behavior_and_back_callback() {
        // Behavior on, no back callback: nothing to invoke, no handler.
1
        let dom = Backstage::office_2013().dom();
1
        assert!(dom.root.callbacks.as_ref().is_empty());
        // Behavior on + back callback: window-level key handler on the root.
1
        let dom = Backstage::office_2013()
1
            .with_on_back(
1
                RefAny::new(()),
1
                back_cb as super::super::button::ButtonOnClickCallbackType,
            )
1
            .dom();
1
        assert_eq!(dom.root.callbacks.as_ref().len(), 1);
1
        assert_eq!(
1
            dom.root.callbacks.as_ref()[0].event,
            EventFilter::Window(WindowEventFilter::VirtualKeyDown)
        );
        // Behavior off: no handler even with a back callback.
1
        let dom = Backstage::office_2013()
1
            .with_on_back(
1
                RefAny::new(()),
1
                back_cb as super::super::button::ButtonOnClickCallbackType,
            )
1
            .with_behavior(BackstageBehavior::inert())
1
            .dom();
1
        assert!(dom.root.callbacks.as_ref().is_empty());
1
    }
    #[test]
1
    fn active_item_gets_the_active_class() {
1
        let dom = Backstage::office_2013().with_active_item(2).dom();
1
        let nav = &dom.children.as_ref()[0];
        // Nav child 0 is the back button; item i is child i+1.
1
        let active = &nav.children.as_ref()[3];
1
        let classes = active.root.get_ids_and_classes();
2
        assert!(classes.as_ref().iter().any(|c| match c {
2
            Class(s) => s.as_str().contains("nav-item-active"),
            IdOrClass::Id(_) => false,
2
        }));
1
    }
}