mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 19:14:26 +00:00
Look align: text parts ignore the host's egui size floor; options bars at the standard control size; selects in a bar fit their widest entry; check box labels in body type; title band glyphs at size.icon.sm with a faint kind caption; Inspector names its target at section weight; Transform fields fill two columns, W and H first
This commit is contained in:
@@ -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<M: Value> 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<M>, 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));
|
||||
}
|
||||
|
||||
@@ -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::<Bases>() = 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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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()));
|
||||
|
||||
@@ -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<Label>,
|
||||
/// Text at the end of the title band, in muted caption text: the kind of what the title names ("Pixel layer").
|
||||
/// Text at the end of the title band, in faint 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.
|
||||
@@ -289,19 +290,19 @@ impl<'a> TitleRow<'a> {
|
||||
if matches!(self.lead, Lead::Disclosure(_)) {
|
||||
band = band.take_start(cx.gap()).1;
|
||||
}
|
||||
let side = band.rect().height();
|
||||
let side = cx.style.icon.side;
|
||||
let mut handle = None;
|
||||
if self.handle {
|
||||
let (slot, rest) = band.take_end(side);
|
||||
let (_, rest) = rest.take_end(cx.gap());
|
||||
handle = Some(slot);
|
||||
handle = Some(Rect::from_center_size(slot.center(), Vec2::splat(side)));
|
||||
band = rest;
|
||||
}
|
||||
let mut icon = None;
|
||||
if self.icon.is_some() {
|
||||
let (slot, rest) = band.take_start(side);
|
||||
let (_, rest) = rest.take_start(cx.gap());
|
||||
icon = Some(slot);
|
||||
icon = Some(Rect::from_center_size(slot.center(), Vec2::splat(side)));
|
||||
band = rest;
|
||||
}
|
||||
let width = |run: &TextRun<'_>| cx.layout_at(run, f32::INFINITY).galley.size().x;
|
||||
@@ -309,7 +310,7 @@ impl<'a> TitleRow<'a> {
|
||||
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()));
|
||||
let side = width(&subtitle_run(text.as_str(), cx.style.subtitle.role));
|
||||
if title + note + cx.gap() + side <= band.rect().width() {
|
||||
let (slot, rest) = band.take_end(side);
|
||||
subtitle = Some(slot);
|
||||
@@ -344,8 +345,11 @@ impl Component for TitleRow<'_> {
|
||||
TitleRowStyle {
|
||||
metrics: Metrics::new().min_size(Vec2::new(0.0, height)).gap(cx.control().gap),
|
||||
text: TextLook::new(role, Stateful::new(shade).off(States::new(shade, shade, shade, disabled))),
|
||||
icon: IconLook::new(cx.control().icon, Stateful::new(ink).off(States::new(ink, ink, ink, disabled))),
|
||||
disclosure: cx.tokens.size.icon.sm,
|
||||
icon: IconLook::new(cx.tokens.size.icon.sm, Stateful::new(ink).off(States::new(ink, ink, ink, disabled))),
|
||||
subtitle: {
|
||||
let faint = cx.color(text.faint);
|
||||
TextLook::new(TypeRole::Caption, Stateful::new(faint).off(States::new(faint, faint, faint, disabled)))
|
||||
},
|
||||
action: cx.control().height,
|
||||
}
|
||||
}
|
||||
@@ -355,14 +359,14 @@ impl Component for TitleRow<'_> {
|
||||
let title = cx.layout(&TextRun::new(cx.resolved.label).role(role)).galley.size();
|
||||
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();
|
||||
let subtitle = self.subtitle.as_ref().map_or(0.0, |subtitle| width(&subtitle_run(subtitle.as_str(), cx.style.subtitle.role)));
|
||||
let parts = usize::from(self.has_lead()) + self.commands.len() + self.actions.len();
|
||||
let glyphs = usize::from(self.icon.is_some()) + usize::from(self.handle);
|
||||
// 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 + 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;
|
||||
let lead = if self.has_lead() { self.lead_side(side, cx.style.icon.side) - side } else { 0.0 };
|
||||
let natural = text + (side + cx.gap()) * parts as f32 + (cx.style.icon.side + cx.gap()) * glyphs 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.
|
||||
let width = cx.room.map_or(natural, |room| if self.fill { room } else { natural.min(room) });
|
||||
Vec2::new(width, title.y)
|
||||
@@ -377,7 +381,7 @@ impl Component for TitleRow<'_> {
|
||||
let side = rect.height();
|
||||
let mut flow = Flow::new(rect, cx.flow.is_rtl());
|
||||
if self.has_lead() {
|
||||
let (lead, rest) = flow.take_start(self.lead_side(side, cx.style.disclosure));
|
||||
let (lead, rest) = flow.take_start(self.lead_side(side, cx.style.icon.side));
|
||||
cx.part(LEAD, lead).sense(Sense::CLICK | Sense::FOCUS).focusable();
|
||||
flow = rest;
|
||||
}
|
||||
@@ -496,7 +500,8 @@ impl Component for TitleRow<'_> {
|
||||
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()));
|
||||
let run = subtitle_run(subtitle.as_str(), cx.style.subtitle.role).color(cx.resolve(&cx.style.subtitle.color));
|
||||
ui.draw().text_on_centre_line(rect, &run);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -514,7 +519,7 @@ 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)
|
||||
/// The subtitle at the band's end in `role`; the paint gives it the style's colour.
|
||||
fn subtitle_run(subtitle: &str, role: TypeRole) -> TextRun<'_> {
|
||||
TextRun::new(subtitle).role(role)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::contract::{BodyCx, LabelScheme, Pad, Props as _, Show as _, ShowConta
|
||||
use crate::notices::{Notice, NoticeLayout};
|
||||
use crate::primitives::IconSpec;
|
||||
use crate::runtime::env::{Env, Label};
|
||||
use crate::sections::{HeaderAction, MenuRows, Panel, PanelOutput};
|
||||
use crate::sections::{HeaderAction, HeaderStrength, MenuRows, Panel, PanelOutput};
|
||||
use craft_theme::variant::Tone;
|
||||
use egui::{AsIdSalt, IdSalt, Ui};
|
||||
|
||||
@@ -61,7 +61,7 @@ impl<'a> Inspector<'a> {
|
||||
self
|
||||
}
|
||||
|
||||
/// The target's kind, at the header's end in muted caption text; a header too narrow for both drops it first.
|
||||
/// The target's kind, at the header's end in faint 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());
|
||||
@@ -94,7 +94,8 @@ impl<'a> Inspector<'a> {
|
||||
let Inspector { label, target, icon, name, kind, empty, actions, menu } = self;
|
||||
let shown = target.is_some();
|
||||
let title = if shown { name.unwrap_or(label) } else { label };
|
||||
let mut panel = Panel::new(title).titled().actions(actions).labels(LabelScheme::Inspector).pad(Pad::None);
|
||||
// The target's name carries a section heading's weight, as the headings of the sections under it do.
|
||||
let mut panel = Panel::new(title).titled().strength(HeaderStrength::Section).actions(actions).labels(LabelScheme::Inspector).pad(Pad::None);
|
||||
if shown {
|
||||
if let Some(icon) = icon {
|
||||
panel = panel.icon(icon);
|
||||
|
||||
@@ -74,8 +74,8 @@ impl Outcome for BarOutput {
|
||||
}
|
||||
}
|
||||
|
||||
/// A bar over a chrome surface whose body holds the members in reading order: a tool bar's at the standard control
|
||||
/// size, an options or status bar's at the small one. They are one roving group unless the bar is made of
|
||||
/// A bar over a chrome surface whose body holds the members in reading order: a tool or options bar's at the standard
|
||||
/// control size, a status bar's at the small one. They are one roving group unless the bar is made of
|
||||
/// [`tab_stops`](Bar::tab_stops). The bar is as tall as its tallest member plus the control padding, and takes the
|
||||
/// width it is offered. On the line of a row given its height (a top or bottom slot of the shell) it fills that height
|
||||
/// and its members sit on the line's middle, with its padding at the start and end only. A bar of one row lays its body out as a row; a bar of several rows as a stack whose rows the
|
||||
@@ -111,7 +111,7 @@ impl<'a> Bar<'a> {
|
||||
BarKind::Status => Gap::Section,
|
||||
};
|
||||
let pad = if kind == BarKind::Options { Pad::Regular } else { Pad::Control };
|
||||
let size = if kind == BarKind::Tool { ControlSize::Md } else { ControlSize::Sm };
|
||||
let size = if kind == BarKind::Status { ControlSize::Sm } else { ControlSize::Md };
|
||||
let mut props = ContainerProps::new()
|
||||
.surface(SurfaceKind::Chrome)
|
||||
.pad(pad)
|
||||
|
||||
@@ -7,7 +7,6 @@ use crate::display::{Divider, Icon};
|
||||
use crate::primitives::IconSpec;
|
||||
use crate::runtime::env::Label;
|
||||
use craft_behavior::IconId;
|
||||
use craft_theme::ControlSize;
|
||||
use egui::{Response, Ui};
|
||||
|
||||
/// The Home button at the start of an options bar: a toggle with the home icon at the standard control size, as tall
|
||||
@@ -35,12 +34,7 @@ impl<'a> BarHome<'a> {
|
||||
|
||||
/// Shows the button and the rule after it.
|
||||
pub fn show(self, ui: &mut Ui) -> EditResponse<bool> {
|
||||
let shown = ToggleButton::new(self.label, self.on)
|
||||
.icon(IconSpec::svg(IconId::new("home")))
|
||||
.icon_only()
|
||||
.size(ControlSize::Md)
|
||||
.enabled(self.enabled)
|
||||
.show(ui);
|
||||
let shown = ToggleButton::new(self.label, self.on).icon(IconSpec::svg(IconId::new("home"))).icon_only().enabled(self.enabled).show(ui);
|
||||
Divider::vertical().show(ui);
|
||||
shown
|
||||
}
|
||||
@@ -87,7 +81,7 @@ impl BarTool {
|
||||
|
||||
/// Shows the icon, its arrow and the rule after them.
|
||||
pub fn show(self, ui: &mut Ui) -> BarToolOutput {
|
||||
let shown: ButtonOutput = IconButton::new(self.icon).label(self.label).size(ControlSize::Md).enabled(self.enabled).show(ui);
|
||||
let shown: ButtonOutput = IconButton::new(self.icon).label(self.label).enabled(self.enabled).show(ui);
|
||||
Icon::new(DisclosureGlyph::dropdown()).enabled(self.enabled).show(ui);
|
||||
Divider::vertical().show(ui);
|
||||
BarToolOutput { response: shown.response }
|
||||
|
||||
@@ -12,7 +12,7 @@ use super::words::PickerWords;
|
||||
use crate::buttons::IconButton;
|
||||
use crate::contract::overlay::{Popup, Trigger};
|
||||
use crate::contract::{
|
||||
Access, Bind, BindMut, BodyCx, CollectionEvent, Common, Component, Cx, Edit as _, EditResponse, Entry, Focus as _, LeadOnOpen, LeadSource,
|
||||
Access, Bind, BindMut, BodyCx, CollectionEvent, Common, Component, Cx, Edit as _, EditResponse, Entry, Focus as _, InBar, LeadOnOpen, LeadSource,
|
||||
MeasureCx, Numeric, Overlay, OverlayUi, Overlays as _, PaintUi, PartsCx, Pointer as _, PopupHandle, PopupKind, Props as _, Role, Show as _,
|
||||
ShowCollection as _, ShowContainer as _, Sizing, WordSetCx as _, step_stop, step_stops,
|
||||
};
|
||||
@@ -186,9 +186,13 @@ impl<'a, T: Value + 'static> Select<'a, T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a select's faces fit their text: only a select sized to its content.
|
||||
fn fits(sizing: Option<Sizing>) -> bool {
|
||||
sizing == Some(Sizing::Content)
|
||||
/// Whether a select's faces fit their text: a select sized to its content, and one in a bar (`InBar`) that sets no
|
||||
/// sizing of its own.
|
||||
fn fits(sizing: Option<Sizing>, in_bar: bool) -> bool {
|
||||
match sizing {
|
||||
Some(sizing) => sizing == Sizing::Content,
|
||||
None => in_bar,
|
||||
}
|
||||
}
|
||||
|
||||
/// The stop a move over the closed field reaches: `stops` are the positions of the stepped entries and `from` the
|
||||
@@ -231,7 +235,7 @@ impl<T: Value + 'static> Component for Select<'_, T> {
|
||||
let mixed = cx.words::<PickerWords>().mixed.clone();
|
||||
let entries = self.entries.iter().filter(|entry| entry.is_item()).map(|entry| (entry.face_label(), true));
|
||||
let texts = entries.chain(self.placeholder.iter().map(|text| (text, false))).chain(std::iter::once((&mixed, false)));
|
||||
let fit = fits(cx.resolved.sizing());
|
||||
let fit = fits(cx.resolved.sizing(), cx.env.get::<InBar>().0);
|
||||
texts.map(|(text, picture)| cx.face(self.sized_face(cx.env.resolve(text), picture, fit))).fold(Vec2::ZERO, Vec2::max)
|
||||
}
|
||||
|
||||
@@ -377,7 +381,7 @@ impl<T: Value + 'static> Component for Select<'_, T> {
|
||||
None if cx.value().is_none() => (cx.env.resolve(&cx.words::<PickerWords>().mixed.clone()), true),
|
||||
None => (self.placeholder.as_ref().map_or(Label::Empty, |text| cx.env.resolve(text)), true),
|
||||
};
|
||||
let mut face = SelectFace::new(text).fit(fits(cx.resolved.sizing()));
|
||||
let mut face = SelectFace::new(text).fit(fits(cx.resolved.sizing(), cx.env.get::<InBar>().0));
|
||||
if let Some(icon) = held.and_then(|at| self.entries[at].icon_spec()) {
|
||||
face = face.leading(icon.clone());
|
||||
}
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
//! Vertical placement of the line in a control.
|
||||
|
||||
use craft_theme::ControlSize;
|
||||
use craft_ui::buttons::Button;
|
||||
use craft_ui::contract::{Bind, Entry, Show as _};
|
||||
use craft_ui::contract::{Bind, Entry, Props as _, Show as _};
|
||||
use craft_ui::pickers::Select;
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
use craft_ui::text::{NumberField, TextField};
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
/// The single line of a button, select, text field and number field sits at the vertical centre of its box. Guards
|
||||
/// against a field style whose padding put the top inset where the end inset belongs, and a select that painted top aligned.
|
||||
/// The single line of a button, select, text field and number field sits at the vertical centre of its box, at either
|
||||
/// control size. Guards against a field style whose padding put the top inset where the end inset belongs, a select that
|
||||
/// painted top aligned, and a text part that took the host's egui `interact_size` as its least height: an app's own
|
||||
/// egui theme sets it taller than a small field, and the text then sat low.
|
||||
#[trial]
|
||||
fn a_single_line_is_centred_in_its_control() {
|
||||
let boxes: Rc<RefCell<Vec<(&'static str, egui::Rect)>>> = Rc::default();
|
||||
@@ -17,6 +20,7 @@ fn a_single_line_is_centred_in_its_control() {
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let mut v = b.borrow_mut();
|
||||
v.clear();
|
||||
ui.spacing_mut().interact_size = egui::vec2(24.0, 32.0);
|
||||
v.push(("button", Button::new("Hamburg").show(ui).rect));
|
||||
let entries = [Entry::new(0u8, "Hamburg"), Entry::new(1, "Multiply")];
|
||||
let mut mode = 0u8;
|
||||
@@ -24,6 +28,8 @@ fn a_single_line_is_centred_in_its_control() {
|
||||
let mut t = String::from("Hamburg");
|
||||
v.push(("text", TextField::new("T", Bind::bound(&mut t)).show(ui).response.rect));
|
||||
v.push(("number", NumberField::new("N", Bind::bound(&mut Some(12.0f64))).show(ui).response.rect));
|
||||
v.push(("small text", TextField::new("S", Bind::bound(&mut t)).size(ControlSize::Sm).show(ui).response.rect));
|
||||
v.push(("small number", NumberField::new("M", Bind::bound(&mut Some(12.0f64))).size(ControlSize::Sm).show(ui).response.rect));
|
||||
});
|
||||
fixture.settle();
|
||||
fixture.idle(3);
|
||||
|
||||
@@ -84,3 +84,23 @@ fn settled_in(mut body: impl FnMut(&mut Ui) + 'static) -> Fixture {
|
||||
fixture.settle();
|
||||
fixture
|
||||
}
|
||||
|
||||
/// A check box's label reads in body type, as a select's face does, and shares its baseline: in an options bar,
|
||||
/// "Anti-alias" after its box lines up with the select beside it. Guards against the label's text taking the caption
|
||||
/// role, which set it smaller and off the face's line.
|
||||
#[trial]
|
||||
fn a_check_box_label_shares_the_line_of_a_face_beside_it() {
|
||||
use craft_ui::bars::{Bar, BarKind};
|
||||
use craft_ui::contract::Entry;
|
||||
use craft_ui::pickers::Select;
|
||||
let mut fixture = Fixture::new(|ui| {
|
||||
Bar::new("Options", BarKind::Options).show(ui, |ui, _| {
|
||||
Checkbox::new(Bind::given(true)).label("Anti-alias").id_salt("smooth").show(ui);
|
||||
let entries = [Entry::new(0u8, "Layer"), Entry::new(1, "Group")];
|
||||
Select::new("Target", Bind::given(0u8), &entries).show(ui);
|
||||
});
|
||||
});
|
||||
fixture.settle();
|
||||
let (label, face) = (baseline_of(&fixture, "Anti-alias"), baseline_of(&fixture, "Layer"));
|
||||
assert!((label - face).abs() <= 0.5, "the check box label lines up with the select's text: label {label}, select {face}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user