diff --git a/crates/draw/src/ui/paint_bar.rs b/crates/draw/src/ui/paint_bar.rs index f5e9f18ce..74a61e601 100644 --- a/crates/draw/src/ui/paint_bar.rs +++ b/crates/draw/src/ui/paint_bar.rs @@ -4,7 +4,6 @@ use std::cell::RefCell; use std::sync::Arc; use craft_behavior::{EditEvent, EditEvents, IconId, Mixed, Value}; -use craft_theme::ControlSize; use craft_theme::Srgba; use craft_ui::buttons::{IconButton, ToggleButton}; use craft_ui::choice::{Checkbox, Swatch}; @@ -349,12 +348,7 @@ impl Pass<'_, M> { /// A pen toggle over a flag: an icon button that stays pressed while on, named `caption`; a click is one `Set`. fn toggle(&mut self, ui: &mut Ui, icon: &'static str, caption: &Label, enabled: bool, current: bool, set: fn(&mut PaintValues, bool)) { - let shown = ToggleButton::new(caption.clone(), Bind::given(current)) - .icon(IconId::new(icon)) - .icon_only() - .size(ControlSize::Md) - .enabled(enabled) - .show(ui); + let shown = ToggleButton::new(caption.clone(), Bind::given(current)).icon(IconId::new(icon)).icon_only().enabled(enabled).show(ui); if let Some(next) = shown.value().copied() { self.set_with(caption, |v| set(v, next)); } diff --git a/crates/draw/src/ui/transform/transform_fields.rs b/crates/draw/src/ui/transform/transform_fields.rs index 42fdc7dd7..13b83c1b4 100644 --- a/crates/draw/src/ui/transform/transform_fields.rs +++ b/crates/draw/src/ui/transform/transform_fields.rs @@ -12,7 +12,7 @@ use super::session::Interpolation; use super::session_bar::TransformBarWords; use craft_behavior::geometry::quad::BoxState; use craft_behavior::kurbo::Rect; -use craft_behavior::{EditEvent, EditEvents, GestureId, IconId, Mixed, RulerUnits}; +use craft_behavior::{ColumnWidth, EditEvent, EditEvents, GestureId, IconId, Mixed, RulerUnits}; use craft_ui::buttons::ToggleButton; use craft_ui::canvas::RulerText; use craft_ui::contract::{ @@ -20,7 +20,7 @@ use craft_ui::contract::{ }; use craft_ui::display::Divider; use craft_ui::form::{Field, FieldGroup}; -use craft_ui::layout_components::Row; +use craft_ui::layout_components::{Grid, Row, Stack}; use craft_ui::menu::Menu; use craft_ui::pickers::{Anchor9, ReferencePoint, Select}; use craft_ui::runtime::env::{Env, Label, UnitKind, Units}; @@ -191,8 +191,9 @@ impl Outcome for TransformFieldsOutput { /// the whole row, the V skew included. /// - **W and H unit.** With [`size_units`](Self::size_units), a secondary click, the Menu key or Shift+F10 on W or H /// opens a menu of the units; a pick is [`TransformFieldsOutput::unit_picked`]. -/// - **Panel form** (the default): the compact reference point with X and Y on one row, W, the link and H on the -/// next, the angle, then the H and V skews on one row. [`groups`](Self::groups) leaves out the rows of hidden groups. +/// - **Panel form** (the default): two field columns that fill the width, the link's column between them: W, the +/// link and H on one row, X and Y on the next, the angle, then the H and V skews; the compact reference point, when +/// shown, leads the first row. [`groups`](Self::groups) leaves out the rows of hidden groups. /// - **Bar form** ([`bar`](Self::bar)): the compact reference point, then captioned fields in Photoshop's order with a /// divider between the groups, the Δ toggle between X and Y, the interpolation select last. /// [`groups`](Self::groups) narrows the strip. @@ -357,6 +358,16 @@ struct Cells<'a> { out: Out, } +/// The panel form's columns: a field, the link, a field; the fields share the width. +static FIELD_COLUMNS: [ColumnWidth; 3] = [ColumnWidth::fill(1.0), ColumnWidth::Content, ColumnWidth::fill(1.0)]; +/// The panel form's columns with the reference point before them. +static REFERENCE_COLUMNS: [ColumnWidth; 4] = [ColumnWidth::Content, ColumnWidth::fill(1.0), ColumnWidth::Content, ColumnWidth::fill(1.0)]; + +/// A grid cell with nothing in it. +fn empty(ui: &mut Ui) { + Stack::new().show(ui, |_, _| {}); +} + /// The pass's shared facts, read before the cells. struct Pass { before: TransformRow, @@ -403,8 +414,8 @@ impl Cells<'_> { (side.scrub(true), name.clone()) } - /// One captioned field. Returns the field's event lifted to the row. - fn field(&mut self, ui: &mut Ui, cx: &mut BodyCx<'_>, pass: &mut Pass, field: TransformField) { + /// One captioned field at `sizing`. Returns the field's event lifted to the row. + fn field(&mut self, ui: &mut Ui, cx: &mut BodyCx<'_>, pass: &mut Pass, field: TransformField, sizing: Sizing) { let (side, name) = self.side_and_name(field); let conversion = &pass.conversion; let (kind, decimals) = conversion.format(field); @@ -419,7 +430,7 @@ impl Cells<'_> { let menu = self.size_units.filter(|_| matches!(field, TransformField::W | TransformField::H)); let mut events = EditEvents::new(); let mut picked = None; - Field::new(name.clone()).id_salt(field.key()).enabled(self.enabled).side(side).sizing(Sizing::Content).show(ui, |ui, _| { + Field::new(name.clone()).id_salt(field.key()).enabled(self.enabled).side(side).sizing(sizing).show(ui, |ui, _| { let mut number = NumberField::new(name.clone(), Bind::given(Some(current))) .range(-bound..=bound) .codec(codec.clone()) @@ -484,15 +495,6 @@ impl Cells<'_> { } } - /// W, the link and H in one row. - fn size(&mut self, ui: &mut Ui, cx: &mut BodyCx<'_>, pass: &mut Pass) { - Row::new().show(ui, |ui, _| { - self.field(ui, cx, pass, TransformField::W); - self.link(ui); - self.field(ui, cx, pass, TransformField::H); - }); - } - /// The interpolation select. fn interpolation(&mut self, ui: &mut Ui) { let Some(bind) = self.interpolation.as_mut() else { return }; @@ -514,36 +516,61 @@ impl Cells<'_> { } } - /// The panel form: the compact reference point with X and Y, W with the link and H, the angle, the two skews. + /// The panel form: one grid whose two field columns fill the width, with the link's column between them. W, the + /// link and H, then X and Y, the angle, then the two skews; the reference point, when shown, leads the first row + /// in a column of its own. A row with nothing in a column shows an empty cell there. fn rows(&mut self, ui: &mut Ui, cx: &mut BodyCx<'_>) { let mut pass = self.pass(cx); let groups = self.groups; - if groups.reference || groups.position { - Row::new().id_salt("position").show(ui, |ui, _| { - if groups.reference { - self.reference(ui, cx, &pass, true); - } + let columns: &'static [ColumnWidth] = if groups.reference { &REFERENCE_COLUMNS } else { &FIELD_COLUMNS }; + let fill = Sizing::FillWidth; + Grid::new(columns).id_salt("fields").fill_width().show(ui, |ui, _| { + let mut first = true; + if groups.size { + self.lead(ui, cx, &pass, &mut first); + self.field(ui, cx, &mut pass, TransformField::W, fill); + self.link(ui); + self.field(ui, cx, &mut pass, TransformField::H, fill); + } + if groups.position || (groups.reference && first) { + self.lead(ui, cx, &pass, &mut first); if groups.position { - self.field(ui, cx, &mut pass, TransformField::X); - self.field(ui, cx, &mut pass, TransformField::Y); + self.field(ui, cx, &mut pass, TransformField::X, fill); + empty(ui); + self.field(ui, cx, &mut pass, TransformField::Y, fill); + } else { + (0..3).for_each(|_| empty(ui)); } - }); - } - if groups.size { - self.size(ui, cx, &mut pass); - } - if groups.angle { - self.field(ui, cx, &mut pass, TransformField::Angle); - } - if groups.skew { - Row::new().id_salt("skew").show(ui, |ui, _| { - self.field(ui, cx, &mut pass, TransformField::SkewH); - self.field(ui, cx, &mut pass, TransformField::SkewV); - }); - } + } + if groups.angle { + self.lead(ui, cx, &pass, &mut first); + self.field(ui, cx, &mut pass, TransformField::Angle, fill); + empty(ui); + empty(ui); + } + if groups.skew { + self.lead(ui, cx, &pass, &mut first); + self.field(ui, cx, &mut pass, TransformField::SkewH, fill); + empty(ui); + self.field(ui, cx, &mut pass, TransformField::SkewV, fill); + } + }); *cx.memory::() = pass.bases; } + /// The panel form's leading cell of a row, while the reference point shows: the point on the first row, an empty + /// cell below it. + fn lead(&mut self, ui: &mut Ui, cx: &mut BodyCx<'_>, pass: &Pass, first: &mut bool) { + if !self.groups.reference { + return; + } + if std::mem::take(first) { + self.reference(ui, cx, pass, true); + } else { + empty(ui); + } + } + /// The options-bar form: the compact reference point, X and Y, W with the link and H, the angle and the skews, the /// interpolation, with a divider between the groups shown. fn bar(&mut self, ui: &mut Ui, cx: &mut BodyCx<'_>) { @@ -560,23 +587,23 @@ impl Cells<'_> { self.reference(ui, cx, &pass, true); } if groups.position { - self.field(ui, cx, &mut pass, TransformField::X); + self.field(ui, cx, &mut pass, TransformField::X, Sizing::Content); self.relative_toggle(ui); - self.field(ui, cx, &mut pass, TransformField::Y); + self.field(ui, cx, &mut pass, TransformField::Y, Sizing::Content); any.set(true); } if divide(ui, groups.size) { - self.field(ui, cx, &mut pass, TransformField::W); + self.field(ui, cx, &mut pass, TransformField::W, Sizing::Content); self.link(ui); - self.field(ui, cx, &mut pass, TransformField::H); + self.field(ui, cx, &mut pass, TransformField::H, Sizing::Content); } if divide(ui, groups.angle || groups.skew) { if groups.angle { - self.field(ui, cx, &mut pass, TransformField::Angle); + self.field(ui, cx, &mut pass, TransformField::Angle, Sizing::Content); } if groups.skew { - self.field(ui, cx, &mut pass, TransformField::SkewH); - self.field(ui, cx, &mut pass, TransformField::SkewV); + self.field(ui, cx, &mut pass, TransformField::SkewH, Sizing::Content); + self.field(ui, cx, &mut pass, TransformField::SkewV, Sizing::Content); } } if self.interpolation.is_some() && divide(ui, groups.interpolation) { diff --git a/crates/ui-contract/src/contract/label/leaf.rs b/crates/ui-contract/src/contract/label/leaf.rs index ad573beb5..e449920db 100644 --- a/crates/ui-contract/src/contract/label/leaf.rs +++ b/crates/ui-contract/src/contract/label/leaf.rs @@ -179,7 +179,7 @@ impl Component for LabelLeaf { } fn measure(&mut self, cx: &MeasureCx<'_, Self>) -> Vec2 { - let line = cx.layout(&TextRun::new(cx.resolved.label)); + let line = cx.layout(&TextRun::new(cx.resolved.label).role(cx.style.name.role)); let name = line.size(); if let Some(glyph) = &self.glyph { let (shown, baseline) = match glyph { @@ -207,7 +207,7 @@ impl Component for LabelLeaf { craft_behavior::Proposal::Width(width) => Some(width), _ => cx.room, }; - let colon = self.colon.as_deref().map_or(0.0, |colon| cx.layout(&TextRun::new(colon)).size().x); + let colon = self.colon.as_deref().map_or(0.0, |colon| cx.layout(&TextRun::new(colon).role(cx.style.name.role)).size().x); let icon = if self.icon.is_some() { cx.style.icon + cx.style.gap } else { 0.0 }; let trailing = self.trailing_width(cx.style.gap); // A name wider than the room the icon, colon, content and slot leave wraps there. @@ -217,7 +217,7 @@ impl Component for LabelLeaf { { let left = (room - self.slot - icon - colon - trailing).max(0.0); if name.x > left { - name = cx.layout_at(&TextRun::new(cx.resolved.label).wrap(Wrap::Wrap), left).size(); + name = cx.layout_at(&TextRun::new(cx.resolved.label).role(cx.style.name.role).wrap(Wrap::Wrap), left).size(); } } let wrapped = name.y > line.size().y; @@ -301,9 +301,9 @@ impl Component for LabelLeaf { let icon_of = |icon: &IconSpec<'static>| IconSpec { color: ink.or(icon.color), ..icon.clone() }; // A wrapped name starts on the first line, which the icon and the content share; a one-line label sits at the // row's vertical centre. - let line = draw.layout(&TextRun::new(cx.core.resolved.label), f32::INFINITY).size(); + let line = draw.layout(&TextRun::new(cx.core.resolved.label).role(cx.style.name.role), f32::INFINITY).size(); let wrapped = self.after && self.glyph.is_none() && { - let colon = self.colon.as_deref().map_or(0.0, |colon| draw.layout(&TextRun::new(colon), f32::INFINITY).size().x); + let colon = self.colon.as_deref().map_or(0.0, |colon| draw.layout(&TextRun::new(colon).role(cx.style.name.role), f32::INFINITY).size().x); let icon = if self.icon.is_some() { cx.style.icon + cx.style.gap } else { 0.0 }; line.x > rest.rect().width() - self.trailing_width(cx.style.gap) - icon - colon }; @@ -346,9 +346,9 @@ impl Component for LabelLeaf { } // A name wider than its room elides, or wraps after its control; the full text stays the accessible name. let name_ink = cx.resolve(&cx.style.name.color); - let colon = self.colon.as_deref().map(|colon| TextRun::new(colon).color(name_ink)); + let colon = self.colon.as_deref().map(|colon| TextRun::new(colon).role(cx.style.name.role).color(name_ink)); let colon_width = colon.as_ref().map_or(0.0, |run| draw.layout(run, f32::INFINITY).size().x); - let run = TextRun::new(cx.core.resolved.label).color(name_ink); + let run = TextRun::new(cx.core.resolved.label).role(cx.style.name.role).color(name_ink); let run = if wrapped { run.wrap(Wrap::Wrap) } else { run.elide() }; let name = draw.layout(&run, (rest.rect().width() - colon_width).max(0.0)).size(); let (name_rect, after) = rest.take_start(name.x); diff --git a/crates/ui-contract/src/runtime/egui/style.rs b/crates/ui-contract/src/runtime/egui/style.rs index f55a8bef9..4285d9b79 100644 --- a/crates/ui-contract/src/runtime/egui/style.rs +++ b/crates/ui-contract/src/runtime/egui/style.rs @@ -22,6 +22,14 @@ pub(crate) fn set_hint_color(ui: &mut Ui, color: egui::Color32) { ui.visuals_mut().weak_text_color = Some(color); } +/// Lets the rect `ui` was given set the height of its text edits: egui raises a text edit to the host's +/// `interact_size` and adds its extra line spacing, which an app's own egui theme sets for its egui widgets. +pub(crate) fn set_text_edit_unfloored(ui: &mut Ui) { + let spacing = ui.spacing_mut(); + spacing.interact_size.y = 0.0; + spacing.extra_text_line_spacing = 0.0; +} + /// Disables `ui` without fading it: the contract already inks a disabled part in its disabled colour, so egui's own /// disabled alpha would dim it a second time. pub(crate) fn disable_without_fade(ui: &mut Ui) { diff --git a/crates/ui-contract/src/runtime/egui/text_edit.rs b/crates/ui-contract/src/runtime/egui/text_edit.rs index 62c935a1b..d9140779a 100644 --- a/crates/ui-contract/src/runtime/egui/text_edit.rs +++ b/crates/ui-contract/src/runtime/egui/text_edit.rs @@ -138,6 +138,7 @@ pub(crate) fn show(ui: &mut Ui, edit: Edit<'_>) -> Shown { // parent's cursor stays past the root, not past the text part inside it. let output = { let ui = &mut super::alloc::child(ui, egui::UiBuilder::new().max_rect(rect)); + super::style::set_text_edit_unfloored(ui); // The text shows only inside the text part, however wide the line is. if galley.is_none() { ui.set_clip_rect(rect.intersect(ui.clip_rect())); diff --git a/crates/ui-panels/src/sections/title_row.rs b/crates/ui-panels/src/sections/title_row.rs index 3c3ec415e..9e8764d99 100644 --- a/crates/ui-panels/src/sections/title_row.rs +++ b/crates/ui-panels/src/sections/title_row.rs @@ -147,17 +147,18 @@ pub struct TitleRowStyle { /// The title's type role and colour. #[style(text)] text: TextLook, - /// The icon before the title. + /// The glyphs of the title band (a disclosure lead's slot, the icon before the title, the drag handle): one side, + /// `size.icon.sm`, a small glyph beside the title. #[style(icon)] icon: IconLook, - /// The width of a disclosure lead's slot: `size.icon.sm`, a small glyph beside the title. - disclosure: f32, + /// The kind at the band's end: caption text in the faint text colour. + subtitle: TextLook, /// The side of an action part: the control height, which is below a tall header's height. action: f32, } /// 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 +/// subtitle at the band's end (faint 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. @@ -179,7 +180,7 @@ pub struct TitleRow<'a> { /// 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