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
//! Tabs: several places of an app side by side, each with a history of its own, one of them shown.
//!
//! [`Tabs`] is the set: the app makes it, puts a router in it for each tab, and moves between them. A tab
//! that is not shown stays as it was, with its screens, their state and their scroll: it is kept out of
//! layout, painting and input until it is shown again.
//!
//! [`TabOutlet`] shows the active tab, and with a [`TabBar`] the bar to choose one with: across the bottom, as a
//! phone's apps have it, or across the top. An app with a strip of tabs of its own draws that from the set and
//! mounts the outlet with no bar.

use std::{
  sync::{
    Arc,
    atomic::{AtomicU64, Ordering},
  },
  time::Duration,
};

use parking_lot::Mutex;

use crate::{
  animation::{Easing, Transition},
  app::{
    component::Component,
    ctx::{BottomBarInset, Ctx},
    window::SafeAreaInsets,
  },
  components::{Column, Router, Row, Stack, Text},
  core::{ElementRef, Signal},
  layout::{
    Alignment, StackAlignment,
    layout_kind::Justify,
    text_style::{FontWeight, TextStyle},
  },
  node::{Element, color::Color, dimension::Dimension, transform::Transform2D},
  router::RouterHandle,
  ui::{Recipe, Themed, engine_look::EngineLook, names},
};

const FILL: Dimension = Dimension::Pct(100.0);

/// What a tab's place in the bar shows.
#[derive(Clone, Default)]
pub struct TabItem {
  pub title: String,
  /// A picture over the title, and the one in its place while the tab is the active one.
  pub icon: Option<Element>,
  pub selected_icon: Option<Element>,
  /// The name of one of the platform's symbols, drawn in the bar's colors where the platform has them (iOS,
  /// with the `raster` feature); elsewhere nothing is drawn for it.
  pub symbol: Option<String>,
  pub selected_symbol: Option<String>,
  /// A few characters in a mark at the picture's corner: a count of what waits there. With no characters
  /// the mark is a dot.
  pub badge: Option<String>,
  /// The tab is the one to search in: a floating bar stands it apart from the others, at its end, as the
  /// platform's does.
  pub search: bool,
}

impl TabItem {
  pub fn new(title: impl Into<String>) -> Self {
    Self {
      title: title.into(),
      ..Self::default()
    }
  }

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

  pub fn selected_icon(mut self, icon: impl Into<Element>) -> Self {
    self.selected_icon = Some(icon.into());
    self
  }

  pub fn symbol(mut self, name: impl Into<String>) -> Self {
    self.symbol = Some(name.into());
    self
  }

  pub fn selected_symbol(mut self, name: impl Into<String>) -> Self {
    self.selected_symbol = Some(name.into());
    self
  }

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

  /// Marks the tab as the one to search in, with the platform's magnifying glass if it has no picture.
  pub fn search(mut self) -> Self {
    self.search = true;
    if self.symbol.is_none() && self.icon.is_none() {
      self.symbol = Some("magnifyingglass".to_owned());
      self.selected_symbol = Some("magnifyingglass".to_owned());
    }
    self
  }
}

struct Tab {
  key: String,
  item: TabItem,
  router: RouterHandle,
  /// How far the tab's own screens have the bar out of view.
  bar_move: Signal<BarMove>,
  /// The tab's list was last scrolled down.
  scrolled: Signal<bool>,
  /// The tab is the one shown: what its screens read as being in front (`Ctx::is_in_front`).
  front: Signal<bool>,
}

/// How far out of view a tab's screens have the bar, from 0 to 1, and how it gets there: a stack of screens
/// says so as one that hides the bar comes in or goes out.
#[derive(Clone, Copy, Debug, PartialEq)]
pub(crate) struct BarMove {
  pub(crate) hidden: f32,
  pub(crate) pace: Duration,
  pub(crate) curve: Easing,
}

impl BarMove {
  pub(crate) const SHOWN: Self = Self {
    hidden: 0.0,
    pace: Duration::ZERO,
    curve: Easing::Linear,
  };
}

#[cfg(feature = "devtools")]
impl crate::app::component::DevtoolsInspectable for BarMove {
  fn write_info(&self, _buffer: &mut Vec<crate::app::component::ComponentInfo>) {}
}

/// A tab's part of the context: where its screens say how far they have the bar out of view, and whether
/// their list was last scrolled down.
#[derive(Clone)]
pub(crate) struct TabBarLink(pub(crate) Signal<BarMove>, pub(crate) Signal<bool>);

struct TabsInner {
  tabs: Mutex<Vec<Tab>>,
  active: Signal<String>,
  /// Bumped when the set or an item of it changes.
  changed: Signal<u64>,
  bar_hidden: Signal<bool>,
  /// Bumped when the active tab is chosen again at its first screen: its page goes to its top.
  to_top: Signal<u64>,
}

/// A set of tabs, each a router with a history of its own, and which of them is shown. Cloning it gives
/// another handle to the same set. Inside a [`TabOutlet`] a component gets the set it is in with
/// `ctx.use_context::<Tabs>()`.
///
/// It is the engine's navigation between places of an app, with no look of its own. A strip of tabs that
/// switches between panels of one page is [`ui::Tabs`](crate::ui::Tabs).
#[derive(Clone)]
pub struct Tabs {
  inner: Arc<TabsInner>,
}

impl Default for Tabs {
  fn default() -> Self {
    Self::new()
  }
}

impl PartialEq for Tabs {
  fn eq(&self, other: &Self) -> bool {
    Arc::ptr_eq(&self.inner, &other.inner)
  }
}

#[cfg(feature = "devtools")]
impl crate::app::component::DevtoolsInspectable for Tabs {
  fn write_info(&self, _buffer: &mut Vec<crate::app::component::ComponentInfo>) {}
}

/// A tab as [`Tabs::list`] tells it.
#[derive(Clone)]
pub struct TabEntry {
  pub key: String,
  pub item: TabItem,
  pub router: RouterHandle,
  pub active: bool,
  bar_move: Signal<BarMove>,
  scrolled: Signal<bool>,
  front: Signal<bool>,
}

impl Tabs {
  pub fn new() -> Self {
    Self {
      inner: Arc::new(TabsInner {
        tabs: Mutex::new(Vec::new()),
        active: Signal::new(String::new()),
        changed: Signal::new(0),
        bar_hidden: Signal::new(false),
        to_top: Signal::new(0),
      }),
    }
  }

  fn bump(&self) {
    self.inner.changed.update(|version| *version += 1);
  }

  /// Adds a tab after the others. `key` tells it from the others; a tab with that key is replaced where it
  /// is. The first tab added is the active one.
  pub fn add(&self, key: impl Into<String>, item: TabItem, router: RouterHandle) -> &Self {
    let at = self.inner.tabs.lock().len();
    self.insert(at, key, item, router)
  }

  /// Adds a tab before the one at `index`.
  pub fn insert(&self, index: usize, key: impl Into<String>, item: TabItem, router: RouterHandle) -> &Self {
    let key = key.into();
    let first = {
      let mut tabs = self.inner.tabs.lock();
      let mut tab = Tab {
        key: key.clone(),
        item,
        router,
        bar_move: Signal::new(BarMove::SHOWN),
        scrolled: Signal::new(false),
        front: Signal::new(false),
      };
      match tabs.iter().position(|tab| tab.key == key) {
        Some(at) => {
          tab.bar_move = tabs[at].bar_move.clone();
          tab.scrolled = tabs[at].scrolled.clone();
          tab.front = tabs[at].front.clone();
          tabs[at] = tab;
        }
        None => {
          let index = index.min(tabs.len());
          tabs.insert(index, tab);
        }
      }
      tabs.len() == 1
    };
    if first {
      self.inner.active.set(key);
    }
    self.bump();
    self
  }

  /// Takes a tab out, with its history and its screens. If it was the active one the tab after it is, or the
  /// one before when it was the last.
  pub fn remove(&self, key: &str) {
    let next = {
      let mut tabs = self.inner.tabs.lock();
      let Some(at) = tabs.iter().position(|tab| tab.key == key) else {
        return;
      };
      tabs.remove(at);
      (self.inner.active.get_untracked() == key).then(|| {
        tabs
          .get(at)
          .or(tabs.last())
          .map(|tab| tab.key.clone())
          .unwrap_or_default()
      })
    };
    if let Some(next) = next {
      self.inner.active.set(next);
    }
    self.bump();
  }

  /// Moves a tab to the place `index` among the others, as taking it out of the list and putting it back there
  /// does: what a strip of tabs a person drags along asks for. The tab keeps its history, its screens and whether
  /// it is the one shown. Does nothing when there is no tab with the key.
  pub fn move_to(&self, key: &str, index: usize) {
    {
      let mut tabs = self.inner.tabs.lock();
      let Some(from) = tabs.iter().position(|tab| tab.key == key) else {
        return;
      };
      let to = index.min(tabs.len() - 1);
      if from == to {
        return;
      }
      let tab = tabs.remove(from);
      tabs.insert(to, tab);
    }
    self.bump();
  }

  /// Shows the tab with the key. Does nothing when there is none.
  pub fn select(&self, key: &str) {
    let known = self.inner.tabs.lock().iter().any(|tab| tab.key == key);
    if known && self.inner.active.get_untracked() != key {
      self.inner.active.set(key.to_owned());
    }
  }

  /// What a press on a tab's place in a bar does. Another tab than the active one is shown. The active one
  /// goes back to its first screen, and once there its page scrolls to its top.
  pub fn press(&self, key: &str) {
    if self.inner.active.get_untracked() != key {
      self.select(key);
      return;
    }
    let Some(router) = self.router(key) else {
      return;
    };
    let above = router.stack().len().saturating_sub(1);
    if above > 0 {
      router.back_by(above);
    } else {
      self.inner.to_top.update(|version| *version += 1);
    }
  }

  /// The key of the tab that is shown; a render that reads it is run again when another is.
  pub fn active(&self) -> String {
    self.inner.active.get()
  }

  pub fn active_signal(&self) -> Signal<String> {
    self.inner.active.clone()
  }

  pub fn router(&self, key: &str) -> Option<RouterHandle> {
    self
      .inner
      .tabs
      .lock()
      .iter()
      .find(|tab| tab.key == key)
      .map(|tab| tab.router.clone())
  }

  /// The router of the tab that is shown: where "back" and a link opened from outside the tabs go.
  pub fn active_router(&self) -> Option<RouterHandle> {
    self.router(&self.inner.active.get_untracked())
  }

  /// The tabs in their order; a render that reads them is run again when the set, an item or the active tab
  /// changes.
  pub fn list(&self) -> Vec<TabEntry> {
    let _ = self.inner.changed.get();
    let active = self.inner.active.get();
    self
      .inner
      .tabs
      .lock()
      .iter()
      .map(|tab| TabEntry {
        key: tab.key.clone(),
        item: tab.item.clone(),
        router: tab.router.clone(),
        active: tab.key == active,
        bar_move: tab.bar_move.clone(),
        scrolled: tab.scrolled.clone(),
        front: tab.front.clone(),
      })
      .collect()
  }

  pub fn len(&self) -> usize {
    self.inner.tabs.lock().len()
  }

  pub fn is_empty(&self) -> bool {
    self.len() == 0
  }

  /// Changes what a tab's place in the bar shows.
  pub fn set_item(&self, key: &str, item: TabItem) {
    if let Some(tab) = self.inner.tabs.lock().iter_mut().find(|tab| tab.key == key) {
      tab.item = item;
    }
    self.bump();
  }

  /// Changes a tab's badge alone; `None` takes it away.
  pub fn set_badge(&self, key: &str, badge: Option<String>) {
    if let Some(tab) = self.inner.tabs.lock().iter_mut().find(|tab| tab.key == key) {
      tab.item.badge = badge;
    }
    self.bump();
  }

  /// Takes the outlet's bar out of view, or brings it back: for a screen that has the whole window.
  pub fn set_bar_hidden(&self, hidden: bool) {
    if self.inner.bar_hidden.get_untracked() != hidden {
      self.inner.bar_hidden.set(hidden);
    }
  }
}

/// Where a [`TabBar`] is.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum TabBarPlace {
  /// Across the bottom, over the home indicator's room.
  #[default]
  Bottom,
  /// Across the top, under the status bar's room.
  Top,
}

/// How a [`TabOutlet`]'s bar looks: the phone's tab bar. The sizes it starts with are the platform's for a phone.
/// Its colors come from the theme, through the recipe it keeps under the name `phone_tab_bar` ([`TabBarPart`]):
/// the design's roles, light or dark as the theme is, and the colors of 0.62 in
/// [`ThemeDefinition::legacy`](crate::app::theme::ThemeDefinition::legacy). They are read where the bar is made,
/// in the theme of what is being built.
///
/// The board draws a design system's tab bar (Mobile/Tab Bar) that `lurq::ui` does not have yet; a strip of tabs
/// on a desktop is [`ui::Tabs`](crate::ui::Tabs).
#[derive(Clone, Debug, PartialEq)]
pub struct TabBar {
  pub place: TabBarPlace,
  pub background: Color,
  /// The line between the bar and the tab.
  pub border: Color,
  /// The active tab's picture and title, and the others'.
  pub tint: Color,
  pub color: Color,
  /// The others' when the person asked for more contrast.
  pub contrast_color: Color,
  /// How much what is behind the bar is blurred where the bar's color lets it show: the content of a tab
  /// that scrolls under a bar across the bottom. 0 is no blur.
  pub blur: f32,
  /// How high the bar is, without the room of the home indicator or the status bar it also covers; and in a
  /// window lower than `low_window`, a phone on its side, where a picture and its title stand side by side.
  pub height: f32,
  pub low_height: f32,
  pub low_window: f32,
  pub low_title_size: f32,
  pub low_symbol_size: f32,
  /// How long the bar takes to go out of view and to come back, for the keyboard or when it is told to.
  pub hide_duration: Duration,
  pub title_size: f32,
  pub title_weight: FontWeight,
  /// The point size a tab's symbol is drawn at.
  pub symbol_size: f32,
  /// The room between a picture and the title under it.
  pub spacing: f32,
  pub badge_background: Color,
  pub badge_color: Color,
  pub badge_size: f32,
  /// The widest a tab's place is; in a wider bar the places stand together in the middle.
  pub item_max_width: f32,
  /// The bar goes out of view while the on-screen keyboard is up.
  pub hides_with_keyboard: bool,
  /// The most places the bar has. With more tabs than that, the last place is one that lists the rest.
  pub max_items: usize,
  /// What that place says, and the platform's symbol for it. An empty title is the app's locale's word
  /// ([`Locale::common`](crate::core::Locale::common)'s `more`), read where the bar is drawn.
  pub more_title: String,
  pub more_symbol: String,
  /// The bar goes out of view as a list of its tab is scrolled down, and comes back as it is scrolled up:
  /// the list of a stack's screen ([`StackOutlet::large_title_scroll`](super::StackOutlet)).
  pub minimizes_on_scroll: bool,
  /// The bar is a rounded bar that stands clear of the window's edges, over the content, as the newest
  /// system's does; see [`TabBar::floating`]. Only across the bottom.
  pub floating: bool,
  /// A floating bar's room at each side and under it, its height, and what is drawn behind the place of the
  /// tab that is chosen.
  pub floating_margin: f32,
  pub floating_bottom: f32,
  pub floating_height: f32,
  pub floating_selection: Color,
}

impl TabBar {
  /// What the place of the tabs that have none says: its title, or the app's locale's word.
  fn more_title(&self) -> String {
    if self.more_title.is_empty() {
      crate::ui::current_locale().common.more.to_string()
    } else {
      self.more_title.clone()
    }
  }
}

/// The parts of the recipe of a [`TabBar`]'s colors.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum TabBarPart {
  /// The bar: its fill is the bar's `background`.
  Root,
  /// The line between the bar and the tab: its fill.
  Separator,
  /// A tab's picture and title: its foreground, and its `contrast_color` where the person asked for more
  /// contrast ([`TabBarPart::ContrastItem`]).
  Item,
  ContrastItem,
  /// The active tab's picture and title: its foreground, the bar's `tint`.
  SelectedItem,
  /// The mark of a count at a picture's corner: its fill and its foreground.
  Badge,
  /// What a floating bar draws behind the place of the active tab: its fill.
  Selection,
}

names!(TabBarPart {
  Root => "root",
  Separator => "separator",
  Item => "item",
  ContrastItem => "contrast_item",
  SelectedItem => "selected_item",
  Badge => "badge",
  Selection => "selection",
});

/// The colors of 0.62's light bar: what the legacy theme gives, and what a theme with no recipe for the bar keeps.
mod legacy {
  use crate::node::color::Color;

  pub(super) const BACKGROUND: Color = Color::new(249, 249, 249, 224);
  pub(super) const BORDER: Color = Color::new(60, 60, 67, 74);
  pub(super) const TINT: Color = Color::new(0x00, 0x7A, 0xFF, 255);
  pub(super) const COLOR: Color = Color::new(0x99, 0x99, 0x99, 255);
  pub(super) const CONTRAST: Color = Color::new(0x51, 0x51, 0x54, 255);
  pub(super) const BADGE: Color = Color::new(0xFF, 0x3B, 0x30, 255);
  pub(super) const BADGE_TEXT: Color = Color::new(255, 255, 255, 255);
  pub(super) const SELECTION: Color = Color::new(120, 120, 128, 41);
}

impl Themed for TabBar {
  const NAME: &'static str = "phone_tab_bar";
  type Renderer = ();

  /// The design's (`pencil/lurq-design-system.pen`, Mobile/Tab Bar): the bar on the background over a line of
  /// the border, the active tab in the foreground and the others in the muted foreground (and in the foreground
  /// where more contrast is asked for), a count's mark in the destructive colors. A floating bar marks the active
  /// tab's place on the muted fill.
  fn recipe() -> Recipe {
    use crate::app::theme::PaletteColor::{
      Background, Border, Destructive, DestructiveForeground, Foreground, Muted, MutedForeground,
    };
    Recipe::new()
      .base(TabBarPart::Root, |s| s.background(Background))
      .base(TabBarPart::Separator, |s| s.background(Border))
      .base(TabBarPart::Item, |s| s.foreground(MutedForeground))
      .base(TabBarPart::ContrastItem, |s| s.foreground(Foreground))
      .base(TabBarPart::SelectedItem, |s| s.foreground(Foreground))
      .base(TabBarPart::Badge, |s| {
        s.background(Destructive).foreground(DestructiveForeground)
      })
      .base(TabBarPart::Selection, |s| s.background(Muted))
  }
}

impl Default for TabBar {
  fn default() -> Self {
    let look = EngineLook::of::<Self>(&[]);
    Self {
      place: TabBarPlace::Bottom,
      background: look.background(TabBarPart::Root, legacy::BACKGROUND),
      border: look.background(TabBarPart::Separator, legacy::BORDER),
      tint: look.foreground(TabBarPart::SelectedItem, legacy::TINT),
      color: look.foreground(TabBarPart::Item, legacy::COLOR),
      contrast_color: look.foreground(TabBarPart::ContrastItem, legacy::CONTRAST),
      blur: 40.0,
      height: 49.0,
      low_height: 32.0,
      low_window: 480.0,
      low_title_size: 12.0,
      low_symbol_size: 13.0,
      hide_duration: Duration::from_millis(250),
      title_size: 10.0,
      title_weight: FontWeight::Medium,
      symbol_size: 18.0,
      spacing: 2.0,
      badge_background: look.background(TabBarPart::Badge, legacy::BADGE),
      badge_color: look.foreground(TabBarPart::Badge, legacy::BADGE_TEXT),
      badge_size: 13.0,
      item_max_width: f32::INFINITY,
      hides_with_keyboard: true,
      max_items: 5,
      more_title: String::new(),
      more_symbol: "ellipsis".to_owned(),
      minimizes_on_scroll: false,
      floating: false,
      floating_margin: 21.0,
      floating_bottom: 21.0,
      floating_height: 62.0,
      floating_selection: look.background(TabBarPart::Selection, legacy::SELECTION),
    }
  }
}

impl TabBar {
  /// The bar in the colors of the theme of what is being built.
  pub fn new() -> Self {
    Self::default()
  }

  /// 0.62's colors: the recipe [`UiDefinition::legacy`](crate::ui::UiDefinition::legacy) gives the bar.
  pub(crate) fn legacy_recipe() -> Recipe {
    Recipe::new()
      .base(TabBarPart::Root, |s| s.background(legacy::BACKGROUND))
      .base(TabBarPart::Separator, |s| s.background(legacy::BORDER))
      .base(TabBarPart::Item, |s| s.foreground(legacy::COLOR))
      .base(TabBarPart::ContrastItem, |s| s.foreground(legacy::CONTRAST))
      .base(TabBarPart::SelectedItem, |s| s.foreground(legacy::TINT))
      .base(TabBarPart::Badge, |s| {
        s.background(legacy::BADGE).foreground(legacy::BADGE_TEXT)
      })
      .base(TabBarPart::Selection, |s| s.background(legacy::SELECTION))
  }

  /// The bar of 0.62 in its light colors, whatever the theme.
  fn legacy_light() -> Self {
    Self {
      background: legacy::BACKGROUND,
      border: legacy::BORDER,
      tint: legacy::TINT,
      color: legacy::COLOR,
      contrast_color: legacy::CONTRAST,
      badge_background: legacy::BADGE,
      badge_color: legacy::BADGE_TEXT,
      floating_selection: legacy::SELECTION,
      ..Self::default()
    }
  }

  /// The platform's dark colors of 0.62.
  #[deprecated(
    since = "0.63.0",
    note = "the theme's appearance gives the dark colors: `TabBar::new()` built in a dark theme is dark"
  )]
  pub fn dark() -> Self {
    Self {
      background: Color::new(22, 22, 22, 204),
      border: Color::new(84, 84, 88, 153),
      tint: Color::from_hex("#0A84FF"),
      color: Color::from_hex("#8E8E93"),
      contrast_color: Color::from_hex("#C7C7CC"),
      ..Self::legacy_light()
    }
  }

  /// The platform's bar of 0.62 for an appearance.
  #[deprecated(
    since = "0.63.0",
    note = "the theme's appearance gives the colors: `TabBar::new()` is light or dark as the theme is"
  )]
  #[allow(deprecated)]
  pub fn for_appearance(appearance: crate::app::window::Appearance) -> Self {
    match appearance {
      crate::app::window::Appearance::Light => Self::legacy_light(),
      crate::app::window::Appearance::Dark => Self::dark(),
    }
  }

  /// A bar that floats over the content, clear of the window's edges, with the place of the chosen tab
  /// marked: the look of the newest system's, without its glass.
  pub fn floating(mut self) -> Self {
    self.floating = true;
    self
  }

  pub fn minimizes_on_scroll(mut self, minimizes: bool) -> Self {
    self.minimizes_on_scroll = minimizes;
    self
  }

  pub fn place(mut self, place: TabBarPlace) -> Self {
    self.place = place;
    self
  }

  pub fn background(mut self, color: Color) -> Self {
    self.background = color;
    self
  }

  pub fn border(mut self, color: Color) -> Self {
    self.border = color;
    self
  }

  pub fn blur(mut self, radius: f32) -> Self {
    self.blur = radius;
    self
  }

  pub fn tint(mut self, color: Color) -> Self {
    self.tint = color;
    self
  }

  pub fn color(mut self, color: Color) -> Self {
    self.color = color;
    self
  }
}

/// What a bar of the app's own is told ([`TabOutletProps::bar_with`]).
pub struct TabBarState {
  pub tabs: Tabs,
  /// The tabs in their order, the active one marked.
  pub entries: Vec<TabEntry>,
  /// The window's, for the bar to keep its content clear of the home indicator.
  pub safe_area: SafeAreaInsets,
  /// The window is too low for a bar of full height: a phone on its side.
  pub low: bool,
}

/// Makes a bar of the app's own from the state of the tabs.
pub type TabBarBuilder = Arc<dyn Fn(&TabBarState) -> Element + Send + Sync>;

#[derive(Clone)]
enum Bar {
  Standard(TabBar),
  Custom(TabBarBuilder, TabBarPlace),
}

#[derive(Clone)]
pub struct TabOutletProps {
  tabs: Tabs,
  bar: Option<Bar>,
}

impl PartialEq for TabOutletProps {
  fn eq(&self, other: &Self) -> bool {
    let same_bar = match (&self.bar, &other.bar) {
      (None, None) => true,
      (Some(Bar::Standard(a)), Some(Bar::Standard(b))) => a == b,
      (Some(Bar::Custom(a, at)), Some(Bar::Custom(b, bt))) => Arc::ptr_eq(a, b) && at == bt,
      _ => false,
    };
    self.tabs == other.tabs && same_bar
  }
}

#[cfg(feature = "devtools")]
impl crate::app::component::DevtoolsInspectable for TabOutletProps {
  fn write_info(&self, _buffer: &mut Vec<crate::app::component::ComponentInfo>) {}
}

impl TabOutletProps {
  /// The active tab of `tabs`, with no bar.
  pub fn new(tabs: Tabs) -> Self {
    Self { tabs, bar: None }
  }

  /// Draws a bar to choose a tab with.
  pub fn bar(mut self, bar: TabBar) -> Self {
    self.bar = Some(Bar::Standard(bar));
    self
  }

  /// Draws a bar of the app's own: what `builder` returns for the state of the tabs, across the outlet at
  /// `place`, at the height it takes. A press on a tab's place calls [`Tabs::press`].
  pub fn bar_with(
    mut self,
    place: TabBarPlace,
    builder: impl Fn(&TabBarState) -> Element + Send + Sync + 'static,
  ) -> Self {
    self.bar = Some(Bar::Custom(Arc::new(builder), place));
    self
  }
}

/// Shows the active tab of a [`Tabs`], and keeps the others as they were.
pub struct TabOutlet {
  /// The last request to scroll to the top that was passed on.
  to_top: AtomicU64,
  /// The bar as it is laid out, and how high that was: the tabs' content keeps clear of as much.
  bar: ElementRef,
  bar_height: Signal<f32>,
  /// The list of the tabs that have no place in the bar is shown.
  more_open: Signal<bool>,
}

impl TabOutlet {
  pub fn mount(ctx: &mut Ctx, props: TabOutletProps) -> Element {
    ctx.mount::<Self>(props)
  }
}

impl Component for TabOutlet {
  type Props = TabOutletProps;

  fn create(ctx: &mut Ctx) -> Self {
    let tabs = ctx.props::<TabOutletProps>().tabs.clone();
    let to_top = AtomicU64::new(tabs.inner.to_top.get_untracked());
    ctx.provide(tabs);
    Self {
      to_top,
      bar: ElementRef::default(),
      bar_height: Signal::new(0.0),
      more_open: Signal::new(false),
    }
  }

  fn render(&self, ctx: &mut Ctx) -> impl Into<Element> {
    let props = ctx.props::<TabOutletProps>().clone();
    let tabs = props.tabs.clone();
    let entries = tabs.list();
    let hidden = tabs.inner.bar_hidden.get();
    // The active tab chosen again at its first screen: the page goes to its top.
    let to_top = tabs.inner.to_top.get();
    if self.to_top.swap(to_top, Ordering::AcqRel) != to_top {
      ctx.scroll_to_top();
    }
    let window = ctx.window();
    let safe_area = window.safe_area;
    let keyboard_up = safe_area.keyboard > 0.0;
    let low = match &props.bar {
      Some(Bar::Standard(bar)) => window.logical_height() < bar.low_window,
      _ => false,
    };

    let (place, away, hide_duration) = match &props.bar {
      None => (TabBarPlace::Bottom, true, Duration::ZERO),
      Some(Bar::Standard(bar)) => (
        bar.place,
        hidden || (bar.hides_with_keyboard && keyboard_up),
        bar.hide_duration,
      ),
      Some(Bar::Custom(_, place)) => (*place, hidden || keyboard_up, TabBar::default().hide_duration),
    };
    let over = props.bar.is_some() && place == TabBarPlace::Bottom;
    // A bar across the bottom is over the tabs' content, which shows through it: the content keeps clear of
    // the bar's height more than of the window's bottom, while the bar is there.
    let bar_height = self.bar_height.get();
    ctx.provide_if_changed(BottomBarInset::Over(if over && !away {
      (bar_height - safe_area.bottom).max(0.0)
    } else {
      0.0
    }));

    let mut screens = Stack::new().size(FILL, FILL);
    let mut moved = BarMove::SHOWN;
    let mut scrolled = false;
    // What the set of tabs is in, where that is a screen that is in front or not.
    let around = ctx.use_context::<crate::app::ctx::InFront>();
    for entry in &entries {
      // The tab's screens are told before the tab is mounted: one that is no longer shown is rendered once
      // more as it leaves, and hears it.
      if entry.front.get_untracked() != entry.active {
        entry.front.set(entry.active);
      }
      let host = ctx.mount_keyed_offstage::<TabHost>(
        &entry.key,
        TabHostProps {
          router: entry.router.clone(),
          bar_move: entry.bar_move.clone(),
          scrolled: entry.scrolled.clone(),
          front: crate::app::ctx::InFront::new(entry.front.clone(), around.clone()),
        },
        entry.active,
      );
      if entry.active {
        moved = entry.bar_move.get();
        scrolled = entry.scrolled.get();
      }
      // A tab that is not shown has nothing to touch, and its holder, over the shown one's, takes no touch
      // from it.
      let holder = Stack::new()
        .key(format!("tab-{}", entry.key))
        .size(FILL, FILL)
        .child(host);
      screens = screens.child(if entry.active {
        holder
      } else {
        holder.pointer_events_none()
      });
    }

    // A bar that gets out of a list's way: a floating one draws in to the tab that is shown, and any other
    // goes out of view.
    let minimized =
      matches!(&props.bar, Some(Bar::Standard(bar)) if bar.minimizes_on_scroll) && scrolled && !self.more_open.get();
    let drawn_in = minimized && matches!(&props.bar, Some(Bar::Standard(bar)) if bar.floating);
    let minimized = minimized && !drawn_in;
    let bar: Option<Element> = match &props.bar {
      None => None,
      _ if away && !over => None,
      Some(Bar::Custom(builder, _)) => Some(builder(&TabBarState {
        tabs: tabs.clone(),
        entries: entries.clone(),
        safe_area,
        low,
      })),
      Some(Bar::Standard(bar)) => {
        // With transparency reduced or contrast increased the bar is all there, and nothing is blurred
        // behind it; with contrast increased the line over it and the tabs that are not chosen stand out.
        let mut bar = bar.clone();
        if window.system.reduce_transparency || window.system.increase_contrast {
          let solid = |color: Color| Color::new(color.r(), color.g(), color.b(), 255);
          bar.background = solid(bar.background);
          bar.blur = 0.0;
          if window.system.increase_contrast {
            bar.border = solid(bar.border);
            bar.color = bar.contrast_color;
          }
        }
        Some(standard_bar(
          &bar,
          &tabs,
          &entries,
          safe_area,
          low,
          &self.more_open,
          drawn_in,
          window.logical_width(),
        ))
      }
    };
    // The tabs with no place in the bar, listed over the tab that is shown while the bar's last place is
    // chosen.
    let more_open = self.more_open.get();
    let more: Option<Element> = match &props.bar {
      Some(Bar::Standard(bar)) if more_open && entries.len() > bar.max_items.max(2) => {
        Some(more_list(bar, &tabs, &entries, safe_area, bar_height, &self.more_open))
      }
      _ => None,
    };
    let whole = Stack::new().size(FILL, FILL);
    match (bar, place) {
      (None, _) => whole.child(screens),
      (Some(bar), TabBarPlace::Top) => whole.child(
        Column::new()
          .size(FILL, FILL)
          .child(bar)
          .child(Column::new().width(FILL).flex(1.0).child(screens)),
      ),
      (Some(bar), TabBarPlace::Bottom) => {
        // Out of view the bar is under the window's bottom edge: all the way there for the keyboard or when
        // told to, with a move of its own, and as far as a screen that hides it has come in, with that
        // screen's move.
        let (share, pace, curve) = if away || minimized {
          (1.0, hide_duration, Easing::EASE)
        } else if moved.pace.is_zero() && moved.hidden == 0.0 {
          (0.0, hide_duration, Easing::EASE)
        } else {
          (moved.hidden, moved.pace, moved.curve)
        };
        // With motion reduced the bar is there or it is not.
        let pace = if window.system.reduce_motion {
          Duration::ZERO
        } else {
          pace
        };
        let bar = Row::new()
          .ref_element(self.bar.clone())
          .width(FILL)
          .hit_test(crate::node::HitTestBehavior::ContentOnly)
          .child(bar)
          .transform(Transform2D::translate(0.0, share * bar_height))
          .transition(Transition::transform().duration(pace).easing(curve));
        let mut whole = whole.stack_align(StackAlignment::BottomStart).child(screens);
        if let Some(more) = more {
          whole = whole.child(more);
        }
        whole.child(if share >= 1.0 { bar.pointer_events_none() } else { bar })
      }
    }
  }

  fn after_layout(&self) {
    if self.bar.is_attached() {
      let height = self.bar.rect().3;
      if (self.bar_height.get_untracked() - height).abs() > 0.25 {
        self.bar_height.set(height);
      }
    }
  }
}

/// A tab's symbol in a color, where the platform draws symbols.
#[allow(unused_variables)]
#[allow(deprecated)]
fn symbol(name: &str, size: f32, color: Color) -> Option<Element> {
  #[cfg(all(target_os = "ios", feature = "raster"))]
  if let Some(symbol) = crate::app::ios_symbol::symbol(name, size, color) {
    return Some(
      crate::components::Image::new(symbol.image)
        .width(symbol.width)
        .height(symbol.height)
        .into(),
    );
  }
  None
}

/// What a tab's place in a bar shows: its picture with its badge, and its title under or beside it.
fn place_content(bar: &TabBar, item: &TabItem, active: bool, low: bool) -> Column {
  let color = if active { bar.tint } else { bar.color };
  let symbol_size = if low { bar.low_symbol_size } else { bar.symbol_size };
  let picture = match (active, &item.selected_icon, &item.selected_symbol) {
    (true, Some(icon), _) => Some(icon.clone()),
    (true, None, Some(name)) => symbol(name, symbol_size, color),
    // The filled one of the tab's symbol, where the platform has it, as its own bars take.
    (true, None, None) => item
      .symbol
      .as_ref()
      .and_then(|name| symbol(&format!("{name}.fill"), symbol_size, color)),
    _ => None,
  }
  .or_else(|| item.icon.clone())
  .or_else(|| item.symbol.as_ref().and_then(|name| symbol(name, symbol_size, color)));

  let mut content = Column::new()
    .align_items(Alignment::Center)
    .spacing(bar.spacing)
    .overflow_visible();
  let badge = item.badge.as_ref().map(|badge| {
    // With nothing to say the badge is a dot.
    let side = if badge.is_empty() {
      bar.badge_size * 0.7
    } else {
      bar.badge_size + 5.0
    };
    let mark = Row::new()
      .min_width(side)
      .height(side)
      .align_items(Alignment::Center)
      .justify(Justify::Center)
      .rounded(side / 2.0)
      .background(bar.badge_background);
    if badge.is_empty() {
      mark
    } else {
      mark.padding_horizontal(5.0).child(
        Text::styled(
          badge,
          TextStyle {
            font_size: bar.badge_size,
            color: bar.badge_color,
            ..TextStyle::default()
          },
        )
        .nowrap(),
      )
    }
  });
  let title = Text::styled(
    &item.title,
    TextStyle {
      font_size: if low { bar.low_title_size } else { bar.title_size },
      weight: bar.title_weight,
      color,
      ..TextStyle::default()
    },
  )
  .nowrap();
  match (picture, badge) {
    (Some(picture), badge) => {
      // The badge at the picture's upper corner, half over it: it reaches past the picture's box, and past
      // the place's own in a low bar.
      let mut over = Stack::new()
        .stack_align(StackAlignment::TopEnd)
        .overflow_visible()
        .child(picture);
      if let Some(badge) = badge {
        over = over.child(badge.transform(Transform2D::translate(bar.badge_size * 0.7, -bar.badge_size * 0.3)));
      }
      if low {
        // In a low bar the title stands beside the picture.
        let mut row = Row::new()
          .align_items(Alignment::Center)
          .spacing(6.0)
          .overflow_visible()
          .child(over);
        if !item.title.is_empty() {
          row = row.child(title);
        }
        content.child(row)
      } else {
        content = content.child(over);
        if item.title.is_empty() {
          content
        } else {
          content.child(title)
        }
      }
    }
    (None, badge) => {
      let mut row = Row::new().align_items(Alignment::Center).spacing(4.0).child(title);
      if let Some(badge) = badge {
        row = row.child(badge);
      }
      content.child(row)
    }
  }
}

/// The tabs that have a place in the bar and those that have none: with more tabs than the bar has places,
/// the last place is for the rest.
fn placed<'a>(bar: &TabBar, entries: &'a [TabEntry]) -> (&'a [TabEntry], &'a [TabEntry]) {
  let places = bar.max_items.max(2);
  if entries.len() > places {
    entries.split_at(places - 1)
  } else {
    (entries, &[])
  }
}

fn standard_bar(
  bar: &TabBar,
  tabs: &Tabs,
  entries: &[TabEntry],
  safe_area: SafeAreaInsets,
  low: bool,
  more_open: &Signal<bool>,
  drawn_in: bool,
  window_width: f32,
) -> Element {
  let floating = bar.floating && bar.place == TabBarPlace::Bottom;
  let (shown, rest) = placed(bar, entries);
  let height = if floating {
    bar.floating_height
  } else if low {
    bar.low_height
  } else {
    bar.height
  };
  let opened = more_open.get_untracked();
  // A floating bar's places have widths of their own, which change with a move: drawn in, as a list is
  // scrolled, the place of the tab that is shown is all the bar has, and the others have no width.
  let apart_there = floating && shown.iter().any(|entry| entry.item.search);
  let count = shown.iter().filter(|entry| !(floating && entry.item.search)).count() + usize::from(!rest.is_empty());
  let full = (window_width
    - safe_area.left
    - safe_area.right
    - 2.0 * bar.floating_margin
    - if apart_there { height + 10.0 } else { 0.0 })
  .max(0.0);
  let each = ((full - 8.0) / count.max(1) as f32).max(0.0);
  let alone = (height + 12.0).min(each.max(height));
  let resize = Transition::width().duration(bar.hide_duration).easing(Easing::EASE);
  let fade = Transition::opacity().duration(bar.hide_duration).easing(Easing::EASE);
  // A place: what it shows, whether it is the chosen one, whether it is in the bar's row, and what a press on
  // it does.
  let place = |id: String, content: Column, chosen: bool, in_row: bool, press: Box<dyn Fn() + Send + Sync>| {
    let mut place = Row::new().id(id);
    place = if floating && in_row {
      let (width, seen) = match (drawn_in, chosen) {
        (false, _) => (each, 1.0),
        (true, true) => (alone, 1.0),
        (true, false) => (0.0, 0.0),
      };
      place
        .width(width)
        .opacity(seen)
        .transition(resize.clone())
        .transition(fade.clone())
    } else {
      place.flex(1.0).max_width(bar.item_max_width)
    };
    let mut place = place
      .height(FILL)
      .align_items(Alignment::Center)
      .justify(Justify::Center)
      .overflow_visible()
      .child(content)
      .on_click(move |_| press());
    if floating {
      // The chosen tab's place is marked, as far as the bar's own round ends.
      place = place.rounded((height - 8.0) / 2.0).background(if chosen {
        bar.floating_selection
      } else {
        Color::new(0, 0, 0, 0)
      });
    }
    place
  };
  let mut places = Row::new()
    .height(if floating { height - 8.0 } else { height })
    .justify(Justify::Center);
  let mut apart: Option<Element> = None;
  for entry in shown {
    let chosen = entry.active && !opened;
    let (tabs, key, open) = (tabs.clone(), entry.key.clone(), more_open.clone());
    let (scrolled, opens) = (entry.scrolled.clone(), drawn_in && entry.active && !entry.item.search);
    let made = place(
      format!("tab-{}", entry.key),
      place_content(bar, &entry.item, chosen, low),
      chosen,
      !entry.item.search,
      Box::new(move || {
        if opens {
          scrolled.set(false);
          return;
        }
        open.set(false);
        tabs.press(&key);
      }),
    );
    if floating && entry.item.search {
      // The tab to search in stands apart from the others, a round place of its own at the bar's end.
      apart = Some(
        Row::new()
          .width(height)
          .height(height)
          .padding(4.0)
          .rounded(height / 2.0)
          .background(bar.background)
          .backdrop_blur(bar.blur)
          .border_inside(0.5, bar.border)
          .child(made)
          .into(),
      );
    } else {
      places = places.child(made);
    }
  }
  if !rest.is_empty() {
    // The last place lists the tabs that have none. It is the chosen one while its list is open, and while
    // the tab that is shown is one of those.
    let chosen = opened || rest.iter().any(|entry| entry.active);
    let item = TabItem::new(bar.more_title()).symbol(bar.more_symbol.clone());
    let open = more_open.clone();
    places = places.child(place(
      "tab-more-places".to_owned(),
      place_content(bar, &item, chosen, low),
      chosen,
      true,
      Box::new(move || open.set(!open.get_untracked())),
    ));
  }

  if floating {
    let capsule = places
      .width(if drawn_in { alone + 8.0 } else { full })
      .transition(resize.clone())
      .height(height)
      .padding(4.0)
      .rounded(height / 2.0)
      .background(bar.background)
      .backdrop_blur(bar.blur)
      .border_inside(0.5, bar.border);
    // The room around the bar is the content's: a touch there goes to what is under.
    let mut row = Row::new()
      .width(FILL)
      .hit_test(crate::node::HitTestBehavior::ContentOnly)
      .padding_left(safe_area.left + bar.floating_margin)
      .padding_right(safe_area.right + bar.floating_margin)
      .padding_bottom(bar.floating_bottom)
      .child(capsule);
    if let Some(apart) = apart {
      // The tab to search in keeps its place at the bar's end as the bar draws in.
      row = row
        .child(Row::new().flex(1.0).min_width(10.0).pointer_events_none())
        .child(apart);
    }
    return row.into();
  }
  let places = places
    .width(FILL)
    .padding_left(safe_area.left)
    .padding_right(safe_area.right);
  let line = Row::new().width(FILL).height(0.5).background(bar.border);
  let column = Column::new()
    .width(FILL)
    .background(bar.background)
    .backdrop_blur(bar.blur);
  match bar.place {
    TabBarPlace::Bottom => column.child(line).child(places).padding_bottom(safe_area.bottom),
    TabBarPlace::Top => column.padding_top(safe_area.top).child(places).child(line),
  }
  .into()
}

/// The tabs that have no place in the bar, as a list over the tab that is shown: a press on one shows it.
fn more_list(
  bar: &TabBar,
  tabs: &Tabs,
  entries: &[TabEntry],
  safe_area: SafeAreaInsets,
  bar_height: f32,
  more_open: &Signal<bool>,
) -> Element {
  let (_, rest) = placed(bar, entries);
  let solid = Color::new(bar.background.r(), bar.background.g(), bar.background.b(), 255);
  let mut rows = Column::new().width(FILL);
  for entry in rest {
    let (tabs, key, open) = (tabs.clone(), entry.key.clone(), more_open.clone());
    let color = if entry.active { bar.tint } else { bar.color };
    let mut row = Row::new()
      .id(format!("tab-{}", entry.key))
      .width(FILL)
      .height(44.0)
      .align_items(Alignment::Center)
      .spacing(12.0)
      .padding_horizontal(16.0);
    if let Some(picture) = entry.item.icon.clone().or_else(|| {
      entry
        .item
        .symbol
        .as_ref()
        .and_then(|name| symbol(name, bar.symbol_size, color))
    }) {
      row = row.child(picture);
    }
    row = row.child(
      Text::styled(
        &entry.item.title,
        TextStyle {
          font_size: 17.0,
          color: bar.tint,
          ..TextStyle::default()
        },
      )
      .nowrap(),
    );
    rows = rows
      .child(row.on_click(move |_| {
        open.set(false);
        tabs.select(&key);
      }))
      .child(Row::new().width(FILL).height(0.5).background(bar.border));
  }
  Column::new()
    .id("tab-more-list")
    .size(FILL, FILL)
    .background(solid)
    .padding_top(safe_area.top + 16.0)
    .padding_left(safe_area.left)
    .padding_right(safe_area.right)
    .padding_bottom(bar_height)
    .child(
      Row::new().padding_horizontal(16.0).padding_bottom(8.0).child(
        Text::styled(
          &bar.more_title(),
          TextStyle {
            font_size: 34.0,
            weight: FontWeight::Bold,
            color: bar.tint,
            ..TextStyle::default()
          },
        )
        .nowrap(),
      ),
    )
    .child(crate::components::ScrollVertical::new(rows).width(FILL).flex(1.0))
    // A press on the list is the list's, not the tab's under it.
    .on_click(|_| {})
    .into()
}

#[derive(Clone)]
struct TabHostProps {
  router: RouterHandle,
  bar_move: Signal<BarMove>,
  scrolled: Signal<bool>,
  front: crate::app::ctx::InFront,
}

impl PartialEq for TabHostProps {
  fn eq(&self, other: &Self) -> bool {
    Arc::ptr_eq(&self.router.inner, &other.router.inner)
  }
}

#[cfg(feature = "devtools")]
impl crate::app::component::DevtoolsInspectable for TabHostProps {
  fn write_info(&self, _buffer: &mut Vec<crate::app::component::ComponentInfo>) {}
}

/// One tab: its router, kept while the tab is not shown.
struct TabHost;

impl Component for TabHost {
  type Props = TabHostProps;

  fn create(ctx: &mut Ctx) -> Self {
    let props = ctx.props::<TabHostProps>();
    let link = TabBarLink(props.bar_move.clone(), props.scrolled.clone());
    let front = props.front.clone();
    ctx.provide(link);
    ctx.provide(front);
    Self
  }

  fn render(&self, ctx: &mut Ctx) -> impl Into<Element> {
    let router = ctx.props::<TabHostProps>().router.clone();
    Router::mount(ctx, router)
  }
}