1
//! Native-styled tab widget consisting of a [`TabHeader`] (the clickable tab bar)
2
//! and [`TabContent`] (the panel shown for the active tab).
3
//!
4
//! Styling emulates the Windows-native tab control appearance via inline CSS
5
//! constants.
6

            
7
use azul_core::{
8
    callbacks::{CoreCallback, CoreCallbackData, Update},
9
    dom::{Dom, DomVec, EventFilter, HoverEventFilter, IdOrClass, IdOrClass::Class, IdOrClassVec},
10
    refany::RefAny,
11
};
12
use azul_css::css::BoxOrStatic;
13
#[allow(clippy::wildcard_imports)]
14
// widget/render module pulls in the css property/value types it builds with
15
use azul_css::{
16
    dynamic_selector::{CssPropertyWithConditions, CssPropertyWithConditionsVec},
17
    props::{
18
        basic::*,
19
        layout::*,
20
        property::{CssProperty, *},
21
        style::*,
22
    },
23
    *,
24
};
25

            
26
use crate::{
27
    callbacks::{Callback, CallbackInfo},
28
    widgets::themes::flat,
29
};
30

            
31
const STRING_16146701490593874959: AzString = AzString::from_const_str("system:ui");
32
const STYLE_BACKGROUND_CONTENT_8560341490937422656_ITEMS: &[StyleBackgroundContent] =
33
    &[StyleBackgroundContent::LinearGradient(LinearGradient {
34
        direction: Direction::FromTo(DirectionCorners {
35
            dir_from: DirectionCorner::Top,
36
            dir_to: DirectionCorner::Bottom,
37
        }),
38
        extend_mode: ExtendMode::Clamp,
39
        stops: NormalizedLinearColorStopVec::from_const_slice(
40
            LINEAR_COLOR_STOP_1400070954008106244_ITEMS,
41
        ),
42
    })];
43

            
44
const STYLE_BACKGROUND_CONTENT_16746671892555275291_ITEMS: &[StyleBackgroundContent] =
45
    &[StyleBackgroundContent::Color(ColorU {
46
        r: 255,
47
        g: 255,
48
        b: 255,
49
        a: 255,
50
    })];
51
const STYLE_FONT_FAMILY_8122988506401935406_ITEMS: &[StyleFontFamily] =
52
    &[StyleFontFamily::System(STRING_16146701490593874959)];
53
const LINEAR_COLOR_STOP_1400070954008106244_ITEMS: &[NormalizedLinearColorStop] = &[
54
    NormalizedLinearColorStop {
55
        offset: PercentageValue::const_new(0),
56
        color: ColorOrSystem::color(ColorU {
57
            r: 240,
58
            g: 240,
59
            b: 240,
60
            a: 255,
61
        }),
62
    },
63
    NormalizedLinearColorStop {
64
        offset: PercentageValue::const_new(100),
65
        color: ColorOrSystem::color(ColorU {
66
            r: 229,
67
            g: 229,
68
            b: 229,
69
            a: 255,
70
        }),
71
    },
72
];
73

            
74
const CSS_MATCH_13824480602841492081_PROPERTIES: &[CssPropertyWithConditions] = &[
75
    // .__azul-native-tabs-header p.__azul-native-tabs-tab-not-active:hover
76
    //
77
    // Thirteen hover rules and their thirteen dark twins, declared in the
78
    // theme module — `themes::flat::TAB_HOVER_STATES` — because the dark half
79
    // of each pair needs a palette this file cannot see. Declared here they
80
    // could only ever name the light-mode blue, which is how a hovered tab
81
    // kept its light ring and fill on a dark surface. The widths and styles
82
    // are part of the set on purpose: they draw back the edge a seam tab
83
    // (`-noleftborder` / `-norightborder`) has nulled, so the ring is whole.
84
    flat::TAB_HOVER_BORDER_BOTTOM_WIDTH,
85
    flat::TAB_HOVER_BORDER_LEFT_WIDTH,
86
    flat::TAB_HOVER_BORDER_RIGHT_WIDTH,
87
    flat::TAB_HOVER_BORDER_TOP_WIDTH,
88
    flat::TAB_HOVER_BORDER_BOTTOM_STYLE,
89
    flat::TAB_HOVER_BORDER_LEFT_STYLE,
90
    flat::TAB_HOVER_BORDER_RIGHT_STYLE,
91
    flat::TAB_HOVER_BORDER_TOP_STYLE,
92
    flat::TAB_HOVER_BORDER_BOTTOM_COLOR,
93
    flat::TAB_HOVER_BORDER_LEFT_COLOR,
94
    flat::TAB_HOVER_BORDER_RIGHT_COLOR,
95
    flat::TAB_HOVER_BORDER_TOP_COLOR,
96
    flat::TAB_HOVER_BG,
97
    flat::TAB_HOVER_BORDER_BOTTOM_WIDTH_DARK,
98
    flat::TAB_HOVER_BORDER_LEFT_WIDTH_DARK,
99
    flat::TAB_HOVER_BORDER_RIGHT_WIDTH_DARK,
100
    flat::TAB_HOVER_BORDER_TOP_WIDTH_DARK,
101
    flat::TAB_HOVER_BORDER_BOTTOM_STYLE_DARK,
102
    flat::TAB_HOVER_BORDER_LEFT_STYLE_DARK,
103
    flat::TAB_HOVER_BORDER_RIGHT_STYLE_DARK,
104
    flat::TAB_HOVER_BORDER_TOP_STYLE_DARK,
105
    flat::TAB_HOVER_BORDER_BOTTOM_COLOR_DARK,
106
    flat::TAB_HOVER_BORDER_LEFT_COLOR_DARK,
107
    flat::TAB_HOVER_BORDER_RIGHT_COLOR_DARK,
108
    flat::TAB_HOVER_BORDER_TOP_COLOR_DARK,
109
    flat::TAB_HOVER_BG_DARK,
110
    // .__azul-native-tabs-header p.__azul-native-tabs-tab-noleftborder
111
    CssPropertyWithConditions::simple(CssProperty::BorderLeftWidth(
112
        LayoutBorderLeftWidthValue::None,
113
    )),
114
    CssPropertyWithConditions::simple(CssProperty::BorderLeftStyle(
115
        StyleBorderLeftStyleValue::None,
116
    )),
117
    CssPropertyWithConditions::simple(CssProperty::BorderLeftColor(
118
        StyleBorderLeftColorValue::None,
119
    )),
120
    // .__azul-native-tabs-header p.__azul-native-tabs-tab-not-active
121
    CssPropertyWithConditions::simple(CssProperty::PaddingRight(LayoutPaddingRightValue::Exact(
122
        LayoutPaddingRight {
123
            inner: PixelValue::const_px(5),
124
        },
125
    ))),
126
    CssPropertyWithConditions::simple(CssProperty::PaddingLeft(LayoutPaddingLeftValue::Exact(
127
        LayoutPaddingLeft {
128
            inner: PixelValue::const_px(5),
129
        },
130
    ))),
131
    CssPropertyWithConditions::simple(CssProperty::PaddingBottom(LayoutPaddingBottomValue::Exact(
132
        LayoutPaddingBottom {
133
            inner: PixelValue::const_px(1),
134
        },
135
    ))),
136
    CssPropertyWithConditions::simple(CssProperty::PaddingTop(LayoutPaddingTopValue::Exact(
137
        LayoutPaddingTop {
138
            inner: PixelValue::const_px(1),
139
        },
140
    ))),
141
    CssPropertyWithConditions::simple(CssProperty::MarginTop(LayoutMarginTopValue::Exact(
142
        LayoutMarginTop {
143
            inner: PixelValue::const_px(2),
144
        },
145
    ))),
146
    // .__azul-native-tabs-header p
147
    CssPropertyWithConditions::simple(CssProperty::TextAlign(StyleTextAlignValue::Exact(
148
        StyleTextAlign::Center,
149
    ))),
150
    CssPropertyWithConditions::simple(CssProperty::Height(LayoutHeightValue::Exact(
151
        LayoutHeight::Px(PixelValue::const_px(21)),
152
    ))),
153
    CssPropertyWithConditions::simple(CssProperty::BorderBottomWidth(
154
        LayoutBorderBottomWidthValue::Exact(LayoutBorderBottomWidth {
155
            inner: PixelValue::const_px(1),
156
        }),
157
    )),
158
    CssPropertyWithConditions::simple(CssProperty::BorderLeftWidth(
159
        LayoutBorderLeftWidthValue::Exact(LayoutBorderLeftWidth {
160
            inner: PixelValue::const_px(1),
161
        }),
162
    )),
163
    CssPropertyWithConditions::simple(CssProperty::BorderRightWidth(
164
        LayoutBorderRightWidthValue::Exact(LayoutBorderRightWidth {
165
            inner: PixelValue::const_px(1),
166
        }),
167
    )),
168
    CssPropertyWithConditions::simple(CssProperty::BorderTopWidth(
169
        LayoutBorderTopWidthValue::Exact(LayoutBorderTopWidth {
170
            inner: PixelValue::const_px(1),
171
        }),
172
    )),
173
    CssPropertyWithConditions::simple(CssProperty::BorderBottomStyle(
174
        StyleBorderBottomStyleValue::Exact(StyleBorderBottomStyle {
175
            inner: BorderStyle::Solid,
176
        }),
177
    )),
178
    CssPropertyWithConditions::simple(CssProperty::BorderLeftStyle(
179
        StyleBorderLeftStyleValue::Exact(StyleBorderLeftStyle {
180
            inner: BorderStyle::Solid,
181
        }),
182
    )),
183
    CssPropertyWithConditions::simple(CssProperty::BorderRightStyle(
184
        StyleBorderRightStyleValue::Exact(StyleBorderRightStyle {
185
            inner: BorderStyle::Solid,
186
        }),
187
    )),
188
    CssPropertyWithConditions::simple(CssProperty::BorderTopStyle(
189
        StyleBorderTopStyleValue::Exact(StyleBorderTopStyle {
190
            inner: BorderStyle::Solid,
191
        }),
192
    )),
193
    CssPropertyWithConditions::simple(CssProperty::BorderBottomColor(
194
        StyleBorderBottomColorValue::Exact(StyleBorderBottomColor {
195
            inner: ColorU {
196
                r: 172,
197
                g: 172,
198
                b: 172,
199
                a: 255,
200
            },
201
        }),
202
    )),
203
    CssPropertyWithConditions::simple(CssProperty::BorderLeftColor(
204
        StyleBorderLeftColorValue::Exact(StyleBorderLeftColor {
205
            inner: ColorU {
206
                r: 172,
207
                g: 172,
208
                b: 172,
209
                a: 255,
210
            },
211
        }),
212
    )),
213
    CssPropertyWithConditions::simple(CssProperty::BorderRightColor(
214
        StyleBorderRightColorValue::Exact(StyleBorderRightColor {
215
            inner: ColorU {
216
                r: 172,
217
                g: 172,
218
                b: 172,
219
                a: 255,
220
            },
221
        }),
222
    )),
223
    CssPropertyWithConditions::simple(CssProperty::BorderTopColor(
224
        StyleBorderTopColorValue::Exact(StyleBorderTopColor {
225
            inner: ColorU {
226
                r: 172,
227
                g: 172,
228
                b: 172,
229
                a: 255,
230
            },
231
        }),
232
    )),
233
    CssPropertyWithConditions::simple(CssProperty::BackgroundContent(
234
        StyleBackgroundContentVecValue::Exact(StyleBackgroundContentVec::from_const_slice(
235
            STYLE_BACKGROUND_CONTENT_8560341490937422656_ITEMS,
236
        )),
237
    )),
238
    CssPropertyWithConditions::simple(CssProperty::AlignItems(LayoutAlignItemsValue::Exact(
239
        LayoutAlignItems::Center,
240
    ))),
241
];
242
const CSS_MATCH_13824480602841492081: CssPropertyWithConditionsVec =
243
    CssPropertyWithConditionsVec::from_const_slice(CSS_MATCH_13824480602841492081_PROPERTIES);
244

            
245
const CSS_MATCH_14575853790110873394_PROPERTIES: &[CssPropertyWithConditions] = &[
246
    // .__azul-native-tabs-header p.__azul-native-tabs-tab-active
247
    CssPropertyWithConditions::simple(CssProperty::PaddingRight(LayoutPaddingRightValue::Exact(
248
        LayoutPaddingRight {
249
            inner: PixelValue::const_px(7),
250
        },
251
    ))),
252
    CssPropertyWithConditions::simple(CssProperty::PaddingLeft(LayoutPaddingLeftValue::Exact(
253
        LayoutPaddingLeft {
254
            inner: PixelValue::const_px(7),
255
        },
256
    ))),
257
    CssPropertyWithConditions::simple(CssProperty::PaddingBottom(LayoutPaddingBottomValue::Exact(
258
        LayoutPaddingBottom {
259
            inner: PixelValue::const_px(3),
260
        },
261
    ))),
262
    CssPropertyWithConditions::simple(CssProperty::PaddingTop(LayoutPaddingTopValue::Exact(
263
        LayoutPaddingTop {
264
            inner: PixelValue::const_px(3),
265
        },
266
    ))),
267
    CssPropertyWithConditions::simple(CssProperty::Height(LayoutHeightValue::Exact(
268
        LayoutHeight::Px(PixelValue::const_px(23)),
269
    ))),
270
    CssPropertyWithConditions::simple(CssProperty::BoxSizing(LayoutBoxSizingValue::Exact(
271
        LayoutBoxSizing::ContentBox,
272
    ))),
273
    CssPropertyWithConditions::simple(CssProperty::BorderBottomWidth(
274
        LayoutBorderBottomWidthValue::Exact(LayoutBorderBottomWidth {
275
            inner: PixelValue::const_px(1),
276
        }),
277
    )),
278
    CssPropertyWithConditions::simple(CssProperty::BorderBottomStyle(
279
        StyleBorderBottomStyleValue::Exact(StyleBorderBottomStyle {
280
            inner: BorderStyle::Solid,
281
        }),
282
    )),
283
    CssPropertyWithConditions::simple(CssProperty::BorderBottomColor(
284
        StyleBorderBottomColorValue::Exact(StyleBorderBottomColor {
285
            inner: ColorU {
286
                r: 255,
287
                g: 255,
288
                b: 255,
289
                a: 255,
290
            },
291
        }),
292
    )),
293
    CssPropertyWithConditions::simple(CssProperty::BackgroundContent(
294
        StyleBackgroundContentVecValue::Exact(StyleBackgroundContentVec::from_const_slice(
295
            STYLE_BACKGROUND_CONTENT_16746671892555275291_ITEMS,
296
        )),
297
    )),
298
    // .__azul-native-tabs-header p
299
    CssPropertyWithConditions::simple(CssProperty::TextAlign(StyleTextAlignValue::Exact(
300
        StyleTextAlign::Center,
301
    ))),
302
    CssPropertyWithConditions::simple(CssProperty::Height(LayoutHeightValue::Exact(
303
        LayoutHeight::Px(PixelValue::const_px(21)),
304
    ))),
305
    CssPropertyWithConditions::simple(CssProperty::BorderBottomWidth(
306
        LayoutBorderBottomWidthValue::Exact(LayoutBorderBottomWidth {
307
            inner: PixelValue::const_px(1),
308
        }),
309
    )),
310
    CssPropertyWithConditions::simple(CssProperty::BorderLeftWidth(
311
        LayoutBorderLeftWidthValue::Exact(LayoutBorderLeftWidth {
312
            inner: PixelValue::const_px(1),
313
        }),
314
    )),
315
    CssPropertyWithConditions::simple(CssProperty::BorderRightWidth(
316
        LayoutBorderRightWidthValue::Exact(LayoutBorderRightWidth {
317
            inner: PixelValue::const_px(1),
318
        }),
319
    )),
320
    CssPropertyWithConditions::simple(CssProperty::BorderTopWidth(
321
        LayoutBorderTopWidthValue::Exact(LayoutBorderTopWidth {
322
            inner: PixelValue::const_px(1),
323
        }),
324
    )),
325
    CssPropertyWithConditions::simple(CssProperty::BorderBottomStyle(
326
        StyleBorderBottomStyleValue::Exact(StyleBorderBottomStyle {
327
            inner: BorderStyle::Solid,
328
        }),
329
    )),
330
    CssPropertyWithConditions::simple(CssProperty::BorderLeftStyle(
331
        StyleBorderLeftStyleValue::Exact(StyleBorderLeftStyle {
332
            inner: BorderStyle::Solid,
333
        }),
334
    )),
335
    CssPropertyWithConditions::simple(CssProperty::BorderRightStyle(
336
        StyleBorderRightStyleValue::Exact(StyleBorderRightStyle {
337
            inner: BorderStyle::Solid,
338
        }),
339
    )),
340
    CssPropertyWithConditions::simple(CssProperty::BorderTopStyle(
341
        StyleBorderTopStyleValue::Exact(StyleBorderTopStyle {
342
            inner: BorderStyle::Solid,
343
        }),
344
    )),
345
    CssPropertyWithConditions::simple(CssProperty::BorderBottomColor(
346
        StyleBorderBottomColorValue::Exact(StyleBorderBottomColor {
347
            inner: ColorU {
348
                r: 172,
349
                g: 172,
350
                b: 172,
351
                a: 255,
352
            },
353
        }),
354
    )),
355
    CssPropertyWithConditions::simple(CssProperty::BorderLeftColor(
356
        StyleBorderLeftColorValue::Exact(StyleBorderLeftColor {
357
            inner: ColorU {
358
                r: 172,
359
                g: 172,
360
                b: 172,
361
                a: 255,
362
            },
363
        }),
364
    )),
365
    CssPropertyWithConditions::simple(CssProperty::BorderRightColor(
366
        StyleBorderRightColorValue::Exact(StyleBorderRightColor {
367
            inner: ColorU {
368
                r: 172,
369
                g: 172,
370
                b: 172,
371
                a: 255,
372
            },
373
        }),
374
    )),
375
    CssPropertyWithConditions::simple(CssProperty::BorderTopColor(
376
        StyleBorderTopColorValue::Exact(StyleBorderTopColor {
377
            inner: ColorU {
378
                r: 172,
379
                g: 172,
380
                b: 172,
381
                a: 255,
382
            },
383
        }),
384
    )),
385
    CssPropertyWithConditions::simple(CssProperty::BackgroundContent(
386
        StyleBackgroundContentVecValue::Exact(StyleBackgroundContentVec::from_const_slice(
387
            STYLE_BACKGROUND_CONTENT_8560341490937422656_ITEMS,
388
        )),
389
    )),
390
    CssPropertyWithConditions::simple(CssProperty::AlignItems(LayoutAlignItemsValue::Exact(
391
        LayoutAlignItems::Center,
392
    ))),
393
];
394
const CSS_MATCH_14575853790110873394: CssPropertyWithConditionsVec =
395
    CssPropertyWithConditionsVec::from_const_slice(CSS_MATCH_14575853790110873394_PROPERTIES);
396

            
397
const CSS_MATCH_17290739305197504468_PROPERTIES: &[CssPropertyWithConditions] = &[
398
    // .__azul-native-tabs-header .__azul-native-tabs-before-tabs
399
    CssPropertyWithConditions::simple(CssProperty::Width(LayoutWidthValue::Exact(
400
        LayoutWidth::Px(PixelValue::const_px(2)),
401
    ))),
402
    CssPropertyWithConditions::simple(CssProperty::FlexGrow(LayoutFlexGrowValue::Exact(
403
        LayoutFlexGrow {
404
            inner: FloatValue::const_new(1),
405
        },
406
    ))),
407
    CssPropertyWithConditions::simple(CssProperty::BorderBottomWidth(
408
        LayoutBorderBottomWidthValue::Exact(LayoutBorderBottomWidth {
409
            inner: PixelValue::const_px(1),
410
        }),
411
    )),
412
    CssPropertyWithConditions::simple(CssProperty::BorderBottomStyle(
413
        StyleBorderBottomStyleValue::Exact(StyleBorderBottomStyle {
414
            inner: BorderStyle::Solid,
415
        }),
416
    )),
417
    CssPropertyWithConditions::simple(CssProperty::BorderBottomColor(
418
        StyleBorderBottomColorValue::Exact(StyleBorderBottomColor {
419
            inner: ColorU {
420
                r: 172,
421
                g: 172,
422
                b: 172,
423
                a: 255,
424
            },
425
        }),
426
    )),
427
];
428
const CSS_MATCH_17290739305197504468: CssPropertyWithConditionsVec =
429
    CssPropertyWithConditionsVec::from_const_slice(CSS_MATCH_17290739305197504468_PROPERTIES);
430

            
431
const CSS_MATCH_18014909903571752977_PROPERTIES: &[CssPropertyWithConditions] = &[
432
    // .__azul-native-tabs-content
433
    CssPropertyWithConditions::simple(CssProperty::PaddingRight(LayoutPaddingRightValue::Exact(
434
        LayoutPaddingRight {
435
            inner: PixelValue::const_px(5),
436
        },
437
    ))),
438
    CssPropertyWithConditions::simple(CssProperty::PaddingLeft(LayoutPaddingLeftValue::Exact(
439
        LayoutPaddingLeft {
440
            inner: PixelValue::const_px(5),
441
        },
442
    ))),
443
    CssPropertyWithConditions::simple(CssProperty::PaddingBottom(LayoutPaddingBottomValue::Exact(
444
        LayoutPaddingBottom {
445
            inner: PixelValue::const_px(5),
446
        },
447
    ))),
448
    CssPropertyWithConditions::simple(CssProperty::PaddingTop(LayoutPaddingTopValue::Exact(
449
        LayoutPaddingTop {
450
            inner: PixelValue::const_px(5),
451
        },
452
    ))),
453
    CssPropertyWithConditions::simple(CssProperty::FlexGrow(LayoutFlexGrowValue::Exact(
454
        LayoutFlexGrow {
455
            inner: FloatValue::const_new(1),
456
        },
457
    ))),
458
    CssPropertyWithConditions::simple(CssProperty::BorderTopWidth(LayoutBorderTopWidthValue::None)),
459
    CssPropertyWithConditions::simple(CssProperty::BorderTopStyle(StyleBorderTopStyleValue::None)),
460
    CssPropertyWithConditions::simple(CssProperty::BorderTopColor(StyleBorderTopColorValue::None)),
461
    CssPropertyWithConditions::simple(CssProperty::BorderBottomWidth(
462
        LayoutBorderBottomWidthValue::Exact(LayoutBorderBottomWidth {
463
            inner: PixelValue::const_px(1),
464
        }),
465
    )),
466
    CssPropertyWithConditions::simple(CssProperty::BorderLeftWidth(
467
        LayoutBorderLeftWidthValue::Exact(LayoutBorderLeftWidth {
468
            inner: PixelValue::const_px(1),
469
        }),
470
    )),
471
    CssPropertyWithConditions::simple(CssProperty::BorderRightWidth(
472
        LayoutBorderRightWidthValue::Exact(LayoutBorderRightWidth {
473
            inner: PixelValue::const_px(1),
474
        }),
475
    )),
476
    CssPropertyWithConditions::simple(CssProperty::BorderBottomStyle(
477
        StyleBorderBottomStyleValue::Exact(StyleBorderBottomStyle {
478
            inner: BorderStyle::Solid,
479
        }),
480
    )),
481
    CssPropertyWithConditions::simple(CssProperty::BorderLeftStyle(
482
        StyleBorderLeftStyleValue::Exact(StyleBorderLeftStyle {
483
            inner: BorderStyle::Solid,
484
        }),
485
    )),
486
    CssPropertyWithConditions::simple(CssProperty::BorderRightStyle(
487
        StyleBorderRightStyleValue::Exact(StyleBorderRightStyle {
488
            inner: BorderStyle::Solid,
489
        }),
490
    )),
491
    CssPropertyWithConditions::simple(CssProperty::BorderBottomColor(
492
        StyleBorderBottomColorValue::Exact(StyleBorderBottomColor {
493
            inner: ColorU {
494
                r: 172,
495
                g: 172,
496
                b: 172,
497
                a: 255,
498
            },
499
        }),
500
    )),
501
    CssPropertyWithConditions::simple(CssProperty::BorderLeftColor(
502
        StyleBorderLeftColorValue::Exact(StyleBorderLeftColor {
503
            inner: ColorU {
504
                r: 172,
505
                g: 172,
506
                b: 172,
507
                a: 255,
508
            },
509
        }),
510
    )),
511
    CssPropertyWithConditions::simple(CssProperty::BorderRightColor(
512
        StyleBorderRightColorValue::Exact(StyleBorderRightColor {
513
            inner: ColorU {
514
                r: 172,
515
                g: 172,
516
                b: 172,
517
                a: 255,
518
            },
519
        }),
520
    )),
521
    CssPropertyWithConditions::simple(CssProperty::BackgroundContent(
522
        StyleBackgroundContentVecValue::Exact(StyleBackgroundContentVec::from_const_slice(
523
            STYLE_BACKGROUND_CONTENT_16746671892555275291_ITEMS,
524
        )),
525
    )),
526
];
527
const CSS_MATCH_18014909903571752977: CssPropertyWithConditionsVec =
528
    CssPropertyWithConditionsVec::from_const_slice(CSS_MATCH_18014909903571752977_PROPERTIES);
529

            
530
const CSS_MATCH_3088386549906605418_PROPERTIES: &[CssPropertyWithConditions] = &[
531
    // .__azul-native-tabs-header .__azul-native-tabs-after-tabs
532
    CssPropertyWithConditions::simple(CssProperty::FlexGrow(LayoutFlexGrowValue::Exact(
533
        LayoutFlexGrow {
534
            inner: FloatValue::const_new(1),
535
        },
536
    ))),
537
    CssPropertyWithConditions::simple(CssProperty::BorderBottomWidth(
538
        LayoutBorderBottomWidthValue::Exact(LayoutBorderBottomWidth {
539
            inner: PixelValue::const_px(1),
540
        }),
541
    )),
542
    CssPropertyWithConditions::simple(CssProperty::BorderBottomStyle(
543
        StyleBorderBottomStyleValue::Exact(StyleBorderBottomStyle {
544
            inner: BorderStyle::Solid,
545
        }),
546
    )),
547
    CssPropertyWithConditions::simple(CssProperty::BorderBottomColor(
548
        StyleBorderBottomColorValue::Exact(StyleBorderBottomColor {
549
            inner: ColorU {
550
                r: 172,
551
                g: 172,
552
                b: 172,
553
                a: 255,
554
            },
555
        }),
556
    )),
557
];
558
const CSS_MATCH_3088386549906605418: CssPropertyWithConditionsVec =
559
    CssPropertyWithConditionsVec::from_const_slice(CSS_MATCH_3088386549906605418_PROPERTIES);
560

            
561
const CSS_MATCH_4415083954137121609_PROPERTIES: &[CssPropertyWithConditions] = &[
562
    // .__azul-native-tabs-header p.__azul-native-tabs-tab-not-active:hover
563
    //
564
    // Thirteen hover rules and their thirteen dark twins, declared in the
565
    // theme module — `themes::flat::TAB_HOVER_STATES` — because the dark half
566
    // of each pair needs a palette this file cannot see. Declared here they
567
    // could only ever name the light-mode blue, which is how a hovered tab
568
    // kept its light ring and fill on a dark surface. The widths and styles
569
    // are part of the set on purpose: they draw back the edge a seam tab
570
    // (`-noleftborder` / `-norightborder`) has nulled, so the ring is whole.
571
    flat::TAB_HOVER_BORDER_BOTTOM_WIDTH,
572
    flat::TAB_HOVER_BORDER_LEFT_WIDTH,
573
    flat::TAB_HOVER_BORDER_RIGHT_WIDTH,
574
    flat::TAB_HOVER_BORDER_TOP_WIDTH,
575
    flat::TAB_HOVER_BORDER_BOTTOM_STYLE,
576
    flat::TAB_HOVER_BORDER_LEFT_STYLE,
577
    flat::TAB_HOVER_BORDER_RIGHT_STYLE,
578
    flat::TAB_HOVER_BORDER_TOP_STYLE,
579
    flat::TAB_HOVER_BORDER_BOTTOM_COLOR,
580
    flat::TAB_HOVER_BORDER_LEFT_COLOR,
581
    flat::TAB_HOVER_BORDER_RIGHT_COLOR,
582
    flat::TAB_HOVER_BORDER_TOP_COLOR,
583
    flat::TAB_HOVER_BG,
584
    flat::TAB_HOVER_BORDER_BOTTOM_WIDTH_DARK,
585
    flat::TAB_HOVER_BORDER_LEFT_WIDTH_DARK,
586
    flat::TAB_HOVER_BORDER_RIGHT_WIDTH_DARK,
587
    flat::TAB_HOVER_BORDER_TOP_WIDTH_DARK,
588
    flat::TAB_HOVER_BORDER_BOTTOM_STYLE_DARK,
589
    flat::TAB_HOVER_BORDER_LEFT_STYLE_DARK,
590
    flat::TAB_HOVER_BORDER_RIGHT_STYLE_DARK,
591
    flat::TAB_HOVER_BORDER_TOP_STYLE_DARK,
592
    flat::TAB_HOVER_BORDER_BOTTOM_COLOR_DARK,
593
    flat::TAB_HOVER_BORDER_LEFT_COLOR_DARK,
594
    flat::TAB_HOVER_BORDER_RIGHT_COLOR_DARK,
595
    flat::TAB_HOVER_BORDER_TOP_COLOR_DARK,
596
    flat::TAB_HOVER_BG_DARK,
597
    // .__azul-native-tabs-header p.__azul-native-tabs-tab-norightborder
598
    CssPropertyWithConditions::simple(CssProperty::BorderRightWidth(
599
        LayoutBorderRightWidthValue::None,
600
    )),
601
    CssPropertyWithConditions::simple(CssProperty::BorderRightStyle(
602
        StyleBorderRightStyleValue::None,
603
    )),
604
    CssPropertyWithConditions::simple(CssProperty::BorderRightColor(
605
        StyleBorderRightColorValue::None,
606
    )),
607
    // .__azul-native-tabs-header p.__azul-native-tabs-tab-not-active
608
    CssPropertyWithConditions::simple(CssProperty::PaddingRight(LayoutPaddingRightValue::Exact(
609
        LayoutPaddingRight {
610
            inner: PixelValue::const_px(5),
611
        },
612
    ))),
613
    CssPropertyWithConditions::simple(CssProperty::PaddingLeft(LayoutPaddingLeftValue::Exact(
614
        LayoutPaddingLeft {
615
            inner: PixelValue::const_px(5),
616
        },
617
    ))),
618
    CssPropertyWithConditions::simple(CssProperty::PaddingBottom(LayoutPaddingBottomValue::Exact(
619
        LayoutPaddingBottom {
620
            inner: PixelValue::const_px(1),
621
        },
622
    ))),
623
    CssPropertyWithConditions::simple(CssProperty::PaddingTop(LayoutPaddingTopValue::Exact(
624
        LayoutPaddingTop {
625
            inner: PixelValue::const_px(1),
626
        },
627
    ))),
628
    CssPropertyWithConditions::simple(CssProperty::MarginTop(LayoutMarginTopValue::Exact(
629
        LayoutMarginTop {
630
            inner: PixelValue::const_px(2),
631
        },
632
    ))),
633
    // .__azul-native-tabs-header p
634
    CssPropertyWithConditions::simple(CssProperty::TextAlign(StyleTextAlignValue::Exact(
635
        StyleTextAlign::Center,
636
    ))),
637
    CssPropertyWithConditions::simple(CssProperty::Height(LayoutHeightValue::Exact(
638
        LayoutHeight::Px(PixelValue::const_px(21)),
639
    ))),
640
    CssPropertyWithConditions::simple(CssProperty::BorderBottomWidth(
641
        LayoutBorderBottomWidthValue::Exact(LayoutBorderBottomWidth {
642
            inner: PixelValue::const_px(1),
643
        }),
644
    )),
645
    CssPropertyWithConditions::simple(CssProperty::BorderLeftWidth(
646
        LayoutBorderLeftWidthValue::Exact(LayoutBorderLeftWidth {
647
            inner: PixelValue::const_px(1),
648
        }),
649
    )),
650
    CssPropertyWithConditions::simple(CssProperty::BorderRightWidth(
651
        LayoutBorderRightWidthValue::Exact(LayoutBorderRightWidth {
652
            inner: PixelValue::const_px(1),
653
        }),
654
    )),
655
    CssPropertyWithConditions::simple(CssProperty::BorderTopWidth(
656
        LayoutBorderTopWidthValue::Exact(LayoutBorderTopWidth {
657
            inner: PixelValue::const_px(1),
658
        }),
659
    )),
660
    CssPropertyWithConditions::simple(CssProperty::BorderBottomStyle(
661
        StyleBorderBottomStyleValue::Exact(StyleBorderBottomStyle {
662
            inner: BorderStyle::Solid,
663
        }),
664
    )),
665
    CssPropertyWithConditions::simple(CssProperty::BorderLeftStyle(
666
        StyleBorderLeftStyleValue::Exact(StyleBorderLeftStyle {
667
            inner: BorderStyle::Solid,
668
        }),
669
    )),
670
    CssPropertyWithConditions::simple(CssProperty::BorderRightStyle(
671
        StyleBorderRightStyleValue::Exact(StyleBorderRightStyle {
672
            inner: BorderStyle::Solid,
673
        }),
674
    )),
675
    CssPropertyWithConditions::simple(CssProperty::BorderTopStyle(
676
        StyleBorderTopStyleValue::Exact(StyleBorderTopStyle {
677
            inner: BorderStyle::Solid,
678
        }),
679
    )),
680
    CssPropertyWithConditions::simple(CssProperty::BorderBottomColor(
681
        StyleBorderBottomColorValue::Exact(StyleBorderBottomColor {
682
            inner: ColorU {
683
                r: 172,
684
                g: 172,
685
                b: 172,
686
                a: 255,
687
            },
688
        }),
689
    )),
690
    CssPropertyWithConditions::simple(CssProperty::BorderLeftColor(
691
        StyleBorderLeftColorValue::Exact(StyleBorderLeftColor {
692
            inner: ColorU {
693
                r: 172,
694
                g: 172,
695
                b: 172,
696
                a: 255,
697
            },
698
        }),
699
    )),
700
    CssPropertyWithConditions::simple(CssProperty::BorderRightColor(
701
        StyleBorderRightColorValue::Exact(StyleBorderRightColor {
702
            inner: ColorU {
703
                r: 172,
704
                g: 172,
705
                b: 172,
706
                a: 255,
707
            },
708
        }),
709
    )),
710
    CssPropertyWithConditions::simple(CssProperty::BorderTopColor(
711
        StyleBorderTopColorValue::Exact(StyleBorderTopColor {
712
            inner: ColorU {
713
                r: 172,
714
                g: 172,
715
                b: 172,
716
                a: 255,
717
            },
718
        }),
719
    )),
720
    CssPropertyWithConditions::simple(CssProperty::BackgroundContent(
721
        StyleBackgroundContentVecValue::Exact(StyleBackgroundContentVec::from_const_slice(
722
            STYLE_BACKGROUND_CONTENT_8560341490937422656_ITEMS,
723
        )),
724
    )),
725
    CssPropertyWithConditions::simple(CssProperty::AlignItems(LayoutAlignItemsValue::Exact(
726
        LayoutAlignItems::Center,
727
    ))),
728
];
729
const CSS_MATCH_4415083954137121609: CssPropertyWithConditionsVec =
730
    CssPropertyWithConditionsVec::from_const_slice(CSS_MATCH_4415083954137121609_PROPERTIES);
731

            
732
const CSS_MATCH_4738503469417034630_PROPERTIES: &[CssPropertyWithConditions] = &[
733
    // .__azul-native-tabs-container
734
    CssPropertyWithConditions::simple(CssProperty::PaddingRight(LayoutPaddingRightValue::Exact(
735
        LayoutPaddingRight {
736
            inner: PixelValue::const_px(5),
737
        },
738
    ))),
739
    CssPropertyWithConditions::simple(CssProperty::PaddingLeft(LayoutPaddingLeftValue::Exact(
740
        LayoutPaddingLeft {
741
            inner: PixelValue::const_px(5),
742
        },
743
    ))),
744
    CssPropertyWithConditions::simple(CssProperty::PaddingBottom(LayoutPaddingBottomValue::Exact(
745
        LayoutPaddingBottom {
746
            inner: PixelValue::const_px(5),
747
        },
748
    ))),
749
    CssPropertyWithConditions::simple(CssProperty::PaddingTop(LayoutPaddingTopValue::Exact(
750
        LayoutPaddingTop {
751
            inner: PixelValue::const_px(5),
752
        },
753
    ))),
754
    CssPropertyWithConditions::simple(CssProperty::FlexGrow(LayoutFlexGrowValue::Exact(
755
        LayoutFlexGrow {
756
            inner: FloatValue::const_new(1),
757
        },
758
    ))),
759
];
760
const CSS_MATCH_4738503469417034630: CssPropertyWithConditionsVec =
761
    CssPropertyWithConditionsVec::from_const_slice(CSS_MATCH_4738503469417034630_PROPERTIES);
762

            
763
const CSS_MATCH_9988039989460234263_PROPERTIES: &[CssPropertyWithConditions] = &[
764
    // A flex container: `flex-direction` / `justify-content` / `align-items`
765
    // below do nothing without it (this rule had none, so the box laid out as
766
    // a block and its children stacked vertically).
767
    CssPropertyWithConditions::simple(CssProperty::Display(LayoutDisplayValue::Exact(
768
        LayoutDisplay::Flex,
769
    ))),
770
    // .__azul-native-tabs-header
771
    CssPropertyWithConditions::simple(CssProperty::FontSize(StyleFontSizeValue::Exact(
772
        StyleFontSize {
773
            inner: PixelValue::const_px(11),
774
        },
775
    ))),
776
    CssPropertyWithConditions::simple(CssProperty::FontFamily(StyleFontFamilyVecValue::Exact(
777
        StyleFontFamilyVec::from_const_slice(STYLE_FONT_FAMILY_8122988506401935406_ITEMS),
778
    ))),
779
    CssPropertyWithConditions::simple(CssProperty::FlexDirection(LayoutFlexDirectionValue::Exact(
780
        LayoutFlexDirection::Row,
781
    ))),
782
];
783
const CSS_MATCH_9988039989460234263: CssPropertyWithConditionsVec =
784
    CssPropertyWithConditionsVec::from_const_slice(CSS_MATCH_9988039989460234263_PROPERTIES);
785

            
786
// -- NO PADDING
787
const CSS_MATCH_18014909903571752977_PROPERTIES_NO_PADDING: &[CssPropertyWithConditions] = &[
788
    // .__azul-native-tabs-content
789
    CssPropertyWithConditions::simple(CssProperty::FlexGrow(LayoutFlexGrowValue::Exact(
790
        LayoutFlexGrow {
791
            inner: FloatValue::const_new(1),
792
        },
793
    ))),
794
    CssPropertyWithConditions::simple(CssProperty::BackgroundContent(
795
        StyleBackgroundContentVecValue::Exact(StyleBackgroundContentVec::from_const_slice(
796
            STYLE_BACKGROUND_CONTENT_16746671892555275291_ITEMS,
797
        )),
798
    )),
799
];
800
const CSS_MATCH_18014909903571752977_NO_PADDING: CssPropertyWithConditionsVec =
801
    CssPropertyWithConditionsVec::from_const_slice(
802
        CSS_MATCH_18014909903571752977_PROPERTIES_NO_PADDING,
803
    );
804

            
805
const CSS_MATCH_4738503469417034630_PROPERTIES_NO_PADDING: &[CssPropertyWithConditions] = &[
806
    // .__azul-native-tabs-container
807
    CssPropertyWithConditions::simple(CssProperty::FlexGrow(LayoutFlexGrowValue::Exact(
808
        LayoutFlexGrow {
809
            inner: FloatValue::const_new(1),
810
        },
811
    ))),
812
];
813
const CSS_MATCH_4738503469417034630_NO_PADDING: CssPropertyWithConditionsVec =
814
    CssPropertyWithConditionsVec::from_const_slice(
815
        CSS_MATCH_4738503469417034630_PROPERTIES_NO_PADDING,
816
    );
817

            
818
// -- REGULAR_INACTIVE_TAB
819

            
820
const CSS_MATCH_11510695043643111367_PROPERTIES: &[CssPropertyWithConditions] = &[
821
    // .__azul-native-tabs-header p.__azul-native-tabs-tab-not-active:hover
822
    //
823
    // Thirteen hover rules and their thirteen dark twins, declared in the
824
    // theme module — `themes::flat::TAB_HOVER_STATES` — because the dark half
825
    // of each pair needs a palette this file cannot see. Declared here they
826
    // could only ever name the light-mode blue, which is how a hovered tab
827
    // kept its light ring and fill on a dark surface. The widths and styles
828
    // are part of the set on purpose: they draw back the edge a seam tab
829
    // (`-noleftborder` / `-norightborder`) has nulled, so the ring is whole.
830
    flat::TAB_HOVER_BORDER_BOTTOM_WIDTH,
831
    flat::TAB_HOVER_BORDER_LEFT_WIDTH,
832
    flat::TAB_HOVER_BORDER_RIGHT_WIDTH,
833
    flat::TAB_HOVER_BORDER_TOP_WIDTH,
834
    flat::TAB_HOVER_BORDER_BOTTOM_STYLE,
835
    flat::TAB_HOVER_BORDER_LEFT_STYLE,
836
    flat::TAB_HOVER_BORDER_RIGHT_STYLE,
837
    flat::TAB_HOVER_BORDER_TOP_STYLE,
838
    flat::TAB_HOVER_BORDER_BOTTOM_COLOR,
839
    flat::TAB_HOVER_BORDER_LEFT_COLOR,
840
    flat::TAB_HOVER_BORDER_RIGHT_COLOR,
841
    flat::TAB_HOVER_BORDER_TOP_COLOR,
842
    flat::TAB_HOVER_BG,
843
    flat::TAB_HOVER_BORDER_BOTTOM_WIDTH_DARK,
844
    flat::TAB_HOVER_BORDER_LEFT_WIDTH_DARK,
845
    flat::TAB_HOVER_BORDER_RIGHT_WIDTH_DARK,
846
    flat::TAB_HOVER_BORDER_TOP_WIDTH_DARK,
847
    flat::TAB_HOVER_BORDER_BOTTOM_STYLE_DARK,
848
    flat::TAB_HOVER_BORDER_LEFT_STYLE_DARK,
849
    flat::TAB_HOVER_BORDER_RIGHT_STYLE_DARK,
850
    flat::TAB_HOVER_BORDER_TOP_STYLE_DARK,
851
    flat::TAB_HOVER_BORDER_BOTTOM_COLOR_DARK,
852
    flat::TAB_HOVER_BORDER_LEFT_COLOR_DARK,
853
    flat::TAB_HOVER_BORDER_RIGHT_COLOR_DARK,
854
    flat::TAB_HOVER_BORDER_TOP_COLOR_DARK,
855
    flat::TAB_HOVER_BG_DARK,
856
    // .__azul-native-tabs-header p.__azul-native-tabs-tab-not-active
857
    CssPropertyWithConditions::simple(CssProperty::PaddingRight(LayoutPaddingRightValue::Exact(
858
        LayoutPaddingRight {
859
            inner: PixelValue::const_px(5),
860
        },
861
    ))),
862
    CssPropertyWithConditions::simple(CssProperty::PaddingLeft(LayoutPaddingLeftValue::Exact(
863
        LayoutPaddingLeft {
864
            inner: PixelValue::const_px(5),
865
        },
866
    ))),
867
    CssPropertyWithConditions::simple(CssProperty::PaddingBottom(LayoutPaddingBottomValue::Exact(
868
        LayoutPaddingBottom {
869
            inner: PixelValue::const_px(1),
870
        },
871
    ))),
872
    CssPropertyWithConditions::simple(CssProperty::PaddingTop(LayoutPaddingTopValue::Exact(
873
        LayoutPaddingTop {
874
            inner: PixelValue::const_px(1),
875
        },
876
    ))),
877
    CssPropertyWithConditions::simple(CssProperty::MarginTop(LayoutMarginTopValue::Exact(
878
        LayoutMarginTop {
879
            inner: PixelValue::const_px(2),
880
        },
881
    ))),
882
    // .__azul-native-tabs-header p
883
    CssPropertyWithConditions::simple(CssProperty::TextAlign(StyleTextAlignValue::Exact(
884
        StyleTextAlign::Center,
885
    ))),
886
    CssPropertyWithConditions::simple(CssProperty::Height(LayoutHeightValue::Exact(
887
        LayoutHeight::Px(PixelValue::const_px(21)),
888
    ))),
889
    CssPropertyWithConditions::simple(CssProperty::BorderBottomWidth(
890
        LayoutBorderBottomWidthValue::Exact(LayoutBorderBottomWidth {
891
            inner: PixelValue::const_px(1),
892
        }),
893
    )),
894
    CssPropertyWithConditions::simple(CssProperty::BorderLeftWidth(
895
        LayoutBorderLeftWidthValue::Exact(LayoutBorderLeftWidth {
896
            inner: PixelValue::const_px(1),
897
        }),
898
    )),
899
    CssPropertyWithConditions::simple(CssProperty::BorderRightWidth(
900
        LayoutBorderRightWidthValue::Exact(LayoutBorderRightWidth {
901
            inner: PixelValue::const_px(1),
902
        }),
903
    )),
904
    CssPropertyWithConditions::simple(CssProperty::BorderTopWidth(
905
        LayoutBorderTopWidthValue::Exact(LayoutBorderTopWidth {
906
            inner: PixelValue::const_px(1),
907
        }),
908
    )),
909
    CssPropertyWithConditions::simple(CssProperty::BorderBottomStyle(
910
        StyleBorderBottomStyleValue::Exact(StyleBorderBottomStyle {
911
            inner: BorderStyle::Solid,
912
        }),
913
    )),
914
    CssPropertyWithConditions::simple(CssProperty::BorderLeftStyle(
915
        StyleBorderLeftStyleValue::Exact(StyleBorderLeftStyle {
916
            inner: BorderStyle::Solid,
917
        }),
918
    )),
919
    CssPropertyWithConditions::simple(CssProperty::BorderRightStyle(
920
        StyleBorderRightStyleValue::Exact(StyleBorderRightStyle {
921
            inner: BorderStyle::Solid,
922
        }),
923
    )),
924
    CssPropertyWithConditions::simple(CssProperty::BorderTopStyle(
925
        StyleBorderTopStyleValue::Exact(StyleBorderTopStyle {
926
            inner: BorderStyle::Solid,
927
        }),
928
    )),
929
    CssPropertyWithConditions::simple(CssProperty::BorderBottomColor(
930
        StyleBorderBottomColorValue::Exact(StyleBorderBottomColor {
931
            inner: ColorU {
932
                r: 172,
933
                g: 172,
934
                b: 172,
935
                a: 255,
936
            },
937
        }),
938
    )),
939
    CssPropertyWithConditions::simple(CssProperty::BorderLeftColor(
940
        StyleBorderLeftColorValue::Exact(StyleBorderLeftColor {
941
            inner: ColorU {
942
                r: 172,
943
                g: 172,
944
                b: 172,
945
                a: 255,
946
            },
947
        }),
948
    )),
949
    CssPropertyWithConditions::simple(CssProperty::BorderRightColor(
950
        StyleBorderRightColorValue::Exact(StyleBorderRightColor {
951
            inner: ColorU {
952
                r: 172,
953
                g: 172,
954
                b: 172,
955
                a: 255,
956
            },
957
        }),
958
    )),
959
    CssPropertyWithConditions::simple(CssProperty::BorderTopColor(
960
        StyleBorderTopColorValue::Exact(StyleBorderTopColor {
961
            inner: ColorU {
962
                r: 172,
963
                g: 172,
964
                b: 172,
965
                a: 255,
966
            },
967
        }),
968
    )),
969
    CssPropertyWithConditions::simple(CssProperty::BackgroundContent(
970
        StyleBackgroundContentVecValue::Exact(StyleBackgroundContentVec::from_const_slice(
971
            STYLE_BACKGROUND_CONTENT_8560341490937422656_ITEMS,
972
        )),
973
    )),
974
    CssPropertyWithConditions::simple(CssProperty::AlignItems(LayoutAlignItemsValue::Exact(
975
        LayoutAlignItems::Center,
976
    ))),
977
];
978
const CSS_MATCH_11510695043643111367: CssPropertyWithConditionsVec =
979
    CssPropertyWithConditionsVec::from_const_slice(CSS_MATCH_11510695043643111367_PROPERTIES);
980

            
981
/// Header bar for a tab widget, containing the clickable tab labels.
982
#[derive(Debug, Clone)]
983
#[repr(C)]
984
pub struct TabHeader {
985
    /// Labels for each tab.
986
    pub tabs: StringVec,
987
    /// Zero-based index of the currently active tab.
988
    pub active_tab: usize,
989
    /// Optional callback invoked when a tab is clicked.
990
    pub on_click: OptionTabOnClick,
991
}
992

            
993
impl Default for TabHeader {
994
4
    fn default() -> Self {
995
4
        Self {
996
4
            tabs: StringVec::from_const_slice(&[]),
997
4
            active_tab: 0,
998
4
            on_click: None.into(),
999
4
        }
4
    }
}
/// State passed to the tab-click callback, indicating which tab was selected.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(C)]
pub struct TabHeaderState {
    /// Zero-based index of the newly selected tab.
    pub active_tab: usize,
}
/// Signature for the tab-click callback function.
pub type TabOnClickCallbackType = extern "C" fn(RefAny, CallbackInfo, TabHeaderState) -> Update;
impl_widget_callback!(
    TabOnClick,
    OptionTabOnClick,
    TabOnClickCallback,
    TabOnClickCallbackType
);
azul_core::impl_managed_callback! {
    wrapper:        TabOnClickCallback,
    info_ty:        CallbackInfo,
    return_ty:      Update,
    default_ret:    Update::DoNothing,
    invoker_static: TAB_ON_CLICK_INVOKER,
    invoker_ty:     AzTabOnClickCallbackInvoker,
    thunk_fn:       az_tab_on_click_callback_thunk,
    setter_fn:      AzApp_setTabOnClickCallbackInvoker,
    from_handle_fn: AzTabOnClickCallback_createFromHostHandle,
    extra_args:     [ state: TabHeaderState ],
}
impl TabHeader {
    #[must_use]
83
    pub fn create(tabs: StringVec) -> Self {
83
        Self {
83
            tabs,
83
            active_tab: 0,
83
            on_click: None.into(),
83
        }
83
    }
    #[must_use]
4
    pub fn swap_with_default(&mut self) -> Self {
4
        let mut default = Self::default();
4
        core::mem::swap(&mut default, self);
4
        default
4
    }
65
    pub const fn set_active_tab(&mut self, active_tab: usize) {
65
        self.active_tab = active_tab;
65
    }
    #[must_use]
38
    pub const fn with_active_tab(mut self, active_tab: usize) -> Self {
38
        self.set_active_tab(active_tab);
38
        self
38
    }
14
    pub fn set_on_click<C: Into<TabOnClickCallback>>(&mut self, refany: RefAny, on_click: C) {
14
        self.on_click = Some(TabOnClick {
14
            refany,
14
            callback: on_click.into(),
14
        })
14
        .into();
14
    }
    #[must_use]
7
    pub fn with_on_click<C: Into<TabOnClickCallback>>(
7
        mut self,
7
        refany: RefAny,
7
        on_click: C,
7
    ) -> Self {
7
        self.set_on_click(refany, on_click);
7
        self
7
    }
    #[allow(clippy::too_many_lines)] // large but cohesive: single-purpose layout/render/parse routine (one branch per case)
    #[must_use]
54
    pub fn dom(self) -> Dom {
        use azul_core::callbacks::CoreCallbackDataVec;
        // classes for previous tab
        const IDS_AND_CLASSES_5117007530891373979: &[IdOrClass] = &[
            Class(AzString::from_const_str(
                "__azul-native-tabs-tab-norightborder",
            )),
            Class(AzString::from_const_str(
                "__azul-native-tabs-tab-not-active",
            )),
        ]; // CSS_MATCH_4415083954137121609
        // classes for current tab
        const IDS_AND_CLASSES_15002865554973741556: &[IdOrClass] = &[Class(
            AzString::from_const_str("__azul-native-tabs-tab-active"),
        )];
        // classes for next tab
        const IDS_AND_CLASSES_16877793354714897051: &[IdOrClass] = &[
            Class(AzString::from_const_str(
                "__azul-native-tabs-tab-noleftborder",
            )),
            Class(AzString::from_const_str(
                "__azul-native-tabs-tab-not-active",
            )),
        ];
        // classes for default inactive tab
        const IDS_AND_CLASSES_INACTIVE: &[IdOrClass] = &[Class(AzString::from_const_str(
            "__azul-native-tabs-tab-not-active",
        ))];
54
        let on_click_is_some = self.on_click.is_some();
54
        Dom::create_div()
54
            .with_css_props(CSS_MATCH_9988039989460234263)
54
            .with_ids_and_classes({
                const IDS_AND_CLASSES_6172459441955124689: &[IdOrClass] =
                    &[Class(AzString::from_const_str("__azul-native-tabs-header"))];
54
                IdOrClassVec::from_const_slice(IDS_AND_CLASSES_6172459441955124689)
            })
54
            .with_children({
54
                let mut tab_items = vec![Dom::create_div()
54
                    .with_css_props(CSS_MATCH_17290739305197504468)
54
                    .with_ids_and_classes({
                        const IDS_AND_CLASSES_8360971686689797550: &[IdOrClass] = &[Class(
                            AzString::from_const_str("__azul-native-tabs-before-tabs"),
                        )];
54
                        IdOrClassVec::from_const_slice(IDS_AND_CLASSES_8360971686689797550)
                    })];
54
                let dataset = TabLocalDataset {
54
                    tab_idx: 0,
54
                    on_click: self.on_click,
54
                };
1257
                for (tab_idx, tab) in self.tabs.as_ref().iter().enumerate() {
1257
                    let next_tab_is_active = self.active_tab == tab_idx.saturating_add(1);
1257
                    let previous_tab_was_active = if self.active_tab == 0 {
1142
                        false
                    } else {
115
                        self.active_tab == tab_idx.saturating_sub(1)
                    };
1257
                    let tab_is_active = self.active_tab == tab_idx;
1257
                    let (ids_and_classes, css_props) = if tab_is_active {
40
                        (
40
                            IDS_AND_CLASSES_15002865554973741556,
40
                            CSS_MATCH_14575853790110873394,
40
                        )
1217
                    } else if next_tab_is_active {
                        // tab before the active tab
16
                        (
16
                            IDS_AND_CLASSES_5117007530891373979,
16
                            CSS_MATCH_4415083954137121609,
16
                        )
1201
                    } else if previous_tab_was_active {
                        // tab after the active tab
11
                        (
11
                            IDS_AND_CLASSES_16877793354714897051,
11
                            CSS_MATCH_13824480602841492081,
11
                        )
                    } else {
                        // default inactive tab
1190
                        (IDS_AND_CLASSES_INACTIVE, CSS_MATCH_11510695043643111367)
                    };
1257
                    let mut dataset = dataset.clone();
1257
                    dataset.tab_idx = tab_idx;
1257
                    let dataset = RefAny::new(dataset);
1257
                    tab_items.push(
1257
                        crate::widgets::widget_p_with_text(tab.clone())
1257
                            .with_callbacks(if on_click_is_some {
21
                                vec![CoreCallbackData {
21
                                    event: EventFilter::Hover(HoverEventFilter::Click),
21
                                    callback: CoreCallback {
21
                                        cb: on_tab_click as usize,
21
                                        ctx: azul_core::refany::OptionRefAny::None,
21
                                    },
21
                                    refany: dataset.clone(),
21
                                }]
21
                                .into()
                            } else {
1236
                                CoreCallbackDataVec::from_const_slice(&[])
                            })
1257
                            .with_dataset(Some(dataset).into())
1257
                            .with_css_props(css_props)
1257
                            .with_ids_and_classes(IdOrClassVec::from_const_slice(ids_and_classes)),
                    );
                }
54
                tab_items.push(
54
                    Dom::create_div()
54
                        .with_css_props(CSS_MATCH_3088386549906605418)
54
                        .with_ids_and_classes({
                            const IDS_AND_CLASSES_11001585590816277275: &[IdOrClass] = &[Class(
                                AzString::from_const_str("__azul-native-tabs-after-tabs"),
                            )];
54
                            IdOrClassVec::from_const_slice(IDS_AND_CLASSES_11001585590816277275)
                        }),
                );
54
                tab_items.into()
            })
54
    }
}
/// Content panel displayed beneath the active tab in a tab widget.
#[derive(Debug, Clone)]
#[repr(C)]
pub struct TabContent {
    /// The DOM subtree shown as the tab's content area.
    pub content: Dom,
    /// Whether the content area includes default padding.
    pub has_padding: bool,
}
impl Default for TabContent {
2
    fn default() -> Self {
2
        Self {
2
            content: Dom::create_div(),
2
            has_padding: true,
2
        }
2
    }
}
impl TabContent {
    #[must_use]
19
    pub const fn new(content: Dom) -> Self {
19
        Self {
19
            content,
19
            has_padding: true,
19
        }
19
    }
    #[must_use]
1
    pub fn swap_with_default(&mut self) -> Self {
1
        let mut default = Self::default();
1
        core::mem::swap(&mut default, self);
1
        default
1
    }
    #[must_use]
8
    pub const fn with_padding(mut self, padding: bool) -> Self {
8
        self.set_padding(padding);
8
        self
8
    }
10
    pub const fn set_padding(&mut self, padding: bool) {
10
        self.has_padding = padding;
10
    }
    #[must_use]
12
    pub fn dom(self) -> Dom {
        const IDS_AND_CLASSES_2989815829020816222: &[IdOrClass] = &[Class(
            AzString::from_const_str("__azul-native-tabs-content"),
        )];
12
        let tab_content_css_style = if self.has_padding {
11
            CSS_MATCH_18014909903571752977
        } else {
1
            CSS_MATCH_18014909903571752977_NO_PADDING
        };
12
        Dom::create_div()
12
            .with_css_props(tab_content_css_style)
12
            .with_children(DomVec::from_vec(vec![Dom::create_div()
12
                .with_ids_and_classes(IdOrClassVec::from_const_slice(
                    IDS_AND_CLASSES_2989815829020816222,
                ))
12
                .with_children(DomVec::from_vec(vec![self.content]))]))
12
    }
}
#[derive(Clone)]
struct TabLocalDataset {
    tab_idx: usize,
    on_click: OptionTabOnClick,
}
23
extern "C" fn on_tab_click(mut refany: RefAny, info: CallbackInfo) -> Update {
23
    fn select_new_tab_inner(mut refany: RefAny, info: &CallbackInfo) -> Option<Update> {
23
        let mut tab_local_dataset = refany.downcast_mut::<TabLocalDataset>()?;
20
        let tab_idx = tab_local_dataset.tab_idx;
20
        let tab_header_state = TabHeaderState {
20
            active_tab: tab_idx,
20
        };
20
        let result = {
            // rustc doesn't understand the borrowing lifetime here
20
            let tab_local_dataset = &mut *tab_local_dataset;
20
            let onclick = &mut tab_local_dataset.on_click;
20
            match onclick.as_mut() {
18
                Some(TabOnClick { callback, refany }) => {
18
                    (callback.cb)(refany.clone(), *info, tab_header_state)
                }
2
                None => Update::DoNothing,
            }
        };
20
        Some(result)
23
    }
23
    select_new_tab_inner(refany, &info).unwrap_or(Update::RefreshDom)
23
}
#[cfg(test)]
mod autotest_generated {
    use std::{
        collections::BTreeMap,
        sync::{Arc, Mutex},
    };
    use azul_core::{
        dom::{DomId, DomNodeId, NodeId, NodeType},
        geom::OptionLogicalPosition,
        gl::OptionGlContextPtr,
        hit_test::ScrollPosition,
        refany::OptionRefAny,
        resources::RendererResources,
        styled_dom::{NodeHierarchyItemId, StyledDom},
        window::{MonitorVec, RawWindowHandle},
    };
    use azul_css::{
        dynamic_selector::{DynamicSelector, PseudoStateType, ThemeCondition},
        system::SystemStyle,
    };
    use rust_fontconfig::FcFontCache;
    use super::*;
    #[cfg(feature = "icu")]
    use crate::icu::IcuLocalizerHandle;
    use crate::{
        callbacks::{CallbackChange, CallbackInfoRefData, ExternalSystemCallbacks},
        widgets::theme_probe,
        window::LayoutWindow,
        window_state::FullWindowState,
    };
    // ------------------------------------------------------------------
    // Helpers
    // ------------------------------------------------------------------
    const CLASS_ACTIVE: &str = "__azul-native-tabs-tab-active";
    const CLASS_NOT_ACTIVE: &str = "__azul-native-tabs-tab-not-active";
    const CLASS_NO_LEFT: &str = "__azul-native-tabs-tab-noleftborder";
    const CLASS_NO_RIGHT: &str = "__azul-native-tabs-tab-norightborder";
    const CLASS_HEADER: &str = "__azul-native-tabs-header";
    const CLASS_BEFORE: &str = "__azul-native-tabs-before-tabs";
    const CLASS_AFTER: &str = "__azul-native-tabs-after-tabs";
    const CLASS_CONTENT: &str = "__azul-native-tabs-content";
    fn strings(items: &[&str]) -> StringVec {
        StringVec::from_vec(items.iter().map(|s| AzString::from(*s)).collect())
    }
    fn numbered_labels(n: usize) -> StringVec {
        StringVec::from_vec((0..n).map(|i| AzString::from(format!("tab {i}"))).collect())
    }
    /// The text of a text node, looking through the `<p>` block wrapper the
    /// label convention mandates (`p > text`).
    fn text_of(node: &Dom) -> Option<&str> {
        match node.root.get_node_type() {
            NodeType::Text(s) => Some(s.as_ref().as_str()),
            NodeType::P => match node.children.as_ref() {
                [only] => match only.root.get_node_type() {
                    NodeType::Text(s) => Some(s.as_ref().as_str()),
                    _ => None,
                },
                _ => None,
            },
            _ => None,
        }
    }
    fn classes(node: &Dom) -> Vec<String> {
        node.root
            .get_ids_and_classes()
            .as_ref()
            .iter()
            .filter_map(|c| match c {
                Class(s) => Some(s.as_str().to_string()),
                IdOrClass::Id(_) => None,
            })
            .collect()
    }
    fn class_strs(node: &Dom) -> Vec<&'static str> {
        // The widget only ever attaches the eight `&'static str` classes above;
        // map back to them so the tests can compare against string literals.
        classes(node)
            .into_iter()
            .map(|c| {
                [
                    CLASS_ACTIVE,
                    CLASS_NOT_ACTIVE,
                    CLASS_NO_LEFT,
                    CLASS_NO_RIGHT,
                    CLASS_HEADER,
                    CLASS_BEFORE,
                    CLASS_AFTER,
                    CLASS_CONTENT,
                ]
                .into_iter()
                .find(|known| *known == c)
                .unwrap_or_else(|| panic!("tabs.rs emitted an unknown class: {c}"))
            })
            .collect()
    }
    /// A style vec as `(property, condition-count)` pairs in declaration order —
    /// the exact shape `Css::from(CssPropertyWithConditionsVec)` preserves.
    fn declared(v: &CssPropertyWithConditionsVec) -> Vec<(CssProperty, usize)> {
        v.as_ref()
            .iter()
            .map(|p| (p.property.clone(), p.apply_if.as_ref().len()))
            .collect()
    }
    /// The same view, read back off a rendered node's inline `Css`.
    fn inline_declared(node: &Dom) -> Vec<(CssProperty, usize)> {
        node.root
            .style
            .iter_inline_properties()
            .map(|(p, conds)| (p.clone(), conds.as_ref().len()))
            .collect()
    }
    /// Every declaration in `v` matching `pred`, in declaration order.
    fn decls_where(
        v: &CssPropertyWithConditionsVec,
        pred: fn(&CssProperty) -> bool,
    ) -> Vec<CssProperty> {
        v.as_ref()
            .iter()
            .filter(|p| pred(&p.property))
            .map(|p| p.property.clone())
            .collect()
    }
    /// Same, but skipping the `:hover` block — these styles declare the border
    /// properties once for hover and again unconditionally, so a raw filter would
    /// mix the two sets.
    fn plain_decls_where(
        v: &CssPropertyWithConditionsVec,
        pred: fn(&CssProperty) -> bool,
    ) -> Vec<CssProperty> {
        v.as_ref()
            .iter()
            .filter(|p| p.apply_if.as_ref().is_empty() && pred(&p.property))
            .map(|p| p.property.clone())
            .collect()
    }
    /// `:hover` alone — the light half of a hover pair.
    fn is_hover_only(conds: &[DynamicSelector]) -> bool {
        matches!(
            conds,
            [DynamicSelector::PseudoState(PseudoStateType::Hover)]
        )
    }
    /// `:hover` AND dark — the twin `themes::flat` pairs with every light rule.
    fn is_dark_hover(conds: &[DynamicSelector]) -> bool {
        conds.len() == 2
            && conds
                .iter()
                .any(|c| matches!(c, DynamicSelector::Theme(ThemeCondition::Dark)))
            && conds
                .iter()
                .any(|c| matches!(c, DynamicSelector::PseudoState(PseudoStateType::Hover)))
    }
    /// The style vec the widget must pair with a given class combination.
    fn style_for_classes(cls: &[&str]) -> CssPropertyWithConditionsVec {
        let cls = cls.to_vec();
        if cls == [CLASS_ACTIVE] {
            CSS_MATCH_14575853790110873394
        } else if cls == [CLASS_NO_RIGHT, CLASS_NOT_ACTIVE] {
            CSS_MATCH_4415083954137121609
        } else if cls == [CLASS_NO_LEFT, CLASS_NOT_ACTIVE] {
            CSS_MATCH_13824480602841492081
        } else if cls == [CLASS_NOT_ACTIVE] {
            CSS_MATCH_11510695043643111367
        } else {
            panic!("unexpected class combination on a tab node: {cls:?}");
        }
    }
    /// The dataset `RefAny` a rendered tab node carries (cloned, so the caller
    /// can `downcast_*` it without borrowing the Dom mutably).
    fn dataset_of(node: &Dom) -> RefAny {
        node.root
            .get_dataset()
            .expect("every tab node carries a TabLocalDataset")
            .clone()
    }
    fn tab_idx_of(node: &Dom) -> usize {
        let mut ds = dataset_of(node);
        let tab_idx = ds
            .downcast_ref::<TabLocalDataset>()
            .expect("the dataset must be a TabLocalDataset")
            .tab_idx;
        tab_idx
    }
    /// A `RefAny` payload recording every state a user `on_click` observes.
    #[derive(Default)]
    struct ClickLog {
        seen: Vec<TabHeaderState>,
    }
    extern "C" fn record_click(
        mut refany: RefAny,
        _: CallbackInfo,
        state: TabHeaderState,
    ) -> Update {
        if let Some(mut log) = refany.downcast_mut::<ClickLog>() {
            log.seen.push(state);
        }
        Update::RefreshDom
    }
    extern "C" fn click_do_nothing(_: RefAny, _: CallbackInfo, _: TabHeaderState) -> Update {
        Update::DoNothing
    }
    extern "C" fn click_refresh_all(_: RefAny, _: CallbackInfo, _: TabHeaderState) -> Update {
        Update::RefreshDomAllWindows
    }
    /// Forces the `fn`-item -> `fn`-pointer coercion the `Into` bound needs.
    fn cb(f: TabOnClickCallbackType) -> TabOnClickCallback {
        f.into()
    }
    fn logged(refany: &mut RefAny) -> Vec<TabHeaderState> {
        refany
            .downcast_ref::<ClickLog>()
            .expect("payload must still be a ClickLog")
            .seen
            .clone()
    }
    fn dataset(tab_idx: usize, on_click: OptionTabOnClick) -> RefAny {
        RefAny::new(TabLocalDataset { tab_idx, on_click })
    }
    fn click_handler(refany: RefAny, callback: TabOnClickCallbackType) -> OptionTabOnClick {
        Some(TabOnClick {
            refany,
            callback: cb(callback),
        })
        .into()
    }
    /// Invokes `on_tab_click` with a minimal `CallbackInfo` (the handler never
    /// touches the layout window — it only downcasts its own dataset — so an
    /// empty `LayoutWindow` and node 0 as the hit node are enough).
    /// Returns the `Update` plus every recorded `CallbackChange`.
    fn run_click(data: RefAny) -> (Update, Vec<CallbackChange>) {
        let layout_window =
            LayoutWindow::new(FcFontCache::default()).expect("LayoutWindow::new failed");
        let renderer_resources = RendererResources::default();
        let previous_window_state: Option<FullWindowState> = None;
        let current_window_state = FullWindowState::default();
        let gl_context = OptionGlContextPtr::None;
        let scroll_states: BTreeMap<DomId, BTreeMap<NodeHierarchyItemId, ScrollPosition>> =
            BTreeMap::new();
        let window_handle = RawWindowHandle::Unsupported;
        let system_callbacks = ExternalSystemCallbacks::rust_internal();
        let ref_data = CallbackInfoRefData {
            layout_window: &layout_window,
            renderer_resources: &renderer_resources,
            previous_window_state: &previous_window_state,
            current_window_state: &current_window_state,
            gl_context: &gl_context,
            current_scroll_manager: &scroll_states,
            current_window_handle: &window_handle,
            system_callbacks: &system_callbacks,
            system_style: Arc::new(SystemStyle::default()),
            monitors: Arc::new(Mutex::new(MonitorVec::from_const_slice(&[]))),
            #[cfg(feature = "icu")]
            icu_localizer: IcuLocalizerHandle::default(),
            ctx: OptionRefAny::None,
        };
        let changes: Arc<Mutex<Vec<CallbackChange>>> = Arc::new(Mutex::new(Vec::new()));
        let info = CallbackInfo::new(
            &ref_data,
            &changes,
            DomNodeId {
                dom: DomId::ROOT_ID,
                node: NodeHierarchyItemId::from_crate_internal(Some(NodeId::new(0))),
            },
            OptionLogicalPosition::None,
            OptionLogicalPosition::None,
        );
        let update = on_tab_click(data, info);
        let recorded = core::mem::take(&mut *changes.lock().expect("change log poisoned"));
        (update, recorded)
    }
    // ==================================================================
    // TabHeader::create
    // ==================================================================
    #[test]
    fn create_keeps_the_label_vec_verbatim_and_starts_inert() {
        for labels in [
            strings(&[]),
            strings(&["only"]),
            strings(&["a", "b", "c"]),
            numbered_labels(1000),
        ] {
            let expected: Vec<AzString> = labels.as_ref().to_vec();
            let header = TabHeader::create(labels);
            assert_eq!(
                header.tabs.as_ref(),
                expected.as_slice(),
                "create must not reorder, drop or rewrite labels"
            );
            assert_eq!(header.active_tab, 0, "a fresh header selects the first tab");
            assert!(
                header.on_click.is_none(),
                "create must not install a callback"
            );
        }
    }
    #[test]
    fn create_accepts_an_empty_label_vec_and_still_renders_the_spacers() {
        // Zero tabs is the degenerate case: the loop body never runs, but the
        // before/after spacers must still be emitted or the header collapses.
        let dom = TabHeader::create(strings(&[])).dom();
        let children = dom.children.as_ref();
        assert_eq!(children.len(), 2, "an empty header is just the two spacers");
        assert_eq!(class_strs(&children[0]), vec![CLASS_BEFORE]);
        assert_eq!(class_strs(&children[1]), vec![CLASS_AFTER]);
    }
    #[test]
    fn create_round_trips_pathological_labels_through_the_dom() {
        // The label is only ever cloned into a `NodeType::Text`, never parsed,
        // trimmed or NUL-terminated — so every byte must survive verbatim.
        let long = "\u{e9}".repeat(50_000);
        let pathological: Vec<String> = vec![
            String::new(),
            " ".to_string(),
            "\0embedded\0nul\0".to_string(),
            "\u{1F600}\u{1F3F4}\u{E0067}\u{E007F}".to_string(), // emoji + tag sequence
            "a\u{0301}\u{0327}\u{0328}".to_string(),            // stacked combining marks
            "\u{202E}reversed\u{202C}".to_string(),             // RTL override
            "\r\n\t".to_string(),
            "\u{FFFD}\u{FEFF}".to_string(), // replacement char + BOM
            long.clone(),
        ];
        let labels = StringVec::from_vec(
            pathological
                .iter()
                .map(|s| AzString::from(s.clone()))
                .collect(),
        );
        let dom = TabHeader::create(labels).dom();
        let children = dom.children.as_ref();
        assert_eq!(children.len(), pathological.len() + 2);
        for (i, expected) in pathological.iter().enumerate() {
            assert_eq!(
                text_of(&children[i + 1]),
                Some(expected.as_str()),
                "label {i} did not round-trip through the DOM"
            );
        }
    }
    // ==================================================================
    // TabHeader::set_active_tab / with_active_tab  (numeric)
    // ==================================================================
    #[test]
    fn set_active_tab_stores_any_usize_without_clamping_or_panicking() {
        // `active_tab` is an unsigned index with no documented upper bound and
        // no relation to `tabs.len()` — there is no signed path to test, so the
        // adversarial values are 0, the wrap-around of 0 and the two extremes.
        let extremes = [
            0usize,
            1,
            2,
            usize::MAX / 2,
            usize::MAX - 1,
            usize::MAX,
            0usize.wrapping_sub(1),
        ];
        for value in extremes {
            let mut header = TabHeader::create(strings(&["a", "b", "c"]));
            header.set_active_tab(value);
            assert_eq!(
                header.active_tab, value,
                "set_active_tab must store the index verbatim (no clamp to len)"
            );
            // Idempotent + last-write-wins.
            header.set_active_tab(value);
            assert_eq!(header.active_tab, value);
            header.set_active_tab(0);
            assert_eq!(header.active_tab, 0, "the last write must win");
        }
    }
    #[test]
    fn set_active_tab_touches_nothing_but_the_index() {
        let mut header = TabHeader::create(strings(&["a", "b"]));
        header.set_on_click(RefAny::new(ClickLog::default()), cb(record_click));
        header.set_active_tab(usize::MAX);
        assert_eq!(
            header.tabs.as_ref(),
            strings(&["a", "b"]).as_ref(),
            "the labels must be untouched"
        );
        assert!(
            header.on_click.is_some(),
            "the callback must survive a selection change"
        );
    }
    #[test]
    fn with_active_tab_agrees_with_set_active_tab_at_every_extreme() {
        for value in [0usize, 1, usize::MAX / 2, usize::MAX - 1, usize::MAX] {
            let built = TabHeader::create(strings(&["a", "b"])).with_active_tab(value);
            let mut mutated = TabHeader::create(strings(&["a", "b"]));
            mutated.set_active_tab(value);
            assert_eq!(built.active_tab, mutated.active_tab);
            assert_eq!(built.active_tab, value);
            assert_eq!(built.tabs.as_ref(), mutated.tabs.as_ref());
            assert!(built.on_click.is_none() && mutated.on_click.is_none());
        }
    }
    #[test]
    fn with_active_tab_chains_last_wins() {
        let header = TabHeader::create(strings(&["a"]))
            .with_active_tab(usize::MAX)
            .with_active_tab(7)
            .with_active_tab(0);
        assert_eq!(header.active_tab, 0);
    }
    #[test]
    fn dom_never_marks_a_tab_active_when_the_index_is_out_of_range() {
        // An out-of-range selection must degrade to "nothing selected" rather
        // than panicking or wrapping onto some other tab.
        let n = 4usize;
        for active in [n, n + 1, n + 2, usize::MAX / 2, usize::MAX - 1, usize::MAX] {
            let dom = TabHeader::create(numbered_labels(n))
                .with_active_tab(active)
                .dom();
            let children = dom.children.as_ref();
            assert_eq!(children.len(), n + 2, "active={active}: wrong child count");
            for (i, node) in children[1..=n].iter().enumerate() {
                let cls = class_strs(node);
                assert!(
                    !cls.contains(&CLASS_ACTIVE),
                    "active={active}: tab {i} must not be styled active"
                );
                assert!(
                    cls.contains(&CLASS_NOT_ACTIVE),
                    "active={active}: tab {i} must be styled inactive"
                );
            }
        }
    }
    #[test]
    fn dom_at_usize_max_gives_every_tab_the_plain_inactive_style() {
        // `tab_idx.saturating_add(1)` / `saturating_sub(1)` must not wrap into a
        // false neighbour match at the extreme.
        let n = 5usize;
        let dom = TabHeader::create(numbered_labels(n))
            .with_active_tab(usize::MAX)
            .dom();
        for (i, node) in dom.children.as_ref()[1..=n].iter().enumerate() {
            assert_eq!(
                class_strs(node),
                vec![CLASS_NOT_ACTIVE],
                "tab {i} must carry the plain inactive class only"
            );
            assert_eq!(
                inline_declared(node),
                declared(&CSS_MATCH_11510695043643111367),
                "tab {i} must carry the plain inactive style"
            );
        }
    }
    #[test]
    fn dom_one_past_the_end_still_seams_the_last_tab() {
        // PINNED QUIRK: with `active_tab == tabs.len()` no tab is active, yet the
        // *last* tab still matches `active_tab == tab_idx + 1` and loses its right
        // border — a visible seam against the after-tabs spacer. Deliberately
        // pinned: if the widget starts range-checking `active_tab`, this flips.
        let n = 3usize;
        let dom = TabHeader::create(numbered_labels(n))
            .with_active_tab(n)
            .dom();
        let children = dom.children.as_ref();
        assert_eq!(
            class_strs(&children[n]),
            vec![CLASS_NO_RIGHT, CLASS_NOT_ACTIVE],
            "the last tab is styled as if the (non-existent) next tab were active"
        );
        for (i, node) in children[1..n].iter().enumerate() {
            assert_eq!(class_strs(node), vec![CLASS_NOT_ACTIVE], "tab {i}");
        }
    }
    // ==================================================================
    // TabHeader::swap_with_default
    // ==================================================================
    #[test]
    fn swap_with_default_moves_the_state_out_and_leaves_a_default() {
        let mut header = TabHeader::create(strings(&["a", "b", "c"])).with_active_tab(2);
        header.set_on_click(RefAny::new(ClickLog::default()), cb(record_click));
        let taken = header.swap_with_default();
        assert_eq!(taken.tabs.as_ref(), strings(&["a", "b", "c"]).as_ref());
        assert_eq!(taken.active_tab, 2);
        assert!(
            taken.on_click.is_some(),
            "the callback moves out with the state"
        );
        assert!(
            header.tabs.as_ref().is_empty(),
            "the husk must have no tabs"
        );
        assert_eq!(header.active_tab, 0);
        assert!(
            header.on_click.is_none(),
            "the husk must not keep a live callback"
        );
    }
    #[test]
    fn swap_with_default_twice_yields_a_default_the_second_time() {
        let mut header = TabHeader::create(strings(&["a"])).with_active_tab(usize::MAX);
        let first = header.swap_with_default();
        let second = header.swap_with_default();
        assert_eq!(first.active_tab, usize::MAX);
        assert_eq!(first.tabs.as_ref().len(), 1);
        assert_eq!(second.active_tab, 0);
        assert!(second.tabs.as_ref().is_empty());
    }
    #[test]
    fn swap_with_default_releases_the_callback_payload_when_dropped() {
        let user = RefAny::new(ClickLog::default());
        let mut header = TabHeader::create(strings(&["a"]));
        header.set_on_click(user.clone(), cb(record_click));
        assert_eq!(user.get_ref_count(), 2);
        drop(header.swap_with_default());
        assert_eq!(
            user.get_ref_count(),
            1,
            "the swapped-out header must drop its payload clone"
        );
    }
    // ==================================================================
    // TabHeader::set_on_click / with_on_click
    // ==================================================================
    #[test]
    fn with_on_click_installs_the_callback_and_touches_nothing_else() {
        let before = TabHeader::create(strings(&["a", "b"])).with_active_tab(1);
        let mut after = TabHeader::create(strings(&["a", "b"]))
            .with_active_tab(1)
            .with_on_click(RefAny::new(ClickLog::default()), cb(record_click));
        assert_eq!(after.tabs.as_ref(), before.tabs.as_ref());
        assert_eq!(after.active_tab, before.active_tab);
        let installed = after
            .on_click
            .as_mut()
            .expect("with_on_click must install Some(..)");
        assert_eq!(installed.callback.cb as usize, record_click as usize);
        assert!(
            installed.refany.downcast_ref::<ClickLog>().is_some(),
            "the payload must be stored as handed in"
        );
    }
    #[test]
    fn set_on_click_overwrites_the_previous_callback_and_payload() {
        let mut header = TabHeader::create(strings(&["a"]));
        header.set_on_click(RefAny::new(ClickLog::default()), cb(record_click));
        header.set_on_click(RefAny::new(42u32), cb(click_do_nothing));
        let installed = header
            .on_click
            .as_mut()
            .expect("still Some after overwrite");
        assert_eq!(
            installed.callback.cb as usize, click_do_nothing as usize,
            "the last set_on_click must win"
        );
        assert_eq!(
            installed.refany.downcast_ref::<u32>().map(|v| *v),
            Some(42),
            "the payload must be replaced together with the fn pointer"
        );
        assert!(
            installed.refany.downcast_ref::<ClickLog>().is_none(),
            "the stale payload must be gone"
        );
    }
    #[test]
    fn set_on_click_drops_the_previous_payload() {
        let first = RefAny::new(ClickLog::default());
        let second = RefAny::new(ClickLog::default());
        let mut header = TabHeader::create(strings(&["a"]));
        header.set_on_click(first.clone(), cb(record_click));
        assert_eq!(first.get_ref_count(), 2);
        header.set_on_click(second.clone(), cb(record_click));
        assert_eq!(
            first.get_ref_count(),
            1,
            "overwriting the callback must release the old payload"
        );
        assert_eq!(second.get_ref_count(), 2);
    }
    #[test]
    fn generic_callback_conversion_round_trips_the_fn_pointer() {
        // The FFI path (`From<Callback>`) transmutes the fn pointer; a corrupted
        // value would be an unconditional jump into garbage at click time.
        // (Never invoked here.)
        let raw = record_click as usize;
        let generic = Callback {
            cb: unsafe { core::mem::transmute::<usize, crate::callbacks::CallbackType>(raw) },
            ctx: OptionRefAny::None,
        };
        let converted: TabOnClickCallback = generic.into();
        assert_eq!(converted.cb as usize, raw);
    }
    // ==================================================================
    // TabHeader::dom — structure
    // ==================================================================
    #[test]
    fn dom_is_a_header_div_wrapping_spacer_tabs_spacer() {
        for n in [0usize, 1, 2, 3, 17] {
            let dom = TabHeader::create(numbered_labels(n)).dom();
            assert_eq!(class_strs(&dom), vec![CLASS_HEADER]);
            assert_eq!(
                inline_declared(&dom),
                declared(&CSS_MATCH_9988039989460234263)
            );
            assert!(
                matches!(dom.root.get_node_type(), NodeType::Div),
                "the header itself is a plain div"
            );
            let children = dom.children.as_ref();
            assert_eq!(children.len(), n + 2, "n={n}: spacer + {n} tabs + spacer");
            assert_eq!(class_strs(&children[0]), vec![CLASS_BEFORE]);
            assert_eq!(
                inline_declared(&children[0]),
                declared(&CSS_MATCH_17290739305197504468)
            );
            assert_eq!(class_strs(&children[n + 1]), vec![CLASS_AFTER]);
            assert_eq!(
                inline_declared(&children[n + 1]),
                declared(&CSS_MATCH_3088386549906605418)
            );
            for (i, node) in children[1..=n].iter().enumerate() {
                assert_eq!(
                    text_of(node),
                    Some(format!("tab {i}").as_str()),
                    "n={n}: tab {i} sits at sibling position {}",
                    i + 1
                );
            }
        }
    }
    #[test]
    fn dom_marks_exactly_one_tab_active_for_every_in_range_index() {
        let n = 6usize;
        for active in 0..n {
            let dom = TabHeader::create(numbered_labels(n))
                .with_active_tab(active)
                .dom();
            let children = dom.children.as_ref();
            let active_nodes: Vec<usize> = children[1..=n]
                .iter()
                .enumerate()
                .filter(|(_, node)| class_strs(node).contains(&CLASS_ACTIVE))
                .map(|(i, _)| i)
                .collect();
            assert_eq!(
                active_nodes,
                vec![active],
                "exactly the selected tab must carry the active class"
            );
            for (i, node) in children[1..=n].iter().enumerate() {
                let cls = class_strs(node);
                assert_eq!(
                    cls.contains(&CLASS_ACTIVE),
                    !cls.contains(&CLASS_NOT_ACTIVE),
                    "active={active}, tab {i}: active/not-active must be exclusive"
                );
                assert!(
                    !(cls.contains(&CLASS_NO_LEFT) && cls.contains(&CLASS_NO_RIGHT)),
                    "active={active}, tab {i}: a tab cannot drop both side borders"
                );
                assert!(
                    !(cls.contains(&CLASS_ACTIVE)
                        && (cls.contains(&CLASS_NO_LEFT) || cls.contains(&CLASS_NO_RIGHT))),
                    "active={active}, tab {i}: the active tab keeps both side borders"
                );
            }
        }
    }
    #[test]
    fn dom_gives_the_neighbours_of_the_active_tab_their_seam_classes() {
        // active = 2 of 5: tab 1 loses its right border, tab 3 its left one.
        let dom = TabHeader::create(numbered_labels(5))
            .with_active_tab(2)
            .dom();
        let children = dom.children.as_ref();
        assert_eq!(class_strs(&children[1]), vec![CLASS_NOT_ACTIVE], "tab 0");
        assert_eq!(
            class_strs(&children[2]),
            vec![CLASS_NO_RIGHT, CLASS_NOT_ACTIVE],
            "tab 1 sits before the active tab"
        );
        assert_eq!(class_strs(&children[3]), vec![CLASS_ACTIVE], "tab 2");
        assert_eq!(
            class_strs(&children[4]),
            vec![CLASS_NO_LEFT, CLASS_NOT_ACTIVE],
            "tab 3 sits after the active tab"
        );
        assert_eq!(class_strs(&children[5]), vec![CLASS_NOT_ACTIVE], "tab 4");
    }
    #[test]
    fn dom_first_tab_active_leaves_the_second_tab_with_a_left_border() {
        // PINNED BUG: `previous_tab_was_active` short-circuits on
        // `self.active_tab == 0`, so for the *default* selection (tab 0) the tab
        // right after the active one never gets `-noleftborder` — it draws a left
        // border straight against the active tab's right edge. Every other
        // selection (see the test above) does emit the class. Pinned as-is so the
        // fix flips this test loudly.
        let dom = TabHeader::create(numbered_labels(4))
            .with_active_tab(0)
            .dom();
        let children = dom.children.as_ref();
        assert_eq!(class_strs(&children[1]), vec![CLASS_ACTIVE], "tab 0");
        assert_eq!(
            class_strs(&children[2]),
            vec![CLASS_NOT_ACTIVE],
            "tab 1 should be [-noleftborder, -not-active] like the active=1..n case"
        );
        assert_eq!(class_strs(&children[3]), vec![CLASS_NOT_ACTIVE], "tab 2");
        // The symmetric neighbour (active = 1) *does* get the class, which is what
        // makes the case above an inconsistency rather than a design choice.
        let dom = TabHeader::create(numbered_labels(4))
            .with_active_tab(1)
            .dom();
        assert_eq!(
            class_strs(&dom.children.as_ref()[3]),
            vec![CLASS_NO_LEFT, CLASS_NOT_ACTIVE],
            "tab 2 after active tab 1"
        );
    }
    #[test]
    fn dom_pairs_every_tab_style_with_the_classes_it_advertises() {
        // A swapped class/style pair (e.g. the "noleftborder" node getting the
        // style that nulls the *right* border) would be invisible in a class-only
        // check, so compare the rendered inline style against the vec the class
        // combination demands.
        let n = 6usize;
        for active in [0usize, 1, 2, n - 1, n, usize::MAX] {
            let dom = TabHeader::create(numbered_labels(n))
                .with_active_tab(active)
                .dom();
            for (i, node) in dom.children.as_ref()[1..=n].iter().enumerate() {
                let cls = class_strs(node);
                assert_eq!(
                    inline_declared(node),
                    declared(&style_for_classes(&cls)),
                    "active={active}, tab {i}: style does not match classes {cls:?}"
                );
            }
        }
    }
    #[test]
    fn neighbour_styles_null_the_border_on_the_side_their_class_names_claim() {
        let no_left = plain_decls_where(&CSS_MATCH_13824480602841492081, |p| {
            matches!(p, CssProperty::BorderLeftWidth(_))
        });
        let no_right = plain_decls_where(&CSS_MATCH_4415083954137121609, |p| {
            matches!(p, CssProperty::BorderRightWidth(_))
        });
        assert_eq!(
            no_left.first(),
            Some(&CssProperty::BorderLeftWidth(
                LayoutBorderLeftWidthValue::None
            )),
            "the -noleftborder style must null the LEFT border first"
        );
        assert_eq!(
            no_right.first(),
            Some(&CssProperty::BorderRightWidth(
                LayoutBorderRightWidthValue::None
            )),
            "the -norightborder style must null the RIGHT border first"
        );
        // ...and must not null the opposite side.
        assert!(
            !decls_where(&CSS_MATCH_13824480602841492081, |p| matches!(
                p,
                CssProperty::BorderRightWidth(_)
            ))
            .contains(&CssProperty::BorderRightWidth(
                LayoutBorderRightWidthValue::None
            )),
            "the -noleftborder style must keep the right border"
        );
        assert!(
            !decls_where(&CSS_MATCH_4415083954137121609, |p| matches!(
                p,
                CssProperty::BorderLeftWidth(_)
            ))
            .contains(&CssProperty::BorderLeftWidth(
                LayoutBorderLeftWidthValue::None
            )),
            "the -norightborder style must keep the left border"
        );
        // The plain inactive style (no active neighbour) keeps both side borders:
        // exactly one unconditional declaration per side, and neither is `None`.
        let plain_left = plain_decls_where(&CSS_MATCH_11510695043643111367, |p| {
            matches!(p, CssProperty::BorderLeftWidth(_))
        });
        let plain_right = plain_decls_where(&CSS_MATCH_11510695043643111367, |p| {
            matches!(p, CssProperty::BorderRightWidth(_))
        });
        assert_eq!(plain_left.len(), 1, "one unconditional left-border width");
        assert_eq!(plain_right.len(), 1, "one unconditional right-border width");
        assert_ne!(
            plain_left[0],
            CssProperty::BorderLeftWidth(LayoutBorderLeftWidthValue::None),
            "a tab with no active neighbour keeps its left border"
        );
        assert_ne!(
            plain_right[0],
            CssProperty::BorderRightWidth(LayoutBorderRightWidthValue::None),
            "a tab with no active neighbour keeps its right border"
        );
    }
    #[test]
    fn tab_styles_redeclare_properties_and_therefore_depend_on_declaration_order() {
        // PINNED HAZARD: each vec is emitted most-specific-block-first, so the
        // generic `.__azul-native-tabs-header p` block *repeats* properties the
        // state-specific block already set, with different values. Which one wins
        // is decided by the resolver, and the two in azul disagree:
        // `PropertyCache::get_property` takes the FIRST match (specific wins,
        // intended), `get_property_with_context` takes the LAST ("last wins",
        // which silently repaints the active tab like an inactive one).
        let heights = decls_where(&CSS_MATCH_14575853790110873394, |p| {
            matches!(p, CssProperty::Height(_))
        });
        assert_eq!(heights.len(), 2, "the active tab declares height twice");
        assert_eq!(
            heights[0],
            CssProperty::Height(LayoutHeightValue::Exact(LayoutHeight::Px(
                PixelValue::const_px(23)
            ))),
            "the active-tab block (23px) must come first"
        );
        assert_eq!(
            heights[1],
            CssProperty::Height(LayoutHeightValue::Exact(LayoutHeight::Px(
                PixelValue::const_px(21)
            ))),
            "the generic p block (21px) shadows it under last-wins"
        );
        let backgrounds = decls_where(&CSS_MATCH_14575853790110873394, |p| {
            matches!(p, CssProperty::BackgroundContent(_))
        });
        assert_eq!(backgrounds.len(), 2);
        let kind = |p: &CssProperty| -> &'static str {
            let CssProperty::BackgroundContent(v) = p else {
                unreachable!()
            };
            match v
                .get_property()
                .expect("an exact background")
                .as_ref()
                .first()
                .expect("one layer")
            {
                StyleBackgroundContent::Color(_) => "flat",
                StyleBackgroundContent::LinearGradient(_) => "gradient",
                _ => "other",
            }
        };
        assert_eq!(kind(&backgrounds[0]), "flat", "active = white fill");
        assert_eq!(
            kind(&backgrounds[1]),
            "gradient",
            "the generic p block re-declares the inactive gradient"
        );
        // Same shape on the seam styles: the None triple is re-declared as 1px.
        let left = plain_decls_where(&CSS_MATCH_13824480602841492081, |p| {
            matches!(p, CssProperty::BorderLeftWidth(_))
        });
        assert_eq!(left.len(), 2, "the -noleftborder style declares it twice");
        assert_eq!(
            left[0],
            CssProperty::BorderLeftWidth(LayoutBorderLeftWidthValue::None)
        );
        assert_eq!(
            left[1],
            CssProperty::BorderLeftWidth(LayoutBorderLeftWidthValue::Exact(
                LayoutBorderLeftWidth {
                    inner: PixelValue::const_px(1)
                }
            ))
        );
    }
    #[test]
    fn hover_declarations_stay_conditional_and_the_rest_stay_unconditional() {
        // A hover rule leaking into the unconditional set would permanently paint
        // every inactive tab in the hover colour.
        for style in [
            CSS_MATCH_11510695043643111367,
            CSS_MATCH_13824480602841492081,
            CSS_MATCH_4415083954137121609,
        ] {
            let conditional = style
                .as_ref()
                .iter()
                .filter(|p| !p.apply_if.as_ref().is_empty())
                .count();
            let hover_only = style
                .as_ref()
                .iter()
                .filter(|p| is_hover_only(p.apply_if.as_ref()))
                .count();
            let dark_hover = style
                .as_ref()
                .iter()
                .filter(|p| is_dark_hover(p.apply_if.as_ref()))
                .count();
            assert_eq!(
                hover_only, 13,
                "each inactive-tab style carries exactly the 13 :hover declarations"
            );
            assert_eq!(
                dark_hover, 13,
                "...and one dark twin per :hover declaration, from `themes::flat`"
            );
            assert_eq!(
                conditional,
                hover_only + dark_hover,
                "nothing else in an inactive-tab style is conditional"
            );
        }
        for style in [
            CSS_MATCH_14575853790110873394,
            CSS_MATCH_9988039989460234263,
            CSS_MATCH_17290739305197504468,
            CSS_MATCH_3088386549906605418,
            CSS_MATCH_18014909903571752977,
            CSS_MATCH_18014909903571752977_NO_PADDING,
            CSS_MATCH_4738503469417034630,
            CSS_MATCH_4738503469417034630_NO_PADDING,
        ] {
            assert!(
                style
                    .as_ref()
                    .iter()
                    .all(|p| p.apply_if.as_ref().is_empty()),
                "this style must apply unconditionally"
            );
        }
    }
    #[test]
    fn dom_carries_the_themes_tab_hover_state_with_dark_twins() {
        // The thirteen hover rules moved OUT of this file and into
        // `themes::flat`, where the dark half of each pair can be written. That
        // is a move nothing else here would notice: no compiler error, and the
        // verbatim style-vs-node comparisons pass whether or not a slice names
        // the twins. So this asks the RENDERED tabs what they carry.
        //
        // active = 1 of 4 renders every inactive variant at once: tab 0 is the
        // `-norightborder` seam, tab 2 the `-noleftborder` seam, tab 3 the plain
        // inactive tab.
        fn gated(node: &Dom, pick: fn(&[DynamicSelector]) -> bool) -> Vec<CssProperty> {
            node.root
                .style
                .iter_inline_properties()
                .filter(|(_, conds)| pick(conds.as_ref()))
                .map(|(p, _)| p.clone())
                .collect()
        }
        fn is_colour(p: &CssProperty) -> bool {
            matches!(
                p,
                CssProperty::BorderTopColor(_)
                    | CssProperty::BorderBottomColor(_)
                    | CssProperty::BorderLeftColor(_)
                    | CssProperty::BorderRightColor(_)
                    | CssProperty::BackgroundContent(_)
            )
        }
        let dom = TabHeader::create(numbered_labels(4))
            .with_active_tab(1)
            .dom();
        let tabs = &dom.children.as_ref()[1..=4];
        assert_eq!(
            class_strs(&tabs[1]),
            vec![CLASS_ACTIVE],
            "the fixture's active tab"
        );
        for (i, node) in tabs.iter().enumerate() {
            let cls = class_strs(node);
            let light = gated(node, is_hover_only);
            let dark = gated(node, is_dark_hover);
            if cls.contains(&CLASS_ACTIVE) {
                assert!(
                    light.is_empty() && dark.is_empty(),
                    "tab {i}: the active tab has no hover state to twin"
                );
                continue;
            }
            assert_eq!(
                light.len(),
                13,
                "tab {i} {cls:?}: the hover ring (4 widths, 4 styles, 4 colours) and the fill"
            );
            assert_eq!(
                dark.len(),
                13,
                "tab {i} {cls:?}: a dark twin is missing, so a hovered tab keeps its light-mode \
                 ring or fill on a dark surface"
            );
            for rule in &light {
                assert!(
                    dark.iter().any(|twin| twin.get_type() == rule.get_type()),
                    "tab {i} {cls:?}: the light hover rule {rule:?} has no dark twin"
                );
            }
            for twin in &dark {
                assert!(
                    light.iter().any(|rule| rule.get_type() == twin.get_type()),
                    "tab {i} {cls:?}: the dark rule {twin:?} twins nothing the light hover sets"
                );
            }
            // The colour twins are genuinely the other mode's values, not the
            // light rule spelled twice. (The widths and styles ARE the same in
            // both modes; only the colours and the fill have a per-mode value.)
            let light_colours: Vec<&CssProperty> = light.iter().filter(|p| is_colour(p)).collect();
            let dark_colours: Vec<&CssProperty> = dark.iter().filter(|p| is_colour(p)).collect();
            assert_eq!(
                light_colours.len(),
                5,
                "tab {i}: four border colours and the fill"
            );
            assert_ne!(
                light_colours, dark_colours,
                "tab {i} {cls:?}: the dark twins repeat the light colours"
            );
            // The twins are gated on dark AND hover. A rule gated on dark alone
            // would restyle the tab at rest, which is not what this section does.
            assert_eq!(
                theme_probe::dark(node).len(),
                dark.len(),
                "tab {i} {cls:?}: every dark-mode declaration on a tab is a hover twin"
            );
        }
    }
    #[test]
    fn dom_datasets_carry_the_position_of_their_tab() {
        for n in [1usize, 2, 5, 1000] {
            let dom = TabHeader::create(numbered_labels(n)).dom();
            let children = dom.children.as_ref();
            for (i, node) in children[1..=n].iter().enumerate() {
                assert_eq!(
                    tab_idx_of(node),
                    i,
                    "n={n}: tab {i} must carry its own index, not the loop seed"
                );
            }
        }
    }
    #[test]
    fn dom_attaches_a_dataset_even_without_a_click_callback() {
        let dom = TabHeader::create(numbered_labels(2)).dom();
        for node in &dom.children.as_ref()[1..=2] {
            assert!(
                node.root.get_dataset().is_some(),
                "the dataset is unconditional (only the callback is not)"
            );
            assert!(
                node.root.get_callbacks().as_ref().is_empty(),
                "no callback must be attached when on_click is None"
            );
        }
    }
    #[test]
    fn dom_attaches_exactly_one_mouseup_callback_per_tab_when_on_click_is_set() {
        let n = 4usize;
        let dom = TabHeader::create(numbered_labels(n))
            .with_on_click(RefAny::new(ClickLog::default()), cb(record_click))
            .dom();
        let children = dom.children.as_ref();
        for node in &children[1..=n] {
            let cbs = node.root.get_callbacks();
            assert_eq!(cbs.as_ref().len(), 1, "exactly one callback per tab");
            let data = &cbs.as_ref()[0];
            assert_eq!(
                data.event,
                EventFilter::Hover(HoverEventFilter::Click),
                "tabs must react on mouse-up, not mouse-down"
            );
            assert_eq!(
                data.callback.cb, on_tab_click as usize,
                "the dispatcher must be the widget's own trampoline"
            );
        }
        // The spacers must stay inert — a click on the filler must not select.
        assert!(children[0].root.get_callbacks().as_ref().is_empty());
        assert!(children[n + 1].root.get_callbacks().as_ref().is_empty());
    }
    #[test]
    fn dom_keeps_the_estimated_child_count_consistent() {
        // `estimated_total_children` is what sizes the flat arena; a stale value
        // makes `convert_dom_into_compact_dom` under-allocate and panic.
        for n in [0usize, 1, 2, 50] {
            let dom = TabHeader::create(numbered_labels(n)).dom();
            assert_eq!(
                dom.estimated_total_children,
                dom.recompute_estimated_total_children(),
                "n={n}: cached descendant count desynced"
            );
            assert_eq!(
                dom.node_count(),
                2 * n + 3,
                "header + spacer + {n} tabs (each a <p> wrapping one text node) + spacer"
            );
            let styled = StyledDom::create_from_dom(dom);
            assert_eq!(
                styled.node_hierarchy.as_ref().len(),
                2 * n + 3,
                "n={n}: the flattened arena must match node_count()"
            );
        }
    }
    #[test]
    fn dom_releases_every_dataset_clone_when_the_dom_is_dropped() {
        // Each tab clones the user payload into its own `TabLocalDataset`; if the
        // widget leaked one, the app state would outlive the DOM forever.
        for n in [0usize, 1, 5] {
            let user = RefAny::new(ClickLog::default());
            let dom = TabHeader::create(numbered_labels(n))
                .with_on_click(user.clone(), cb(record_click))
                .dom();
            assert_eq!(
                user.get_ref_count(),
                n + 1,
                "n={n}: one payload clone per tab, plus the caller's handle"
            );
            drop(dom);
            assert_eq!(
                user.get_ref_count(),
                1,
                "n={n}: dropping the DOM must release every payload clone"
            );
        }
    }
    #[test]
    fn dom_is_deterministic() {
        let build = || {
            let dom = TabHeader::create(numbered_labels(5))
                .with_active_tab(2)
                .dom();
            let children = dom.children.as_ref();
            let shape: Vec<(Option<String>, Vec<&'static str>)> = children
                .iter()
                .map(|c| (text_of(c).map(str::to_string), class_strs(c)))
                .collect();
            shape
        };
        assert_eq!(
            build(),
            build(),
            "dom() must be a pure function of its state"
        );
    }
    // ==================================================================
    // TabContent
    // ==================================================================
    fn nested(depth: usize) -> Dom {
        let mut dom = Dom::create_text_do_not_use_without_block_level_wrapper("leaf");
        for _ in 0..depth {
            dom = Dom::create_div().with_child(dom);
        }
        dom
    }
    #[test]
    fn content_new_defaults_to_padding_and_keeps_the_content_verbatim() {
        let content = nested(3);
        let tab_content = TabContent::new(content.clone());
        assert!(tab_content.has_padding, "new() defaults to padded");
        assert_eq!(
            tab_content.content, content,
            "new() must not rewrap or normalise the content"
        );
        assert!(
            TabContent::default().has_padding,
            "Default agrees with new()"
        );
    }
    #[test]
    fn with_padding_and_set_padding_agree_and_are_last_wins() {
        for flag in [true, false] {
            let built = TabContent::new(Dom::create_div()).with_padding(flag);
            let mut mutated = TabContent::new(Dom::create_div());
            mutated.set_padding(flag);
            assert_eq!(built.has_padding, flag);
            assert_eq!(built.has_padding, mutated.has_padding);
        }
        let toggled = TabContent::new(Dom::create_div())
            .with_padding(false)
            .with_padding(true)
            .with_padding(false);
        assert!(!toggled.has_padding, "the last write must win");
    }
    #[test]
    fn content_dom_nests_the_content_under_the_content_class() {
        let content = nested(2);
        let dom = TabContent::new(content.clone()).dom();
        assert!(
            class_strs(&dom).is_empty(),
            "the outer wrapper carries the style, not the class"
        );
        assert_eq!(dom.children.as_ref().len(), 1, "one wrapper child");
        let inner = &dom.children.as_ref()[0];
        assert_eq!(class_strs(inner), vec![CLASS_CONTENT]);
        assert!(
            inline_declared(inner).is_empty(),
            "the classed node carries no inline style of its own"
        );
        assert_eq!(inner.children.as_ref().len(), 1);
        assert_eq!(
            inner.children.as_ref()[0],
            content,
            "the user content must survive the two wrappers untouched"
        );
    }
    #[test]
    fn content_dom_picks_the_style_vec_the_padding_flag_asks_for() {
        let padded = TabContent::new(Dom::create_div()).with_padding(true).dom();
        assert_eq!(
            inline_declared(&padded),
            declared(&CSS_MATCH_18014909903571752977)
        );
        let bare = TabContent::new(Dom::create_div()).with_padding(false).dom();
        assert_eq!(
            inline_declared(&bare),
            declared(&CSS_MATCH_18014909903571752977_NO_PADDING)
        );
        assert_ne!(
            inline_declared(&padded),
            inline_declared(&bare),
            "the two padding modes must not collapse to the same style"
        );
    }
    #[test]
    fn the_unpadded_content_style_declares_no_padding_at_all() {
        let padding_decls = decls_where(&CSS_MATCH_18014909903571752977_NO_PADDING, |p| {
            matches!(
                p,
                CssProperty::PaddingTop(_)
                    | CssProperty::PaddingBottom(_)
                    | CssProperty::PaddingLeft(_)
                    | CssProperty::PaddingRight(_)
            )
        });
        assert!(
            padding_decls.is_empty(),
            "has_padding == false must not leave a padding declaration behind"
        );
        let padded = decls_where(&CSS_MATCH_18014909903571752977, |p| {
            matches!(
                p,
                CssProperty::PaddingTop(_)
                    | CssProperty::PaddingBottom(_)
                    | CssProperty::PaddingLeft(_)
                    | CssProperty::PaddingRight(_)
            )
        });
        assert_eq!(padded.len(), 4, "the padded variant sets all four sides");
    }
    #[test]
    fn content_dom_keeps_the_estimated_child_count_consistent() {
        for depth in [0usize, 1, 3, 64] {
            let content = nested(depth);
            let expected = content.node_count() + 2; // outer wrapper + classed wrapper
            let dom = TabContent::new(content).dom();
            assert_eq!(
                dom.estimated_total_children,
                dom.recompute_estimated_total_children(),
                "depth={depth}: cached descendant count desynced"
            );
            assert_eq!(dom.node_count(), expected, "depth={depth}");
            let styled = StyledDom::create_from_dom(dom);
            assert_eq!(
                styled.node_hierarchy.as_ref().len(),
                expected,
                "depth={depth}: the flattened arena must match node_count()"
            );
        }
    }
    #[test]
    fn content_swap_with_default_returns_the_old_state_and_leaves_an_empty_div() {
        let content = nested(2);
        let mut tab_content = TabContent::new(content.clone()).with_padding(false);
        let taken = tab_content.swap_with_default();
        assert_eq!(taken.content, content);
        assert!(!taken.has_padding, "the flag moves out with the content");
        assert_eq!(
            tab_content.content,
            Dom::create_div(),
            "the husk must be an empty div"
        );
        assert!(
            tab_content.has_padding,
            "the husk is a Default, i.e. padded again"
        );
    }
    // ==================================================================
    // on_tab_click
    // ==================================================================
    #[test]
    fn on_tab_click_reports_the_clicked_index_to_the_user_callback() {
        for idx in [0usize, 1, 7, usize::MAX / 2, usize::MAX - 1, usize::MAX] {
            let mut user = RefAny::new(ClickLog::default());
            let (update, changes) =
                run_click(dataset(idx, click_handler(user.clone(), record_click)));
            assert_eq!(update, Update::RefreshDom);
            assert!(
                changes.is_empty(),
                "the tab handler is stateless — it must not push CallbackChanges"
            );
            assert_eq!(
                logged(&mut user),
                vec![TabHeaderState { active_tab: idx }],
                "the index must be forwarded verbatim, without arithmetic"
            );
        }
    }
    #[test]
    fn on_tab_click_propagates_the_user_update_verbatim() {
        for (callback, expected) in [
            (record_click as TabOnClickCallbackType, Update::RefreshDom),
            (click_do_nothing, Update::DoNothing),
            (click_refresh_all, Update::RefreshDomAllWindows),
        ] {
            let (update, _) = run_click(dataset(
                3,
                click_handler(RefAny::new(ClickLog::default()), callback),
            ));
            assert_eq!(update, expected, "the user verdict must not be overridden");
        }
    }
    #[test]
    fn on_tab_click_without_a_user_callback_does_nothing() {
        // A dataset with no `on_click` is reachable only by hand (dom() attaches
        // the trampoline only when a callback exists) — it must stay silent
        // rather than force a relayout.
        let (update, changes) = run_click(dataset(2, None.into()));
        assert_eq!(update, Update::DoNothing);
        assert!(changes.is_empty());
    }
    #[test]
    fn on_tab_click_on_a_foreign_payload_falls_back_to_refresh() {
        // Wrong-typed payload => `downcast_mut` returns None => the documented
        // `unwrap_or(RefreshDom)` fallback. Note this is the *opposite* verdict
        // from the no-callback case above, which is the asymmetry to watch.
        for foreign in [RefAny::new(42u32), RefAny::new(String::from("nope"))] {
            let (update, changes) = run_click(foreign);
            assert_eq!(update, Update::RefreshDom);
            assert!(changes.is_empty());
        }
    }
    #[test]
    fn on_tab_click_declines_while_the_dataset_is_already_borrowed() {
        // Borrow tracking is shared across clones, so a live `Ref` from anywhere
        // must make the handler bail out safely instead of aliasing or panicking.
        let mut held = dataset(1, None.into());
        let clone = held.clone();
        let guard = held
            .downcast_ref::<TabLocalDataset>()
            .expect("the fixture is a TabLocalDataset");
        let (update, changes) = run_click(clone);
        assert_eq!(
            update,
            Update::RefreshDom,
            "a contended dataset must fall back, not panic"
        );
        assert!(changes.is_empty());
        drop(guard);
        // ...and the borrow must be released again afterwards.
        let (update, _) = run_click(held.clone());
        assert_eq!(update, Update::DoNothing);
    }
    #[test]
    fn on_tab_click_releases_its_borrow_so_repeated_clicks_keep_working() {
        let mut user = RefAny::new(ClickLog::default());
        let data = dataset(4, click_handler(user.clone(), record_click));
        let (first, _) = run_click(data.clone());
        let (second, _) = run_click(data.clone());
        let (third, _) = run_click(data.clone());
        assert_eq!(
            [first, second, third],
            [Update::RefreshDom; 3],
            "a leaked RefMut would turn later clicks into the RefreshDom fallback without ever \
             reaching the user callback"
        );
        assert_eq!(
            logged(&mut user),
            vec![TabHeaderState { active_tab: 4 }; 3],
            "every click must reach the user callback"
        );
    }
    #[test]
    fn clicking_a_rendered_tab_selects_that_tab_end_to_end() {
        let n = 5usize;
        let mut user = RefAny::new(ClickLog::default());
        let dom = TabHeader::create(numbered_labels(n))
            .with_on_click(user.clone(), cb(record_click))
            .dom();
        for i in 0..n {
            let data = dom.children.as_ref()[i + 1]
                .root
                .get_callbacks()
                .as_ref()
                .first()
                .expect("every tab carries the click callback")
                .refany
                .clone();
            let (update, changes) = run_click(data);
            assert_eq!(update, Update::RefreshDom);
            assert!(changes.is_empty());
        }
        assert_eq!(
            logged(&mut user),
            (0..n)
                .map(|active_tab| TabHeaderState { active_tab })
                .collect::<Vec<_>>(),
            "clicking tab i must report exactly i"
        );
    }
    #[test]
    fn clicking_a_tab_does_not_move_the_active_tab_by_itself() {
        // The widget is stateless: the handler reports the click and nothing
        // else. Re-rendering the *same* header must therefore keep tab 0 active.
        let user = RefAny::new(ClickLog::default());
        let header =
            TabHeader::create(numbered_labels(3)).with_on_click(user.clone(), cb(record_click));
        let dom = header.clone().dom();
        let data = dom.children.as_ref()[3]
            .root
            .get_callbacks()
            .as_ref()
            .first()
            .expect("tab 2 carries the click callback")
            .refany
            .clone();
        let (update, _) = run_click(data);
        assert_eq!(update, Update::RefreshDom);
        assert_eq!(
            header.active_tab, 0,
            "the header itself must be untouched by a click"
        );
        assert_eq!(
            class_strs(&header.dom().children.as_ref()[1]),
            vec![CLASS_ACTIVE],
            "re-rendering the unchanged header keeps tab 0 active"
        );
    }
}