1
//! Microsoft Office-style status bar widget (the Office-2013-era look look by default).
2
//!
3
//! Models the bottom chrome band of an Office document window:
4
//!
5
//! ```text
6
//! StatusBar ─ segments (left)             StatusBarSegment (icon? + label, clickable?)
7
//!           ─ filler
8
//!           ─ view switcher               StatusBarViewSwitcher (icon buttons, one active)
9
//!           ─ zoom cluster                StatusBarZoom (− button, slider, + button, "100%")
10
//! ```
11
//!
12
//! the Office-2013-era look reference (bottom of the window):
13
//! `PAGE 1 OF 1   0 WORDS   [spellcheck]  ENGLISH (UNITED STATES) …
14
//!  [read mode] [print layout] [web layout]   − ──────╂────── +  100%`
15
//!
16
//! Buttons are not re-implemented: the view-switcher buttons and the zoom
17
//! −/+ buttons expand to the existing [`super::button::Button`] widget with
18
//! status-bar part styles injected through `Button`'s public style fields
19
//! (the same composition rule the ribbon uses). The zoom slider embeds the
20
//! existing [`super::slider::Slider`] widget, restyled through its public
21
//! `track_style` / `thumb_style` fields, so dragging it reports values
22
//! through the regular [`super::slider::SliderOnValueChange`] callback.
23
//!
24
//! All visual parts are exposed on [`StatusBarStyle`] (defaults = the Office-2013-era look
25
//! look, [`StatusBarStyle::office_2013`]); replace any field to re-theme
26
//! without touching widget code. There is no behavior struct: the status bar
27
//! has no self-driven chrome interactions - every event is forwarded to the
28
//! application callbacks.
29

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

            
59
use super::{
60
    button::{Button, OptionButtonOnClick},
61
    slider::{OptionSliderOnValueChange, Slider},
62
    themes::flat,
63
};
64
use crate::callbacks::CallbackInfo;
65

            
66
// -- Callbacks --
67

            
68
/// Callback signature invoked when a view-switcher button is clicked
69
/// (receives the view index).
70
pub type StatusBarOnViewSelectCallbackType = extern "C" fn(RefAny, CallbackInfo, usize) -> Update;
71
impl_widget_callback!(
72
    StatusBarOnViewSelect,
73
    OptionStatusBarOnViewSelect,
74
    StatusBarOnViewSelectCallback,
75
    StatusBarOnViewSelectCallbackType
76
);
77

            
78
azul_core::impl_managed_callback! {
79
    wrapper:        StatusBarOnViewSelectCallback,
80
    info_ty:        CallbackInfo,
81
    return_ty:      Update,
82
    default_ret:    Update::DoNothing,
83
    invoker_static: STATUS_BAR_ON_VIEW_SELECT_INVOKER,
84
    invoker_ty:     AzStatusBarOnViewSelectCallbackInvoker,
85
    thunk_fn:       az_status_bar_on_view_select_callback_thunk,
86
    setter_fn:      AzApp_setStatusBarOnViewSelectCallbackInvoker,
87
    from_handle_fn: AzStatusBarOnViewSelectCallback_createFromHostHandle,
88
    extra_args:     [ view_index: usize ],
89
}
90

            
91
// -- Font --
92

            
93
const SYSTEM_UI_STR: AzString = AzString::from_const_str("system:ui");
94
const SYSTEM_UI_FAMILIES: &[StyleFontFamily] = &[StyleFontFamily::System(SYSTEM_UI_STR)];
95
const SYSTEM_UI_FAMILY: StyleFontFamilyVec =
96
    StyleFontFamilyVec::from_const_slice(SYSTEM_UI_FAMILIES);
97

            
98
// -- the Office-2013-era look palette (seeds StatusBarTheme::office_2013) --
99

            
100
const WHITE: ColorU = ColorU {
101
    r: 255,
102
    g: 255,
103
    b: 255,
104
    a: 255,
105
};
106
const TRANSPARENT: ColorU = ColorU {
107
    r: 0,
108
    g: 0,
109
    b: 0,
110
    a: 0,
111
};
112
/// Office 2013 accent blue (#2B579A): the bar fill.
113
const W13_BLUE: ColorU = ColorU {
114
    r: 43,
115
    g: 87,
116
    b: 154,
117
    a: 255,
118
};
119
/// Hover fill on bar controls (lighter blue, #3E6DB5).
120
const W13_BAR_HOVER: ColorU = ColorU {
121
    r: 62,
122
    g: 109,
123
    b: 181,
124
    a: 255,
125
};
126
/// Pressed / active-view fill (darker blue, #1E3E6F).
127
const W13_BAR_PRESSED: ColorU = ColorU {
128
    r: 30,
129
    g: 62,
130
    b: 111,
131
    a: 255,
132
};
133
/// Zoom slider rail (semi-light blue-gray, #A5BDDE).
134
const W13_RAIL: ColorU = ColorU {
135
    r: 165,
136
    g: 189,
137
    b: 222,
138
    a: 255,
139
};
140
/// Zoom slider thumb border (#8E9BB3).
141
const W13_THUMB_BORDER: ColorU = ColorU {
142
    r: 142,
143
    g: 155,
144
    b: 179,
145
    a: 255,
146
};
147

            
148
// -- Metrics (the Office-2013-era look, logical px) --
149

            
150
/// Bar height.
151
const BAR_HEIGHT: isize = 23;
152
/// Status text size.
153
const TEXT_PX: isize = 11;
154
/// View-switcher / zoom glyph size.
155
const ICON_PX: isize = 15;
156
/// Width of one view-switcher button.
157
const VIEW_BUTTON_W: isize = 29;
158
/// Width of the zoom −/+ buttons.
159
const ZOOM_BUTTON_W: isize = 21;
160
/// Total width of the zoom slider track.
161
const ZOOM_TRACK_W: isize = 100;
162
/// Zoom thumb size (office-2013: a small vertical bar).
163
const ZOOM_THUMB_W: isize = 6;
164
const ZOOM_THUMB_H: isize = 11;
165
/// Width reserved for the "100%" label.
166
const ZOOM_LABEL_W: isize = 42;
167

            
168
// -- Theme --
169

            
170
/// Color palette from which a full [`StatusBarStyle`] is derived via
171
/// [`StatusBarStyle::from_theme`]. All fields are plain colors, so themes
172
/// are trivially constructible over FFI. Preset: [`StatusBarTheme::office_2013`]
173
/// (the default).
174
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
175
#[repr(C)]
176
pub struct StatusBarTheme {
177
    /// Bar fill (office-2013: accent blue).
178
    pub bar_bg: ColorU,
179
    /// Text and glyph color on the bar.
180
    pub text: ColorU,
181
    /// Hover fill on clickable bar controls.
182
    pub hover_bg: ColorU,
183
    /// Pressed fill on bar controls.
184
    pub pressed_bg: ColorU,
185
    /// Fill of the active view-switcher button.
186
    pub view_active_bg: ColorU,
187
    /// Zoom slider rail line.
188
    pub rail: ColorU,
189
    /// Zoom slider thumb fill.
190
    pub thumb: ColorU,
191
    /// Zoom slider thumb border.
192
    pub thumb_border: ColorU,
193
}
194

            
195
impl StatusBarTheme {
196
    /// The the Office-2013-era look palette: #2B579A bar, white text, lighter-blue hovers.
197
    #[must_use]
198
77
    pub const fn office_2013() -> Self {
199
77
        Self {
200
77
            bar_bg: W13_BLUE,
201
77
            text: WHITE,
202
77
            hover_bg: W13_BAR_HOVER,
203
77
            pressed_bg: W13_BAR_PRESSED,
204
77
            view_active_bg: W13_BAR_PRESSED,
205
77
            rail: W13_RAIL,
206
77
            thumb: WHITE,
207
77
            thumb_border: W13_THUMB_BORDER,
208
77
        }
209
77
    }
210

            
211
    /// Extracts a bar palette from the OS theme.
212
    ///
213
    /// The status bar is an ACCENT-FILLED strip, so it is the accent colour
214
    /// and the colour the platform says goes on top of it that drive the
215
    /// whole palette - not the window background. A colour the platform does
216
    /// not report falls back to that field's own Office-2013 value, never to
217
    /// another derived value; same discipline as
218
    /// [`super::ribbon::RibbonTheme::from_system`], no colour arithmetic.
219
    ///
220
    /// Takes the style by value (FFI constructor convention).
221
    #[must_use]
222
3
    pub fn from_system(style: SystemStyle) -> Self {
223
3
        let d = Self::office_2013();
224
3
        let c = &style.colors;
225
3
        let selection = c.selection_background.into_option();
226
3
        let inactive_selection = c.selection_background_inactive.into_option();
227
3
        let on_accent = c.accent_text.into_option();
228
3
        let separator = c.separator.into_option();
229
3
        Self {
230
3
            bar_bg: c.accent.into_option().unwrap_or(d.bar_bg),
231
3
            text: on_accent.unwrap_or(d.text),
232
3
            hover_bg: selection.unwrap_or(d.hover_bg),
233
3
            pressed_bg: inactive_selection.unwrap_or(d.pressed_bg),
234
3
            view_active_bg: inactive_selection.unwrap_or(d.view_active_bg),
235
3
            rail: separator.unwrap_or(d.rail),
236
3
            thumb: on_accent.unwrap_or(d.thumb),
237
3
            thumb_border: separator.unwrap_or(d.thumb_border),
238
3
        }
239
3
    }
240
}
241

            
242
impl Default for StatusBarTheme {
243
    fn default() -> Self {
244
        Self::office_2013()
245
    }
246
}
247

            
248
// -- Theme -> property-list builders --
249
//
250
// Every themed status-bar part is built from `StatusBarTheme` colors by the
251
// functions below; `StatusBarStyle::office_2013()` is just
252
// `from_theme(StatusBarTheme::office_2013())`, so there is exactly one source
253
// of truth for each part's property list.
254

            
255
237
fn bg_vec(c: ColorU) -> StyleBackgroundContentVec {
256
237
    StyleBackgroundContentVec::from_vec(vec![StyleBackgroundContent::Color(c)])
257
237
}
258

            
259
235
fn cond_bg(c: ColorU) -> Cond {
260
235
    Cond::simple(P::const_background_content(bg_vec(c)))
261
235
}
262

            
263
220
const fn cond_text_color(c: ColorU) -> Cond {
264
220
    Cond::simple(P::const_text_color(StyleTextColor { inner: c }))
265
220
}
266

            
267
229
const fn cond_border_box() -> Cond {
268
229
    Cond::simple(P::const_box_sizing(LayoutBoxSizing::BorderBox))
269
229
}
270

            
271
226
fn push_row_center(v: &mut Vec<Cond>) {
272
226
    v.push(Cond::simple(P::const_display(LayoutDisplay::Flex)));
273
226
    v.push(Cond::simple(P::const_flex_direction(
274
226
        LayoutFlexDirection::Row,
275
    )));
276
226
    v.push(Cond::simple(P::const_align_items(LayoutAlignItems::Center)));
277
226
    v.push(Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(
278
        0,
279
    ))));
280
226
    v.push(Cond::simple(P::const_flex_shrink(LayoutFlexShrink {
281
226
        inner: FloatValue::const_new(0),
282
226
    })));
283
226
}
284

            
285
/// Transparent, hover-highlighted flat button chassis shared by every
286
/// clickable status-bar control. The explicit TRANSPARENT border overrides
287
/// the [`Button`] widget's default frame (the bar's controls are flat).
288
118
fn push_flat_button(v: &mut Vec<Cond>, t: &StatusBarTheme) {
289
118
    v.push(cond_border_box());
290
118
    v.push(Cond::simple(P::const_cursor(StyleCursor::Default)));
291
118
    v.push(Cond::simple(P::user_select(StyleUserSelect::None)));
292
118
    v.push(cond_bg(TRANSPARENT));
293
118
    push_box_border(v, TRANSPARENT);
294
    // Hover and pressed, light AND dark, built by the theme module so the pair
295
    // cannot be split: the dark half needs a palette this file cannot see, and
296
    // a rule written here could only ever name the light colour.
297
    //
298
    // The dark twins are the SAME colours, on purpose. The bar is an ACCENT
299
    // strip in either mode (`theme_bar` paints `bar_bg` with no dark variant;
300
    // `from_system` reads it from the desktop's accent), and both state fills
301
    // are shades of that accent — #3E6DB5 and #1E3E6F on the #2B579A bar in
302
    // the Office look. The theme's neutral `DARK_HT` / `DARK_PT` on a blue bar
303
    // would be worse than today's light-only rule; see
304
    // `themes::flat::hover_bg_both` for the rule, and `flat::button_states`
305
    // for the same call on a Primary button.
306
118
    v.extend(flat::hover_bg_both(t.hover_bg, t.hover_bg));
307
118
    v.extend(flat::active_bg_both(t.pressed_bg, t.pressed_bg));
308
118
}
309

            
310
/// 1px solid border on all four sides in the given color.
311
118
fn push_box_border(v: &mut Vec<Cond>, c: ColorU) {
312
118
    v.push(Cond::simple(P::const_border_top_width(
313
118
        LayoutBorderTopWidth::const_px(1),
314
    )));
315
118
    v.push(Cond::simple(P::const_border_left_width(
316
118
        LayoutBorderLeftWidth::const_px(1),
317
    )));
318
118
    v.push(Cond::simple(P::const_border_right_width(
319
118
        LayoutBorderRightWidth::const_px(1),
320
    )));
321
118
    v.push(Cond::simple(P::const_border_bottom_width(
322
118
        LayoutBorderBottomWidth::const_px(1),
323
    )));
324
118
    v.push(Cond::simple(P::const_border_top_style(
325
118
        StyleBorderTopStyle {
326
118
            inner: BorderStyle::Solid,
327
118
        },
328
    )));
329
118
    v.push(Cond::simple(P::const_border_left_style(
330
118
        StyleBorderLeftStyle {
331
118
            inner: BorderStyle::Solid,
332
118
        },
333
    )));
334
118
    v.push(Cond::simple(P::const_border_right_style(
335
118
        StyleBorderRightStyle {
336
118
            inner: BorderStyle::Solid,
337
118
        },
338
    )));
339
118
    v.push(Cond::simple(P::const_border_bottom_style(
340
118
        StyleBorderBottomStyle {
341
118
            inner: BorderStyle::Solid,
342
118
        },
343
    )));
344
118
    v.push(Cond::simple(P::const_border_top_color(
345
118
        StyleBorderTopColor { inner: c },
346
    )));
347
118
    v.push(Cond::simple(P::const_border_left_color(
348
118
        StyleBorderLeftColor { inner: c },
349
    )));
350
118
    v.push(Cond::simple(P::const_border_right_color(
351
118
        StyleBorderRightColor { inner: c },
352
    )));
353
118
    v.push(Cond::simple(P::const_border_bottom_color(
354
118
        StyleBorderBottomColor { inner: c },
355
    )));
356
118
}
357

            
358
102
fn theme_bar(t: &StatusBarTheme) -> CssPropertyWithConditionsVec {
359
102
    let mut v = Vec::new();
360
102
    push_row_center(&mut v);
361
102
    v.push(cond_border_box());
362
102
    v.push(Cond::simple(P::const_height(LayoutHeight::const_px(
363
        BAR_HEIGHT,
364
    ))));
365
102
    v.push(Cond::simple(P::const_font_family(SYSTEM_UI_FAMILY)));
366
102
    v.push(Cond::simple(P::const_font_size(StyleFontSize::const_px(
367
        TEXT_PX,
368
    ))));
369
102
    v.push(cond_bg(t.bar_bg));
370
102
    v.push(cond_text_color(t.text));
371
102
    v.push(Cond::simple(P::const_padding_left(
372
102
        LayoutPaddingLeft::const_px(6),
373
    )));
374
102
    v.push(Cond::simple(P::const_padding_right(
375
102
        LayoutPaddingRight::const_px(4),
376
    )));
377
102
    CssPropertyWithConditionsVec::from_vec(v)
378
102
}
379

            
380
101
fn theme_segment(t: &StatusBarTheme) -> CssPropertyWithConditionsVec {
381
101
    let mut v = Vec::new();
382
101
    push_row_center(&mut v);
383
101
    push_flat_button(&mut v, t);
384
101
    v.push(Cond::simple(P::const_height(LayoutHeight::const_px(
385
        BAR_HEIGHT,
386
    ))));
387
101
    v.push(Cond::simple(P::const_padding_left(
388
101
        LayoutPaddingLeft::const_px(7),
389
    )));
390
101
    v.push(Cond::simple(P::const_padding_right(
391
101
        LayoutPaddingRight::const_px(7),
392
    )));
393
101
    CssPropertyWithConditionsVec::from_vec(v)
394
101
}
395

            
396
fn theme_segment_icon(t: &StatusBarTheme) -> CssPropertyWithConditionsVec {
397
    CssPropertyWithConditionsVec::from_vec(vec![
398
        Cond::simple(P::const_font_size(StyleFontSize::const_px(ICON_PX - 1))),
399
        cond_text_color(t.text),
400
    ])
401
}
402

            
403
101
fn theme_segment_label(t: &StatusBarTheme) -> CssPropertyWithConditionsVec {
404
101
    CssPropertyWithConditionsVec::from_vec(vec![
405
101
        Cond::simple(P::const_font_size(StyleFontSize::const_px(TEXT_PX))),
406
101
        cond_text_color(t.text),
407
    ])
408
101
}
409

            
410
62
fn theme_filler(_t: &StatusBarTheme) -> CssPropertyWithConditionsVec {
411
62
    CssPropertyWithConditionsVec::from_vec(vec![Cond::simple(P::const_flex_grow(
412
62
        LayoutFlexGrow::const_new(1),
413
    ))])
414
62
}
415

            
416
3
fn theme_views(_t: &StatusBarTheme) -> CssPropertyWithConditionsVec {
417
3
    let mut v = Vec::new();
418
3
    push_row_center(&mut v);
419
3
    v.push(Cond::simple(P::const_margin_right(
420
3
        LayoutMarginRight::const_px(6),
421
    )));
422
3
    CssPropertyWithConditionsVec::from_vec(v)
423
3
}
424

            
425
9
fn theme_view_button(t: &StatusBarTheme) -> CssPropertyWithConditionsVec {
426
9
    let mut v = Vec::new();
427
9
    push_row_center(&mut v);
428
9
    push_flat_button(&mut v, t);
429
9
    v.push(Cond::simple(P::const_justify_content(
430
9
        LayoutJustifyContent::Center,
431
    )));
432
9
    v.push(Cond::simple(P::const_width(LayoutWidth::const_px(
433
        VIEW_BUTTON_W,
434
    ))));
435
9
    v.push(Cond::simple(P::const_height(LayoutHeight::const_px(
436
        BAR_HEIGHT,
437
    ))));
438
9
    CssPropertyWithConditionsVec::from_vec(v)
439
9
}
440

            
441
/// APPENDED to the active view-switcher button.
442
///
443
/// `active` is deliberately not the LAST word of the name: a name ending in
444
/// `button_active` ends, textually, in the name of the pressed-state
445
/// constructor, and `scripts/check_widget_theme_migration.py` counts such
446
/// calls in this file.
447
3
fn theme_active_view_button(t: &StatusBarTheme) -> CssPropertyWithConditionsVec {
448
3
    CssPropertyWithConditionsVec::from_vec(vec![cond_bg(t.view_active_bg)])
449
3
}
450

            
451
9
fn theme_view_icon(t: &StatusBarTheme) -> CssPropertyWithConditionsVec {
452
9
    CssPropertyWithConditionsVec::from_vec(vec![
453
9
        Cond::simple(P::const_font_size(StyleFontSize::const_px(ICON_PX))),
454
9
        cond_text_color(t.text),
455
    ])
456
9
}
457

            
458
3
fn theme_zoom(_t: &StatusBarTheme) -> CssPropertyWithConditionsVec {
459
3
    let mut v = Vec::new();
460
3
    push_row_center(&mut v);
461
3
    CssPropertyWithConditionsVec::from_vec(v)
462
3
}
463

            
464
6
fn theme_zoom_button(t: &StatusBarTheme) -> CssPropertyWithConditionsVec {
465
6
    let mut v = Vec::new();
466
6
    push_row_center(&mut v);
467
6
    push_flat_button(&mut v, t);
468
6
    v.push(Cond::simple(P::const_justify_content(
469
6
        LayoutJustifyContent::Center,
470
    )));
471
6
    v.push(Cond::simple(P::const_width(LayoutWidth::const_px(
472
        ZOOM_BUTTON_W,
473
    ))));
474
6
    v.push(Cond::simple(P::const_height(LayoutHeight::const_px(
475
        BAR_HEIGHT,
476
    ))));
477
6
    CssPropertyWithConditionsVec::from_vec(v)
478
6
}
479

            
480
6
fn theme_zoom_icon(t: &StatusBarTheme) -> CssPropertyWithConditionsVec {
481
6
    CssPropertyWithConditionsVec::from_vec(vec![
482
6
        Cond::simple(P::const_font_size(StyleFontSize::const_px(ICON_PX - 2))),
483
6
        cond_text_color(t.text),
484
    ])
485
6
}
486

            
487
/// Positioning context for the rail line, the center tick and the slider.
488
3
fn theme_zoom_track_host(_t: &StatusBarTheme) -> CssPropertyWithConditionsVec {
489
3
    CssPropertyWithConditionsVec::from_vec(vec![
490
3
        cond_border_box(),
491
3
        Cond::simple(P::const_position(LayoutPosition::Relative)),
492
3
        Cond::simple(P::const_display(LayoutDisplay::Flex)),
493
3
        Cond::simple(P::const_flex_direction(LayoutFlexDirection::Row)),
494
3
        Cond::simple(P::const_align_items(LayoutAlignItems::Center)),
495
3
        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(0))),
496
3
        Cond::simple(P::const_width(LayoutWidth::const_px(ZOOM_TRACK_W))),
497
3
        Cond::simple(P::const_height(LayoutHeight::const_px(BAR_HEIGHT))),
498
    ])
499
3
}
500

            
501
/// The 1px horizontal rail line behind the slider.
502
3
fn theme_zoom_rail(t: &StatusBarTheme) -> CssPropertyWithConditionsVec {
503
3
    CssPropertyWithConditionsVec::from_vec(vec![
504
3
        Cond::simple(P::const_position(LayoutPosition::Absolute)),
505
3
        Cond::simple(P::const_left(LayoutLeft::const_px(0))),
506
3
        Cond::simple(P::const_top(LayoutTop::const_px(BAR_HEIGHT / 2))),
507
3
        Cond::simple(P::const_width(LayoutWidth::const_px(ZOOM_TRACK_W))),
508
3
        Cond::simple(P::const_height(LayoutHeight::const_px(1))),
509
3
        cond_bg(t.rail),
510
    ])
511
3
}
512

            
513
/// The small vertical tick marking the 100% center of the rail.
514
3
fn theme_zoom_tick(t: &StatusBarTheme) -> CssPropertyWithConditionsVec {
515
3
    CssPropertyWithConditionsVec::from_vec(vec![
516
3
        Cond::simple(P::const_position(LayoutPosition::Absolute)),
517
3
        Cond::simple(P::const_left(LayoutLeft::const_px(ZOOM_TRACK_W / 2))),
518
3
        Cond::simple(P::const_top(LayoutTop::const_px(BAR_HEIGHT / 2 - 3))),
519
3
        Cond::simple(P::const_width(LayoutWidth::const_px(1))),
520
3
        Cond::simple(P::const_height(LayoutHeight::const_px(7))),
521
3
        cond_bg(t.rail),
522
    ])
523
3
}
524

            
525
/// Injected into the embedded [`Slider`]'s `track_style`: a transparent
526
/// full-height hit area (the visible rail is drawn by the host).
527
3
fn theme_slider_track(_t: &StatusBarTheme) -> CssPropertyWithConditionsVec {
528
3
    CssPropertyWithConditionsVec::from_vec(vec![
529
3
        cond_border_box(),
530
3
        Cond::simple(P::const_display(LayoutDisplay::Flex)),
531
3
        Cond::simple(P::const_flex_direction(LayoutFlexDirection::Row)),
532
3
        Cond::simple(P::const_align_items(LayoutAlignItems::Center)),
533
3
        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(0))),
534
3
        Cond::simple(P::const_width(LayoutWidth::const_px(ZOOM_TRACK_W))),
535
3
        Cond::simple(P::const_height(LayoutHeight::const_px(BAR_HEIGHT))),
536
3
        cond_bg(TRANSPARENT),
537
3
        Cond::simple(P::const_cursor(StyleCursor::Default)),
538
    ])
539
3
}
540

            
541
/// Injected into the embedded [`Slider`]'s `thumb_style` (position-independent
542
/// part; `StatusBar::dom` appends the `margin-left` computed from the zoom
543
/// percent).
544
3
fn theme_slider_thumb(t: &StatusBarTheme) -> CssPropertyWithConditionsVec {
545
3
    let mut v = vec![
546
3
        cond_border_box(),
547
3
        Cond::simple(P::const_width(LayoutWidth::const_px(ZOOM_THUMB_W))),
548
3
        Cond::simple(P::const_height(LayoutHeight::const_px(ZOOM_THUMB_H))),
549
3
        Cond::simple(P::const_flex_grow(LayoutFlexGrow::const_new(0))),
550
3
        cond_bg(t.thumb),
551
    ];
552
3
    v.push(Cond::simple(P::const_border_top_width(
553
3
        LayoutBorderTopWidth::const_px(1),
554
    )));
555
3
    v.push(Cond::simple(P::const_border_left_width(
556
3
        LayoutBorderLeftWidth::const_px(1),
557
    )));
558
3
    v.push(Cond::simple(P::const_border_right_width(
559
3
        LayoutBorderRightWidth::const_px(1),
560
    )));
561
3
    v.push(Cond::simple(P::const_border_bottom_width(
562
3
        LayoutBorderBottomWidth::const_px(1),
563
    )));
564
3
    v.push(Cond::simple(P::const_border_top_style(
565
3
        StyleBorderTopStyle {
566
3
            inner: BorderStyle::Solid,
567
3
        },
568
    )));
569
3
    v.push(Cond::simple(P::const_border_left_style(
570
3
        StyleBorderLeftStyle {
571
3
            inner: BorderStyle::Solid,
572
3
        },
573
    )));
574
3
    v.push(Cond::simple(P::const_border_right_style(
575
3
        StyleBorderRightStyle {
576
3
            inner: BorderStyle::Solid,
577
3
        },
578
    )));
579
3
    v.push(Cond::simple(P::const_border_bottom_style(
580
3
        StyleBorderBottomStyle {
581
3
            inner: BorderStyle::Solid,
582
3
        },
583
    )));
584
3
    v.push(Cond::simple(P::const_border_top_color(
585
3
        StyleBorderTopColor {
586
3
            inner: t.thumb_border,
587
3
        },
588
    )));
589
3
    v.push(Cond::simple(P::const_border_left_color(
590
3
        StyleBorderLeftColor {
591
3
            inner: t.thumb_border,
592
3
        },
593
    )));
594
3
    v.push(Cond::simple(P::const_border_right_color(
595
3
        StyleBorderRightColor {
596
3
            inner: t.thumb_border,
597
3
        },
598
    )));
599
3
    v.push(Cond::simple(P::const_border_bottom_color(
600
3
        StyleBorderBottomColor {
601
3
            inner: t.thumb_border,
602
3
        },
603
    )));
604
3
    CssPropertyWithConditionsVec::from_vec(v)
605
3
}
606

            
607
2
fn theme_zoom_label(t: &StatusBarTheme) -> CssPropertyWithConditionsVec {
608
2
    let mut v = Vec::new();
609
2
    push_row_center(&mut v);
610
2
    push_flat_button(&mut v, t);
611
2
    v.push(Cond::simple(P::const_justify_content(
612
2
        LayoutJustifyContent::End,
613
    )));
614
2
    v.push(Cond::simple(P::const_width(LayoutWidth::const_px(
615
        ZOOM_LABEL_W,
616
    ))));
617
2
    v.push(Cond::simple(P::const_height(LayoutHeight::const_px(
618
        BAR_HEIGHT,
619
    ))));
620
2
    v.push(Cond::simple(P::const_padding_right(
621
2
        LayoutPaddingRight::const_px(6),
622
    )));
623
2
    v.push(Cond::simple(P::const_font_size(StyleFontSize::const_px(
624
        TEXT_PX,
625
    ))));
626
2
    v.push(cond_text_color(t.text));
627
2
    CssPropertyWithConditionsVec::from_vec(v)
628
2
}
629

            
630
// -- Style --
631

            
632
/// All part styles of the status bar. Every part defaults to the the Office-2013-era look
633
/// look; replace any field for finer control (the same override API as
634
/// [`super::ribbon::RibbonStyle`]).
635
#[derive(Debug, Clone, PartialEq, Eq)]
636
#[repr(C)]
637
pub struct StatusBarStyle {
638
    /// The palette this style bundle was derived from. Kept for consumers
639
    /// deriving matching custom parts.
640
    pub theme: StatusBarTheme,
641
    /// The bar itself (horizontal row).
642
    ///
643
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
644
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
645
    /// a real answer — "no properties at all" — which the pre-filled field could
646
    /// not express.
647
    pub bar_style: OptionCssPropertyWithConditionsVec,
648
    /// One left-hand segment (page count, word count, language, …).
649
    ///
650
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
651
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
652
    /// a real answer — "no properties at all" — which the pre-filled field could
653
    /// not express.
654
    pub segment_style: OptionCssPropertyWithConditionsVec,
655
    /// Icon inside a segment.
656
    ///
657
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
658
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
659
    /// a real answer — "no properties at all" — which the pre-filled field could
660
    /// not express.
661
    pub segment_icon_style: OptionCssPropertyWithConditionsVec,
662
    /// Text label inside a segment.
663
    ///
664
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
665
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
666
    /// a real answer — "no properties at all" — which the pre-filled field could
667
    /// not express.
668
    pub segment_label_style: OptionCssPropertyWithConditionsVec,
669
    /// Flexible spacer between the left segments and the right clusters.
670
    ///
671
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
672
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
673
    /// a real answer — "no properties at all" — which the pre-filled field could
674
    /// not express.
675
    pub filler_style: OptionCssPropertyWithConditionsVec,
676
    /// The view-switcher cluster.
677
    ///
678
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
679
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
680
    /// a real answer — "no properties at all" — which the pre-filled field could
681
    /// not express.
682
    pub views_style: OptionCssPropertyWithConditionsVec,
683
    /// Container style injected into one view-switcher [`Button`].
684
    ///
685
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
686
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
687
    /// a real answer — "no properties at all" — which the pre-filled field could
688
    /// not express.
689
    pub view_button_style: OptionCssPropertyWithConditionsVec,
690
    /// APPENDED to the active view-switcher button.
691
    ///
692
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
693
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
694
    /// a real answer — "no properties at all" — which the pre-filled field could
695
    /// not express.
696
    pub view_button_active_style: OptionCssPropertyWithConditionsVec,
697
    /// Icon style injected into the view-switcher [`Button`]s.
698
    ///
699
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
700
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
701
    /// a real answer — "no properties at all" — which the pre-filled field could
702
    /// not express.
703
    pub view_icon_style: OptionCssPropertyWithConditionsVec,
704
    /// The zoom cluster (− slider + label).
705
    ///
706
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
707
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
708
    /// a real answer — "no properties at all" — which the pre-filled field could
709
    /// not express.
710
    pub zoom_style: OptionCssPropertyWithConditionsVec,
711
    /// Container style injected into the zoom −/+ [`Button`]s.
712
    ///
713
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
714
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
715
    /// a real answer — "no properties at all" — which the pre-filled field could
716
    /// not express.
717
    pub zoom_button_style: OptionCssPropertyWithConditionsVec,
718
    /// Icon style injected into the zoom −/+ [`Button`]s.
719
    ///
720
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
721
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
722
    /// a real answer — "no properties at all" — which the pre-filled field could
723
    /// not express.
724
    pub zoom_icon_style: OptionCssPropertyWithConditionsVec,
725
    /// Positioning host around the rail, tick and embedded slider.
726
    ///
727
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
728
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
729
    /// a real answer — "no properties at all" — which the pre-filled field could
730
    /// not express.
731
    pub zoom_track_host_style: OptionCssPropertyWithConditionsVec,
732
    /// The 1px rail line.
733
    ///
734
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
735
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
736
    /// a real answer — "no properties at all" — which the pre-filled field could
737
    /// not express.
738
    pub zoom_rail_style: OptionCssPropertyWithConditionsVec,
739
    /// The center (100%) tick on the rail.
740
    ///
741
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
742
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
743
    /// a real answer — "no properties at all" — which the pre-filled field could
744
    /// not express.
745
    pub zoom_tick_style: OptionCssPropertyWithConditionsVec,
746
    /// Track style injected into the embedded [`Slider`].
747
    ///
748
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
749
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
750
    /// a real answer — "no properties at all" — which the pre-filled field could
751
    /// not express.
752
    pub slider_track_style: OptionCssPropertyWithConditionsVec,
753
    /// Thumb style injected into the embedded [`Slider`] (without the
754
    /// position; `dom()` appends the computed `margin-left`).
755
    ///
756
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
757
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
758
    /// a real answer — "no properties at all" — which the pre-filled field could
759
    /// not express.
760
    pub slider_thumb_style: OptionCssPropertyWithConditionsVec,
761
    /// The "100%" zoom percent label.
762
    ///
763
    /// `None` means "no opinion": the part is derived from [`Self::theme`] at
764
    /// render time. `Some` is an override the caller chose, and `Some(empty)` is
765
    /// a real answer — "no properties at all" — which the pre-filled field could
766
    /// not express.
767
    pub zoom_label_style: OptionCssPropertyWithConditionsVec,
768
}
769

            
770
impl StatusBarStyle {
771
    /// The the Office-2013-era look look (#2B579A bar, white text) - the default.
772
    #[must_use]
773
26
    pub const fn office_2013() -> Self {
774
26
        Self::from_theme(StatusBarTheme::office_2013())
775
26
    }
776

            
777
    /// Every part style, derived from the OS theme - see
778
    /// [`StatusBarTheme::from_system`]. Takes the style by value (FFI
779
    /// constructor convention).
780
    #[must_use]
781
1
    pub fn from_system(style: SystemStyle) -> Self {
782
1
        Self::from_theme(StatusBarTheme::from_system(style))
783
1
    }
784

            
785
    /// Derives every part style from the given palette.
786
    #[must_use]
787
72
    pub const fn from_theme(theme: StatusBarTheme) -> Self {
788
72
        Self {
789
72
            theme,
790
72
            bar_style: OptionCssPropertyWithConditionsVec::None,
791
72
            segment_style: OptionCssPropertyWithConditionsVec::None,
792
72
            segment_icon_style: OptionCssPropertyWithConditionsVec::None,
793
72
            segment_label_style: OptionCssPropertyWithConditionsVec::None,
794
72
            filler_style: OptionCssPropertyWithConditionsVec::None,
795
72
            views_style: OptionCssPropertyWithConditionsVec::None,
796
72
            view_button_style: OptionCssPropertyWithConditionsVec::None,
797
72
            view_button_active_style: OptionCssPropertyWithConditionsVec::None,
798
72
            view_icon_style: OptionCssPropertyWithConditionsVec::None,
799
72
            zoom_style: OptionCssPropertyWithConditionsVec::None,
800
72
            zoom_button_style: OptionCssPropertyWithConditionsVec::None,
801
72
            zoom_icon_style: OptionCssPropertyWithConditionsVec::None,
802
72
            zoom_track_host_style: OptionCssPropertyWithConditionsVec::None,
803
72
            zoom_rail_style: OptionCssPropertyWithConditionsVec::None,
804
72
            zoom_tick_style: OptionCssPropertyWithConditionsVec::None,
805
72
            slider_track_style: OptionCssPropertyWithConditionsVec::None,
806
72
            slider_thumb_style: OptionCssPropertyWithConditionsVec::None,
807
72
            zoom_label_style: OptionCssPropertyWithConditionsVec::None,
808
72
        }
809
72
    }
810

            
811
    /// The `bar_style` this bundle renders with: the caller's override if there is one,
812
    /// else derived from [`Self::theme`].
813
    #[must_use]
814
102
    pub fn resolved_bar_style(&self) -> CssPropertyWithConditionsVec {
815
102
        self.bar_style
816
102
            .clone()
817
102
            .into_option()
818
102
            .unwrap_or_else(|| theme_bar(&self.theme))
819
102
    }
820

            
821
    /// The `segment_style` this bundle renders with: the caller's override if there is one,
822
    /// else derived from [`Self::theme`].
823
    #[must_use]
824
101
    pub fn resolved_segment_style(&self) -> CssPropertyWithConditionsVec {
825
101
        self.segment_style
826
101
            .clone()
827
101
            .into_option()
828
101
            .unwrap_or_else(|| theme_segment(&self.theme))
829
101
    }
830

            
831
    /// The `segment_icon_style` this bundle renders with: the caller's override if there is one,
832
    /// else derived from [`Self::theme`].
833
    #[must_use]
834
    pub fn resolved_segment_icon_style(&self) -> CssPropertyWithConditionsVec {
835
        self.segment_icon_style
836
            .clone()
837
            .into_option()
838
            .unwrap_or_else(|| theme_segment_icon(&self.theme))
839
    }
840

            
841
    /// The `segment_label_style` this bundle renders with: the caller's override if there is one,
842
    /// else derived from [`Self::theme`].
843
    #[must_use]
844
101
    pub fn resolved_segment_label_style(&self) -> CssPropertyWithConditionsVec {
845
101
        self.segment_label_style
846
101
            .clone()
847
101
            .into_option()
848
101
            .unwrap_or_else(|| theme_segment_label(&self.theme))
849
101
    }
850

            
851
    /// The `filler_style` this bundle renders with: the caller's override if there is one,
852
    /// else derived from [`Self::theme`].
853
    #[must_use]
854
62
    pub fn resolved_filler_style(&self) -> CssPropertyWithConditionsVec {
855
62
        self.filler_style
856
62
            .clone()
857
62
            .into_option()
858
62
            .unwrap_or_else(|| theme_filler(&self.theme))
859
62
    }
860

            
861
    /// The `views_style` this bundle renders with: the caller's override if there is one,
862
    /// else derived from [`Self::theme`].
863
    #[must_use]
864
3
    pub fn resolved_views_style(&self) -> CssPropertyWithConditionsVec {
865
3
        self.views_style
866
3
            .clone()
867
3
            .into_option()
868
3
            .unwrap_or_else(|| theme_views(&self.theme))
869
3
    }
870

            
871
    /// The `view_button_style` this bundle renders with: the caller's override if there is one,
872
    /// else derived from [`Self::theme`].
873
    #[must_use]
874
9
    pub fn resolved_view_button_style(&self) -> CssPropertyWithConditionsVec {
875
9
        self.view_button_style
876
9
            .clone()
877
9
            .into_option()
878
9
            .unwrap_or_else(|| theme_view_button(&self.theme))
879
9
    }
880

            
881
    /// The `view_button_active_style` this bundle renders with: the caller's override if there is
882
    /// one, else derived from [`Self::theme`].
883
    #[must_use]
884
3
    pub fn resolved_view_button_active_style(&self) -> CssPropertyWithConditionsVec {
885
3
        self.view_button_active_style
886
3
            .clone()
887
3
            .into_option()
888
3
            .unwrap_or_else(|| theme_active_view_button(&self.theme))
889
3
    }
890

            
891
    /// The `view_icon_style` this bundle renders with: the caller's override if there is one,
892
    /// else derived from [`Self::theme`].
893
    #[must_use]
894
9
    pub fn resolved_view_icon_style(&self) -> CssPropertyWithConditionsVec {
895
9
        self.view_icon_style
896
9
            .clone()
897
9
            .into_option()
898
9
            .unwrap_or_else(|| theme_view_icon(&self.theme))
899
9
    }
900

            
901
    /// The `zoom_style` this bundle renders with: the caller's override if there is one,
902
    /// else derived from [`Self::theme`].
903
    #[must_use]
904
3
    pub fn resolved_zoom_style(&self) -> CssPropertyWithConditionsVec {
905
3
        self.zoom_style
906
3
            .clone()
907
3
            .into_option()
908
3
            .unwrap_or_else(|| theme_zoom(&self.theme))
909
3
    }
910

            
911
    /// The `zoom_button_style` this bundle renders with: the caller's override if there is one,
912
    /// else derived from [`Self::theme`].
913
    #[must_use]
914
6
    pub fn resolved_zoom_button_style(&self) -> CssPropertyWithConditionsVec {
915
6
        self.zoom_button_style
916
6
            .clone()
917
6
            .into_option()
918
6
            .unwrap_or_else(|| theme_zoom_button(&self.theme))
919
6
    }
920

            
921
    /// The `zoom_icon_style` this bundle renders with: the caller's override if there is one,
922
    /// else derived from [`Self::theme`].
923
    #[must_use]
924
6
    pub fn resolved_zoom_icon_style(&self) -> CssPropertyWithConditionsVec {
925
6
        self.zoom_icon_style
926
6
            .clone()
927
6
            .into_option()
928
6
            .unwrap_or_else(|| theme_zoom_icon(&self.theme))
929
6
    }
930

            
931
    /// The `zoom_track_host_style` this bundle renders with: the caller's override if there is one,
932
    /// else derived from [`Self::theme`].
933
    #[must_use]
934
3
    pub fn resolved_zoom_track_host_style(&self) -> CssPropertyWithConditionsVec {
935
3
        self.zoom_track_host_style
936
3
            .clone()
937
3
            .into_option()
938
3
            .unwrap_or_else(|| theme_zoom_track_host(&self.theme))
939
3
    }
940

            
941
    /// The `zoom_rail_style` this bundle renders with: the caller's override if there is one,
942
    /// else derived from [`Self::theme`].
943
    #[must_use]
944
3
    pub fn resolved_zoom_rail_style(&self) -> CssPropertyWithConditionsVec {
945
3
        self.zoom_rail_style
946
3
            .clone()
947
3
            .into_option()
948
3
            .unwrap_or_else(|| theme_zoom_rail(&self.theme))
949
3
    }
950

            
951
    /// The `zoom_tick_style` this bundle renders with: the caller's override if there is one,
952
    /// else derived from [`Self::theme`].
953
    #[must_use]
954
3
    pub fn resolved_zoom_tick_style(&self) -> CssPropertyWithConditionsVec {
955
3
        self.zoom_tick_style
956
3
            .clone()
957
3
            .into_option()
958
3
            .unwrap_or_else(|| theme_zoom_tick(&self.theme))
959
3
    }
960

            
961
    /// The `slider_track_style` this bundle renders with: the caller's override if there is one,
962
    /// else derived from [`Self::theme`].
963
    #[must_use]
964
3
    pub fn resolved_slider_track_style(&self) -> CssPropertyWithConditionsVec {
965
3
        self.slider_track_style
966
3
            .clone()
967
3
            .into_option()
968
3
            .unwrap_or_else(|| theme_slider_track(&self.theme))
969
3
    }
970

            
971
    /// The `slider_thumb_style` this bundle renders with: the caller's override if there is one,
972
    /// else derived from [`Self::theme`].
973
    #[must_use]
974
3
    pub fn resolved_slider_thumb_style(&self) -> CssPropertyWithConditionsVec {
975
3
        self.slider_thumb_style
976
3
            .clone()
977
3
            .into_option()
978
3
            .unwrap_or_else(|| theme_slider_thumb(&self.theme))
979
3
    }
980

            
981
    /// The `zoom_label_style` this bundle renders with: the caller's override if there is one,
982
    /// else derived from [`Self::theme`].
983
    #[must_use]
984
2
    pub fn resolved_zoom_label_style(&self) -> CssPropertyWithConditionsVec {
985
2
        self.zoom_label_style
986
2
            .clone()
987
2
            .into_option()
988
2
            .unwrap_or_else(|| theme_zoom_label(&self.theme))
989
2
    }
990
}
991

            
992
impl Default for StatusBarStyle {
993
1
    fn default() -> Self {
994
1
        Self::office_2013()
995
1
    }
996
}
997

            
998
// -- Data model --
999

            
/// One left-hand status segment ("PAGE 1 OF 1", "0 WORDS", the language, …).
///
/// An empty `icon` means "no icon". With an `on_click` the segment renders
/// as a flat hover-highlighted button (office-2013: the segments open panes /
/// toggle counters); without one it is inert text.
#[derive(Debug, Clone, PartialEq, Eq)]
#[repr(C)]
pub struct StatusBarSegment {
    /// Optional leading icon name, resolved through the registered icon
    /// provider (e.g. the builtin Material Icons pack: "spellcheck").
    pub icon: AzString,
    /// The segment text.
    pub label: AzString,
    /// Optional click handler.
    pub on_click: OptionButtonOnClick,
    /// Optional marker (`Dom::with_marker`) that makes an INERT text segment
    /// live-updatable: the label becomes a `VirtualView` whose node carries
    /// this marker, so a callback anywhere can find it by
    /// `CallbackInfo::get_node_id_by_marker` and rewrite the text with
    /// [`StatusBar::update_segment_label`] - without a `RefreshDom`, a DOM
    /// diff, or a round trip through the app's data model. Empty = plain
    /// static text. Ignored for icon / clickable segments (those are buttons).
    pub marker: AzString,
}
impl StatusBarSegment {
    /// Creates a text-only, inert segment.
    #[must_use]
24
    pub fn new(label: AzString) -> Self {
24
        Self {
24
            icon: AzString::from_const_str(""),
24
            label,
24
            on_click: None.into(),
24
            marker: AzString::from_const_str(""),
24
        }
24
    }
    /// Builder method: sets the leading icon name.
    #[must_use]
    pub fn with_icon(mut self, icon: AzString) -> Self {
        self.icon = icon;
        self
    }
    /// Builder method: marks the segment for live label updates (see the
    /// `marker` field). Use a unique string - a `Uuid::short()` the app keeps
    /// in its state is the intended shape - so two bars never collide.
    #[must_use]
40
    pub fn with_marker(mut self, marker: AzString) -> Self {
40
        self.marker = marker;
40
        self
40
    }
    /// Sets the click callback.
    pub fn set_on_click<C: Into<super::button::ButtonOnClickCallback>>(
        &mut self,
        data: RefAny,
        on_click: C,
    ) {
        self.on_click = Some(super::button::ButtonOnClick {
            refany: data,
            callback: on_click.into(),
        })
        .into();
    }
    /// Builder method: sets the click callback and returns `self`.
    #[must_use]
    pub fn with_on_click<C: Into<super::button::ButtonOnClickCallback>>(
        mut self,
        data: RefAny,
        on_click: C,
    ) -> Self {
        self.set_on_click(data, on_click);
        self
    }
}
impl_option!(
    StatusBarSegment,
    OptionStatusBarSegment,
    copy = false,
    [Debug, Clone, PartialEq]
);
impl_vec!(
    StatusBarSegment,
    StatusBarSegmentVec,
    StatusBarSegmentVecDestructor,
    StatusBarSegmentVecDestructorType,
    StatusBarSegmentVecSlice,
    OptionStatusBarSegment
);
impl_vec_clone!(
    StatusBarSegment,
    StatusBarSegmentVec,
    StatusBarSegmentVecDestructor
);
impl_vec_debug!(StatusBarSegment, StatusBarSegmentVec);
impl_vec_mut!(StatusBarSegment, StatusBarSegmentVec);
/// One view-switcher button (office-2013: read mode / print layout / web layout).
#[derive(Debug, Clone, PartialEq, Eq)]
#[repr(C)]
pub struct StatusBarView {
    /// Icon name, resolved through the registered icon provider.
    pub icon: AzString,
}
impl StatusBarView {
    /// Creates a view button with the given icon name.
    #[must_use]
12
    pub const fn new(icon: AzString) -> Self {
12
        Self { icon }
12
    }
}
impl_option!(
    StatusBarView,
    OptionStatusBarView,
    copy = false,
    [Debug, Clone, PartialEq]
);
impl_vec!(
    StatusBarView,
    StatusBarViewVec,
    StatusBarViewVecDestructor,
    StatusBarViewVecDestructorType,
    StatusBarViewVecSlice,
    OptionStatusBarView
);
impl_vec_clone!(StatusBarView, StatusBarViewVec, StatusBarViewVecDestructor);
impl_vec_debug!(StatusBarView, StatusBarViewVec);
impl_vec_mut!(StatusBarView, StatusBarViewVec);
/// The view-switcher cluster: a row of icon buttons with one active view.
#[derive(Debug, Clone)]
#[repr(C)]
pub struct StatusBarViewSwitcher {
    /// The view buttons, left to right.
    pub views: StatusBarViewVec,
    /// Index of the active view (highlighted).
    pub active_view: usize,
    /// Optional callback fired when a view is clicked (receives the index).
    pub on_select: OptionStatusBarOnViewSelect,
}
impl StatusBarViewSwitcher {
    /// Creates a view switcher with the given views; view 0 is active.
    #[must_use]
    pub fn new(views: StatusBarViewVec) -> Self {
        Self {
            views,
            active_view: 0,
            on_select: None.into(),
        }
    }
    /// The the Office-2013-era look trio: read mode, print layout (active), web layout.
    #[must_use]
4
    pub fn office_2013() -> Self {
4
        let views = StatusBarViewVec::from_vec(vec![
4
            StatusBarView::new(AzString::from_const_str("menu_book")),
4
            StatusBarView::new(AzString::from_const_str("description")),
4
            StatusBarView::new(AzString::from_const_str("public")),
        ]);
4
        Self {
4
            views,
4
            active_view: 1,
4
            on_select: None.into(),
4
        }
4
    }
    /// Builder method: sets the active view index.
    #[must_use]
    pub const fn with_active_view(mut self, active_view: usize) -> Self {
        self.active_view = active_view;
        self
    }
    /// Sets the view-select callback.
1
    pub fn set_on_select<C: Into<StatusBarOnViewSelectCallback>>(
1
        &mut self,
1
        data: RefAny,
1
        on_select: C,
1
    ) {
1
        self.on_select = Some(StatusBarOnViewSelect {
1
            refany: data,
1
            callback: on_select.into(),
1
        })
1
        .into();
1
    }
    /// Builder method: sets the view-select callback and returns `self`.
    #[must_use]
    pub fn with_on_select<C: Into<StatusBarOnViewSelectCallback>>(
        mut self,
        data: RefAny,
        on_select: C,
    ) -> Self {
        self.set_on_select(data, on_select);
        self
    }
}
impl_option!(
    StatusBarViewSwitcher,
    OptionStatusBarViewSwitcher,
    copy = false,
    [Debug, Clone]
);
/// The zoom cluster: − button, slider, + button and the percent label.
///
/// The slider is the existing [`Slider`] widget with `value = percent` over
/// the linear `[min, max]` window. The the Office-2013-era look default window is
/// `[10, 190]` so the 100% default rests exactly on the center tick (the
/// original office-suite slider maps 10-100-500 piecewise; a linear window keeps the
/// widget dumb - the application decides what a slider value means).
#[derive(Debug, Clone, PartialEq)]
#[repr(C)]
pub struct StatusBarZoom {
    /// Optional − button callback.
    pub on_zoom_out: OptionButtonOnClick,
    /// Optional + button callback.
    pub on_zoom_in: OptionButtonOnClick,
    /// Optional slider drag/press callback (reports the raw slider value).
    pub on_slider_change: OptionSliderOnValueChange,
    /// Current zoom percent, shown in the label and placing the thumb.
    pub percent: f32,
    /// Slider window minimum (thumb far left).
    pub min: f32,
    /// Slider window maximum (thumb far right).
    pub max: f32,
    /// Renders the "100%" label after the + button.
    pub show_label: bool,
}
impl StatusBarZoom {
    /// 100% zoom over the the Office-2013-era look `[10, 190]` window, label shown.
    #[must_use]
4
    pub fn office_2013() -> Self {
4
        Self {
4
            percent: 100.0,
4
            min: 10.0,
4
            max: 190.0,
4
            on_zoom_out: None.into(),
4
            on_zoom_in: None.into(),
4
            on_slider_change: None.into(),
4
            show_label: true,
4
        }
4
    }
    /// Builder method: sets the zoom percent.
    #[must_use]
    pub const fn with_percent(mut self, percent: f32) -> Self {
        self.percent = percent;
        self
    }
}
impl Default for StatusBarZoom {
    fn default() -> Self {
        Self::office_2013()
    }
}
impl_option!(
    StatusBarZoom,
    OptionStatusBarZoom,
    copy = false,
    [Debug, Clone, PartialEq]
);
/// Top-level status bar widget: left segments, a filler, then the
/// view switcher and zoom cluster on the right.
#[derive(Debug, Clone)]
#[repr(C)]
pub struct StatusBar {
    /// Left-hand segments, in order.
    pub segments: StatusBarSegmentVec,
    /// Optional view-switcher cluster.
    pub views: OptionStatusBarViewSwitcher,
    /// Optional zoom cluster.
    pub zoom: OptionStatusBarZoom,
    /// All part styles (defaults to the the Office-2013-era look look).
    pub style: StatusBarStyle,
}
// -- CSS classes --
static CLS_STATUSBAR: &[IdOrClass] = &[Class(AzString::from_const_str("__azul-native-statusbar"))];
static CLS_SEGMENT: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-statusbar-segment",
))];
static CLS_FILLER: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-statusbar-filler",
))];
static CLS_VIEWS: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-statusbar-views",
))];
static CLS_ZOOM: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-statusbar-zoom",
))];
static CLS_ZOOM_TRACK: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-statusbar-zoom-track",
))];
static CLS_ZOOM_RAIL: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-statusbar-zoom-rail",
))];
static CLS_ZOOM_TICK: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-statusbar-zoom-tick",
))];
static CLS_ZOOM_LABEL: &[IdOrClass] = &[Class(AzString::from_const_str(
    "__azul-native-statusbar-zoom-label",
))];
// -- Constructors / builders --
impl StatusBar {
    /// Creates a status bar with the given left segments, no view switcher
    /// and no zoom cluster, in the the Office-2013-era look style.
    #[must_use]
20
    pub fn new(segments: StatusBarSegmentVec) -> Self {
20
        Self {
20
            segments,
20
            views: None.into(),
20
            zoom: None.into(),
20
            style: StatusBarStyle::office_2013(),
20
        }
20
    }
    /// Sets the view-switcher cluster.
3
    pub fn set_views(&mut self, views: StatusBarViewSwitcher) {
3
        self.views = Some(views).into();
3
    }
    /// Builder method: sets the view-switcher cluster and returns `self`.
    #[must_use]
3
    pub fn with_views(mut self, views: StatusBarViewSwitcher) -> Self {
3
        self.set_views(views);
3
        self
3
    }
    /// Sets the zoom cluster.
3
    pub fn set_zoom(&mut self, zoom: StatusBarZoom) {
3
        self.zoom = Some(zoom).into();
3
    }
    /// Builder method: sets the zoom cluster and returns `self`.
    #[must_use]
3
    pub fn with_zoom(mut self, zoom: StatusBarZoom) -> Self {
3
        self.set_zoom(zoom);
3
        self
3
    }
    /// Builder method: replaces the style bundle.
    #[must_use]
    pub fn with_style(mut self, style: StatusBarStyle) -> Self {
        self.style = style;
        self
    }
    /// Rewrites the text of a MARKED segment in place, from any callback.
    ///
    /// `node_id` is the segment label's `VirtualView` node - the one that
    /// carries the marker given to [`StatusBarSegment::with_marker`], found
    /// with `CallbackInfo::get_node_id_by_marker`. The label's private
    /// dataset is downcast INSIDE this function, the new text stored, and the
    /// node's view re-rendered (`CallbackInfo::trigger_virtual_view_rerender`)
    /// at the size the new text measures to - so only this label re-renders,
    /// the bar re-flows around it, and nothing else in the window is touched.
    /// No `RefreshDom`, no DOM diff, no app-data-model round trip: this is
    /// how a word count keeps up with typing (`AzWriter`'s status bar reads
    /// the committed text from an `On::TextChanged` callback and lands it
    /// here).
    ///
    /// Returns `false` (and changes nothing) when `node_id` does not name a
    /// live marked segment: no layout result, no dataset, or a dataset of
    /// some other widget's type. Returns `true` without re-rendering when the
    /// text is unchanged, so calling it on every keystroke is free when
    /// nothing moved.
50
    pub fn update_segment_label(
50
        info: &mut CallbackInfo,
50
        node_id: DomNodeId,
50
        label: AzString,
50
    ) -> bool {
50
        let Some(mut dataset) = info.get_dataset(node_id) else {
20
            return false;
        };
        {
            // Scoped: the downcast guard must drop before the re-render
            // trigger runs the queue drain path.
30
            let Some(mut state) = dataset.downcast_mut::<StatusBarLabelLocalDataset>() else {
                return false;
            };
30
            if state.label == label {
10
                return true;
20
            }
20
            state.label = label;
        }
20
        let Some(node) = node_id.node.into_crate_internal() else {
            return false;
        };
20
        info.trigger_virtual_view_rerender(node_id.dom, node);
20
        true
50
    }
    /// Renders the status bar.
    #[must_use]
62
    pub fn dom(self) -> Dom {
        let Self {
62
            segments,
62
            views,
62
            zoom,
62
            style,
62
        } = self;
62
        let mut children: Vec<Dom> = Vec::with_capacity(segments.len() + 3);
102
        for seg in segments.into_library_owned_vec() {
101
            children.push(segment_dom(seg, &style));
101
        }
62
        children.push(
62
            Dom::create_div()
62
                .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_FILLER))
62
                .with_css_props(style.resolved_filler_style()),
        );
62
        if let Some(switcher) = views.into_option() {
3
            children.push(views_dom(switcher, &style));
59
        }
62
        if let Some(zoom) = zoom.into_option() {
3
            children.push(zoom_dom(zoom, &style));
59
        }
62
        Dom::create_div()
62
            .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_STATUSBAR))
62
            .with_css_props(style.resolved_bar_style())
62
            .with_children(DomVec::from_vec(children))
62
    }
}
impl Default for StatusBar {
    fn default() -> Self {
        Self::new(StatusBarSegmentVec::from_vec(Vec::new()))
    }
}
impl From<StatusBar> for Dom {
    fn from(s: StatusBar) -> Self {
        s.dom()
    }
}
// -- DOM builders --
/// Expands widget config to the existing [`Button`] widget with the
/// status-bar part styles injected (the ribbon's composition rule).
15
fn styled_button(
15
    icon: AzString,
15
    container_style: CssPropertyWithConditionsVec,
15
    icon_style: CssPropertyWithConditionsVec,
15
    on_click: OptionButtonOnClick,
15
) -> Dom {
15
    let mut b = Button::create(AzString::from_const_str(""));
15
    b.icon = icon;
15
    b.container_style = OptionCssPropertyWithConditionsVec::Some(container_style);
15
    b.icon_style = OptionCssPropertyWithConditionsVec::Some(icon_style);
15
    b.on_click = on_click;
15
    b.dom()
15
}
6
fn merged_style(
6
    base: &CssPropertyWithConditionsVec,
6
    extra: &CssPropertyWithConditionsVec,
6
) -> CssPropertyWithConditionsVec {
6
    if extra.as_ref().is_empty() {
        return base.clone();
6
    }
6
    let mut v: Vec<Cond> = base.as_ref().to_vec();
6
    v.extend_from_slice(extra.as_ref());
6
    CssPropertyWithConditionsVec::from_vec(v)
6
}
101
fn segment_dom(seg: StatusBarSegment, style: &StatusBarStyle) -> Dom {
    let StatusBarSegment {
101
        icon,
101
        label,
101
        on_click,
101
        marker,
101
    } = seg;
101
    if !icon.as_str().is_empty() || on_click.is_some() {
        // Icon and/or clickable: expand to a Button (flat chassis).
        let mut b = Button::create(label);
        b.icon = icon;
        b.container_style =
            OptionCssPropertyWithConditionsVec::Some(style.resolved_segment_style());
        b.icon_style =
            OptionCssPropertyWithConditionsVec::Some(style.resolved_segment_icon_style());
        b.label_style =
            OptionCssPropertyWithConditionsVec::Some(style.resolved_segment_label_style());
        b.on_click = on_click;
        return b
            .dom()
            .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_SEGMENT));
101
    }
101
    let label_dom = if marker.as_str().is_empty() {
        // Inert text segment. `<p>` so it has the same `div > p > text` shape
        // as the clickable one (Button puts `label_style` on a `<p>` too).
61
        crate::widgets::widget_p_with_text(label)
61
            .with_css_props(style.resolved_segment_label_style())
    } else {
        // Live segment: the `<p>` lives inside a `VirtualView` that this
        // module can re-render in place (`StatusBar::update_segment_label`).
40
        segment_label_view(label, marker, style)
    };
101
    Dom::create_div()
101
        .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_SEGMENT))
101
        .with_css_props(style.resolved_segment_style())
101
        .with_children(DomVec::from_vec(vec![label_dom]))
101
}
/// The dataset behind a marked segment's label `VirtualView`. Private to this
/// module, like every widget dataset: the app talks to it through
/// [`StatusBar::update_segment_label`] only.
#[derive(Debug)]
struct StatusBarLabelLocalDataset {
    label: AzString,
    /// `segment_label_style` plus what the label would have INHERITED from
    /// the bar (the font family): the view's DOM is styled as a document of
    /// its own, nothing cascades into it from the host node.
    label_style: CssPropertyWithConditionsVec,
}
/// The `VirtualView` node that stands in for a marked segment's `<p>`.
///
/// Sized by its content: the node has no width or height of its own, so it
/// takes the size the callback reports (`measure_dom_shrink_to_fit` of the
/// `<p>`) - `display: inline-block` so it lays out in the segment's row like
/// the `<p>` did, `overflow: hidden` so a report a hair wider than the box
/// never grows a scrollbar. No padding on the node itself (the segment div
/// keeps `segment_style`), so what the callback reports IS the box and the
/// size converges in one extra pass, not two.
40
fn segment_label_view(label: AzString, marker: AzString, style: &StatusBarStyle) -> Dom {
40
    let mut label_style: Vec<Cond> = style.resolved_segment_label_style().as_ref().to_vec();
40
    if let Some(family) = inherited_font_family(&style.resolved_bar_style()) {
40
        label_style.push(family);
40
    }
40
    let dataset = RefAny::new(StatusBarLabelLocalDataset {
40
        label,
40
        label_style: CssPropertyWithConditionsVec::from_vec(label_style),
40
    });
40
    Dom::create_virtual_view(
40
        dataset.clone(),
40
        VirtualViewCallback::create(statusbar_label_render_virtual_view),
    )
    // The SAME `RefAny` as the view's payload, on the node: `update_segment_label`
    // reaches it through `CallbackInfo::get_dataset` (the progress bar's fast
    // path is built the same way).
40
    .with_dataset(Some(dataset).into())
40
    .with_marker(Some(marker).into())
40
    .with_css("display: inline-block; overflow: hidden;")
40
}
/// The font family a child of the bar would inherit: the LAST unconditional
/// `font-family` in the bar's style (a later push wins, which is how an app
/// pins its UI font onto the bar - `AzWriter`'s `push_ui_font`).
40
fn inherited_font_family(bar_style: &CssPropertyWithConditionsVec) -> Option<Cond> {
40
    bar_style
40
        .as_ref()
40
        .iter()
40
        .rev()
240
        .find(|c| c.apply_if.as_ref().is_empty() && matches!(c.property, P::FontFamily(_)))
40
        .cloned()
40
}
/// The "no constraint" box a label is measured in: wider than any status-bar
/// text, finite so a bug cannot turn into a NaN geometry.
const LABEL_MEASURE_BOUND: f32 = 4096.0;
/// [`segment_label_view`]'s callback: render the label the dataset currently
/// holds, at the size the text asks for.
60
extern "C" fn statusbar_label_render_virtual_view(
60
    mut data: RefAny,
60
    info: VirtualViewCallbackInfo,
60
) -> VirtualViewReturn {
60
    let dom = match data.downcast_ref::<StatusBarLabelLocalDataset>() {
        // Foreign payload: render nothing rather than lie about bounds.
        None => return VirtualViewReturn::default(),
60
        Some(state) => crate::widgets::widget_p_with_text(state.label.clone())
60
            .with_css_props(state.label_style.clone()),
    };
    // Shrink-to-fit, not the extent: a `<p>` is a block, and measured against
    // a box it stretches to the box's width - the text's own width is the
    // question. The bound is deliberately NOT the view's box: the box is
    // whatever the LAST label needed, and a longer label measured inside it
    // would wrap.
60
    let measured = info.measure_dom_shrink_to_fit(
60
        dom.clone(),
60
        LogicalSize::new(LABEL_MEASURE_BOUND, LABEL_MEASURE_BOUND),
    );
    // A measurement of zero means there was no measure hook (or nothing to
    // draw); reporting it would collapse the view to nothing.
60
    let size = if measured.width > 0.0 && measured.height > 0.0 {
60
        measured
    } else {
        info.bounds.get_logical_size()
    };
60
    let rect = LogicalRect::new(LogicalPosition::zero(), size);
    // A label does not scroll, so all three rects are the same box.
60
    VirtualViewReturn::with_dom(dom, rect, rect)
60
}
3
fn views_dom(switcher: StatusBarViewSwitcher, style: &StatusBarStyle) -> Dom {
    let StatusBarViewSwitcher {
3
        views,
3
        active_view,
3
        on_select,
3
    } = switcher;
3
    let mut children: Vec<Dom> = Vec::with_capacity(views.len());
9
    for (idx, view) in views.into_library_owned_vec().into_iter().enumerate() {
9
        let container = if idx == active_view {
3
            merged_style(
3
                &style.resolved_view_button_style(),
3
                &style.resolved_view_button_active_style(),
            )
        } else {
6
            style.resolved_view_button_style()
        };
9
        let on_click: OptionButtonOnClick = match on_select.as_ref() {
3
            Some(cb) => Some(super::button::ButtonOnClick {
3
                refany: RefAny::new(ViewClickData {
3
                    view_idx: idx,
3
                    on_select: cb.clone(),
3
                }),
3
                callback: super::button::ButtonOnClickCallback {
3
                    cb: on_status_bar_view_click,
3
                    ctx: azul_core::refany::OptionRefAny::None,
3
                },
3
            })
3
            .into(),
6
            None => None.into(),
        };
9
        children.push(styled_button(
9
            view.icon,
9
            container,
9
            style.resolved_view_icon_style(),
9
            on_click,
        ));
    }
3
    Dom::create_div()
3
        .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_VIEWS))
3
        .with_css_props(style.resolved_views_style())
3
        .with_children(DomVec::from_vec(children))
3
}
#[allow(clippy::cast_possible_truncation, clippy::cast_precision_loss)] // bounded layout numeric
                                                                        // cast
3
fn zoom_dom(zoom: StatusBarZoom, style: &StatusBarStyle) -> Dom {
    let StatusBarZoom {
3
        percent,
3
        min,
3
        max,
3
        on_zoom_out,
3
        on_zoom_in,
3
        on_slider_change,
3
        show_label,
3
    } = zoom;
3
    let mut children: Vec<Dom> = Vec::with_capacity(4);
3
    children.push(styled_button(
3
        AzString::from_const_str("remove"),
3
        style.resolved_zoom_button_style(),
3
        style.resolved_zoom_icon_style(),
3
        on_zoom_out,
    ));
    // Rail + tick + embedded Slider, layered inside the positioning host.
3
    let fraction = if max > min {
3
        ((percent - min) / (max - min)).clamp(0.0, 1.0)
    } else {
        0.0
    };
3
    let margin = (fraction * (ZOOM_TRACK_W - ZOOM_THUMB_W) as f32).round() as isize;
3
    let thumb_style = merged_style(
3
        &style.resolved_slider_thumb_style(),
3
        &CssPropertyWithConditionsVec::from_vec(vec![Cond::simple(P::const_margin_left(
3
            LayoutMarginLeft::const_px(margin),
3
        ))]),
    );
3
    let mut slider = Slider::create(percent, min, max);
3
    slider.track_style =
3
        OptionCssPropertyWithConditionsVec::Some(style.resolved_slider_track_style());
3
    slider.thumb_style = OptionCssPropertyWithConditionsVec::Some(thumb_style);
3
    slider.slider_state.on_value_change = on_slider_change;
3
    children.push(
3
        Dom::create_div()
3
            .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_ZOOM_TRACK))
3
            .with_css_props(style.resolved_zoom_track_host_style())
3
            .with_children(DomVec::from_vec(vec![
3
                Dom::create_div()
3
                    .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_ZOOM_RAIL))
3
                    .with_css_props(style.resolved_zoom_rail_style()),
3
                Dom::create_div()
3
                    .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_ZOOM_TICK))
3
                    .with_css_props(style.resolved_zoom_tick_style()),
3
                slider.dom(),
            ])),
    );
3
    children.push(styled_button(
3
        AzString::from_const_str("add"),
3
        style.resolved_zoom_button_style(),
3
        style.resolved_zoom_icon_style(),
3
        on_zoom_in,
    ));
3
    if show_label {
2
        let label = format!("{}%", percent.round() as i64);
2
        children.push(
2
            Dom::create_div()
2
                .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_ZOOM_LABEL))
2
                .with_css_props(style.resolved_zoom_label_style())
2
                .with_children(DomVec::from_vec(vec![crate::widgets::widget_p_with_text(
2
                    AzString::from(label),
2
                )])),
2
        );
2
    }
3
    Dom::create_div()
3
        .with_ids_and_classes(IdOrClassVec::from_const_slice(CLS_ZOOM))
3
        .with_css_props(style.resolved_zoom_style())
3
        .with_children(DomVec::from_vec(children))
3
}
// -- View-click plumbing --
/// Payload of one view-switcher button: the view index plus the user's
/// view-select callback.
struct ViewClickData {
    view_idx: usize,
    on_select: StatusBarOnViewSelect,
}
extern "C" fn on_status_bar_view_click(mut data: RefAny, info: CallbackInfo) -> Update {
    let Some(payload) = data.downcast_ref::<ViewClickData>() else {
        return Update::DoNothing;
    };
    let idx = payload.view_idx;
    let cb = payload.on_select.callback.cb;
    let refany = payload.on_select.refany.clone();
    drop(payload);
    (cb)(refany, info, idx)
}
#[cfg(test)]
mod tests {
    use azul_css::{
        dynamic_selector::{DynamicSelector, DynamicSelectorVec, PseudoStateType, ThemeCondition},
        props::property::{CssProperty, CssPropertyType},
    };
    use super::*;
10
    fn seg(label: &str) -> StatusBarSegment {
10
        StatusBarSegment::new(AzString::from(label))
10
    }
10
    fn segs(count: usize) -> StatusBarSegmentVec {
10
        StatusBarSegmentVec::from_vec((0..count).map(|i| seg(&format!("s{i}"))).collect())
10
    }
    // ------------------------------------------------------------------
    // Constructors and invariants
    // ------------------------------------------------------------------
    #[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
            StatusBarTheme::from_system(sys.clone()),
1
            StatusBarTheme::office_2013()
        );
1
        assert_eq!(
1
            StatusBarStyle::from_system(sys),
1
            StatusBarStyle::office_2013()
        );
1
    }
    #[test]
1
    fn from_system_fills_the_bar_with_the_accent_and_writes_in_the_on_accent_colour() {
1
        let accent = ColorU {
1
            r: 61,
1
            g: 174,
1
            b: 233,
1
            a: 255,
1
        };
1
        let on_accent = ColorU {
1
            r: 252,
1
            g: 252,
1
            b: 252,
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.accent_text = Some(on_accent).into();
        // Deliberately ALSO report a window background: the bar is an
        // accent-filled strip and must not take it.
1
        sys.colors.window_background = Some(ColorU {
1
            r: 239,
1
            g: 240,
1
            b: 241,
1
            a: 255,
1
        })
1
        .into();
1
        let t = StatusBarTheme::from_system(sys);
1
        assert_eq!(t.bar_bg, accent);
1
        assert_eq!(t.text, on_accent);
1
        assert_eq!(t.thumb, on_accent, "the thumb sits on the accent fill too");
1
        assert_eq!(
            t.hover_bg,
1
            StatusBarTheme::office_2013().hover_bg,
            "an unreported colour falls back to its OWN office value, never to another derived one"
        );
1
    }
    #[test]
1
    fn status_bar_new_defaults_to_office_2013_with_no_clusters() {
4
        for count in [0usize, 1, 3] {
3
            let s = StatusBar::new(segs(count));
3
            assert_eq!(s.segments.len(), count);
3
            assert!(s.views.is_none());
3
            assert!(s.zoom.is_none());
3
            assert_eq!(s.style, StatusBarStyle::office_2013());
        }
1
    }
    #[test]
1
    fn status_bar_style_default_is_office_2013() {
1
        assert_eq!(StatusBarStyle::default(), StatusBarStyle::office_2013());
1
    }
    #[test]
1
    fn zoom_office_2013_centers_the_default_percent() {
1
        let z = StatusBarZoom::office_2013();
        // 100% must rest exactly on the center tick of the [10, 190] window.
1
        let fraction = (z.percent - z.min) / (z.max - z.min);
1
        assert!((fraction - 0.5).abs() < 1e-6);
1
        assert!(z.show_label);
1
    }
    #[test]
1
    fn view_switcher_office_2013_has_three_views_with_print_layout_active() {
1
        let v = StatusBarViewSwitcher::office_2013();
1
        assert_eq!(v.views.len(), 3);
1
        assert_eq!(v.active_view, 1);
1
        assert!(v.on_select.is_none());
1
    }
    // ------------------------------------------------------------------
    // DOM shape
    // ------------------------------------------------------------------
    #[test]
1
    fn dom_renders_segments_filler_views_and_zoom_in_order() {
1
        let bar = StatusBar::new(segs(2))
1
            .with_views(StatusBarViewSwitcher::office_2013())
1
            .with_zoom(StatusBarZoom::office_2013());
1
        let dom = bar.dom();
        // 2 segments + filler + views + zoom
1
        assert_eq!(dom.children.as_ref().len(), 5);
1
    }
    #[test]
1
    fn dom_without_clusters_renders_segments_and_filler_only() {
1
        let dom = StatusBar::new(segs(3)).dom();
1
        assert_eq!(dom.children.as_ref().len(), 4);
1
    }
    #[test]
1
    fn zoom_cluster_without_label_has_three_children() {
1
        let mut zoom = StatusBarZoom::office_2013();
1
        zoom.show_label = false;
1
        let dom = StatusBar::new(segs(0)).with_zoom(zoom).dom();
        // filler + zoom
1
        assert_eq!(dom.children.as_ref().len(), 2);
1
        let zoom_dom = &dom.children.as_ref()[1];
        // − button, track host, + button (no label)
1
        assert_eq!(zoom_dom.children.as_ref().len(), 3);
1
    }
    #[test]
1
    fn zoom_track_host_layers_rail_tick_and_slider() {
1
        let dom = StatusBar::new(segs(0))
1
            .with_zoom(StatusBarZoom::office_2013())
1
            .dom();
1
        let zoom_dom = &dom.children.as_ref()[1];
1
        let track_host = &zoom_dom.children.as_ref()[1];
1
        assert_eq!(track_host.children.as_ref().len(), 3);
1
    }
    // ------------------------------------------------------------------
    // Interactive states (declared by the theme module, with dark twins)
    // ------------------------------------------------------------------
    /// Every hover / pressed / focus declaration in `decls` has a twin gated
    /// on `Theme(Dark)` for the same property — and there is at least one.
    ///
    /// The states moved OUT of this file into `themes::flat` (phase 2 of the
    /// widget theme migration), which is a move nothing else in this suite
    /// would notice: it compiles either way, and every other assertion here
    /// passes if the theme silently drops them or ships the light half alone.
1
    fn assert_every_state_rule_has_a_dark_twin<'a>(
1
        what: &str,
1
        decls: impl Iterator<Item = (&'a CssProperty, &'a DynamicSelectorVec)>,
1
    ) {
1
        let mut light: Vec<(CssPropertyType, PseudoStateType)> = Vec::new();
1
        let mut dark: Vec<(CssPropertyType, PseudoStateType)> = Vec::new();
29
        for (p, conds) in decls {
28
            let conds = conds.as_ref();
28
            let state = conds.iter().find_map(|c| match c {
                DynamicSelector::PseudoState(
4
                    s @ (PseudoStateType::Hover | PseudoStateType::Active | PseudoStateType::Focus),
4
                ) => Some(*s),
2
                _ => None,
6
            });
28
            let Some(state) = state else { continue };
4
            let is_dark = conds
4
                .iter()
4
                .any(|c| matches!(c, DynamicSelector::Theme(ThemeCondition::Dark)));
4
            if is_dark {
2
                dark.push((p.get_type(), state));
2
            } else {
2
                light.push((p.get_type(), state));
2
            }
        }
1
        assert!(
1
            !light.is_empty(),
            "{what}: carries no hover/pressed/focus rule at all — the theme forgot to append them"
        );
3
        for (ty, state) in &light {
2
            assert!(
2
                dark.contains(&(*ty, *state)),
                "{what}: `{ty:?}` on {state:?} has no dark twin, so its light-mode value is \
                 painted on a dark surface"
            );
        }
1
    }
    #[test]
1
    fn segment_state_fills_have_dark_twins_that_keep_the_bars_own_blue() {
        // An inert text segment is a plain <div> carrying the flat chassis, so
        // the state rules on it are this widget's alone (a clickable segment
        // expands to a Button, which appends its own on top).
1
        let dom = StatusBar::new(segs(1)).dom();
1
        let segment = &dom.children.as_ref()[0];
1
        assert_every_state_rule_has_a_dark_twin(
1
            "segment",
1
            segment.root.style.iter_inline_properties(),
        );
        // The first background fill gated on `state`, in the light or the dark
        // half.
6
        let fill = |state: PseudoStateType, want_dark: bool| -> CssProperty {
6
            segment
6
                .root
6
                .style
6
                .iter_inline_properties()
140
                .find(|(p, conds)| {
140
                    let conds = conds.as_ref();
140
                    let gated_on_state = conds
140
                        .iter()
140
                        .any(|c| matches!(c, DynamicSelector::PseudoState(s) if *s == state));
140
                    let is_dark = conds
140
                        .iter()
140
                        .any(|c| matches!(c, DynamicSelector::Theme(ThemeCondition::Dark)));
140
                    matches!(p, CssProperty::BackgroundContent(_))
20
                        && gated_on_state
8
                        && is_dark == want_dark
140
                })
6
                .map(|(p, _)| p.clone())
6
                .unwrap_or_else(|| panic!("no {state:?} fill on the segment (dark: {want_dark})"))
6
        };
        // The light halves are the palette's own values, unchanged by the move.
1
        let t = StatusBarTheme::office_2013();
1
        assert_eq!(
1
            fill(PseudoStateType::Hover, false),
1
            P::const_background_content(bg_vec(t.hover_bg))
        );
1
        assert_eq!(
1
            fill(PseudoStateType::Active, false),
1
            P::const_background_content(bg_vec(t.pressed_bg))
        );
        // And the dark twins REPEAT them: the bar is an accent strip in either
        // mode, so a hover on it stays a shade of that accent rather than
        // taking the theme's neutral grey.
2
        for state in [PseudoStateType::Hover, PseudoStateType::Active] {
2
            assert_eq!(
2
                fill(state, true),
2
                fill(state, false),
                "{state:?}: the dark twin must keep the bar's own colour — the bar does not go \
                 grey in dark mode, so neither may its highlights"
            );
        }
1
    }
    #[test]
1
    fn view_buttons_get_click_callbacks_only_with_a_select_handler() {
        extern "C" fn on_select(_: RefAny, _: CallbackInfo, _: usize) -> Update {
            Update::DoNothing
        }
        // Without a handler: no callbacks on the buttons.
1
        let dom = StatusBar::new(segs(0))
1
            .with_views(StatusBarViewSwitcher::office_2013())
1
            .dom();
1
        let views = &dom.children.as_ref()[1];
3
        for btn in views.children.as_ref() {
3
            assert!(btn.root.callbacks.as_ref().is_empty());
        }
        // With a handler: every button carries one.
1
        let mut switcher = StatusBarViewSwitcher::office_2013();
1
        switcher.set_on_select(
1
            RefAny::new(()),
1
            on_select as StatusBarOnViewSelectCallbackType,
        );
1
        let dom = StatusBar::new(segs(0)).with_views(switcher).dom();
1
        let views = &dom.children.as_ref()[1];
3
        for btn in views.children.as_ref() {
3
            assert_eq!(btn.root.callbacks.as_ref().len(), 1);
        }
1
    }
}