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
//! A progress dialog: a dialog that shows how far a piece of work is, and cannot be dismissed while it runs.

use std::sync::Arc;

use super::{
  button::{Button, ButtonPart, ButtonSize, ButtonVariant},
  dialog::{Dialog, DialogPart},
  message_box::{DisclosureParts, autofocus, disclosure, disclosure_recipe, wrapping},
  names,
  part_style::{Length, PartStyle},
  progress::{Progress, ProgressFormat, ProgressPart, ProgressSize},
  recipe::{Case, Name, Recipe, ResolvedPart, ResolvedRecipe},
  shared::glyph,
  theme::{Themed, current_theme},
};
use crate::{
  app::{
    events::KeyboardEvent,
    theme::{PaletteColor, Theme, TypographyStyle},
  },
  components::{Column, Row},
  core::Signal,
  layout::{Alignment, layout_kind::Justify, text_style::FontWeight},
  node::{Element, dimension::Dimension, node_kind::TextOverflow},
};

/// The parts of a progress dialog a recipe styles.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum ProgressDialogPart {
  /// What covers the window behind the panel, laid over the dialog's veil.
  Veil,
  /// The panel, laid over the dialog's: its width and its padding.
  Panel,
  /// What the panel holds, one thing under another.
  Content,
  /// The icon beside the title and the description.
  Header,
  /// The icon of the work, before the title.
  Icon,
  /// The title over the description.
  Text,
  /// What is being done: "Copying 128 items".
  Title,
  /// A line more of it: "from Downloads to projects/lurq/assets".
  Description,
  /// The bar, laid over the progress's root.
  Progress,
  /// The row under the bar: how much is done at its start, what the app says of the rest at its end.
  Meta,
  /// How much is done: "42 of 128", or a percentage.
  Count,
  /// What the app says of the rest: "about 2 min left".
  Status,
  /// The row at the bottom: what opens the detail at its start, the buttons at its end.
  Footer,
  /// What opens the detail: a chevron and its label.
  DetailTrigger,
  /// The chevron of the trigger, which points down while the detail is open.
  DetailChevron,
  /// The label of the trigger: "Details".
  DetailLabel,
  /// What opens and closes with the detail.
  DetailPanel,
  /// The detail itself.
  Detail,
  /// The buttons at the end of the footer.
  Actions,
  /// A button of the app's ([`ProgressDialog::button`]) before the cancel one ("Pause"), laid over the button's root.
  ActionButton,
  /// Its label, laid over the button's.
  ActionLabel,
  /// The cancel button, laid over the button's root.
  CancelButton,
  /// Its label, laid over the button's.
  CancelLabel,
}

names!(ProgressDialogPart {
  Veil => "veil",
  Panel => "panel",
  Content => "content",
  Header => "header",
  Icon => "icon",
  Text => "text",
  Title => "title",
  Description => "description",
  Progress => "progress",
  Meta => "meta",
  Count => "count",
  Status => "status",
  Footer => "footer",
  DetailTrigger => "detail_trigger",
  DetailChevron => "detail_chevron",
  DetailLabel => "detail_label",
  DetailPanel => "detail_panel",
  Detail => "detail",
  Actions => "actions",
  ActionButton => "action_button",
  ActionLabel => "action_label",
  CancelButton => "cancel_button",
  CancelLabel => "cancel_label",
});

/// The states of a progress dialog a recipe styles.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum ProgressDialogState {
  /// How far the work is is not known.
  Indeterminate,
  /// Its detail is open.
  DetailOpen,
}

names!(ProgressDialogState {
  Indeterminate => "indeterminate",
  DetailOpen => "detail_open",
});

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

/// What a button of a progress dialog does when it is pressed.
type Handler = Arc<dyn Fn() + Send + Sync>;

/// A progress dialog: a dialog over the window while a piece of work runs,
/// which says what is being done and how far it is. Copying files,
/// exporting a project, installing an update.
///
/// ```
/// use lurq::{core::Signal, ui::{ProgressDialog, icons}};
///
/// let (open, details) = (Signal::new(true), Signal::new(false));
/// let copying = ProgressDialog::new(open)
///   .icon(icons::COPY)
///   .title("Copying 128 items")
///   .description("from Downloads to projects/lurq/assets")
///   .value(42.0)
///   .max(128.0)
///   .format(|done, all| format!("{done} of {all}"))
///   .status("about 2 min left")
///   .detail("assets/icons/warning.svg", details)
///   .button("Pause", || println!("paused"))
///   .on_cancel(|| println!("cancelled"));
/// ```
///
/// A progress dialog does not keep whether it is open, nor how far the work
/// is: the app's signal and the values it gives do, and it closes when the
/// app sets the signal to `false`. Escape and a press of the veil do not
/// close it. Its cancel button, there when the app gives it
/// [`ProgressDialog::on_cancel`], runs what the app gave it and does not close
/// it: the app closes it once the work has stopped. Escape presses it, and the
/// focus goes to it as the dialog opens. Without a value it shows work whose
/// end is not known. It is a [`Dialog`], with the veil, the focus and Tab of
/// one; to tooling that reads the tree it is called by its label or its
/// title and described by its description.
pub struct ProgressDialog {
  open: Signal<bool>,
  icon: Option<Name>,
  title: Option<Arc<str>>,
  description: Option<Arc<str>>,
  label: Option<Arc<str>>,
  value: Option<f32>,
  max: f32,
  format: Option<ProgressFormat>,
  status: Option<Arc<str>>,
  detail: Option<(Arc<str>, Signal<bool>)>,
  detail_label: Arc<str>,
  actions: Vec<(Arc<str>, Handler)>,
  cancel_label: Arc<str>,
  on_cancel: Vec<Handler>,
  inline: bool,
  states: Vec<Name>,
  rules: Recipe,
  id: Option<Arc<str>>,
  key: Option<Arc<str>>,
}

impl ProgressDialog {
  /// A progress dialog shown while `open` holds `true`.
  pub fn new(open: Signal<bool>) -> Self {
    Self {
      open,
      icon: None,
      title: None,
      description: None,
      label: None,
      value: None,
      max: 1.0,
      format: None,
      status: None,
      detail: None,
      detail_label: super::current_locale().common.details.clone(),
      actions: Vec::new(),
      cancel_label: super::current_locale().common.cancel.clone(),
      on_cancel: Vec::new(),
      inline: false,
      states: Vec::new(),
      rules: Recipe::new(),
      id: None,
      key: None,
    }
  }

  /// An icon of the theme's set before the title: what kind of work it is.
  pub fn icon(mut self, name: impl Into<Name>) -> Self {
    self.icon = Some(name.into());
    self
  }

  /// What is being done: "Copying 128 items". It is also what the dialog is
  /// called to tooling that reads the tree.
  pub fn title(mut self, title: &str) -> Self {
    self.title = Some(Arc::from(title));
    self
  }

  /// A line more of it, under the title: where from, where to, which file.
  pub fn description(mut self, description: &str) -> Self {
    self.description = Some(Arc::from(description));
    self
  }

  /// What the dialog is called to tooling that reads the tree, over its title.
  pub fn label(mut self, label: &str) -> Self {
    self.label = Some(Arc::from(label));
    self
  }

  /// How far the work is, of the greatest value: a fraction of one unless
  /// [`ProgressDialog::max`] says otherwise. Without one the work's end is
  /// not known.
  pub fn value(mut self, value: impl Into<f64>) -> Self {
    self.value = Some(value.into() as f32);
    self
  }

  /// The greatest value: the whole of the work. 1 when not given.
  pub fn max(mut self, max: impl Into<f64>) -> Self {
    self.max = max.into() as f32;
    self
  }

  /// Says how much is done as the app does, given the value and the
  /// greatest: "42 of 128". A percentage when not given.
  pub fn format(mut self, format: impl Fn(f32, f32) -> String + Send + Sync + 'static) -> Self {
    self.format = Some(Arc::new(format));
    self
  }

  /// What the app says of the rest of the work, under the end of the bar: "about 2 min left".
  pub fn status(mut self, status: &str) -> Self {
    self.status = Some(Arc::from(status));
    self
  }

  /// A text a person opens to see more, under the footer: the file being
  /// copied, a log. It is open while `open` holds `true`, and its trigger at
  /// the start of the footer turns it.
  pub fn detail(mut self, detail: &str, open: Signal<bool>) -> Self {
    self.detail = Some((Arc::from(detail), open));
    self
  }

  /// The label of what opens the detail: "Details" when not given.
  pub fn detail_label(mut self, label: &str) -> Self {
    self.detail_label = Arc::from(label);
    self
  }

  /// Adds a button of the app's before the cancel one, after those already
  /// there: "Pause". It does not close the dialog.
  pub fn button(mut self, label: &str, handler: impl Fn() + Send + Sync + 'static) -> Self {
    self.actions.push((Arc::from(label), Arc::new(handler)));
    self
  }

  /// What the cancel button does: the dialog has one only with this. It does
  /// not close the dialog; the app does, once the work has stopped. A second
  /// handler runs after the first.
  pub fn on_cancel(mut self, handler: impl Fn() + Send + Sync + 'static) -> Self {
    self.on_cancel.push(Arc::new(handler));
    self
  }

  /// The label of the cancel button: "Cancel" when not given.
  pub fn cancel_label(mut self, label: &str) -> Self {
    self.cancel_label = Arc::from(label);
    self
  }

  /// A width of its own over the board's 420: logical pixels, or any [`Length`].
  pub fn width(mut self, width: impl Into<Length>) -> Self {
    let width = width.into();
    self.rules = self.rules.base(ProgressDialogPart::Panel, |s| s.width(width));
    self
  }

  /// Draws the panel where the dialog is declared, whether or not it is
  /// open, without the veil: for a gallery, a screenshot, a test.
  pub fn inline(mut self, inline: bool) -> Self {
    self.inline = inline;
    self
  }

  /// Puts the dialog in a state the theme's recipe names, or takes it out.
  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
  }

  /// Styles one part of this dialog over what the theme gives it.
  pub fn style(mut self, part: impl Into<Name>, style: impl FnOnce(PartStyle) -> PartStyle) -> Self {
    self.rules = self.rules.base(part, style);
    self
  }

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

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

  /// The key of what the dialog lays over the window.
  pub fn key(mut self, key: impl Into<Arc<str>>) -> Self {
    self.key = Some(key.into());
    self
  }

  /// Builds the dialog in `theme`. Converting a progress dialog into an
  /// element does this in the theme of what is being rendered.
  pub fn build(self, theme: &Theme) -> Element {
    let detail_open = self.detail.as_ref().is_some_and(|(_, open)| open.get());
    let case = Case {
      variant: None,
      size: None,
      density: None,
      breakpoint: super::current_breakpoint(),
      states: self.states,
    }
    .state(ProgressDialogState::Indeterminate, self.value.is_none())
    .state(ProgressDialogState::DetailOpen, detail_open);
    let view = ProgressDialogView {
      icon: self.icon,
      title: self.title,
      description: self.description,
      label: self.label,
      value: self.value,
      max: self.max,
      status: self.status,
      detail: self.detail.as_ref().map(|(detail, _)| detail.clone()),
      detail_label: self.detail_label,
      detail_open,
      actions: self.actions.iter().map(|(label, _)| label.clone()).collect(),
      cancel_label: (!self.on_cancel.is_empty()).then_some(self.cancel_label),
      inline: self.inline,
      recipe: theme
        .resolve::<ProgressDialog>(&case, Some(&self.rules))
        .owned_by(self.id.as_ref()),
      open: self.open,
      format: self.format,
      detail_signal: self.detail.map(|(_, open)| open),
      handlers: self.actions.into_iter().map(|(_, handler)| handler).collect(),
      on_cancel: self.on_cancel,
      id: self.id,
      key: self.key,
    };
    match theme.renderer::<ProgressDialog>() {
      Some(renderer) => renderer(view),
      None => view.render(),
    }
  }
}

impl From<ProgressDialog> for Element {
  fn from(dialog: ProgressDialog) -> Self {
    dialog.build(&current_theme())
  }
}

/// A progress dialog as a renderer sees it: what it was given, the style of
/// its parts, and its behavior ready to be dressed.
pub struct ProgressDialogView {
  pub icon: Option<Name>,
  pub title: Option<Arc<str>>,
  pub description: Option<Arc<str>>,
  /// What it is called to tooling, over its title.
  pub label: Option<Arc<str>>,
  /// How far the work is; `None` while it is not known.
  pub value: Option<f32>,
  pub max: f32,
  pub status: Option<Arc<str>>,
  pub detail: Option<Arc<str>>,
  pub detail_label: Arc<str>,
  pub detail_open: bool,
  /// The labels of the app's buttons, before the cancel one.
  pub actions: Vec<Arc<str>>,
  /// The label of the cancel button, where there is one.
  pub cancel_label: Option<Arc<str>>,
  pub inline: bool,
  /// The style of each part of this dialog.
  pub recipe: ResolvedRecipe,
  open: Signal<bool>,
  format: Option<ProgressFormat>,
  detail_signal: Option<Signal<bool>>,
  handlers: Vec<Handler>,
  on_cancel: Vec<Handler>,
  id: Option<Arc<str>>,
  key: Option<Arc<str>>,
}

impl ProgressDialogView {
  /// The style of a part, as this dialog is to be drawn.
  pub fn part(&self, part: impl Into<Name>) -> ResolvedPart {
    self.recipe.part(part)
  }

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

  /// The signal that holds whether the dialog is open.
  pub fn open(&self) -> &Signal<bool> {
    &self.open
  }

  /// How much of the work is done, from 0 to 1; `None` while it is not known.
  pub fn fraction(&self) -> Option<f32> {
    let value = self.value?;
    Some(if self.max > 0.0 {
      value.clamp(0.0, self.max) / self.max
    } else {
      0.0
    })
  }

  /// How much is done as it is said: what the app's format says, or a
  /// percentage. `None` while it is not known.
  pub fn count(&self) -> Option<String> {
    let fraction = self.fraction()?;
    Some(match &self.format {
      Some(format) => format(self.value?.clamp(0.0, self.max.max(0.0)), self.max),
      None => format!("{}%", (fraction * 100.0).round() as i32),
    })
  }

  /// The icon, the title and the description.
  pub fn header(&self) -> Row {
    let mut text = Column::new()
      .flex(1.0)
      .align_items(Alignment::Stretch)
      .part(&self.part(ProgressDialogPart::Text));
    for (part, content) in [
      (ProgressDialogPart::Title, &self.title),
      (ProgressDialogPart::Description, &self.description),
    ] {
      if let Some(content) = content {
        text = text.child(wrapping(&self.part(part), content));
      }
    }
    let mut header = Row::new()
      .width(Dimension::Pct(100.0))
      .align_items(Alignment::Center)
      .part(&self.part(ProgressDialogPart::Header));
    if let Some(icon) = self.icon {
      header = header.child(glyph(&self.part(ProgressDialogPart::Icon), icon, false));
    }
    header.child(text)
  }

  /// The bar: a [`Progress`] with the dialog's rules for it laid over the theme's.
  pub fn progress(&self) -> Element {
    let progress = match self.value {
      Some(value) => Progress::new(value).max(self.max),
      None => Progress::indeterminate(),
    };
    progress
      .size(ProgressSize::Md)
      .rules(&self.recipe.rules_for(ProgressDialogPart::Progress, ProgressPart::Root))
      .build(self.theme())
  }

  /// How much is done at the start and what the app says of the rest at the end: `None` where there is neither.
  pub fn meta(&self) -> Option<Row> {
    let count = self.count();
    if count.is_none() && self.status.is_none() {
      return None;
    }
    let mut meta = Row::new()
      .width(Dimension::Pct(100.0))
      .align_items(Alignment::Center)
      .part(&self.part(ProgressDialogPart::Meta));
    if let Some(count) = &count {
      let part = self.part(ProgressDialogPart::Count);
      meta = meta.child(Row::new().part(&part).child(part.text(count).nowrap()));
    }
    // The status takes the room the count leaves and stands at its end, with no count too; a status longer than
    // that room is cut with an ellipsis.
    if let Some(status) = &self.status {
      let part = self.part(ProgressDialogPart::Status);
      meta = meta.child(
        Row::new()
          .flex_full(1.0, 1.0, Some(0.0))
          .min_width(Dimension::Px(0.0))
          .justify(Justify::End)
          .part(&part)
          .child(part.text(status).nowrap().text_overflow(TextOverflow::Elipsis)),
      );
    }
    Some(meta)
  }

  /// What the cancel button and Escape do: what the app gave
  /// [`ProgressDialog::on_cancel`], in the order it was given. `None` where it
  /// gave nothing.
  pub fn canceller(&self) -> Option<impl Fn() + Send + Sync + Clone + 'static> {
    if self.on_cancel.is_empty() {
      return None;
    }
    let handlers = self.on_cancel.clone();
    Some(move || {
      for handler in &handlers {
        handler();
      }
    })
  }

  /// A button of the dialog's, with the dialog's rules for `parts` laid over the theme's for a button.
  fn button(&self, label: &str, parts: (ProgressDialogPart, ProgressDialogPart), handler: Handler) -> Element {
    let rules = self
      .recipe
      .rules_for(parts.0, ButtonPart::Root)
      .extend(&self.recipe.rules_for(parts.1, ButtonPart::Label));
    Button::new(label)
      .variant(ButtonVariant::Outline)
      .size(ButtonSize::Sm)
      .rules(&rules)
      .on_click(move |_| handler())
      .build(self.theme())
  }

  /// The app's buttons and the cancel one, which the focus goes to as the dialog opens.
  pub fn actions(&self) -> Row {
    let mut actions = Row::new()
      .align_items(Alignment::Center)
      .overflow_visible()
      .part(&self.part(ProgressDialogPart::Actions));
    for (label, handler) in self.actions.iter().zip(&self.handlers) {
      actions = actions.child(self.button(
        label,
        (ProgressDialogPart::ActionButton, ProgressDialogPart::ActionLabel),
        handler.clone(),
      ));
    }
    if let (Some(label), Some(cancel)) = (&self.cancel_label, self.canceller()) {
      actions = actions.child(autofocus(self.button(
        label,
        (ProgressDialogPart::CancelButton, ProgressDialogPart::CancelLabel),
        Arc::new(cancel),
      )));
    }
    actions
  }

  /// What opens the detail, and what opens and closes with it: `None` for a dialog with no detail.
  pub fn detail(&self) -> Option<(crate::components::Button, Column)> {
    let (detail, open) = (self.detail.as_ref()?, self.detail_signal.as_ref()?);
    Some(disclosure(
      &self.recipe,
      detail_parts(),
      &self.detail_label,
      detail,
      open,
    ))
  }

  /// The footer: what opens the detail at its start, the buttons at its end. `None` where there are neither.
  pub fn footer(&self, trigger: Option<crate::components::Button>) -> Option<Row> {
    let actions = (!self.actions.is_empty() || self.cancel_label.is_some()).then(|| self.actions());
    if trigger.is_none() && actions.is_none() {
      return None;
    }
    let mut footer = Row::new()
      .width(Dimension::Pct(100.0))
      .align_items(Alignment::Center)
      .justify(if trigger.is_some() {
        Justify::SpaceBetween
      } else {
        Justify::End
      })
      .overflow_visible()
      .part(&self.part(ProgressDialogPart::Footer));
    if let Some(trigger) = trigger {
      footer = footer.child(trigger);
    }
    if let Some(actions) = actions {
      footer = footer.child(actions);
    }
    Some(footer)
  }

  /// What the panel holds, with nothing in it yet: Escape with the focus in it presses the cancel button.
  pub fn content(&self) -> Column {
    let mut content = Column::new()
      .width(Dimension::Pct(100.0))
      .align_items(Alignment::Stretch)
      .overflow_visible()
      .part(&self.part(ProgressDialogPart::Content));
    if let Some(cancel) = self.canceller() {
      content = content.on_key_down(move |event: KeyboardEvent| {
        if event.focus_within && event.key == "Escape" && !event.default_prevented() {
          event.prevent_default();
          cancel();
        }
      });
    }
    content
  }

  /// `content` in a [`Dialog`] that neither Escape nor a press of its veil
  /// closes, its panel and its veil in the dialog's rules over the dialog's.
  pub fn dialog(&self, content: impl Into<Element>) -> Element {
    let rules = self
      .recipe
      .rules_for(ProgressDialogPart::Panel, DialogPart::Panel)
      .extend(&self.recipe.rules_for(ProgressDialogPart::Veil, DialogPart::Veil));
    let mut dialog = Dialog::new(self.open.clone())
      .rules(&rules)
      .inline(self.inline)
      .dismiss_on_escape(false)
      .dismiss_on_veil(false)
      .child(content);
    if let Some(label) = self.label.as_ref().or(self.title.as_ref()) {
      dialog = dialog.label(label);
    }
    if let Some(description) = &self.description {
      dialog = dialog.described(description);
    }
    if let Some(id) = &self.id {
      dialog = dialog.id(id.clone());
    }
    if let Some(key) = &self.key {
      dialog = dialog.key(key.clone());
    }
    dialog.build(self.theme())
  }

  /// How the default renderer builds a progress dialog: the header, the bar,
  /// what is done, the footer and the detail under it, in a dialog.
  pub fn render(self) -> Element {
    let mut content = self.content().child(self.header()).child(self.progress());
    if let Some(meta) = self.meta() {
      content = content.child(meta);
    }
    let (trigger, panel) = match self.detail() {
      Some((trigger, panel)) => (Some(trigger), Some(panel)),
      None => (None, None),
    };
    // The detail opens under the footer, and is in one column with it, so that nothing of the content's gap is
    // left under the footer while the detail is closed.
    let mut bottom = Column::new()
      .width(Dimension::Pct(100.0))
      .align_items(Alignment::Stretch)
      .overflow_visible();
    if let Some(footer) = self.footer(trigger) {
      bottom = bottom.child(footer);
    }
    if let Some(panel) = panel {
      bottom = bottom.child(panel);
    }
    self.dialog(content.child(bottom))
  }
}

/// The parts of the detail of a progress dialog.
fn detail_parts() -> DisclosureParts {
  use ProgressDialogPart::*;
  DisclosureParts {
    trigger: DetailTrigger.into(),
    icon: DetailChevron.into(),
    label: DetailLabel.into(),
    panel: DetailPanel.into(),
    content: Detail.into(),
  }
}

impl crate::ui::Styled for ProgressDialog {
  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 ProgressDialog {
  const NAME: &'static str = "progress_dialog";
  /// The id is the dialog's panel's.
  const ROOT: &'static str = "panel";
  type Renderer = ProgressDialogRenderer;

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

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

  /// The design's progress dialog (`pencil/lurq-design-system.pen`, Progress
  /// Dialog): a dialog's panel 420 wide, padded 20 with 12 between its parts.
  /// The header is the icon of 20, 12 before the title of 15/600 over the
  /// description of 12 in the muted color, 2 apart; under it the bar of 6 across
  /// the panel, and under that what is done and what is left in the mono type
  /// of 11 in the muted color. The footer, 4 further down, has "Details" at
  /// its start and the outlined buttons of 32 padded 14 at its end, 8 apart.
  fn recipe() -> Recipe {
    use PaletteColor::{Foreground, MutedForeground};
    use ProgressDialogPart::*;
    let recipe = Recipe::new()
      // Of the 20 the panel is padded, 4 are the dialog's body's, which is room for the ring of a focused button.
      .base(Panel, |s| {
        s.width(420.0)
          .max_width(Length::Fill)
          .padding_x(16.0)
          .padding_y(16.0)
      })
      .base(Content, |s| s.gap(12.0))
      .base(Header, |s| s.gap(12.0))
      .base(Icon, |s| s.square(20.0).foreground(Foreground))
      .base(Text, |s| s.gap(2.0))
      .base(Title, |s| {
        s.typography(TypographyStyle::Body)
          .font_size(15.0)
          .weight(FontWeight::SemiBold)
          .foreground(Foreground)
      })
      .base(Description, |s| {
        s.typography(TypographyStyle::Description)
          .font_size(12.0)
          .foreground(MutedForeground)
      })
      .base(Progress, |s| s.width(Length::Fill))
      .base(Meta, |s| s.gap(8.0))
      .base(Count, |s| {
        s.typography(TypographyStyle::Mono)
          .font_size(11.0)
          .foreground(MutedForeground)
      })
      .base(Status, |s| {
        s.typography(TypographyStyle::Mono)
          .font_size(11.0)
          .foreground(MutedForeground)
      })
      .base(Footer, |s| s.gap(8.0).padding_top(4.0))
      .base(Actions, |s| s.gap(8.0))
      .base(ActionButton, |s| s.padding_x(14.0))
      .base(CancelButton, |s| s.padding_x(14.0));
    disclosure_recipe(recipe, &detail_parts(), ProgressDialogState::DetailOpen.into())
  }
}