mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 00:34:25 +00:00
Title rows: a note runs on after the title in muted body text, and the subtitle sits at the band's end in muted caption text; the gallery card shows its story name as the note, the Inspector its target's kind as the subtitle
This commit is contained in:
@@ -149,7 +149,7 @@ impl Card<'_> {
|
||||
.strength(HeaderStrength::Heading)
|
||||
.pad(pad);
|
||||
if let Some(note) = self.note {
|
||||
panel = panel.subtitle(format!("· {note}"));
|
||||
panel = panel.note(note.to_owned());
|
||||
}
|
||||
let mut commands = Vec::new();
|
||||
if self.open {
|
||||
|
||||
@@ -60,8 +60,8 @@ type FooterFn<'a> = Box<dyn FnMut(&mut Ui, &mut BodyCx<'_>) + 'a>;
|
||||
/// A panel of a workspace: scrolling body, optional footer, optional title row.
|
||||
///
|
||||
/// - Title: names the panel for assistive technology. A docked panel shows no header, since its dock tab names it.
|
||||
/// - Header: [`titled`](Panel::titled) or [`band`](Panel::band) shows the title in a header, with the optional icon and
|
||||
/// subtitle, the commands in `commands` and the actions in `actions`; without a header these show nowhere. The Menu
|
||||
/// - Header: [`titled`](Panel::titled) or [`band`](Panel::band) shows the title in a header, with the optional icon,
|
||||
/// note and subtitle, the commands in `commands` and the actions in `actions`; without a header these show nowhere. The Menu
|
||||
/// action opens the rows given to `menu` under the title row; Close asks the panel to close, which hides its body
|
||||
/// until the host stops showing it (bind the state with `opened` to keep it); Float is reported in
|
||||
/// `PanelOutput::action` for the host.
|
||||
@@ -79,7 +79,10 @@ pub struct Panel<'a> {
|
||||
/// Binds the open state to `open`.
|
||||
#[prop(name = "opened")]
|
||||
open: Option<Bind<'a, bool>>,
|
||||
/// Text after the title in the header.
|
||||
/// A note run on after the title in the header ("· note").
|
||||
#[prop(into)]
|
||||
note: Option<Label>,
|
||||
/// Text at the end of the header's title band: the kind of what the title names.
|
||||
#[prop(into)]
|
||||
subtitle: Option<Label>,
|
||||
/// An icon before the title.
|
||||
@@ -114,6 +117,7 @@ impl<'a> Panel<'a> {
|
||||
common: Common::new(),
|
||||
props,
|
||||
open: None,
|
||||
note: None,
|
||||
subtitle: None,
|
||||
icon: None,
|
||||
menu: None,
|
||||
@@ -243,6 +247,9 @@ impl Container for Panel<'_> {
|
||||
|
||||
fn header(&mut self, ui: &mut Ui, cx: &mut BodyCx<'_>) {
|
||||
let mut row = TitleRow::new(cx.label()).strength(self.strength).actions(self.actions.iter().copied()).commands(self.commands.iter().cloned());
|
||||
if let Some(note) = self.note.clone() {
|
||||
row = row.note(note);
|
||||
}
|
||||
if let Some(subtitle) = self.subtitle.clone() {
|
||||
row = row.subtitle(subtitle);
|
||||
}
|
||||
|
||||
@@ -155,10 +155,11 @@ pub struct TitleRowStyle {
|
||||
action: f32,
|
||||
}
|
||||
|
||||
/// An optional icon, a title with an optional subtitle, a lead (a disclosure bound to the container's open state, or
|
||||
/// a check box bound to its gate) and action parts. A row too narrow for the title and subtitle together drops the
|
||||
/// subtitle before it elides the title; an elided title shows whole in a tooltip. A click on the title band toggles a
|
||||
/// disclosure lead, as a click on the lead does.
|
||||
/// An optional icon, a title with an optional note run on after it ("· note", muted body text) and an optional
|
||||
/// subtitle at the band's end (muted caption text: the target's kind), a lead (a disclosure bound to the container's
|
||||
/// open state, or a check box bound to its gate) and action parts. A row too narrow for all its texts drops the
|
||||
/// subtitle, then the note, before it elides the title; an elided title shows whole in a tooltip. A click on the title
|
||||
/// band toggles a disclosure lead, as a click on the lead does.
|
||||
#[derive(crate::contract::Component, crate::contract::Props)]
|
||||
pub struct TitleRow<'a> {
|
||||
#[common]
|
||||
@@ -170,7 +171,10 @@ pub struct TitleRow<'a> {
|
||||
/// The heading level AccessKit reports.
|
||||
#[prop]
|
||||
level: usize,
|
||||
/// Text after the title.
|
||||
/// A note run on after the title, as "· note" in muted body text: a story's name after its component's.
|
||||
#[prop(into)]
|
||||
note: Option<Label>,
|
||||
/// Text at the end of the title band, in muted caption text: the kind of what the title names ("Pixel layer").
|
||||
#[prop(into)]
|
||||
subtitle: Option<Label>,
|
||||
/// An icon before the title, painted in the style's icon colour unless the spec names another.
|
||||
@@ -199,12 +203,13 @@ pub struct TitleRow<'a> {
|
||||
placed: Option<Placed>,
|
||||
}
|
||||
|
||||
/// Where the icon, title and subtitle sit in the row, decided with the final width in `parts`.
|
||||
/// Where the icon, title, note and subtitle sit in the row, decided with the final width in `parts`.
|
||||
#[derive(Clone, Copy)]
|
||||
struct Placed {
|
||||
icon: Option<Rect>,
|
||||
handle: Option<Rect>,
|
||||
title: Rect,
|
||||
note: Option<Rect>,
|
||||
subtitle: Option<Rect>,
|
||||
}
|
||||
|
||||
@@ -216,6 +221,7 @@ impl<'a> TitleRow<'a> {
|
||||
common,
|
||||
strength: HeaderStrength::Normal,
|
||||
level: 2,
|
||||
note: None,
|
||||
subtitle: None,
|
||||
icon: None,
|
||||
fill: true,
|
||||
@@ -269,8 +275,8 @@ impl<'a> TitleRow<'a> {
|
||||
if matches!(self.lead, Lead::Disclosure(_)) { icon } else { row }
|
||||
}
|
||||
|
||||
/// Divides the room left between the lead and the actions: the icon, then the title, then the subtitle when
|
||||
/// both texts fit whole.
|
||||
/// Divides the room left between the lead and the actions: the icon, the title, the note after it and the subtitle
|
||||
/// at the end. The subtitle shows when every text fits whole, the note when the title and the note do.
|
||||
fn place(&self, mut band: Flow, cx: &PartsCx<'_, Self>) -> Placed {
|
||||
// A disclosure's glyph sits a gap before the title, as a title's own icon does; the gap is part of the title band,
|
||||
// so a click beside the glyph toggles too.
|
||||
@@ -292,20 +298,24 @@ impl<'a> TitleRow<'a> {
|
||||
icon = Some(slot);
|
||||
band = rest;
|
||||
}
|
||||
let role = cx.style.text.role;
|
||||
let subtitle = self.subtitle.as_ref().and_then(|subtitle| {
|
||||
let title = cx.layout_at(&TextRun::new(cx.resolved.label).role(role), f32::INFINITY).galley.size().x;
|
||||
let width = cx.layout_at(&subtitle_run(subtitle.as_str(), role), f32::INFINITY).galley.size().x;
|
||||
(title + cx.gap() + width <= band.rect().width()).then_some(title)
|
||||
});
|
||||
match subtitle {
|
||||
Some(title) => {
|
||||
let (title, rest) = band.take_start(title);
|
||||
let (_, rest) = rest.take_start(cx.gap());
|
||||
Placed { icon, handle, title, subtitle: Some(rest.rect()) }
|
||||
let width = |run: &TextRun<'_>| cx.layout_at(run, f32::INFINITY).galley.size().x;
|
||||
let title = width(&TextRun::new(cx.resolved.label).role(cx.style.text.role));
|
||||
let note = self.note.as_ref().map_or(0.0, |note| width(¬e_run(note.as_str())) + cx.gap());
|
||||
let mut subtitle = None;
|
||||
if let Some(text) = &self.subtitle {
|
||||
let side = width(&subtitle_run(text.as_str()));
|
||||
if title + note + cx.gap() + side <= band.rect().width() {
|
||||
let (slot, rest) = band.take_end(side);
|
||||
subtitle = Some(slot);
|
||||
band = rest.take_end(cx.gap()).1;
|
||||
}
|
||||
None => Placed { icon, handle, title: band.rect(), subtitle: None },
|
||||
}
|
||||
if self.note.is_some() && title + note <= band.rect().width() {
|
||||
let (title, rest) = band.take_start(title);
|
||||
let (_, rest) = rest.take_start(cx.gap());
|
||||
return Placed { icon, handle, title, note: Some(rest.rect()), subtitle };
|
||||
}
|
||||
Placed { icon, handle, title: band.rect(), note: None, subtitle }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,12 +346,14 @@ impl Component for TitleRow<'_> {
|
||||
fn measure(&mut self, cx: &MeasureCx<'_, Self>) -> Vec2 {
|
||||
let role = cx.style.text.role;
|
||||
let title = cx.layout(&TextRun::new(cx.resolved.label).role(role)).galley.size();
|
||||
let subtitle = self.subtitle.as_ref().map(|subtitle| cx.layout(&subtitle_run(subtitle.as_str(), role)).galley.size().x);
|
||||
let width = |run: &TextRun<'_>| cx.layout(run).galley.size().x + cx.gap();
|
||||
let note = self.note.as_ref().map_or(0.0, |note| width(¬e_run(note.as_str())));
|
||||
let subtitle = self.subtitle.as_ref().map_or(0.0, |subtitle| width(&subtitle_run(subtitle.as_str())));
|
||||
let parts =
|
||||
usize::from(self.has_lead()) + usize::from(self.icon.is_some()) + usize::from(self.handle) + self.commands.len() + self.actions.len();
|
||||
// The parts are square on the row's height, which the height token can raise above the text's.
|
||||
let side = title.y.max(cx.style.metrics.min_size.y);
|
||||
let text = title.x + subtitle.map_or(0.0, |width| width + cx.gap());
|
||||
let text = title.x + note + subtitle;
|
||||
let lead = if self.has_lead() { self.lead_side(side, cx.style.disclosure) - side } else { 0.0 };
|
||||
let natural = text + side * parts as f32 + cx.gap() * parts as f32 + lead;
|
||||
// A row takes the room it is offered, a filling row all of it, and never more: the title elides to what is left.
|
||||
@@ -473,8 +485,11 @@ impl Component for TitleRow<'_> {
|
||||
title = title.color(cx.resolve(&cx.style.text.color));
|
||||
}
|
||||
ui.draw().text_on_centre_line(placed.title, &title);
|
||||
if let (Some(rect), Some(note)) = (placed.note, &self.note) {
|
||||
ui.draw().text_on_centre_line(rect, ¬e_run(note.as_str()));
|
||||
}
|
||||
if let (Some(rect), Some(subtitle)) = (placed.subtitle, &self.subtitle) {
|
||||
ui.draw().text_on_centre_line(rect, &subtitle_run(subtitle.as_str(), role));
|
||||
ui.draw().text_on_centre_line(rect, &subtitle_run(subtitle.as_str()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -487,6 +502,12 @@ impl Component for TitleRow<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
fn subtitle_run(subtitle: &str, role: TypeRole) -> TextRun<'_> {
|
||||
TextRun::spans(vec![Span::new(subtitle).muted()]).role(role)
|
||||
/// The note after the title: "· note" in muted body text.
|
||||
fn note_run(note: &str) -> TextRun<'static> {
|
||||
TextRun::spans(vec![Span::new(format!("\u{b7} {note}")).muted()]).role(TypeRole::Body)
|
||||
}
|
||||
|
||||
/// The subtitle at the band's end, in muted caption text.
|
||||
fn subtitle_run(subtitle: &str) -> TextRun<'_> {
|
||||
TextRun::spans(vec![Span::new(subtitle).muted()]).role(TypeRole::Caption)
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ use egui::{AsIdSalt, IdSalt, Ui};
|
||||
#[cfg(feature = "testing")]
|
||||
mod stories;
|
||||
|
||||
/// A properties panel: a `Panel` whose header names the target (icon, name and, after it, the kind), and whose body
|
||||
/// A properties panel: a `Panel` whose header names the target (icon and name, and the kind at the end), and whose body
|
||||
/// the caller fills with the target's controls, labelled as inspector rows (`LabelScheme::Inspector`).
|
||||
///
|
||||
/// - Target: [`target`](Inspector::target) gives the key of what is inspected. Every control of the body gets its id
|
||||
@@ -60,7 +60,7 @@ impl<'a> Inspector<'a> {
|
||||
self
|
||||
}
|
||||
|
||||
/// The target's kind, after its name; a header too narrow for both drops it first.
|
||||
/// The target's kind, at the header's end in muted caption text; a header too narrow for both drops it first.
|
||||
#[must_use]
|
||||
pub fn kind(mut self, kind: impl Into<Label>) -> Self {
|
||||
self.kind = Some(kind.into());
|
||||
|
||||
@@ -67,7 +67,7 @@ Generated by `cargo run -p craft-ui-gallery --bin components-index`; edit the do
|
||||
| `ReorderableSections<'_>` | Pattern | `craft_ui_panels::sections::reorderable` | Sidebar sections the user folds, hides, pins and reorders, over the host's [`SectionLayout`] |
|
||||
| `Section<'_>` | Body | `craft_ui_panels::sections::section` | An inline section of a panel that fills the width offered: a rule over a section-strength title row over a body |
|
||||
| `SectionStack<'_, u8>` | Body | `craft_ui_panels::sections::stack` | Sections in the order of `order`, each shown by the caller's closure as a `Section::in_stack` |
|
||||
| `TitleRow<'_>` | Leaf | `craft_ui_panels::sections::title_row` | An optional icon, a title with an optional subtitle, a lead (a disclosure bound to the container's open state, or a check box bound to its gate) and action parts |
|
||||
| `TitleRow<'_>` | Leaf | `craft_ui_panels::sections::title_row` | An optional icon, a title with an optional note run on after it ("· note", muted body text) and an optional subtitle at the band's end (muted caption text: the target's kind), a lead (a disclosure bound to the container's open state, or a check box bound to its gate) and action parts |
|
||||
| `DockArea<'_, usize>` | Pattern | `craft_ui_patterns::patterns::dock::area` | The docking pattern over a workspace |
|
||||
| `PaneArea<'_, u32>` | Pattern | `craft_ui_patterns::patterns::dock::panes` | The app's side panes, bottom panes and floating panes around its document |
|
||||
| `PaneFrame<'_>` | Body | `craft_ui_patterns::patterns::dock::panes` | A docked pane: a shell pane on one edge of the area, with a title row and a scrolling body |
|
||||
@@ -95,7 +95,7 @@ Generated by `cargo run -p craft-ui-gallery --bin components-index`; edit the do
|
||||
| `CanvasSize<'_>` | Pattern | `craft_ui_patterns::patterns::form_dialogs::sizing::canvas` | Canvas Size: the current size, the new width and height with a unit each (no chain: the sides are independent), the Relative box, the 3 by 3 anchor and the colour that fills a larger canvas |
|
||||
| `ImageSize<'_>` | Pattern | `craft_ui_patterns::patterns::form_dialogs::sizing::image` | Image Size: the width, height and resolution with a unit each, the chain that keeps the proportions, Resample with its method list and Scale Styles, over a readout of the file size and the dimensions |
|
||||
| `Watermark<'_>` | Pattern | `craft_ui_patterns::patterns::form_dialogs::watermark` | The watermark rows of an export dialog: Style (Text, Graphic), the text field or the image path with Choose…, Orientation, Position as the 3 by 3 reference point, Rotation, Size, Opacity, Inset X and Y, and Shadow |
|
||||
| `Inspector<'_>` | Pattern | `craft_ui_patterns::patterns::panels::inspector` | A properties panel: a `Panel` whose header names the target (icon, name and, after it, the kind), and whose body the caller fills with the target's controls, labelled as inspector rows (`LabelScheme::Inspector`) |
|
||||
| `Inspector<'_>` | Pattern | `craft_ui_patterns::patterns::panels::inspector` | A properties panel: a `Panel` whose header names the target (icon and name, and the kind at the end), and whose body the caller fills with the target's controls, labelled as inspector rows (`LabelScheme::Inspector`) |
|
||||
| `CommandPalette<'_>` | Pattern | `craft_ui_patterns::patterns::panels::palette` | A search over the app's commands in a centred modal box: a search field over the matching commands |
|
||||
| `Tour<'_>` | Pattern | `craft_ui_patterns::patterns::panels::tour` | A guided tour of the interface: a card with the step count and a close button, the step's heading and text, Skip, Back and Next (Done on the last step), beside the part the step points at, which a pulsing ring marks |
|
||||
| `PreferencesWindow<'_>` | Pattern | `craft_ui_patterns::patterns::preferences::window` | The preferences window: a search field over a page list and the shown page, with OK, Cancel and Apply under them |
|
||||
|
||||
Reference in New Issue
Block a user