lurq 0.65.1

A Rust UI toolkit with typed components, retained state, reactive signals, GPU rendering, and DevTools.
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
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
//! A lightbox: pictures looked at one at a time over the window, larger and closer.

use std::sync::Arc;

use super::{
  Carousel, FontFamily, Menu, MenuItem, Picture, icons, names,
  part_style::{Length, PartTransition},
  recipe::{Case, Name, Recipe, ResolvedPart, ResolvedRecipe, Selector},
  shared::{fading, glyph, pressable},
  theme::{Themed, current_theme},
};
use crate::{
  animation::Transition,
  app::{
    component::Component,
    ctx::{Ctx, Placement},
    events::{GesturePhase, KeyboardEvent, MouseEvent, PanEvent, TapEvent},
    theme::{MotionDuration, RadiusSize, Theme, TypographyStyle},
  },
  components::{Column, Modal, Root, Row, Stack, ZoomScroll, ZoomScrollProps},
  core::{ElementRef, Signal},
  layout::{
    Alignment, StackAlignment,
    layout_kind::{Justify, ScrollState},
    text_style::{FontWeight, TextAlign},
  },
  node::{
    CursorIcon, Element, HitTestBehavior, NodeUpdate, border::Border, color::Color, dimension::Dimension,
    outline::Outline,
  },
};

/// How much one press of Zoom in, or one notch of the wheel, brings the picture closer.
const ZOOM_STEP: f32 = 1.5;
/// How far an arrow key moves a picture that is zoomed in.
const PAN_STEP: f32 = 48.0;
/// The top row's padding at its two ends, the room a button of it takes with the gap after it, the level's, the
/// gap alone, and the width of a letter of the counter: what tells whether the row has room for its level.
const TOP_SIDES: f32 = 24.0;
const CONTROL_ROOM: f32 = 40.0;
const LEVEL_ROOM: f32 = 60.0;
const CONTROL_GAP: f32 = 4.0;
const COUNTER_LETTER: f32 = 8.0;

/// The room between the strip's small pictures, as the design has it, and the least there is at its ends:
/// what tells how many of them the strip has room for.
const STRIP_GAP: f32 = 6.0;
const STRIP_INSET: f32 = 8.0;

/// The parts of a lightbox a recipe styles.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum LightboxPart {
  /// What covers the window under the lightbox.
  Veil,
  /// The lightbox: its fill, and its corners where it stands in a page.
  Root,
  /// The row along the top: the counter at its start, the buttons at its end.
  Top,
  /// Which picture is shown, in the counter.
  Counter,
  /// How many there are, after it.
  Total,
  /// A button of the top row.
  Control,
  /// The glyph of a button of the top row.
  ControlIcon,
  /// The button that says how close the picture is, and fits it again.
  Level,
  /// The room the picture is shown in.
  Stage,
  /// The round button over a side of the stage that turns to the picture before or after.
  Step,
  /// The glyph of that button.
  StepIcon,
  /// The side of the stage such a button lies over: its padding is how far in from the edge the button is.
  Side,
  /// The picture's title and description, over its lower edge. Its background is the color the gradient under
  /// them ends in, from nothing at its top.
  Caption,
  /// The picture's title.
  Title,
  /// The line under it.
  Description,
  /// The strip of small pictures along the bottom.
  Filmstrip,
  /// One of them.
  Thumb,
  /// What stands under the picture on a phone: its caption and the dots.
  Bottom,
  /// The row of dots on a phone, one for each picture about the one shown.
  Pages,
  /// A dot of that row.
  Page,
}

names!(LightboxPart {
  Veil => "veil",
  Root => "root",
  Top => "top",
  Counter => "counter",
  Total => "total",
  Control => "control",
  ControlIcon => "control_icon",
  Level => "level",
  Stage => "stage",
  Step => "step",
  StepIcon => "step_icon",
  Side => "side",
  Caption => "caption",
  Title => "title",
  Description => "description",
  Filmstrip => "filmstrip",
  Thumb => "thumb",
  Bottom => "bottom",
  Pages => "pages",
  Page => "page",
});

/// The states of a lightbox a recipe styles.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum LightboxState {
  /// It stands in the page where it is declared, not over the window.
  Inline,
  /// The small picture of the strip that is the one shown.
  Current,
}

names!(LightboxState {
  Inline => "inline",
  Current => "current",
});

/// The forms of a lightbox.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Default)]
pub enum LightboxVariant {
  /// A panel with a top row of buttons, round buttons over the picture's sides and a strip of small pictures:
  /// for a pointer and a keyboard.
  #[default]
  Desktop,
  /// The whole screen, black: a top row of a close button, the counter, share and more, the picture, and its
  /// caption and dots under it. A swipe turns, a pinch and a double tap bring closer, a drag down closes.
  Phone,
}

names!(LightboxVariant {
  Desktop => "desktop",
  Phone => "phone",
});

/// How many dots the phone's row shows at most, about the picture shown.
const PAGES_SHOWN: usize = 9;
/// How far a drag down takes the picture before letting go closes the lightbox, and how fast a throw down does.
const DROP_CLOSES: f32 = 120.0;
const THROW_CLOSES: f32 = 900.0;
/// How far down the picture is dragged when the black under it is gone to its least.
const DROP_FADES: f32 = 400.0;

/// What builds a lightbox's nodes: a theme's in place of the default one.
pub type LightboxRenderer = Arc<dyn Fn(LightboxView) -> Element + Send + Sync>;

type Action = Arc<dyn Fn() + Send + Sync>;
type Told<T> = Arc<dyn Fn(T) + Send + Sync>;

/// The words a lightbox writes itself.
#[derive(Clone)]
struct Words {
  label: Arc<str>,
  close: Arc<str>,
  previous: Arc<str>,
  next: Arc<str>,
  zoom_in: Arc<str>,
  zoom_out: Arc<str>,
  fit: Arc<str>,
  download: Arc<str>,
  share: Arc<str>,
  more: Arc<str>,
}

impl Default for Words {
  fn default() -> Self {
    let locale = super::current_locale();
    let words = &locale.navigation;
    Self {
      label: words.pictures.clone(),
      close: locale.common.close.clone(),
      previous: words.previous_picture.clone(),
      next: words.next_picture.clone(),
      zoom_in: words.zoom_in.clone(),
      zoom_out: words.zoom_out.clone(),
      fit: words.fit_to_window.clone(),
      download: locale.common.download.clone(),
      share: locale.common.share.clone(),
      more: locale.common.more.clone(),
    }
  }
}

/// A lightbox: pictures shown one at a time over the window.
///
/// ```
/// use lurq::{core::Signal, ui::{Lightbox, Picture}};
///
/// let open = Signal::new(false);
/// let viewer = Lightbox::new(open.clone(), [
///   Picture::from_file("lake.jpg").title("Lake at dusk"),
///   Picture::from_file("ridge.jpg").title("The ridge"),
/// ]);
/// open.set(true);
/// ```
///
/// It is open while its signal says so. The picture fills the room it has, whole; the counter says which one it
/// is; the buttons at the top bring it closer and further and fit it again, and close the lightbox; the round
/// buttons over its sides turn to the one before and after; the strip along the bottom shows them all. The
/// picture's [`title`](Picture::title) and [`description`](Picture::description) lie over its lower edge.
///
/// The wheel brings the picture closer about the pointer, as `+` and `-` do about its middle; `0` fits it
/// again and a double click goes in and back out. Closer than it fits, a drag and the arrow keys move it;
/// fitted, the left and right arrows turn to the picture before and after. Escape closes it.
///
/// A lightbox is a component: it keeps which picture is shown and how close, unless the app gives it signals
/// for them ([`index`](Self::index), [`zoom`](Self::zoom)).
#[derive(Clone)]
pub struct Lightbox {
  open: Signal<bool>,
  pictures: Vec<Picture>,
  index: Option<Signal<usize>>,
  controlled: Option<usize>,
  on_index_change: Vec<Told<usize>>,
  zoom: Option<Signal<f32>>,
  on_zoom_change: Vec<Told<f64>>,
  zoom_max: f32,
  preload: usize,
  filmstrip: Option<bool>,
  counter: Option<bool>,
  counter_text: Option<Arc<dyn Fn(usize, usize) -> String + Send + Sync>>,
  wrap: bool,
  on_download: Vec<Told<usize>>,
  on_share: Vec<Told<usize>>,
  menu_items: Vec<MenuItem>,
  variant: Option<Name>,
  actions: Vec<Element>,
  inline: bool,
  width: Option<Length>,
  height: Option<Length>,
  on_dismiss: Vec<Action>,
  dismiss_on_escape: bool,
  dismiss_on_veil: bool,
  close_button: bool,
  words: Words,
  states: Vec<Name>,
  rules: Recipe,
  id: Option<Arc<str>>,
  key: Option<Arc<str>>,
}

impl Lightbox {
  /// A lightbox of `pictures`, open while `open` says so.
  pub fn new(open: Signal<bool>, pictures: impl IntoIterator<Item = Picture>) -> Self {
    Self {
      open,
      pictures: pictures.into_iter().collect(),
      index: None,
      controlled: None,
      on_index_change: Vec::new(),
      zoom: None,
      on_zoom_change: Vec::new(),
      zoom_max: 4.0,
      preload: 1,
      filmstrip: None,
      counter: None,
      counter_text: None,
      wrap: false,
      on_download: Vec::new(),
      on_share: Vec::new(),
      menu_items: Vec::new(),
      variant: None,
      actions: Vec::new(),
      inline: false,
      width: None,
      height: None,
      on_dismiss: Vec::new(),
      dismiss_on_escape: true,
      dismiss_on_veil: true,
      close_button: true,
      words: Words::default(),
      states: Vec::new(),
      rules: Recipe::new(),
      id: None,
      key: None,
    }
  }

  /// One more picture, after the others.
  pub fn picture(mut self, picture: Picture) -> Self {
    self.pictures.push(picture);
    self
  }

  /// More pictures, after the others.
  pub fn pictures(mut self, pictures: impl IntoIterator<Item = Picture>) -> Self {
    self.pictures.extend(pictures);
    self
  }

  /// Which picture is shown, counted from 0, to read and to set. Without it the lightbox keeps it, and starts
  /// at the first.
  pub fn index(mut self, index: Signal<usize>) -> Self {
    self.index = Some(index);
    self
  }

  /// Which picture is shown, as the app says it each time: the lightbox asks for another with `on_change` and
  /// shows what it is told.
  pub fn index_controlled(mut self, index: usize, on_change: impl Fn(usize) + Send + Sync + 'static) -> Self {
    self.controlled = Some(index);
    self.on_index_change.push(Arc::new(on_change));
    self
  }

  /// Called when another picture is turned to, with the one it is.
  pub fn on_index_change(mut self, handler: impl Fn(usize) + Send + Sync + 'static) -> Self {
    self.on_index_change.push(Arc::new(handler));
    self
  }

  /// How close the picture is, 1 where it fits, to read and to set. Without it the lightbox keeps it.
  pub fn zoom(mut self, zoom: Signal<f32>) -> Self {
    self.zoom = Some(zoom);
    self
  }

  /// Called when the picture is brought closer or further, with how close it is.
  pub fn on_zoom_change(mut self, handler: impl Fn(f64) + Send + Sync + 'static) -> Self {
    self.on_zoom_change.push(Arc::new(handler));
    self
  }

  /// How many pictures each way of the one shown are brought on once it is there, so that an arrow shows the
  /// next at once: 1 unless told, 0 for none.
  pub fn preload(mut self, preload: usize) -> Self {
    self.preload = preload;
    self
  }

  /// The closest the picture is brought, as a multiple of the size it fits at: 4 unless set.
  pub fn zoom_max(mut self, max: f32) -> Self {
    self.zoom_max = max.max(1.0);
    self
  }

  /// Whether the strip of small pictures shows: with more than one picture unless told.
  pub fn filmstrip(mut self, filmstrip: bool) -> Self {
    self.filmstrip = Some(filmstrip);
    self
  }

  /// Whether the counter shows: with more than one picture unless told.
  pub fn counter(mut self, counter: bool) -> Self {
    self.counter = Some(counter);
    self
  }

  /// What the counter says, from which picture is shown, counted from 1, and how many there are: "3 / 12"
  /// unless told.
  pub fn counter_text(mut self, text: impl Fn(usize, usize) -> String + Send + Sync + 'static) -> Self {
    self.counter_text = Some(Arc::new(text));
    self
  }

  /// Whether the first picture comes after the last, and the last before the first.
  pub fn wrap(mut self, wrap: bool) -> Self {
    self.wrap = wrap;
    self
  }

  /// Shows the Download button, and is called with the picture shown when it is pressed.
  pub fn on_download(mut self, handler: impl Fn(usize) + Send + Sync + 'static) -> Self {
    self.on_download.push(Arc::new(handler));
    self
  }

  /// Shows the Share button on a phone, and is called with the picture shown when it is pressed.
  pub fn on_share(mut self, handler: impl Fn(usize) + Send + Sync + 'static) -> Self {
    self.on_share.push(Arc::new(handler));
    self
  }

  /// An item of the menu behind More on a phone, after Download. More shows where the menu has an item.
  pub fn menu_item(mut self, item: MenuItem) -> Self {
    self.menu_items.push(item);
    self
  }

  /// Items of the menu behind More on a phone.
  pub fn menu_items(mut self, items: impl IntoIterator<Item = MenuItem>) -> Self {
    self.menu_items.extend(items);
    self
  }

  /// The form ([`LightboxVariant`]): the phone's where the person points with a finger
  /// ([`Pointer::Coarse`](crate::app::Pointer::Coarse), [`touch_form`](super::touch_form)), whatever the window's
  /// width and the theme's density, unless told. In a narrow window of a desktop it is the desktop's, laid out
  /// narrow. Open, it keeps the form it opened in until it closes (in a page, the one it was first shown in), so a
  /// finger that lands on it does not change it under itself; the app setting the pointer changes it at once.
  pub fn variant(mut self, variant: impl Into<Name>) -> Self {
    self.variant = Some(variant.into());
    self
  }

  /// What Share is called: "Share" unless told.
  pub fn share_label(mut self, label: &str) -> Self {
    self.words.share = Arc::from(label);
    self
  }

  /// What More is called: "More" unless told.
  pub fn more_label(mut self, label: &str) -> Self {
    self.words.more = Arc::from(label);
    self
  }

  /// A button of the app's in the top row, before Download.
  pub fn action(mut self, action: impl Into<Element>) -> Self {
    self.actions.push(action.into());
    self
  }

  /// Buttons of the app's in the top row.
  pub fn actions(mut self, actions: impl IntoIterator<Item = impl Into<Element>>) -> Self {
    self.actions.extend(actions.into_iter().map(Into::into));
    self
  }

  /// Stands in the page where it is declared, in place of over the window: open or not, it is there.
  pub fn inline(mut self, inline: bool) -> Self {
    self.inline = inline;
    self
  }

  /// How wide it is where it stands in a page: all the room unless told.
  pub fn width(mut self, width: impl Into<Length>) -> Self {
    self.width = Some(width.into());
    self
  }

  /// How high it is where it stands in a page: all the room unless told.
  pub fn height(mut self, height: impl Into<Length>) -> Self {
    self.height = Some(height.into());
    self
  }

  /// Called when it is dismissed: by Escape, by a press on what is around the picture, or by Close.
  pub fn on_dismiss(mut self, handler: impl Fn() + Send + Sync + 'static) -> Self {
    self.on_dismiss.push(Arc::new(handler));
    self
  }

  /// Whether Escape closes it: it does unless told.
  pub fn dismiss_on_escape(mut self, dismiss: bool) -> Self {
    self.dismiss_on_escape = dismiss;
    self
  }

  /// Whether a press on the room around the picture closes it: it does unless told.
  pub fn dismiss_on_veil(mut self, dismiss: bool) -> Self {
    self.dismiss_on_veil = dismiss;
    self
  }

  /// Whether it has a Close button: it has unless told.
  pub fn close_button(mut self, close_button: bool) -> Self {
    self.close_button = close_button;
    self
  }

  /// What it is called to tooling that reads the tree: "Pictures" unless told.
  pub fn label(mut self, label: &str) -> Self {
    self.words.label = Arc::from(label);
    self
  }

  pub fn close_label(mut self, label: &str) -> Self {
    self.words.close = Arc::from(label);
    self
  }

  pub fn previous_label(mut self, label: &str) -> Self {
    self.words.previous = Arc::from(label);
    self
  }

  pub fn next_label(mut self, label: &str) -> Self {
    self.words.next = Arc::from(label);
    self
  }

  pub fn zoom_in_label(mut self, label: &str) -> Self {
    self.words.zoom_in = Arc::from(label);
    self
  }

  pub fn zoom_out_label(mut self, label: &str) -> Self {
    self.words.zoom_out = Arc::from(label);
    self
  }

  pub fn fit_label(mut self, label: &str) -> Self {
    self.words.fit = Arc::from(label);
    self
  }

  pub fn download_label(mut self, label: &str) -> Self {
    self.words.download = Arc::from(label);
    self
  }

  /// Turns a state a recipe's rules name on or off.
  pub fn state(mut self, state: impl Into<Name>, on: bool) -> Self {
    let state = state.into();
    self.states.retain(|held| *held != state);
    if on {
      self.states.push(state);
    }
    self
  }

  /// The style of one part, over the theme's.
  pub fn style(mut self, part: impl Into<Name>, style: impl FnOnce(super::PartStyle) -> super::PartStyle) -> Self {
    self.rules = self.rules.base(part, style);
    self
  }

  /// Rules over the theme's.
  pub fn rules(mut self, rules: &Recipe) -> Self {
    self.rules = self.rules.extend(rules);
    self
  }

  pub fn id(mut self, id: impl Into<Arc<str>>) -> Self {
    self.id = Some(id.into());
    self
  }

  pub fn key(mut self, key: impl Into<Arc<str>>) -> Self {
    self.key = Some(key.into());
    self
  }

  /// The lightbox mounted in `ctx`: what converting it into an element does once the render that returns it
  /// has returned.
  pub fn mount(self, ctx: &mut Ctx) -> Element {
    let key = self.key.clone();
    let props = LightboxProps(self);
    match key {
      Some(key) => ctx.mount_keyed::<LightboxHost>(&key, props),
      None => ctx.mount::<LightboxHost>(props),
    }
  }
}

/// A lightbox in a tree is its component, declared: the component that renders the tree mounts it.
impl From<Lightbox> for Element {
  fn from(lightbox: Lightbox) -> Self {
    let key = lightbox.key.clone();
    let props = LightboxProps(lightbox);
    match key {
      Some(key) => Element::component_keyed::<LightboxHost>(key, props),
      None => Element::component::<LightboxHost>(props),
    }
  }
}

/// A lightbox to mount.
#[derive(Clone)]
struct LightboxProps(Lightbox);

/// Its pictures and its handlers are made anew by every render of what holds it.
impl PartialEq for LightboxProps {
  fn eq(&self, _: &Self) -> bool {
    false
  }
}

impl crate::app::component::DevtoolsInspectable for LightboxProps {}

/// The component of a lightbox: what it keeps between renders.
struct LightboxHost {
  /// Which picture is shown, where the app names no signal for it.
  index: Signal<usize>,
  /// How close it is, where the app names no signal for it.
  zoom: Signal<f32>,
  /// Where a picture closer than it fits is moved to: the list that scrolls it.
  scroll: ScrollState,
  /// How close the picture was when the app was last told.
  told: Arc<parking_lot::Mutex<f32>>,
  /// What to tell the app once this render is laid out.
  news: Arc<parking_lot::Mutex<Vec<Action>>>,
  /// The stage as it is laid out: where it is in the window, and how large.
  stage: ElementRef,
  /// The stage's size the picture was last laid out for.
  room: Signal<(f32, f32)>,
  /// The picture whose pixels came, by its place.
  came: Signal<Option<usize>>,
  /// Whether the menu behind More is open, and the button it hangs from.
  more_open: Signal<bool>,
  more: ElementRef,
  /// How far down a finger has dragged the picture, on a phone: what closes it once let go far enough.
  drop: Signal<f32>,
  /// Whether the fingers on the stage are a drag down the lightbox took.
  taken: Arc<std::sync::atomic::AtomicBool>,
  /// Whether it was open at the last render: one that opens again shows its picture fitted.
  was_open: std::sync::atomic::AtomicBool,
  /// The form it took when it opened, and how many times the pointer had been told then: an open lightbox keeps
  /// its form while a finger or a mouse moves the pointer, and gives way when the app sets it.
  held: parking_lot::Mutex<Option<(bool, u64)>>,
  /// The pictures about the one shown brought on ahead, by their places, with the loads held while they are
  /// on their way.
  ahead: parking_lot::Mutex<Vec<(usize, Option<crate::resources::Load>)>>,
  /// Moves on when a load ahead ends: what decodes what it brought.
  ahead_tick: Signal<u64>,
  /// Whether a lightbox in a page is shown over the whole screen too, opened by a tap on a phone.
  full: Signal<bool>,
  /// What a load ahead calls when it ends: one waker, which a load keeps once.
  ahead_wake: Arc<dyn Fn() + Send + Sync>,
}

impl Component for LightboxHost {
  type Props = LightboxProps;

  fn create(ctx: &mut Ctx) -> Self {
    // A load ahead that ends renders the lightbox again; one that only came further does not.
    let ahead_tick = ctx.signal(0u64);
    let ahead_wake: Arc<dyn Fn() + Send + Sync> = {
      let tick = ahead_tick.clone();
      Arc::new(move || tick.set(tick.get_untracked().wrapping_add(1)))
    };
    Self {
      index: ctx.signal(0),
      zoom: ctx.signal(1.0),
      scroll: ScrollState::new(),
      told: Arc::new(parking_lot::Mutex::new(1.0)),
      news: Arc::default(),
      stage: ElementRef::new(),
      room: ctx.signal((0.0, 0.0)),
      came: ctx.signal(None),
      more_open: ctx.signal(false),
      more: ElementRef::new(),
      drop: ctx.signal(0.0),
      taken: Arc::default(),
      was_open: std::sync::atomic::AtomicBool::new(false),
      held: parking_lot::Mutex::new(None),
      ahead: parking_lot::Mutex::new(Vec::new()),
      ahead_tick,
      ahead_wake,
      full: ctx.signal(false),
    }
  }

  fn render(&self, ctx: &mut Ctx) -> impl Into<Element> {
    let lightbox = ctx.props::<LightboxProps>().0.clone();
    let theme = current_theme();
    let count = lightbox.pictures.len();
    let index_signal = lightbox.index.clone().unwrap_or_else(|| self.index.clone());
    let index = lightbox
      .controlled
      .unwrap_or_else(|| index_signal.get())
      .min(count.saturating_sub(1));
    let zoom_signal = lightbox.zoom.clone().unwrap_or_else(|| self.zoom.clone());
    // Opened again, the picture is fitted, as it is the first time: how close it was is the lightbox's own, and
    // the app's where it gives a signal for it.
    let open = lightbox.inline || lightbox.open.get();
    let opened = open && !self.was_open.swap(open, std::sync::atomic::Ordering::Relaxed);
    if !open {
      self.was_open.store(false, std::sync::atomic::Ordering::Relaxed);
    }
    if opened && lightbox.zoom.is_none() && self.zoom.get_untracked() != 1.0 {
      self.zoom.set(1.0);
      self.scroll.set_scroll(0.0, 0.0);
    }
    let max = lightbox.zoom_max;
    // The phone's form is for a finger, which the person's pointer says; a narrow window is a desktop's still, and
    // the desktop's form lays itself out in the room it has. Open, it keeps the form it opened in, so that it does
    // not change under the finger that just touched it; the app setting the pointer reaches it at once.
    let phone = match lightbox.variant {
      Some(variant) => variant == Name::from(LightboxVariant::Phone),
      None => {
        let (finger, told) = (super::touch_form(), super::theme::pointer_told());
        let mut held = self.held.lock();
        match *held {
          Some((phone, at)) if open && at == told => phone,
          _ => {
            *held = open.then_some((finger, told));
            finger
          }
        }
      }
    };
    // Over the whole of a phone's screen it keeps clear of what the system draws over its edges: the status bar
    // and the home indicator, and on its side the camera's notch and the corners. In either form: a phone on its
    // side may be wide enough for the form of a pointer.
    let safe = match lightbox.inline {
      false => ctx.safe_area(),
      true => crate::app::window::SafeAreaInsets::default(),
    };
    let drop = self.drop.get();
    let zoom = zoom_signal.get().clamp(1.0, max);
    let room = self.room.get();

    // The app hears of every change of how close the picture is, whatever made it: a button, a key, the wheel,
    // two fingers. Once the render that shows it is laid out.
    {
      let mut told = self.told.lock();
      if (*told - zoom).abs() > f32::EPSILON {
        *told = zoom;
        let handlers = lightbox.on_zoom_change.clone();
        self.news.lock().push(Arc::new(move || {
          handlers.iter().for_each(|tell| tell(f64::from(zoom)));
        }));
      }
    }
    // Brings the picture to a scale, about the middle of the stage: what a button and a key do. The wheel, a
    // double click and two fingers do it about where they are, in what shows the picture.
    let go: Arc<dyn Fn(f32) + Send + Sync> = {
      let zoom_signal = zoom_signal.clone();
      Arc::new(move |next: f32| {
        let next = next.clamp(1.0, max);
        if (next - zoom_signal.get_untracked()).abs() > f32::EPSILON {
          zoom_signal.set(next);
        }
      })
    };
    // Moves a picture closer than it fits, no further than its edges.
    let shift: Arc<dyn Fn(f32, f32) + Send + Sync> = {
      let scroll = self.scroll.clone();
      Arc::new(move |x: f32, y: f32| scroll.scroll_by(x, y))
    };
    // Turns to the picture `to`: fitted, as every picture is first seen.
    let turn: Told<usize> = {
      let (signal, controlled, told) = (
        index_signal.clone(),
        lightbox.controlled.is_some(),
        lightbox.on_index_change.clone(),
      );
      let (zoom_signal, scroll) = (zoom_signal.clone(), self.scroll.clone());
      Arc::new(move |to: usize| {
        if to >= count || to == index {
          return;
        }
        zoom_signal.set(1.0);
        scroll.set_scroll(0.0, 0.0);
        if !controlled {
          signal.set(to);
        }
        told.iter().for_each(|tell| tell(to));
      })
    };

    // The picture in the room it has: laid out as large as the stage, where it fits whole, and drawn closer
    // from there by what scrolls it (`ZoomScroll`): the wheel about the pointer, two fingers about their
    // middle, a double click, a drag. Until the stage is laid out it has no size to be laid out at.
    self.bring_on(ctx, &lightbox, index);
    let shown = lightbox.pictures.get(index).cloned().map(|picture| {
      let came = self.came.clone();
      let picture: Element = picture
        .in_viewer()
        .on_load(move || {
          if came.get_untracked() != Some(index) {
            came.set(Some(index));
          }
        })
        .key(format!("picture-{index}"))
        .into();
      if room.0 <= 0.0 || room.1 <= 0.0 {
        return picture;
      }
      let props = ZoomScrollProps::new(room.0, room.1)
        .range(1.0, max)
        .wheel_zoom(ZOOM_STEP)
        // On a phone a drag of the fitted picture is the slides': it pans only once it is closer.
        .drag_pan(!phone || zoom > 1.0)
        // It pans by a drag and by the arrows: the board draws no bars over the picture's black.
        .scrollbars(false)
        .zoom(zoom_signal.clone())
        .scroll(self.scroll.clone());
      ZoomScroll::mount(ctx, props, picture)
    });

    let case = |current: bool| {
      Case {
        variant: Some(
          if phone {
            LightboxVariant::Phone
          } else {
            LightboxVariant::Desktop
          }
          .into(),
        ),
        size: None,
        density: None,
        breakpoint: super::current_breakpoint(),
        states: lightbox.states.clone(),
      }
      .state(LightboxState::Inline, lightbox.inline)
      .state(LightboxState::Current, current)
    };
    // On a phone a lightbox in a page opens over the whole screen at a tap of its picture: the same pictures, at the
    // one shown, in the phone's form. Closed, the one in the page is at the picture it was closed on.
    let in_page_on_a_phone = lightbox.inline && phone;
    let expand: Option<Action> = in_page_on_a_phone.then(|| {
      let full = self.full.clone();
      Arc::new(move || full.set(true)) as Action
    });
    let expanded: Option<Element> = (in_page_on_a_phone && self.full.get()).then(|| {
      let mut whole = lightbox.clone();
      whole.inline = false;
      whole.open = self.full.clone();
      whole.index = Some(index_signal.clone());
      whole.key = None;
      whole.id = whole.id.map(|id| Arc::from(format!("{id}-full")));
      whole.into()
    });
    let recipe = theme
      .resolve::<Lightbox>(&case(false), Some(&lightbox.rules))
      .owned_by(lightbox.id.as_ref());
    let current = theme
      .resolve::<Lightbox>(&case(true), Some(&lightbox.rules))
      .owned_like(&recipe);
    let view = LightboxView {
      expand,
      expanded,
      recipe,
      current,
      index,
      zoom,
      shown,
      go,
      turn,
      stage: self.stage.clone(),
      shift,
      phone,
      safe,
      room,
      drop,
      dropped: self.drop.clone(),
      taken: self.taken.clone(),
      more_open: self.more_open.clone(),
      more: self.more.clone(),
      lightbox,
    };
    match theme.renderer::<Lightbox>() {
      Some(renderer) => renderer(view),
      None => view.render(),
    }
  }

  /// The picture is laid out as large as the stage, which is known once it is laid out.
  fn after_layout(&self) {
    if !self.stage.is_attached() {
      return;
    }
    let room = (self.stage.width(), self.stage.height());
    let last = self.room.get_untracked();
    if (last.0 - room.0).abs() > 0.25 || (last.1 - room.1).abs() > 0.25 {
      self.room.set(room);
    }
    let news = std::mem::take(&mut *self.news.lock());
    news.iter().for_each(|tell| tell());
  }
}

impl LightboxHost {
  /// Brings on the pictures about the one shown, once its own pixels are there: as many each way as the
  /// lightbox says, round the ends where it wraps. A load that ends renders this again, which decodes what it
  /// brought.
  fn bring_on(&self, ctx: &Ctx, lightbox: &Lightbox, index: usize) {
    let _ = self.ahead_tick.get();
    let count = lightbox.pictures.len();
    let open = lightbox.inline || lightbox.open.get();
    if !open || lightbox.preload == 0 || self.came.get() != Some(index) {
      return;
    }
    let mut places = Vec::new();
    for step in 1..=lightbox.preload.min(count) {
      let after = index + step;
      let before = index.checked_sub(step);
      let after = if after < count {
        Some(after)
      } else {
        lightbox.wrap.then(|| after % count)
      };
      let before = before.or_else(|| lightbox.wrap.then(|| (index + count - step % count) % count));
      for at in [after, before].into_iter().flatten() {
        if at != index && !places.contains(&at) {
          places.push(at);
        }
      }
    }
    #[cfg(feature = "image")]
    {
      let loader = ctx.app_handle().map(|app| app.loader().clone());
      let mut ahead = self.ahead.lock();
      let held = std::mem::take(&mut *ahead);
      for at in places {
        // Asked once: a load that is on its way is held, and decoded here once it has ended.
        let load = match held.iter().find(|(place, _)| *place == at) {
          Some((_, None)) => None,
          Some((_, Some(load))) if load.state().is_loading() => Some(load.clone()),
          _ => lightbox.pictures[at].fetch(loader.as_ref()),
        };
        if let Some(load) = &load {
          load.wake_with(self.ahead_wake.clone());
        }
        ahead.push((at, load));
      }
    }
    #[cfg(not(feature = "image"))]
    let _ = (ctx, places);
  }
}

/// A lightbox as a renderer sees it: what it was given, which picture it shows and how close, and the style of
/// its parts.
pub struct LightboxView {
  /// The style of each part.
  pub recipe: ResolvedRecipe,
  /// The style of each part of the strip's small picture that is the one shown.
  current: ResolvedRecipe,
  /// Which picture is shown, counted from 0.
  pub index: usize,
  /// How close it is: 1 where it fits.
  pub zoom: f32,
  /// The picture shown, in what brings it closer.
  shown: Option<Element>,
  go: Arc<dyn Fn(f32) + Send + Sync>,
  turn: Told<usize>,
  stage: ElementRef,
  shift: Arc<dyn Fn(f32, f32) + Send + Sync>,
  /// Whether it is the phone's form.
  pub phone: bool,
  /// How far in from each edge of the screen what the system draws ends, on a phone; nothing where it stands in
  /// a page.
  safe: crate::app::window::SafeAreaInsets,
  /// The stage's size, once it is laid out.
  room: (f32, f32),
  /// How far down a finger has dragged the picture, and where that is kept.
  drop: f32,
  dropped: Signal<f32>,
  taken: Arc<std::sync::atomic::AtomicBool>,
  more_open: Signal<bool>,
  more: ElementRef,
  /// On a phone, for a lightbox in a page: what a tap of the picture does (open it over the whole screen), and the
  /// lightbox over the whole screen while it is open.
  expand: Option<Action>,
  expanded: Option<Element>,
  lightbox: Lightbox,
}

impl LightboxView {
  /// The style of a part.
  pub fn part(&self, part: impl Into<Name>) -> ResolvedPart {
    self.recipe.part(part)
  }

  pub fn theme(&self) -> &Theme {
    self.recipe.theme()
  }

  /// How many pictures there are.
  pub fn count(&self) -> usize {
    self.lightbox.pictures.len()
  }

  /// Whether the picture is closer than it fits.
  pub fn zoomed(&self) -> bool {
    self.zoom > 1.0 + f32::EPSILON
  }

  fn id(&self, suffix: &str) -> Option<String> {
    self.lightbox.id.as_ref().map(|id| format!("{id}-{suffix}"))
  }

  /// What closes the lightbox and tells the app it was dismissed.
  pub fn dismisser(&self) -> impl Fn() + Send + Sync + Clone + 'static {
    let (open, told) = (self.lightbox.open.clone(), self.lightbox.on_dismiss.clone());
    move || {
      open.set(false);
      told.iter().for_each(|tell| tell());
    }
  }

  /// The picture before the one shown, and the one after, where there is one to turn to.
  fn neighbours(&self) -> (Option<usize>, Option<usize>) {
    let count = self.count();
    if count < 2 {
      return (None, None);
    }
    let wrap = self.lightbox.wrap;
    let before = match self.index {
      0 => wrap.then_some(count - 1),
      index => Some(index - 1),
    };
    let after = match self.index + 1 {
      next if next >= count => wrap.then_some(0),
      next => Some(next),
    };
    (before, after)
  }

  /// A button of the top row: its glyph and its name.
  fn control(&self, icon: &'static str, label: &Arc<str>, id: &str, press: Action) -> Element {
    let mut button = pressable(&self.part(LightboxPart::Control), false)
      .describe("a11y_role", "button")
      .describe("a11y_name", label.clone())
      .child(glyph(&self.part(LightboxPart::ControlIcon), Name::new(icon), false))
      .on_click(move |event: MouseEvent| {
        event.stop_propagation();
        press();
      });
    if let Some(id) = self.id(id) {
      button = button.id(id);
    }
    button.into()
  }

  /// What the counter says, where it shows: which picture is shown, counted from 1, of how many.
  pub fn counter(&self) -> Option<Element> {
    let lightbox = &self.lightbox;
    let count = self.count();
    if !lightbox.counter.unwrap_or(count > 1) {
      return None;
    }
    let part = self.part(LightboxPart::Counter);
    Some(
      match &lightbox.counter_text {
        Some(text) => Row::new().child(part.text(&text(self.index + 1, count)).nowrap().part(&part)),
        None => Row::new()
          .spacing(4.0)
          .child(part.text(&(self.index + 1).to_string()).nowrap().part(&part))
          .child({
            let total = self.part(LightboxPart::Total);
            total.text(&format!("/ {count}")).nowrap().part(&total)
          }),
      }
      .into(),
    )
  }

  /// The row along the top: the counter, and the buttons that bring the picture closer and further, fit it,
  /// download it and close the lightbox.
  pub fn top(&self) -> Element {
    let lightbox = &self.lightbox;
    let count = self.count();
    let mut top = Row::new()
      .part(&self.part(LightboxPart::Top))
      .width(Dimension::Pct(100.0))
      .align_items(Alignment::Center);
    // How wide the counter is, about: its letters are of one width.
    let mut said = 0.0;
    if let Some(counter) = self.counter() {
      let letters = match &lightbox.counter_text {
        Some(text) => text(self.index + 1, count).chars().count(),
        None => format!("{} / {count}", self.index + 1).chars().count(),
      };
      said = letters as f32 * COUNTER_LETTER + CONTROL_GAP;
      top = top.child(counter);
    }
    top = top.child(Row::new().flex(1.0));

    let (go, zoom) = (self.go.clone(), self.zoom);
    let closer: Action = {
      let go = go.clone();
      Arc::new(move || go(zoom * ZOOM_STEP))
    };
    let further: Action = {
      let go = go.clone();
      Arc::new(move || go(zoom / ZOOM_STEP))
    };
    let fit: Action = Arc::new(move || go(1.0));
    top = top.child(self.control(icons::ZOOM_OUT, &lightbox.words.zoom_out, "zoom-out", further));
    // In a room too narrow for the whole row the level gives way: the buttons about it bring the picture closer
    // and further still, and a double click and `0` fit it.
    let buttons =
      2 + lightbox.actions.len() + usize::from(!lightbox.on_download.is_empty()) + usize::from(lightbox.close_button);
    let needed = TOP_SIDES + said + buttons as f32 * CONTROL_ROOM + LEVEL_ROOM;
    let room = self.stage.width();
    let level = self.part(LightboxPart::Level);
    let mut fitter = pressable(&level, false)
      .describe("a11y_role", "button")
      .describe("a11y_name", lightbox.words.fit.clone())
      .child(level.text(&format!("{}%", (self.zoom * 100.0).round())).nowrap())
      .on_click(move |event: MouseEvent| {
        event.stop_propagation();
        fit();
      });
    if let Some(id) = self.id("level") {
      fitter = fitter.id(id);
    }
    if room <= 0.0 || room >= needed {
      top = top.child(fitter);
    }
    top = top
      .child(self.control(icons::ZOOM_IN, &lightbox.words.zoom_in, "zoom-in", closer))
      .with_children(lightbox.actions.iter().cloned());
    if !lightbox.on_download.is_empty() {
      let (handlers, index) = (lightbox.on_download.clone(), self.index);
      let download: Action = Arc::new(move || handlers.iter().for_each(|handler| handler(index)));
      top = top.child(self.control(icons::DOWNLOAD, &lightbox.words.download, "download", download));
    }
    if lightbox.close_button {
      let close = self.dismisser();
      top = top.child(self.control(icons::CLOSE, &lightbox.words.close, "close", Arc::new(close)));
    }
    top.into()
  }

  /// A round button over a side of the stage, which turns to the picture `to`.
  fn step(&self, icon: &'static str, label: &Arc<str>, id: &str, to: usize) -> Element {
    let turn = self.turn.clone();
    let mut button = pressable(&self.part(LightboxPart::Step), false)
      .describe("a11y_role", "button")
      .describe("a11y_name", label.clone())
      .child(glyph(&self.part(LightboxPart::StepIcon), Name::new(icon), false))
      .on_click(move |event: MouseEvent| {
        event.stop_propagation();
        turn(to);
      });
    if let Some(id) = self.id(id) {
      button = button.id(id);
    }
    button.into()
  }

  /// The picture's title and description over its lower edge, where it has either and is not closer than it
  /// fits.
  pub fn caption(&self) -> Option<Element> {
    let (title, description) = self.lightbox.pictures.get(self.index)?.caption_of();
    if self.zoomed() || (title.is_none() && description.is_none()) {
      return None;
    }
    let part = self.part(LightboxPart::Caption);
    let end = part
      .rest()
      .background
      .clone()
      .unwrap_or(crate::node::BackgroundColor::Color(Color::new(0, 0, 0, 0xB3)));
    let clear = crate::node::BackgroundColor::Color(Color::new(0, 0, 0, 0));
    let mut caption = Column::new()
      .part(&part)
      .width(Dimension::Pct(100.0))
      .align_items(Alignment::Center)
      .background_gradient(crate::node::Gradient::linear(
        180.0,
        [(clear, 0.0), (end, 1.0)].map(|(color, at)| crate::node::gradient::GradientStop::at(color, at)),
      ));
    for (text, part) in [(title, LightboxPart::Title), (description, LightboxPart::Description)] {
      if let Some(text) = text {
        let part = self.part(part);
        caption = caption.child(
          part
            .text(&text)
            .text_align(TextAlign::Center)
            .width(Dimension::Pct(100.0))
            .part(&part),
        );
      }
    }
    Some(caption.into())
  }

  /// The room the picture is shown in: the picture, its caption over its lower edge, and the round buttons
  /// over its sides. The wheel brings the picture closer about the pointer, and a drag moves it.
  pub fn stage(&mut self) -> Element {
    let full = Dimension::Pct(100.0);
    let layer = || Stack::new().size(full, full).hit_test(HitTestBehavior::ContentOnly);
    // The stage is what the keys act on, and what takes the focus as the lightbox opens: the arrows, `+`, `-`, `0`
    // and Escape work at once, and Tab goes on to the buttons. Its ring shows where the keyboard put the focus.
    let name = self
      .lightbox
      .pictures
      .get(self.index)
      .and_then(Picture::label_of)
      .unwrap_or_else(|| Arc::from(format!("{} / {}", self.index + 1, self.count())));
    let mut room = Stack::new()
      .part(&self.part(LightboxPart::Stage))
      .width(full)
      .flex(1.0)
      .clip()
      .tab_index(0)
      .describe("a11y_role", "group")
      .describe("a11y_name", name)
      .ref_element(self.stage.clone());
    if let Some(shown) = self.shown.take() {
      room = room.child(shown);
    }
    if let Some(id) = self.id("stage") {
      room = room.id(id);
    }
    if let Some(caption) = self.caption() {
      // The caption is read, not pressed: the wheel and a drag over it are the picture's under it.
      room = room.child(
        layer()
          .stack_align(StackAlignment::BottomCenter)
          .pointer_events_none()
          .child(caption),
      );
    }
    let (before, after) = self.neighbours();
    if let Some(before) = before {
      let words = self.lightbox.words.previous.clone();
      room = room.child(
        layer()
          .stack_align(StackAlignment::CenterStart)
          .part(&self.part(LightboxPart::Side))
          .child(self.step(icons::CHEVRON_LEFT, &words, "previous", before)),
      );
    }
    if let Some(after) = after {
      let words = self.lightbox.words.next.clone();
      room = room.child(
        layer()
          .stack_align(StackAlignment::CenterEnd)
          .part(&self.part(LightboxPart::Side))
          .child(self.step(icons::CHEVRON_RIGHT, &words, "next", after)),
      );
    }
    let mut room: Element = room.into();
    if !self.lightbox.inline {
      NodeUpdate::autofocus(&mut *room.node, true);
    }
    room
  }

  /// The strip of small pictures along the bottom, the one shown marked, where it shows.
  pub fn filmstrip(&self) -> Option<Element> {
    let count = self.count();
    if !self.lightbox.filmstrip.unwrap_or(count > 1) {
      return None;
    }
    let mut strip = Row::new()
      .part(&self.part(LightboxPart::Filmstrip))
      .width(Dimension::Pct(100.0))
      .align_items(Alignment::Center)
      .justify(Justify::Center);
    // The strip shows as many as it has room for, about the one shown: a strip of a hundred pictures is not
    // cut at both ends with the one shown out of sight. Until the lightbox is laid out it shows them all.
    let (first, last) = {
      let (width, _) = thumb_size(&self.part(LightboxPart::Thumb));
      let room = self.stage.width();
      let fits = match room > 0.0 {
        true => (((room - 2.0 * STRIP_INSET + STRIP_GAP) / (width + STRIP_GAP)).floor() as usize).max(1),
        false => count,
      };
      let first = self.index.saturating_sub(fits / 2).min(count.saturating_sub(fits));
      (first, (first + fits).min(count))
    };
    for (at, picture) in self.lightbox.pictures.iter().enumerate().take(last).skip(first) {
      let recipe = if at == self.index { &self.current } else { &self.recipe };
      let part = recipe.part(LightboxPart::Thumb);
      let (width, height) = thumb_size(&part);
      let turn = self.turn.clone();
      let name = picture
        .label_of()
        .unwrap_or_else(|| Arc::from(format!("{} / {count}", at + 1)));
      let mut thumb = pressable(&part, false)
        .describe("a11y_role", "button")
        .describe("a11y_name", name)
        .describe("a11y_current", if at == self.index { "true" } else { "false" })
        .clip()
        .child(picture.clone().as_thumb(width, height).key(format!("thumb-{at}")))
        .on_click(move |event: MouseEvent| {
          event.stop_propagation();
          turn(at);
        });
      if let Some(id) = self.id(&format!("thumb-{at}")) {
        thumb = thumb.id(id);
      }
      strip = strip.child(thumb);
    }
    Some(strip.into())
  }

  /// The phone's top row: Close at its start, the counter in its middle, Share and More at its end.
  pub fn phone_top(&self) -> Element {
    let lightbox = &self.lightbox;
    let full = Dimension::Pct(100.0);
    // Its two ends share what the counter leaves alike: the counter is in the middle of the row.
    let mut start = Row::new().flex(1.0).min_width(0.0).align_items(Alignment::Center);
    if lightbox.close_button {
      let close = self.dismisser();
      start = start.child(self.control(icons::CLOSE, &lightbox.words.close, "close", Arc::new(close)));
    }
    let mut end = Row::new()
      .flex(1.0)
      .min_width(0.0)
      .align_items(Alignment::Center)
      .justify(Justify::End)
      .with_children(lightbox.actions.iter().cloned());
    if !lightbox.on_share.is_empty() {
      let (handlers, index) = (lightbox.on_share.clone(), self.index);
      let share: Action = Arc::new(move || handlers.iter().for_each(|handler| handler(index)));
      end = end.child(self.control(icons::SHARE, &lightbox.words.share, "share", share));
    }
    let mut items = Vec::new();
    if !lightbox.on_download.is_empty() {
      let (handlers, index) = (lightbox.on_download.clone(), self.index);
      items.push(
        MenuItem::new(&lightbox.words.download)
          .icon(icons::DOWNLOAD)
          .on_select(move || handlers.iter().for_each(|handler| handler(index))),
      );
    }
    items.extend(lightbox.menu_items.iter().cloned());
    let mut menu = None;
    if !items.is_empty() {
      let open = self.more_open.clone();
      let press: Action = Arc::new(move || open.set(!open.get_untracked()));
      end = end.child(Row::new().ref_element(self.more.clone()).child(self.control(
        icons::MORE_HORIZONTAL,
        &lightbox.words.more,
        "more",
        press,
      )));
      menu = Some(
        Menu::new(self.more_open.clone(), self.more.clone())
          .rules(&self.recipe.lend("menu"))
          .label(&lightbox.words.more)
          .placement(Placement::BottomEnd)
          .items(items)
          .build(self.theme()),
      );
    }
    let top = Row::new()
      .part(&self.part(LightboxPart::Top))
      .width(full)
      .align_items(Alignment::Center)
      .child(start)
      .with_children(self.counter())
      .child(end);
    match menu {
      Some(menu) => Column::new().width(full).child(top).child(menu).into(),
      None => top.into(),
    }
  }

  /// The phone's stage: the pictures side by side, which a finger swipes from one to the next, the one shown
  /// in what brings it closer. A drag down carries it, and let go far enough closes the lightbox.
  pub fn phone_stage(&mut self) -> Element {
    let full = Dimension::Pct(100.0);
    let (width, height) = self.room;
    let count = self.count();
    let mut shown = self.shown.take();
    let content: Element = if width > 0.0 && height > 0.0 && count > 1 {
      // The pictures beside the one shown are there to be swiped to; the others are empty pages.
      let pages = (0..count).map(|at| {
        let page = Stack::new().size(width, height).stack_align(StackAlignment::Center);
        if at == self.index {
          page.with_children(shown.take())
        } else if at + 1 == self.index || at == self.index + 1 {
          page.child(self.lightbox.pictures[at].clone().in_viewer().key(format!("page-{at}")))
        } else {
          page
        }
      });
      let turn = self.turn.clone();
      let mut pages = Carousel::new(pages)
        .gap(0.0)
        .arrows(false)
        .dots(false)
        .index_controlled(self.index, move |to| turn(to))
        .label(&self.lightbox.words.label)
        .key("pages");
      if let Some(id) = self.id("pages") {
        pages = pages.id(id);
      }
      pages.into()
    } else {
      Stack::new().size(full, full).with_children(shown).into()
    };
    let name = self
      .lightbox
      .pictures
      .get(self.index)
      .and_then(Picture::label_of)
      .unwrap_or_else(|| Arc::from(format!("{} / {count}", self.index + 1)));
    let (dropped, close, fitted) = (self.dropped.clone(), self.dismisser(), !self.zoomed());
    // Kept by the lightbox: the drag renders it again at every step, and its end goes to the handler of the last.
    let taken = self.taken.clone();
    let mut room = Stack::new()
      .part(&self.part(LightboxPart::Stage))
      .width(full)
      .flex(1.0)
      .clip()
      .tab_index(0)
      .describe("a11y_role", "group")
      .describe("a11y_name", name)
      .ref_element(self.stage.clone())
      .on_pan(move |event: PanEvent| {
        use std::sync::atomic::Ordering;
        match event.phase {
          // A fitted picture dragged down more than across is the lightbox's to close; any other drag is
          // the slides' or the picture's.
          GesturePhase::Start => {
            let down = event.translation_y > 0.0 && event.translation_y.abs() > event.translation_x.abs();
            if fitted && down && event.fingers == 1 {
              event.prevent_default();
              taken.store(true, Ordering::Relaxed);
              dropped.set(event.translation_y);
            }
          }
          GesturePhase::Change if taken.load(Ordering::Relaxed) => dropped.set(event.translation_y.max(0.0)),
          GesturePhase::End if taken.swap(false, Ordering::Relaxed) => {
            dropped.set(0.0);
            if event.translation_y > DROP_CLOSES || event.velocity_y > THROW_CLOSES {
              close();
            }
          }
          _ => {}
        }
      })
      .child({
        let pictures = Stack::new().size(full, full).offset(0.0, self.drop).child(content);
        // A tap of the picture of a lightbox in a page opens it over the whole screen: a finger's tap, which a swipe
        // of the slides is not.
        match self.expand.clone() {
          Some(expand) => pictures.on_tap(move |event: TapEvent| {
            event.stop_propagation();
            expand()
          }),
          None => pictures,
        }
      });
    // A tap of the picture of a lightbox in a page opens it over the whole screen; a swipe is the slides'.
    // The lightbox over the whole screen is drawn over the window, wherever it is declared.
    if let Some(expanded) = self.expanded.take() {
      room = room.child(expanded);
    }
    if let Some(id) = self.id("stage") {
      room = room.id(id);
    }
    let mut room: Element = room.into();
    if !self.lightbox.inline {
      NodeUpdate::autofocus(&mut *room.node, true);
    }
    room
  }

  /// What stands under the picture on a phone: its title and description, and a dot for each picture about
  /// the one shown.
  pub fn phone_bottom(&self) -> Element {
    let full = Dimension::Pct(100.0);
    let mut bottom = Column::new()
      .part(&self.part(LightboxPart::Bottom))
      .width(full)
      .align_items(Alignment::Center);
    let (title, description) = match self.lightbox.pictures.get(self.index) {
      Some(picture) => picture.caption_of(),
      None => (None, None),
    };
    if title.is_some() || description.is_some() {
      let mut caption = Column::new().part(&self.part(LightboxPart::Caption)).width(full);
      for (part, text) in [(LightboxPart::Title, title), (LightboxPart::Description, description)] {
        if let Some(text) = text {
          let part = self.part(part);
          caption = caption.child(part.text(&text).width(full).part(&part));
        }
      }
      bottom = bottom.child(caption);
    }
    let count = self.count();
    if count > 1 {
      // As many as fit the row's purpose, about the one shown: a hundred pictures are not a hundred dots.
      let shown = count.min(PAGES_SHOWN);
      let first = self.index.saturating_sub(shown / 2).min(count - shown);
      let mut pages = Row::new()
        .part(&self.part(LightboxPart::Pages))
        .align_items(Alignment::Center);
      for at in first..first + shown {
        let recipe = if at == self.index { &self.current } else { &self.recipe };
        let mut page = Row::new().part(&recipe.part(LightboxPart::Page));
        if let Some(id) = self.id(&format!("page-{at}")) {
          page = page.id(id);
        }
        pages = pages.child(page);
      }
      bottom = bottom.child(pages);
    }
    // Under it, what the system draws over the screen's lower edge.
    Column::new()
      .width(full)
      .padding_bottom(self.safe.bottom)
      .child(bottom)
      .into()
  }

  /// The lightbox itself: its top row, its stage and its strip, with its keys.
  pub fn panel(&mut self) -> Element {
    let lightbox = &self.lightbox;
    let theme = self.theme();
    let (go, turn, shift) = (self.go.clone(), self.turn.clone(), self.shift.clone());
    let (zoom, zoomed) = (self.zoom, self.zoomed());
    let (before, after) = self.neighbours();
    let mut panel = Column::new()
      .part(&self.part(LightboxPart::Root))
      .clip()
      .describe("a11y_role", "dialog")
      .describe("a11y_name", lightbox.words.label.clone())
      // A press in the lightbox is not one on what is around it.
      .on_click(|event: MouseEvent| event.stop_propagation())
      .on_key_down(move |event: KeyboardEvent| {
        // A key is told to every element: these are the lightbox's while the focus is in it.
        if !event.focus_within || event.ctrl || event.alt || event.meta {
          return;
        }
        let handled = match event.key.as_str() {
          "+" | "=" => {
            go(zoom * ZOOM_STEP);
            true
          }
          "-" | "_" => {
            go(zoom / ZOOM_STEP);
            true
          }
          "0" => {
            go(1.0);
            true
          }
          // Closer than it fits, the arrows move the picture; fitted, they turn to another.
          "ArrowLeft" if zoomed => {
            shift(-PAN_STEP, 0.0);
            true
          }
          "ArrowRight" if zoomed => {
            shift(PAN_STEP, 0.0);
            true
          }
          "ArrowUp" if zoomed => {
            shift(0.0, -PAN_STEP);
            true
          }
          "ArrowDown" if zoomed => {
            shift(0.0, PAN_STEP);
            true
          }
          "ArrowLeft" => before.map(|to| turn(to)).is_some(),
          "ArrowRight" => after.map(|to| turn(to)).is_some(),
          _ => false,
        };
        if handled {
          event.prevent_default();
          event.stop_propagation();
        }
      });
    let full = Dimension::Pct(100.0);
    let (width, height) = match lightbox.inline {
      true => (
        lightbox.width.and_then(|width| width.resolve(theme)).unwrap_or(full),
        lightbox.height.and_then(|height| height.resolve(theme)).unwrap_or(full),
      ),
      false => (full, full),
    };
    // The width said is the most the panel takes: in a narrower room it is as wide as the room.
    panel = panel.size(width, height).max_width(full);
    if let Some(id) = &lightbox.id {
      panel = panel.id(id.clone());
    }
    if let (Some(key), true) = (&lightbox.key, lightbox.inline) {
      panel = panel.key(key.clone());
    }
    if self.phone {
      if self.drop > 0.0 {
        // The black goes as the picture is dragged down: what is under it shows through.
        let black = match self.part(LightboxPart::Root).rest().background.clone() {
          Some(crate::node::BackgroundColor::Color(color)) => color,
          _ => Color::new(0, 0, 0, 255),
        };
        let left = 1.0 - (self.drop / DROP_FADES).min(0.7);
        panel = panel.background(Color::new(
          black.r(),
          black.g(),
          black.b(),
          (black.a() as f32 * left) as u8,
        ));
      }
      let top = self.phone_top();
      let stage = self.phone_stage();
      let bottom = self.phone_bottom();
      return panel
        .padding_top(self.safe.top)
        .padding_left(self.safe.left)
        .padding_right(self.safe.right)
        .child(top)
        .child(stage)
        .child(bottom)
        .into();
    }
    let top = self.top();
    let stage = self.stage();
    panel = panel
      .padding_top(self.safe.top)
      .padding_left(self.safe.left)
      .padding_right(self.safe.right)
      .padding_bottom(self.safe.bottom)
      .child(top)
      .child(stage);
    if let Some(strip) = self.filmstrip() {
      panel = panel.child(strip);
    }
    panel.into()
  }

  /// How the default renderer builds a lightbox: its panel where it stands in a page, or over the window, on
  /// what covers it, while it is open.
  pub fn render(mut self) -> Element {
    let panel = self.panel();
    if self.lightbox.inline {
      return panel;
    }
    let mut veil = Column::new()
      .size(Dimension::Pct(100.0), Dimension::Pct(100.0))
      .part(&self.part(LightboxPart::Veil))
      .child(panel);
    if self.lightbox.dismiss_on_veil {
      let close = self.dismisser();
      veil = veil.on_click(move |_: MouseEvent| close());
    }
    if let Some(key) = &self.lightbox.key {
      veil = veil.key(key.clone());
    }
    let mut modal = Modal::new(veil)
      .open(self.lightbox.open.clone())
      .target(Root)
      .dismiss_on_escape(self.lightbox.dismiss_on_escape)
      .takes_focus(true);
    for handler in &self.lightbox.on_dismiss {
      let handler = handler.clone();
      modal = modal.on_dismiss(move || handler());
    }
    modal.into()
  }
}

/// How large a small picture of the strip is, from the style of its part.
fn thumb_size(part: &ResolvedPart) -> (f32, f32) {
  let px = |length: Option<Length>, or: f32| match length.and_then(|length| length.resolve(part.theme())) {
    Some(Dimension::Px(px)) => px,
    _ => or,
  };
  let rest = part.rest();
  (px(rest.width, 44.0), px(rest.height, 32.0))
}

impl crate::ui::Styled for Lightbox {
  type Component = Self;

  fn rules(self, rules: &crate::ui::Recipe) -> Self {
    Self::rules(self, rules)
  }

  fn state(self, state: impl Into<crate::ui::Name>, on: bool) -> Self {
    Self::state(self, state, on)
  }
}

impl Themed for Lightbox {
  const NAME: &'static str = "lightbox";
  type Renderer = LightboxRenderer;

  fn parts() -> crate::ui::Declared {
    LightboxPart::declared()
  }

  fn states() -> crate::ui::Declared {
    LightboxState::declared()
  }

  /// The design's lightbox (`pencil/lurq-design-system.pen`, Lightbox): near black at 95% in both themes, and
  /// white on it. A top row of 52, 16 before the counter and 8 around the buttons, 4 between them: the counter
  /// in mono 12, how many at 60% white; buttons of 36 with glyphs of 20, the pointer's fill on them at 12%
  /// white; the level a button of 56 by 36 with 13 medium. The stage takes the rest. Over its sides, 12 in,
  /// round buttons of 36 on 40% black with a chevron of 20. The caption lies over the picture's lower edge on
  /// a gradient to 70% black: 20 above, 16 beside and 8 under a title of 14 medium and a line of 13 at 60%
  /// white, 2 apart. The strip is 52 high, its pictures 44 by 32 with small corners, 6 apart, at 60%; the one
  /// shown at full, with a line of 2 in white inside it. In a page it has the corners of a surface.
  fn recipe() -> Recipe {
    use LightboxPart::*;
    use LightboxState::{Current, Inline};
    let white = Color::new(255, 255, 255, 255);
    let white_60 = Color::new(255, 255, 255, 0x99);
    let white_12 = Color::new(255, 255, 255, 0x1F);
    let black_40 = Color::new(0, 0, 0, 0x66);
    let black_60 = Color::new(0, 0, 0, 0x99);
    let black_70 = Color::new(0, 0, 0, 0xB3);
    Recipe::new()
      .base(Root, |s| s.background(Color::new(0x09, 0x09, 0x0B, 0xF2)))
      .state(Inline, Root, |s| s.radius(RadiusSize::Lg))
      .base(Top, |s| {
        s.height(52.0)
          .padding_top(8.0)
          .padding_bottom(8.0)
          .padding_start(16.0)
          .padding_end(8.0)
          .gap(4.0)
      })
      .base(Counter, |s| {
        s.typography(TypographyStyle::Caption)
          .font_family(FontFamily::Mono)
          .font_size(12.0)
          .foreground(white)
      })
      .base(Total, |s| {
        s.typography(TypographyStyle::Caption)
          .font_family(FontFamily::Mono)
          .font_size(12.0)
          .foreground(white_60)
      })
      .base(Control, |s| {
        fading(
          s.square(36.0)
            .radius(RadiusSize::Md)
            .foreground(white)
            .cursor(CursorIcon::Pointer),
        )
      })
      .hovered(Control, |s| s.background(white_12))
      .focus_visible(Control, |s| s.outline(Outline::new(2.0, white)))
      // Inside the stage, which reaches the panel's edges.
      .focus_visible(Stage, |s| s.outline(Outline::new(2.0, white).offset(-2.0)))
      .base(ControlIcon, |s| s.square(20.0))
      .base(Level, |s| {
        fading(
          s.width(56.0)
            .height(36.0)
            .radius(RadiusSize::Md)
            .typography(TypographyStyle::Body)
            .font_size(13.0)
            .weight(FontWeight::Medium)
            .foreground(white)
            .cursor(CursorIcon::Pointer),
        )
      })
      .hovered(Level, |s| s.background(white_12))
      .focus_visible(Level, |s| s.outline(Outline::new(2.0, white)))
      .base(Step, |s| {
        fading(
          s.square(36.0)
            .radius(RadiusSize::Full)
            .background(black_40)
            .foreground(white)
            .cursor(CursorIcon::Pointer),
        )
      })
      .hovered(Step, |s| s.background(black_60))
      .focus_visible(Step, |s| s.outline(Outline::new(2.0, white)))
      .base(StepIcon, |s| s.square(20.0))
      .base(Side, |s| s.padding_x(12.0))
      .base(Caption, |s| {
        s.background(black_70)
          .padding_top(20.0)
          .padding_bottom(8.0)
          .padding_x(16.0)
          .gap(2.0)
      })
      .base(Title, |s| {
        s.typography(TypographyStyle::Body)
          .font_size(14.0)
          .weight(FontWeight::Medium)
          .foreground(white)
      })
      .base(Description, |s| {
        s.typography(TypographyStyle::Body).font_size(13.0).foreground(white_60)
      })
      .base(Filmstrip, |s| s.height(52.0).gap(6.0))
      .base(Thumb, |s| {
        s.width(44.0)
          .height(32.0)
          .radius(RadiusSize::Sm)
          .opacity(0.6)
          .cursor(CursorIcon::Pointer)
          .transition(PartTransition::new(Transition::opacity(), MotionDuration::Fast))
      })
      .hovered(Thumb, |s| s.opacity(1.0))
      .focus_visible(Thumb, |s| s.outline(Outline::new(2.0, white)))
      .state(Current, Thumb, |s| s.opacity(1.0).border(Border::inside(2.0, white)))
      // The phone's viewer (`pencil/lurq-design-system.pen`, Mobile/Picture/Viewer): black, the whole screen. A
      // top row of 44, 4 in at its ends, of buttons of 44 with glyphs of 24, the counter in its middle. Under the
      // picture its caption, 16 in and 16 over the dots, a title of 15 medium and a line of 13 at 60% white;
      // dots of 8, 8 apart, at 35% white and the one shown white, and 8 under them.
      .variant(LightboxVariant::Phone, Root, |s| {
        s.background(Color::new(0, 0, 0, 255)).radius(0.0)
      })
      .when(
        Selector::new().variant(LightboxVariant::Phone).state(Inline),
        Root,
        |s| s.radius(0.0),
      )
      .variant(LightboxVariant::Phone, Top, |s| {
        s.height(44.0)
          .padding_top(0.0)
          .padding_bottom(0.0)
          .padding_start(4.0)
          .padding_end(4.0)
          .gap(0.0)
      })
      .variant(LightboxVariant::Phone, Control, |s| {
        s.square(44.0).radius(RadiusSize::Full)
      })
      .variant(LightboxVariant::Phone, ControlIcon, |s| s.square(24.0))
      .variant(LightboxVariant::Phone, Caption, |s| {
        s.background(Color::new(0, 0, 0, 0))
          .padding_top(0.0)
          .padding_bottom(16.0)
          .padding_x(16.0)
          .gap(2.0)
      })
      .variant(LightboxVariant::Phone, Title, |s| s.font_size(15.0))
      .base(Bottom, |s| s.padding_bottom(8.0))
      .base(Pages, |s| s.gap(8.0))
      .base(Page, |s| {
        s.square(8.0)
          .radius(RadiusSize::Full)
          .background(Color::new(255, 255, 255, 0x59))
      })
      .state(Current, Page, |s| s.background(white))
  }
}