icedtea 0.17.2

Native desktop widgets and chrome for iced
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
//! Public widget and pattern ids.
//!
//! Each id has one constructor. Drawing constructors take
//! [`crate::a11y::A11y`] and tokens. Chrome rows take an
//! [`crate::action::ActionTable`]. Rustdoc with a working example sits
//! immediately above the function.
//!
//! ```
//! assert!(icedtea::catalog::get("button").is_some());
//! assert_eq!(icedtea::catalog::get("button").unwrap().page, "controls");
//! ```

/// Every exported control or pattern. Gallery pages this list.
///
/// ```
/// assert!(icedtea::catalog::ENTRIES.iter().any(|e| e.id == "button"));
/// assert!(icedtea::catalog::ENTRIES.iter().any(|e| e.id == "about"));
/// ```
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Entry {
    pub id: &'static str,
    pub title: &'static str,
    pub group: &'static str,
    /// Gallery page that hosts this widget. Several ids can share a page.
    pub page: &'static str,
}

/// Closed list, like iced's `Theme::ALL`. Named fields so id / title /
/// group cannot be swapped. One row per public surface.
#[rustfmt::skip]
pub const ENTRIES: &[Entry] = &[
    // Button faces, toggle-icon, and slider sit first so idle QA shows
    // Outlined / Elevated, icon-plus-label, toggle-icon, and the vertical
    // slider above the fold.
    Entry { id: "button", title: "Button", group: "Controls", page: "controls" },
    Entry { id: "toggle-icon-button", title: "Toggle icon button", group: "Controls", page: "controls" },
    Entry { id: "slider", title: "Slider", group: "Controls", page: "controls" },
    Entry { id: "button-group", title: "Button group", group: "Controls", page: "controls" },
    // Compact vs Default must sit above the fold; the rest of Controls is tall.
    Entry { id: "segmented-button", title: "Segmented button", group: "Controls", page: "controls" },
    Entry { id: "checkbox", title: "Checkbox", group: "Controls", page: "controls" },
    Entry { id: "radio", title: "Radio", group: "Controls", page: "controls" },
    Entry { id: "switch", title: "Switch", group: "Controls", page: "controls" },
    Entry { id: "range-slider", title: "Range slider", group: "Controls", page: "controls" },
    Entry { id: "icon-button", title: "Icon button", group: "Controls", page: "controls" },
    Entry { id: "split-button", title: "Split button", group: "Controls", page: "controls" },
    Entry { id: "toggle-button", title: "Toggle button", group: "Controls", page: "controls" },
    // Search first so Enter submit status is on the first screenful.
    Entry { id: "search", title: "Search", group: "Fields", page: "fields" },
    Entry { id: "search-view", title: "Search view", group: "Fields", page: "fields" },
    Entry { id: "text-input", title: "Text input", group: "Fields", page: "fields" },
    Entry { id: "field-support", title: "Field support", group: "Fields", page: "fields" },
    Entry { id: "password", title: "Password", group: "Fields", page: "fields" },
    Entry { id: "secret", title: "Secret field", group: "Fields", page: "fields" },
    Entry { id: "value-field", title: "Value field", group: "Fields", page: "fields" },
    Entry { id: "textarea", title: "Text area", group: "Fields", page: "fields" },
    Entry { id: "suggest", title: "Suggest", group: "Fields", page: "fields" },
    // Select and form start the Fields right column (gallery pack_at).
    Entry { id: "select", title: "Select", group: "Fields", page: "fields" },
    Entry { id: "form", title: "Form", group: "Fields", page: "fields" },
    Entry { id: "number", title: "Number", group: "Fields", page: "fields" },
    Entry { id: "date", title: "Date", group: "Fields", page: "fields" },
    Entry { id: "time", title: "Time", group: "Fields", page: "fields" },
    Entry { id: "progress", title: "Progress", group: "Readout", page: "readout" },
    Entry { id: "progress-ring", title: "Progress ring", group: "Readout", page: "readout" },
    Entry { id: "spinner", title: "Spinner", group: "Readout", page: "readout" },
    Entry { id: "label", title: "Label", group: "Content", page: "type" },
    Entry { id: "icon", title: "Icon", group: "Content", page: "type" },
    Entry { id: "tooltip", title: "Tooltip", group: "Content", page: "type" },
    Entry { id: "rich-tooltip", title: "Rich tooltip", group: "Content", page: "type" },
    Entry { id: "link", title: "Hyperlink", group: "Content", page: "type" },
    Entry { id: "markdown", title: "Markdown", group: "Content", page: "markdown" },
    Entry { id: "code", title: "Code", group: "Content", page: "code" },
    Entry { id: "image", title: "Image", group: "Content", page: "image" },
    Entry { id: "selectable", title: "Selectable", group: "Content", page: "selectable" },
    // Virtual column first so open-face inject is above the fold.
    Entry { id: "virtual-column", title: "Virtual column", group: "Collections", page: "list" },
    Entry { id: "list", title: "List", group: "Collections", page: "list" },
    // Pages a large set; lives with list, not disclosure chrome.
    Entry { id: "pagination", title: "Pagination", group: "Collections", page: "list" },
    Entry { id: "log", title: "Log", group: "Collections", page: "log" },
    Entry { id: "grid", title: "Item grid", group: "Collections", page: "grid" },
    Entry { id: "table", title: "Data table", group: "Collections", page: "table" },
    Entry { id: "tree", title: "Tree", group: "Collections", page: "tree" },
    // Accordion and expander above the fold for inject proof.
    Entry { id: "accordion", title: "Accordion", group: "Collections", page: "sections" },
    Entry { id: "expander", title: "Expander", group: "Collections", page: "sections" },
    Entry { id: "tabs", title: "Tabs", group: "Collections", page: "sections" },
    Entry { id: "cheatsheet", title: "Cheatsheet", group: "Chrome", page: "keys" },
    // Pack then wrap so idle QA shows hug/share and measuring reflow first.
    Entry { id: "pack", title: "Pack", group: "Chrome", page: "layout" },
    Entry { id: "wrap", title: "Wrap", group: "Chrome", page: "layout" },
    // Filter chips first so selected/idle faces are above the fold on Marks.
    Entry { id: "filter-chips", title: "Filter chips", group: "Chrome", page: "marks" },
    Entry { id: "chip", title: "Chip", group: "Chrome", page: "marks" },
    Entry { id: "badge", title: "Badge", group: "Chrome", page: "marks" },
    Entry { id: "card", title: "Card", group: "Chrome", page: "marks" },
    Entry { id: "rule", title: "Rule", group: "Chrome", page: "marks" },
    Entry { id: "banner", title: "Banner", group: "Chrome", page: "marks" },
    Entry { id: "command-bar", title: "Command bar", group: "Chrome", page: "chrome-rows" },
    Entry { id: "context-menu", title: "Context menu", group: "Chrome", page: "chrome-rows" },
    Entry { id: "sectioned-menu", title: "Sectioned menu", group: "Chrome", page: "chrome-rows" },
    Entry { id: "cascade-menu", title: "Cascade menu", group: "Chrome", page: "chrome-rows" },
    Entry { id: "breadcrumb", title: "Breadcrumb", group: "Chrome", page: "chrome-rows" },
    Entry { id: "menu", title: "Menu", group: "Chrome", page: "chrome-rows" },
    Entry { id: "toolbar", title: "Toolbar", group: "Chrome", page: "chrome-rows" },
    Entry { id: "status-bar", title: "Status bar", group: "Chrome", page: "chrome-rows" },
    Entry { id: "busy", title: "Busy overlay", group: "Chrome", page: "feedback" },
    Entry { id: "toast", title: "Toast", group: "Chrome", page: "feedback" },
    Entry { id: "scrollbar", title: "Scrollbar", group: "Chrome", page: "feedback" },
    // Side sheet first so open-state inject is above the fold on Dialogs.
    Entry { id: "side-sheet", title: "Side sheet", group: "Patterns", page: "dialogs" },
    Entry { id: "dialogs", title: "Dialogs", group: "Patterns", page: "dialogs" },
    Entry { id: "list-detail", title: "List/detail", group: "Patterns", page: "list-detail" },
    Entry { id: "inspector", title: "Inspector", group: "Patterns", page: "inspector" },
    Entry { id: "drawer", title: "Drawer", group: "Patterns", page: "workspace" },
    Entry { id: "workspace", title: "Workspace", group: "Patterns", page: "workspace" },
    Entry { id: "tool-panel", title: "Tool panel", group: "Patterns", page: "workspace" },
    Entry { id: "nav-rail", title: "Navigation rail", group: "Patterns", page: "navigation" },
    Entry { id: "navigation", title: "Navigation view", group: "Patterns", page: "navigation" },
    Entry { id: "tab-view", title: "Tab view", group: "Patterns", page: "tab-view" },
    Entry { id: "preferences", title: "Preferences", group: "Patterns", page: "preferences" },
    Entry { id: "about", title: "About", group: "Patterns", page: "about" },
    Entry { id: "status-page", title: "Status page", group: "Patterns", page: "status-page" },
    Entry { id: "palette", title: "Command palette", group: "Patterns", page: "palette" },
    Entry { id: "main-window", title: "Main window", group: "Patterns", page: "main-window" },
    Entry { id: "motion", title: "Motion", group: "Chrome", page: "motion" },
    Entry { id: "switch-motion", title: "Switch motion", group: "Chrome", page: "motion" },
    Entry { id: "attention-motion", title: "Attention motion", group: "Chrome", page: "motion" },
    Entry { id: "expand-motion", title: "Expand motion", group: "Chrome", page: "motion" },
];

pub fn get(id: &str) -> Option<&'static Entry> {
    ENTRIES.iter().find(|e| e.id == id)
}

pub fn groups() -> Vec<&'static str> {
    let mut g = Vec::new();
    for e in ENTRIES {
        if !g.contains(&e.group) {
            g.push(e.group);
        }
    }
    g
}

/// Gallery page ids in catalog order. Several widgets can share a page.
pub fn pages() -> Vec<&'static str> {
    let mut p = Vec::new();
    for e in ENTRIES {
        if !p.contains(&e.page) {
            p.push(e.page);
        }
    }
    p
}

pub fn page_entries(page: &str) -> impl Iterator<Item = &'static Entry> + '_ {
    ENTRIES.iter().filter(move |e| e.page == page)
}

pub fn page_title(page: &str) -> &'static str {
    match page {
        "controls" => "Controls",
        "fields" => "Fields",
        "readout" => "Readout",
        "type" => "Type",
        "sections" => "Tabs and sections",
        "marks" => "Marks",
        "layout" => "Layout",
        "chrome-rows" => "Chrome rows",
        "feedback" => "Feedback",
        "workspace" => "Workspace",
        "motion" => "Motion",
        "expand-motion" => "Expand motion",
        "keys" => "Keys",
        "theme" => "Theme",
        "colors" => "Colors",
        id => get(id).map(|e| e.title).unwrap_or("Page"),
    }
}

/// Module and `pub fn` for a catalog id.
///
/// ```
/// assert_eq!(
///     icedtea::catalog::constructor("button"),
///     Some(("widget", "button"))
/// );
/// ```
pub fn constructor(id: &str) -> Option<(&'static str, &'static str)> {
    Some(match id {
        "button" => ("widget", "button"),
        "segmented-button" => ("widget", "segmented_button"),
        "button-group" => ("widget", "button_group"),
        "icon-button" => ("widget", "icon_button"),
        "toggle-icon-button" => ("widget", "icon_button_toggle"),
        "split-button" => ("widget", "split_button"),
        "toggle-button" => ("widget", "toggle_button"),
        "checkbox" => ("widget", "checkbox"),

        "radio" => ("widget", "radio"),
        "switch" => ("widget", "switch"),
        "slider" => ("widget", "slider"),
        "range-slider" => ("widget", "range_slider"),
        "text-input" => ("widget", "text_input"),
        "field-support" => ("widget", "field_support"),
        "password" => ("widget", "password_input"),
        "secret" => ("widget", "secret_field"),
        "value-field" => ("widget", "value_field"),
        "textarea" => ("widget", "textarea"),
        "search" => ("widget", "search_input"),
        "search-view" => ("widget", "search_view"),
        "suggest" => ("widget", "suggest_field"),
        "select" => ("widget", "pick_list"),
        "form" => ("widget", "form_group"),
        "number" => ("widget", "number_input"),
        "date" => ("widget", "date_stepper"),
        "time" => ("widget", "time_picker"),
        "progress" => ("widget", "progress"),
        "progress-ring" => ("widget", "progress_ring"),
        "spinner" => ("widget", "spinner"),
        "label" => ("widget", "label"),
        "icon" => ("widget", "icon_svg"),
        "tooltip" => ("widget", "tooltip_wrap"),
        "rich-tooltip" => ("widget", "tooltip_rich"),
        "link" => ("widget", "hyperlink"),
        "markdown" => ("widget", "markdown_view"),
        "code" => ("widget", "highlighted_code"),
        "image" => ("widget", "image_slot"),
        "selectable" => ("widget", "selectable"),
        "list" => ("widget", "list_view"),
        "virtual-column" => ("widget", "virtual_column"),
        "log" => ("widget", "log_view"),
        "grid" => ("widget", "item_grid"),
        "table" => ("widget", "data_table"),
        "tree" => ("widget", "tree_view"),
        "tabs" => ("widget", "tab_bar"),
        "accordion" => ("widget", "accordion_view"),
        "expander" => ("widget", "expander"),
        "pagination" => ("widget", "pagination"),
        "cheatsheet" => ("pattern", "cheatsheet"),
        "card" => ("widget", "group_box"),
        "rule" => ("widget", "rule_h"),
        "chip" => ("widget", "chip"),
        "filter-chips" => ("widget", "filter_chips"),
        "badge" => ("widget", "badge"),
        "pack" => ("layout", "pack"),
        "wrap" => ("layout", "wrap"),
        "banner" => ("widget", "banner"),
        "command-bar" => ("pattern", "command_bar"),
        "context-menu" => ("pattern", "context_menu"),
        "sectioned-menu" => ("pattern", "sectioned_menu"),
        "cascade-menu" => ("pattern", "cascade_menu"),
        "breadcrumb" => ("widget", "breadcrumb"),
        "menu" => ("pattern", "menu_bar"),
        "toolbar" => ("pattern", "toolbar"),
        "status-bar" => ("pattern", "status_bar"),
        "busy" => ("widget", "busy_overlay"),
        "toast" => ("widget", "toast_view"),
        "scrollbar" => ("widget", "scroll"),
        "dialogs" => ("pattern", "dialog_sheet"),
        "side-sheet" => ("pattern", "side_sheet"),
        "list-detail" => ("pattern", "list_detail"),
        "inspector" => ("pattern", "inspector"),
        "workspace" => ("pattern", "workspace"),
        "tool-panel" => ("pattern", "tool_panel"),
        "drawer" => ("pattern", "drawer"),
        "nav-rail" => ("pattern", "nav_rail"),
        "navigation" => ("pattern", "navigation_view"),
        "tab-view" => ("pattern", "tab_view"),
        "preferences" => ("pattern", "preferences_page"),
        "about" => ("pattern", "about_page"),
        "status-page" => ("pattern", "status_page"),
        "palette" => ("pattern", "command_palette_view"),
        "main-window" => ("pattern", "main_window"),
        "motion" => ("motion", "overlay"),
        "switch-motion" => ("motion", "switch"),
        "attention-motion" => ("motion", "attention"),
        "expand-motion" => ("motion", "expand"),
        _ => return None,
    })
}

#[cfg(test)]
mod tests {
    use super::*;

    fn must(ok: bool, msg: impl std::fmt::Display) {
        if !ok {
            panic!("{msg}");
        }
    }

    #[test]
    #[should_panic(expected = "cover-must")]
    fn must_rejects_a_failed_check() {
        must(false, "cover-must");
    }

    #[test]
    fn catalog_covers_public_surfaces() {
        assert!(get("button").is_some());
        assert!(get("about").is_some());
        assert!(get("missing").is_none());
        assert!(constructor("missing").is_none());
        assert_eq!(
            groups(),
            [
                "Controls",
                "Fields",
                "Readout",
                "Content",
                "Collections",
                "Chrome",
                "Patterns"
            ]
        );
        assert!(ENTRIES.len() >= 40);
        assert_eq!(get("table").unwrap().group, "Collections");
        assert_eq!(get("cheatsheet").unwrap().group, "Chrome");
        assert_eq!(get("time").unwrap().group, "Fields");
        assert_eq!(get("button").unwrap().page, "controls");
        assert_eq!(get("checkbox").unwrap().page, "controls");
        for page in pages() {
            let title = page_title(page);
            assert!(!title.is_empty());
            assert_ne!(title, "Page", "{page}");
        }
        assert_eq!(page_title("no-such-page"), "Page");
        assert!(pages().contains(&"controls"));
        assert!(page_entries("controls").count() > 1);
        assert!(pages().len() < ENTRIES.len());
        for id in [
            "image",
            "progress-ring",
            "wrap",
            "pack",
            "badge",
            "command-bar",
            "context-menu",
            "scrollbar",
            "cheatsheet",
            "button",
            "list",
        ] {
            assert!(get(id).is_some());
        }
        for id in crate::m3::mapping::deleted_ids() {
            assert!(get(id).is_none());
            assert!(constructor(id).is_none());
        }
        for name in [
            "install.md",
            "introduction.md",
            "first-window.md",
            "widgets.md",
            "actions.md",
            "layout.md",
            "theming.md",
            "architecture.md",
            "accessibility.md",
            "m3-foundations.md",
            "motion.md",
            "navigation.md",
            "cookbook/save.md",
            "cookbook/list-detail.md",
            "cookbook/table.md",
            "cookbook/palette.md",
            "cookbook/icons.md",
            "overlay-windows.md",
            "compact-tools.md",
            "reference/controls.md",
            "reference/fields.md",
            "reference/readout.md",
            "reference/content.md",
            "reference/collections.md",
            "reference/chrome.md",
            "reference/patterns.md",
        ] {
            let p = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
                .join("book/src")
                .join(name);
            assert!(p.is_file());
        }
    }

    #[test]
    fn handbook_describes_every_catalog_id() {
        let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("book/src");
        let group_file = [
            ("Controls", "reference/controls.md"),
            ("Fields", "reference/fields.md"),
            ("Readout", "reference/readout.md"),
            ("Content", "reference/content.md"),
            ("Collections", "reference/collections.md"),
            ("Chrome", "reference/chrome.md"),
            ("Patterns", "reference/patterns.md"),
        ];
        assert!(ENTRIES.iter().all(|e| constructor(e.id).is_some()));
        for (group, rel) in group_file {
            let text = std::fs::read_to_string(root.join(rel)).unwrap();
            must(
                text.contains(&format!("# {group}")),
                format!("{rel} must be the {group} handbook page"),
            );
            for e in ENTRIES.iter().filter(|e| e.group == group) {
                let marker = format!("**`{}`**", e.id);
                let at = text
                    .find(&marker)
                    .unwrap_or_else(|| panic!("{rel} missing catalog id {}", e.id));
                let rest = &text[at..];
                let end = rest[marker.len()..]
                    .find("\n### ")
                    .map(|i| i + marker.len())
                    .unwrap_or(rest.len());
                let section = &rest[..end];
                let ctor = constructor(e.id).map(|(_, n)| n).unwrap();
                assert!(section.contains(ctor), "{} section must name {ctor}", e.id);
                for id in [e.id, "not-a-catalog-id"] {
                    if let Some((module, name)) = constructor(id) {
                        let takes = module_src(module)
                            .is_some_and(|src| fn_params_mention(src, name, "A11y"));
                        if takes {
                            must(
                                section.contains("A11y"),
                                format!("{} section must mention A11y", e.id),
                            );
                        } else {
                            must(
                                !section.contains("Pass `A11y`"),
                                format!("{} section must not say Pass `A11y`", e.id),
                            );
                        }
                    }
                }
                must(
                    section.contains("docs.rs/icedtea"),
                    format!("{} section must link rustdoc", e.id),
                );
                must(
                    section.contains("github.com/indynull/icedtea/blob/main"),
                    format!("{} section must link source", e.id),
                );
                let tea = section.contains("crates.io/crates/icedtea");
                let iced = section.contains("crates.io/crates/iced");
                must(
                    tea || iced,
                    format!("{} section must link the published crate", e.id),
                );
            }
        }
    }

    fn first_png_src(text: &str) -> Option<&str> {
        let mut rest = text;
        while let Some(i) = rest.find("](") {
            let after = &rest[i + 2..];
            let end = after.find(')')?;
            let src = &after[..end];
            if src.ends_with(".png") {
                return Some(src);
            }
            rest = &after[end + 1..];
        }
        None
    }

    #[test]
    fn first_png_src_reads_markdown_images() {
        assert_eq!(first_png_src("![a](images/x.png)"), Some("images/x.png"));
        assert_eq!(first_png_src("![a](gallery.gif)"), None);
        assert_eq!(first_png_src("no image"), None);
        assert_eq!(first_png_src("](unterminated"), None);
        assert_eq!(
            first_png_src("[link](page.md)\n![s](../images/x.png)"),
            Some("../images/x.png")
        );
    }

    #[test]
    fn handbook_shows_constructor_stills() {
        let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("book/src");
        let pages = [
            "first-window.md",
            "reference/controls.md",
            "reference/fields.md",
            "reference/readout.md",
            "reference/content.md",
            "reference/collections.md",
            "reference/chrome.md",
            "reference/patterns.md",
        ];
        for rel in pages {
            let path = root.join(rel);
            let text = std::fs::read_to_string(&path).unwrap();
            let src = first_png_src(&text)
                .unwrap_or_else(|| panic!("{rel} must show a constructor still"));
            must(
                !src.contains("placeholder"),
                format!("{rel} still must be a capture"),
            );
            let dest = path.parent().unwrap().join(src);
            let bytes = std::fs::read(&dest)
                .unwrap_or_else(|_| panic!("{rel} still missing at {}", dest.display()));
            must(bytes.len() >= 1000, format!("{src} is empty"));
            must(
                bytes.starts_with(b"\x89PNG\r\n\x1a\n"),
                format!("{src} must be a PNG capture"),
            );
        }
    }

    #[test]
    fn handbook_stills_have_a_recapture_command() {
        let just = include_str!("../justfile");
        assert!(just.contains("\nbook-stills"));
        assert!(just.contains("gallery_qa.py --book"));
    }

    #[test]
    fn handbook_architecture_composes_a_window() {
        let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR"));
        let page = std::fs::read_to_string(root.join("book/src/architecture.md")).unwrap();
        let fig = std::fs::read_to_string(root.join("book/src/images/compose.svg")).unwrap();
        for needle in ["Boot", "Tokens", "ActionTable", "constructor", "pattern"] {
            must(
                page.contains(needle),
                format!("architecture page must name {needle}"),
            );
        }
        for needle in ["Boot", "Tokens", "ActionTable", "Constructor", "Pattern"] {
            must(
                fig.contains(needle),
                format!("compose.svg must name {needle}"),
            );
        }
        let pattern_src = include_str!("pattern.rs");
        let recipes = include_str!("layout/recipes.rs");
        must(
            !pattern_src.contains("pub fn dock<"),
            "dock is not a pattern constructor",
        );
        must(recipes.contains("pub fn dock<"), "dock lives in layout");
        must(
            page.contains("layout::"),
            "architecture must send readers to layout for box recipes",
        );
        for recipe in ["dock", "split_view", "clamp", "form"] {
            must(
                page.contains(recipe),
                format!("architecture must name layout::{recipe}"),
            );
        }
        must(
            !page.contains("are the same module"),
            "layout recipes must not be filed under pattern",
        );
        for (label, src) in [("page", page.as_str()), ("figure", fig.as_str())] {
            must(
                !src.contains("Notes"),
                format!("{label} must not use hello fixture Notes"),
            );
            must(
                !src.contains("Ready"),
                format!("{label} must not use hello fixture Ready"),
            );
            let lower = src.to_ascii_lowercase();
            must(
                !lower.contains("one action feeds"),
                format!("{label} must not say one Action feeds chrome"),
            );
            must(
                !lower.contains("one `action` feeds"),
                format!("{label} must not say one Action feeds chrome"),
            );
        }
    }

    #[test]
    fn reader_path_omits_maintainer_process() {
        let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR"));
        let files = [
            "README.md",
            "book/src/introduction.md",
            "book/src/first-window.md",
            "book/src/architecture.md",
            "book/src/actions.md",
            "book/src/layout.md",
            "book/src/theming.md",
            "book/src/navigation.md",
            "book/src/overlay-windows.md",
            "book/src/compact-tools.md",
            "book/src/widgets.md",
            "book/src/reference/controls.md",
            "book/src/reference/fields.md",
            "book/src/reference/readout.md",
            "book/src/reference/content.md",
            "book/src/reference/collections.md",
            "book/src/reference/chrome.md",
            "book/src/reference/patterns.md",
            "book/src/cookbook/save.md",
            "book/src/cookbook/list-detail.md",
            "book/src/cookbook/table.md",
            "book/src/cookbook/palette.md",
            "book/src/cookbook/icons.md",
        ];
        for rel in files {
            let text = std::fs::read_to_string(root.join(rel)).unwrap();
            for needle in [
                "one catalog id",
                "one constructor",
                "llvm-cov",
                "fail-under",
                "identity token",
                "catalog id",
                "see also catalog",
            ] {
                must(
                    !text.to_ascii_lowercase().contains(needle),
                    format!("{rel} must not teach {needle}"),
                );
            }
            let stripped = text
                .to_ascii_lowercase()
                .replace("gallery.gif", "")
                .replace("assets/gallery.gif", "");
            must(
                !stripped.contains("gallery"),
                format!("{rel} must not send readers to the gallery demo"),
            );
        }
        let root_rs = include_str!("lib.rs");
        let tour = root_rs.split("#![cfg_attr").next().unwrap_or(root_rs);
        for needle in [
            "one catalog id",
            "one constructor",
            "llvm-cov",
            "fail-under",
            "gallery",
            "catalog id",
        ] {
            must(
                !tour.contains(needle),
                format!("crate-root tour must not teach {needle}"),
            );
        }
    }

    #[test]
    fn every_catalog_id_has_one_shipped_constructor() {
        let widget = include_str!("widget.rs");
        let pattern = include_str!("pattern.rs");
        let layout = include_str!("layout/flow.rs");
        let motion = include_str!("motion.rs");
        let map = [
            ("button", "button", widget),
            ("segmented-button", "segmented_button", widget),
            ("button-group", "button_group", widget),
            ("icon-button", "icon_button", widget),
            ("toggle-icon-button", "icon_button_toggle", widget),
            ("split-button", "split_button", widget),
            ("toggle-button", "toggle_button", widget),
            ("checkbox", "checkbox", widget),
            ("radio", "radio", widget),
            ("switch", "switch", widget),
            ("slider", "slider", widget),
            ("range-slider", "range_slider", widget),
            ("text-input", "text_input", widget),
            ("field-support", "field_support", widget),
            ("password", "password_input", widget),
            ("secret", "secret_field", widget),
            ("value-field", "value_field", widget),
            ("textarea", "textarea", widget),
            ("search", "search_input", widget),
            ("search-view", "search_view", widget),
            ("suggest", "suggest_field", widget),
            ("select", "pick_list", widget),
            ("form", "form_group", widget),
            ("number", "number_input", widget),
            ("date", "date_stepper", widget),
            ("time", "time_picker", widget),
            ("progress", "progress", widget),
            ("progress-ring", "progress_ring", widget),
            ("spinner", "spinner", widget),
            ("label", "label", widget),
            ("icon", "icon_svg", widget),
            ("tooltip", "tooltip_wrap", widget),
            ("rich-tooltip", "tooltip_rich", widget),
            ("link", "hyperlink", widget),
            ("markdown", "markdown_view", widget),
            ("code", "highlighted_code", widget),
            ("image", "image_slot", widget),
            ("selectable", "selectable", widget),
            ("list", "list_view", widget),
            ("virtual-column", "virtual_column", widget),
            ("log", "log_view", widget),
            ("grid", "item_grid", widget),
            ("table", "data_table", widget),
            ("tree", "tree_view", widget),
            ("tabs", "tab_bar", widget),
            ("accordion", "accordion_view", widget),
            ("expander", "expander", widget),
            ("pagination", "pagination", widget),
            ("cheatsheet", "cheatsheet", pattern),
            ("card", "group_box", widget),
            ("rule", "rule_h", widget),
            ("chip", "chip", widget),
            ("filter-chips", "filter_chips", widget),
            ("badge", "badge", widget),
            ("pack", "pack", layout),
            ("wrap", "wrap", layout),
            ("banner", "banner", widget),
            ("command-bar", "command_bar", pattern),
            ("context-menu", "context_menu", pattern),
            ("sectioned-menu", "sectioned_menu", pattern),
            ("cascade-menu", "cascade_menu", pattern),
            ("breadcrumb", "breadcrumb", widget),
            ("menu", "menu_bar", pattern),
            ("toolbar", "toolbar", pattern),
            ("status-bar", "status_bar", pattern),
            ("busy", "busy_overlay", widget),
            ("toast", "toast_view", widget),
            ("scrollbar", "scroll", widget),
            ("dialogs", "dialog_sheet", pattern),
            ("side-sheet", "side_sheet", pattern),
            ("list-detail", "list_detail", pattern),
            ("inspector", "inspector", pattern),
            ("workspace", "workspace", pattern),
            ("tool-panel", "tool_panel", pattern),
            ("drawer", "drawer", pattern),
            ("nav-rail", "nav_rail", pattern),
            ("navigation", "navigation_view", pattern),
            ("tab-view", "tab_view", pattern),
            ("preferences", "preferences_page", pattern),
            ("about", "about_page", pattern),
            ("status-page", "status_page", pattern),
            ("palette", "command_palette_view", pattern),
            ("main-window", "main_window", pattern),
            ("motion", "overlay", motion),
            ("switch-motion", "switch", motion),
            ("attention-motion", "attention", motion),
            ("expand-motion", "expand", motion),
        ];
        assert_eq!(map.len(), ENTRIES.len());
        for e in ENTRIES {
            let hit = map.iter().find(|(id, _, _)| *id == e.id);
            let (_, name, src) = hit.expect(e.id);
            let at = find_pub_fn(src, name)
                .unwrap_or_else(|| panic!("{} missing constructor pub fn {}(", e.id, name));
            must(
                rustdoc_example_immediately_above(&src[..at]),
                format!(
                    "{} constructor pub fn {} needs a rustdoc example immediately above it",
                    e.id, name
                ),
            );
            let rustdoc = rustdoc_block_above(&src[..at]);
            must(
                !rustdoc.contains("catalog id") && !rustdoc.contains("Catalog `"),
                format!("{} rustdoc must not teach catalog id", e.id),
            );
            must(
                !rustdoc.contains("|_| ()") && !rustdoc.contains("|_, _| ()"),
                format!(
                    "{} rustdoc must name the message, not a dummy closure",
                    e.id
                ),
            );
        }
    }

    fn module_src(module: &str) -> Option<&'static str> {
        Some(match module {
            "widget" => include_str!("widget.rs"),
            "pattern" => include_str!("pattern.rs"),
            "motion" => include_str!("motion.rs"),
            "theme" => include_str!("theme.rs"),
            "key" => include_str!("key.rs"),
            "layout" => include_str!("layout/flow.rs"),
            _ => return None,
        })
    }

    fn fn_params_mention(src: &str, name: &str, needle: &str) -> bool {
        let Some(at) = find_pub_fn(src, name) else {
            return false;
        };
        let rest = &src[at..];
        let open = match rest.find('(') {
            Some(i) => i,
            None => return false,
        };
        let bytes = rest.as_bytes();
        let mut depth = 0i32;
        let mut i = open;
        while i < bytes.len() {
            match bytes[i] {
                b'(' => depth += 1,
                b')' => {
                    depth -= 1;
                    if depth == 0 {
                        return rest[open..=i].contains(needle);
                    }
                }
                _ => {}
            }
            i += 1;
        }
        false
    }

    fn find_pub_fn(src: &str, name: &str) -> Option<usize> {
        let pat = format!("pub fn {name}");
        let mut start = 0;
        while let Some(rel) = src[start..].find(&pat) {
            let at = start + rel;
            let after = src[at + pat.len()..].chars().next();
            if matches!(after, Some('(') | Some('<')) {
                return Some(at);
            }
            start = at + pat.len();
        }
        None
    }

    fn rustdoc_block_above(before: &str) -> String {
        let mut docs = Vec::new();
        for line in before.lines().rev() {
            let t = line.trim_start();
            if t.is_empty() {
                if docs.is_empty() {
                    continue;
                }
                break;
            }
            if t.starts_with("///") || t.starts_with("#[") {
                docs.push(t);
                continue;
            }
            break;
        }
        docs.join("\n")
    }

    fn rustdoc_example_immediately_above(before: &str) -> bool {
        let mut docs = Vec::new();
        for line in before.lines().rev() {
            let t = line.trim_start();
            if t.is_empty() {
                if docs.is_empty() {
                    continue;
                }
                break;
            }
            if t.starts_with("///") || t.starts_with("#[") {
                docs.push(t);
                continue;
            }
            break;
        }
        docs.iter().any(|l| l.contains("```"))
    }

    #[test]
    fn fn_params_mention_reads_the_shipped_signature() {
        assert!(fn_params_mention(
            include_str!("widget.rs"),
            "button",
            "A11y"
        ));
        assert!(!fn_params_mention(
            include_str!("pattern.rs"),
            "toolbar",
            "A11y"
        ));
        assert!(fn_params_mention(
            include_str!("pattern.rs"),
            "dialog_sheet",
            "A11y"
        ));
        assert!(!fn_params_mention(
            include_str!("layout/flow.rs"),
            "wrap",
            "A11y"
        ));
        assert!(!fn_params_mention(
            include_str!("layout/flow.rs"),
            "pack",
            "A11y"
        ));
        assert!(fn_params_mention(
            include_str!("pattern.rs"),
            "nav_rail",
            "A11y"
        ));
        assert_eq!(constructor("wrap"), Some(("layout", "wrap")));
        assert_eq!(constructor("pack"), Some(("layout", "pack")));
        assert!(module_src("no-such-module").is_none());
        assert!(!fn_params_mention("fn other() {}", "missing", "A11y"));
        assert!(!fn_params_mention("pub fn bare", "bare", "A11y"));
        assert!(!fn_params_mention("pub fn foo<T>", "foo", "A11y"));
        assert!(!fn_params_mention("pub fn open(( leftover", "open", "A11y"));
    }

    #[test]
    fn accessibility_guide_names_who_takes_the_record() {
        let page = include_str!("../book/src/accessibility.md");
        let widgets = include_str!("../book/src/widgets.md");
        must(
            !page
                .to_ascii_lowercase()
                .contains("every public constructor"),
            "accessibility.md must not say every public constructor takes A11y",
        );
        must(
            page.contains("toolbar")
                && page.contains("dialog_sheet")
                && page.contains("layout::wrap")
                && page.contains("layout::pack"),
            "accessibility.md must name chrome rows and pack/wrap as not taking A11y",
        );
        must(
            widgets.contains("Chrome rows") && widgets.contains("recipes do not take"),
            "widgets.md must split widget A11y from chrome rows and layout",
        );
    }

    #[test]
    fn constructor_name_is_not_a_prefix_of_a_neighbor() {
        assert_eq!(
            find_pub_fn("pub fn spinner_angles()\npub fn spinner()", "spinner"),
            Some("pub fn spinner_angles()\n".len())
        );
        assert_eq!(find_pub_fn("pub fn spinner_angles()", "spinner"), None);
        assert_eq!(find_pub_fn("pub fn progress<T>()", "progress"), Some(0));
        assert_eq!(find_pub_fn("pub fn foo", "foo"), None);
        assert_eq!(find_pub_fn("fn foo()", "foo"), None);
    }

    #[test]
    fn workspace_center_fills_first_leaf() {
        let pattern = include_str!("pattern.rs");
        let at = find_pub_fn(pattern, "workspace").expect("workspace constructor");
        let rustdoc = rustdoc_block_above(&pattern[..at]);
        must(
            rustdoc.contains("each leaf id"),
            "workspace rustdoc must say each leaf id gets a pane",
        );
        assert_eq!(rustdoc_block_above("\n\n"), "");
        assert!(rustdoc_block_above("/// hi\n/// there").contains("/// hi"));
        assert!(rustdoc_block_above("code\n\n/// doc").contains("/// doc"));
        assert!(rustdoc_block_above("fn other()\n/// doc").contains("/// doc"));
    }

    #[test]
    fn hello_is_a_tool() {
        let hello = include_str!("../examples/hello.rs");
        assert!(hello.contains("file.save"));
        assert!(hello.contains("ctrl+s"));
        assert!(hello.contains("pattern::toolbar") || hello.contains("main_window"));
        assert!(hello.contains("textarea") || hello.contains("text_input"));
        assert!(!hello.contains("count.inc"));
        assert!(!hello.contains("n: i32"));
    }

    #[test]
    fn readme_points_at_hello() {
        let readme = include_str!("../README.md");
        assert!(readme.contains("examples/hello.rs"));
        assert!(readme.contains("icedtea::run!"));
        assert!(!readme.contains("struct Hello"));
    }

    #[test]
    fn crate_root_walks() {
        let root = include_str!("lib.rs");
        let tour = root.split("#![cfg_attr").next().unwrap_or(root);
        for heading in ["First compose", "Boot", "Keys", "Tokens", "Scope"] {
            assert!(tour.contains(heading));
        }
        assert!(tour.contains("file.save"));
        assert!(!tour.contains("catalog id"));
        assert!(!tour.contains("closed list"));
    }

    #[test]
    fn cookbook_exists() {
        let summary = include_str!("../book/src/SUMMARY.md");
        assert!(summary.contains("- [Start]()"));
        assert!(summary.contains("- [Compose]()"));
        assert!(summary.contains("- [Cookbook]()"));
        assert!(summary.contains("- [Reference]()"));
        assert!(summary.contains("    - [Install](install.md)"));
        assert!(summary.contains("    - [Widgets](widgets.md)"));
        assert!(summary.contains("    - [Accessibility](accessibility.md)"));
        let pages: [(&str, &[&str]); 5] = [
            (
                include_str!("../book/src/cookbook/save.md"),
                &["file.save", "toolbar", "key::handle", "textarea"],
            ),
            (
                include_str!("../book/src/cookbook/list-detail.md"),
                &["list_detail", "list_view", "layout::fixed"],
            ),
            (
                include_str!("../book/src/cookbook/table.md"),
                &["data_table", "TableModel", "ColumnLayout", "VisibleWindow"],
            ),
            (
                include_str!("../book/src/cookbook/palette.md"),
                &["CommandPalette", "command_palette_view"],
            ),
            (
                include_str!("../book/src/cookbook/icons.md"),
                &[
                    "adapt_material_svg",
                    "material_symbol_sharp_url",
                    "Glyph::Bytes",
                    "icon_svg",
                ],
            ),
        ];
        for (text, needles) in pages {
            for n in needles.iter().copied() {
                assert!(text.contains(n));
            }
            assert!(!text.to_ascii_lowercase().contains("gallery"));
            assert!(!text.contains("Nop"));
        }
    }

    #[test]
    fn constructor_rustdoc_has_no_catalog_title() {
        let widget = include_str!("widget.rs");
        assert!(
            !rustdoc_block_above(&widget[..find_pub_fn(widget, "button").unwrap()])
                .contains("catalog id")
        );
    }

    #[test]
    fn rustdoc_example_must_sit_on_the_constructor() {
        assert!(rustdoc_example_immediately_above(
            "/// ```\n/// x\n/// ```\n"
        ));
        assert!(rustdoc_example_immediately_above("/// ```\n#[must_use]\n"));
        assert!(rustdoc_example_immediately_above("/// ```\n\n"));
        assert!(!rustdoc_example_immediately_above("/// no fence\n"));
        assert!(!rustdoc_example_immediately_above(
            "/// ```\n/// neighbor\n/// ```\n\n/// this fn has no fence\n"
        ));
        assert!(!rustdoc_example_immediately_above("fn other() {}\n"));
    }

    #[test]
    fn collapsed_dual_paths_are_not_public() {
        let widget = include_str!("widget.rs");
        must(
            !widget.contains("pub fn image<"),
            "image_slot is the image constructor",
        );
        let key = include_str!("key.rs");
        must(
            !key.contains("pub fn listen_raw"),
            "listen is the keyboard subscription",
        );
        let recipes = include_str!("layout/recipes.rs");
        must(
            !recipes.contains("pub fn scroll_y<"),
            "scroll is the scroll constructor",
        );
        must(
            !recipes.contains("pub fn sidebar_mode"),
            "Breakpoint::from_width picks the sidebar recipe",
        );
    }
}