From 9d61d87e46fc920bc6c450d39b8b4a0c082703bf Mon Sep 17 00:00:00 2001 From: aiongg Date: Mon, 16 Nov 2026 18:29:58 +0000 Subject: [PATCH] cargo fmt --- crates/color/src/ui/readout.rs | 4 +- crates/draw/src/ui/paint_bar.rs | 42 +++--- crates/draw/src/ui/shape/bar.rs | 16 +- crates/text/src/ui/style_panel.rs | 137 +++++++++--------- crates/ui-contract/src/layout/body.rs | 9 +- crates/ui-contract/src/style/cx.rs | 3 +- crates/ui-contract/src/style/mod.rs | 4 +- crates/ui-panels/src/dialog/mod.rs | 1 - crates/ui-panels/src/docking/group.rs | 6 +- crates/ui-panels/src/sections/footer.rs | 3 +- crates/ui-panels/src/sections/mod.rs | 4 +- crates/ui-patterns/src/patterns/dock/area.rs | 4 +- .../form_dialogs/save_for_web/options.rs | 5 +- .../src/patterns/form_dialogs/sizing.rs | 3 +- .../patterns/form_dialogs/sizing/canvas.rs | 7 +- .../src/patterns/presets/picker/stories.rs | 4 +- crates/ui-shell/src/shell/app_shell.rs | 4 +- .../ui-widgets/src/bars/constraint_fields.rs | 43 +++--- crates/ui-widgets/src/bars/stories.rs | 3 +- crates/ui-widgets/src/list/row/paint.rs | 4 +- 20 files changed, 146 insertions(+), 160 deletions(-) diff --git a/crates/color/src/ui/readout.rs b/crates/color/src/ui/readout.rs index 781574ea9..34887e221 100644 --- a/crates/color/src/ui/readout.rs +++ b/crates/color/src/ui/readout.rs @@ -144,7 +144,9 @@ impl<'a> ColorReadout<'a> { events.clear(); channel_edits.clear(); let hex = Field::new(words.hex.clone()).side(HexField::hash_label()).sizing(Sizing::Content); - if let Some(out) = hex.show(ui, |ui, _| TextField::hex(words.hex.as_str().to_owned(), Bind::given(held)).sizing(Sizing::Content).show(ui)).inner { + if let Some(out) = + hex.show(ui, |ui, _| TextField::hex(words.hex.as_str().to_owned(), Bind::given(held)).sizing(Sizing::Content).show(ui)).inner + { events.extend(out.events); } Row::new().show(ui, |ui, _| { diff --git a/crates/draw/src/ui/paint_bar.rs b/crates/draw/src/ui/paint_bar.rs index 1f05c95c9..f5e9f18ce 100644 --- a/crates/draw/src/ui/paint_bar.rs +++ b/crates/draw/src/ui/paint_bar.rs @@ -4,8 +4,8 @@ use std::cell::RefCell; use std::sync::Arc; use craft_behavior::{EditEvent, EditEvents, IconId, Mixed, Value}; -use craft_theme::Srgba; use craft_theme::ControlSize; +use craft_theme::Srgba; use craft_ui::buttons::{IconButton, ToggleButton}; use craft_ui::choice::{Checkbox, Swatch}; use craft_ui::contract::{ @@ -349,7 +349,12 @@ 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() + .size(ControlSize::Md) + .enabled(enabled) + .show(ui); if let Some(next) = shown.value().copied() { self.set_with(caption, |v| set(v, next)); } @@ -360,24 +365,21 @@ impl Pass<'_, M> { // The body may run more than once in a pass and only the run that reads the input reports its events, so every // run's events and alert are collected. let collected: RefCell<(EditEvents>, Option)> = RefCell::new((EditEvents::new(), None)); - let _ = Field::new(caption.clone()).side(SideLabel::new().scrub(true)).id_salt(salt).enabled(enabled).show( - ui, - |ui, _| { - let field = NumberField::new(caption.clone(), Bind::given(Some(current * 100.0))) - .unit_kind(UnitKind::Percent) - .range(0.0..=100.0) - .commit_decimals(0) - .scrub_by_label() - .show(ui); - let mut sink = collected.borrow_mut(); - for event in field.edit.events.clone() { - sink.0.push(event); - } - if field.out_of_range.is_some() { - sink.1 = field.out_of_range; - } - }, - ); + let _ = Field::new(caption.clone()).side(SideLabel::new().scrub(true)).id_salt(salt).enabled(enabled).show(ui, |ui, _| { + let field = NumberField::new(caption.clone(), Bind::given(Some(current * 100.0))) + .unit_kind(UnitKind::Percent) + .range(0.0..=100.0) + .commit_decimals(0) + .scrub_by_label() + .show(ui); + let mut sink = collected.borrow_mut(); + for event in field.edit.events.clone() { + sink.0.push(event); + } + if field.out_of_range.is_some() { + sink.1 = field.out_of_range; + } + }); let (events, alert) = collected.into_inner(); if alert.is_some() { self.out_of_range = alert; diff --git a/crates/draw/src/ui/shape/bar.rs b/crates/draw/src/ui/shape/bar.rs index 5c3f9ec28..22f62834b 100644 --- a/crates/draw/src/ui/shape/bar.rs +++ b/crates/draw/src/ui/shape/bar.rs @@ -122,15 +122,11 @@ impl<'a> ShapeBar<'a> { let check = Checkbox::new(Bind::given(fill_on)).label(words.fill.clone()).show(ui).events; pass.events.extend(check.map(ShapeChange::FillOn)); let hidden = SideLabel::new().kind(LabelKind::Hidden); - let fill = Field::new(words.fill_color.clone()) - .id_salt("fill") - .side(hidden) - .show(ui, |ui, _| pass.chip(ui, ShapePaint::Fill)); + let fill = Field::new(words.fill_color.clone()).id_salt("fill").side(hidden).show(ui, |ui, _| pass.chip(ui, ShapePaint::Fill)); if let Some(out) = fill.inner { pass.take_chip(ShapePaint::Fill, out); } - let stroke = - Field::new(words.stroke.clone()).id_salt("stroke").show(ui, |ui, _| pass.chip(ui, ShapePaint::Stroke)); + let stroke = Field::new(words.stroke.clone()).id_salt("stroke").show(ui, |ui, _| pass.chip(ui, ShapePaint::Stroke)); if let Some(out) = stroke.inner { pass.take_chip(ShapePaint::Stroke, out); } @@ -160,12 +156,8 @@ impl<'a> ShapeBar<'a> { if let Some((cell, change)) = cell { Divider::vertical().show(ui); let side = SideLabel::new().scrub(true); - let (events, alert) = Field::new(cell.caption.clone()) - .id_salt(cell.key) - .side(side) - .show(ui, |ui, _| cell.show(ui)) - .inner - .unwrap_or_default(); + let (events, alert) = + Field::new(cell.caption.clone()).id_salt(cell.key).side(side).show(ui, |ui, _| cell.show(ui)).inner.unwrap_or_default(); pass.events.extend(events.map(change)); pass.alert(alert); } diff --git a/crates/text/src/ui/style_panel.rs b/crates/text/src/ui/style_panel.rs index 2c58e332a..53b87ee00 100644 --- a/crates/text/src/ui/style_panel.rs +++ b/crates/text/src/ui/style_panel.rs @@ -355,78 +355,79 @@ impl<'a> TextStylesPanel<'a> { } }; - let shown = Panel::new(label.clone()).pad(Pad::None).collection_body().command_scope(TextStyleCommand::SCOPE).footer(footer).show(ui, |ui, cx| { - let before = cx.memory::().clone(); - while let Some((command, _)) = cx.take_command::() { - if let Some(found) = before.action(command) { - action.set(Some(found)); - } - } - let held = selection.reborrow().read(cx).and_then(|held| held.same().cloned()).unwrap_or_default(); - let facts = Facts { paragraph, target, overridden, current, picked: held.lead.or(current), selected: held.items.clone() }; - for command in [ - TextStyleCommand::ClearOverride, - TextStyleCommand::Redefine, - TextStyleCommand::New, - TextStyleCommand::Duplicate, - TextStyleCommand::Delete, - TextStyleCommand::Options, - TextStyleCommand::SelectUnused, - ] { - cx.publish(command, CommandState::new().enabled(facts.action(command).is_some())); - } - *cx.memory::() = facts; - - let source = keyed(rows, |row: &TextStyleRow| row.id); - let mode = if highlighting { SelectMode::Multi } else { SelectMode::Single }; - let list = List::new(label.clone()) - .id(list_id) - .select(mode) - .activate(ActivateOn::Click) - .allow_empty(true) - .deletable(true) - .max_rows(8) - .can_drag(move |_| highlighting) - .drag_payload(|drag: &ListDrag| Some(drag.clone())) - .selection(selection.reborrowed()); - let list = match &empty { - Some(text) => list.empty(text.clone()), - None => list, - }; - let shown_rows = list.show_items(ui, &source, &mut |id, _| { - let Some(row) = rows.iter().find(|row| row.id == *id) else { return ListRow::new(Label::Empty) }; - let is_current = target && current == Some(*id); - let marked = is_current && overridden; - let none = *id == 0 && !paragraph; - let name = if marked { words.overridden_name.fill(&[("name", row.name.as_str())]) } else { row.name.clone() }; - let spoken = if marked { words.overridden_spoken.fill(&[("name", row.name.as_str())]) } else { row.name.clone() }; - let description = if none { words.no_character_style.as_str().to_owned() } else { tip.clone() }; - let styled = ListRow::new(name).accessible_name(spoken).description(description).highlight(is_current); - if none { styled.ink(RowInk::Dimmed) } else { styled } - }); - let (events, second) = (shown_rows.events, shown_rows.activation_clicks >= 2); - - let pointer = craft_ui::runtime::pointer::frame(ui.ctx()); - let alt = pointer.mods.alt; - let plain = !pointer.mods.shift && !pointer.mods.cmd; - for event in events { - match event { - CollectionEvent::Activate(id) if second && (id != 0 || paragraph) => action.set(Some(TextStyleAction::Options(id))), - CollectionEvent::Activate(id) if target && (paragraph || text_selected) && plain => { - action.set(Some(TextStyleAction::apply(id, alt))); + let shown = + Panel::new(label.clone()).pad(Pad::None).collection_body().command_scope(TextStyleCommand::SCOPE).footer(footer).show(ui, |ui, cx| { + let before = cx.memory::().clone(); + while let Some((command, _)) = cx.take_command::() { + if let Some(found) = before.action(command) { + action.set(Some(found)); } - // A character style at a bare caret has nothing to apply to: the attempt warns instead. - CollectionEvent::Activate(_) if target && !paragraph && !text_selected && plain => hint.set(true), - CollectionEvent::Delete(keys) if keys.len() > 1 => action.set(Some(TextStyleAction::DeleteHighlighted)), - CollectionEvent::Delete(keys) => { - if let Some(id) = keys.first().copied().filter(|id| *id != 0) { - action.set(Some(TextStyleAction::Delete(id))); + } + let held = selection.reborrow().read(cx).and_then(|held| held.same().cloned()).unwrap_or_default(); + let facts = Facts { paragraph, target, overridden, current, picked: held.lead.or(current), selected: held.items.clone() }; + for command in [ + TextStyleCommand::ClearOverride, + TextStyleCommand::Redefine, + TextStyleCommand::New, + TextStyleCommand::Duplicate, + TextStyleCommand::Delete, + TextStyleCommand::Options, + TextStyleCommand::SelectUnused, + ] { + cx.publish(command, CommandState::new().enabled(facts.action(command).is_some())); + } + *cx.memory::() = facts; + + let source = keyed(rows, |row: &TextStyleRow| row.id); + let mode = if highlighting { SelectMode::Multi } else { SelectMode::Single }; + let list = List::new(label.clone()) + .id(list_id) + .select(mode) + .activate(ActivateOn::Click) + .allow_empty(true) + .deletable(true) + .max_rows(8) + .can_drag(move |_| highlighting) + .drag_payload(|drag: &ListDrag| Some(drag.clone())) + .selection(selection.reborrowed()); + let list = match &empty { + Some(text) => list.empty(text.clone()), + None => list, + }; + let shown_rows = list.show_items(ui, &source, &mut |id, _| { + let Some(row) = rows.iter().find(|row| row.id == *id) else { return ListRow::new(Label::Empty) }; + let is_current = target && current == Some(*id); + let marked = is_current && overridden; + let none = *id == 0 && !paragraph; + let name = if marked { words.overridden_name.fill(&[("name", row.name.as_str())]) } else { row.name.clone() }; + let spoken = if marked { words.overridden_spoken.fill(&[("name", row.name.as_str())]) } else { row.name.clone() }; + let description = if none { words.no_character_style.as_str().to_owned() } else { tip.clone() }; + let styled = ListRow::new(name).accessible_name(spoken).description(description).highlight(is_current); + if none { styled.ink(RowInk::Dimmed) } else { styled } + }); + let (events, second) = (shown_rows.events, shown_rows.activation_clicks >= 2); + + let pointer = craft_ui::runtime::pointer::frame(ui.ctx()); + let alt = pointer.mods.alt; + let plain = !pointer.mods.shift && !pointer.mods.cmd; + for event in events { + match event { + CollectionEvent::Activate(id) if second && (id != 0 || paragraph) => action.set(Some(TextStyleAction::Options(id))), + CollectionEvent::Activate(id) if target && (paragraph || text_selected) && plain => { + action.set(Some(TextStyleAction::apply(id, alt))); } + // A character style at a bare caret has nothing to apply to: the attempt warns instead. + CollectionEvent::Activate(_) if target && !paragraph && !text_selected && plain => hint.set(true), + CollectionEvent::Delete(keys) if keys.len() > 1 => action.set(Some(TextStyleAction::DeleteHighlighted)), + CollectionEvent::Delete(keys) => { + if let Some(id) = keys.first().copied().filter(|id| *id != 0) { + action.set(Some(TextStyleAction::Delete(id))); + } + } + _ => {} } - _ => {} } - } - }); + }); TextStylesPanelOutput { response: shown.output.response, action: action.get(), diff --git a/crates/ui-contract/src/layout/body.rs b/crates/ui-contract/src/layout/body.rs index 0c506491e..28fc1c390 100644 --- a/crates/ui-contract/src/layout/body.rs +++ b/crates/ui-contract/src/layout/body.rs @@ -1196,10 +1196,11 @@ fn row_line(ctx: &egui::Context, sizing: bool, id: Id, shared: Option) -> O /// with its container's regions already in it: what the container's end region sets its children on, so the end /// content meets the members' line as the members meet each other. `None` for any other body. pub(crate) fn members_line(ctx: &egui::Context, body: Id) -> Option { - layout_memory::measured(ctx, sub(body, "line")) - .map(|found| found.took) - .filter(|took| took.y > 0.0) - .map(|took| RowLine { body, centre: Some(took.x), height: Some(took.y) }) + layout_memory::measured(ctx, sub(body, "line")).map(|found| found.took).filter(|took| took.y > 0.0).map(|took| RowLine { + body, + centre: Some(took.x), + height: Some(took.y), + }) } /// The line the unwrapped `Row` body `body` sets its children on: its own (`centre`, `height`), or the line `shared` diff --git a/crates/ui-contract/src/style/cx.rs b/crates/ui-contract/src/style/cx.rs index e3ba59825..6de3b7df7 100644 --- a/crates/ui-contract/src/style/cx.rs +++ b/crates/ui-contract/src/style/cx.rs @@ -3,8 +3,7 @@ use super::key::{EnvKey, Ink}; use super::look::{DataColor, FocusLook, StyleColor, SurfaceKind, SurfaceLook, TrackLook}; use super::paint::{ - HandleLook, MarkerLook, ResetMarkLook, RuleKind, RuleLook, ScrollBarLook, handle_look, marker_look, reset_mark_look, rule_look, - scroll_bar_look, + HandleLook, MarkerLook, ResetMarkLook, RuleKind, RuleLook, ScrollBarLook, handle_look, marker_look, reset_mark_look, rule_look, scroll_bar_look, }; use super::surface::{SurfaceStyle, surface_style}; use super::tokens::UiTokens; diff --git a/crates/ui-contract/src/style/mod.rs b/crates/ui-contract/src/style/mod.rs index 4efd11df1..9d2f53ae8 100644 --- a/crates/ui-contract/src/style/mod.rs +++ b/crates/ui-contract/src/style/mod.rs @@ -25,9 +25,7 @@ pub use cx::{GlyphRole, StyleCx, VariantParts}; pub use key::{EnvKey, Ink, StyleKey}; pub(crate) use look::StyleView; pub use look::{ComponentStyle, Corners, DataColor, FocusLook, IconLook, StyleColor, SurfaceKind, SurfaceLook, TextLook, TrackLook}; -pub use paint::{ - HandleLook, MarkerLook, ResetMarkLook, ResizeLineLook, RuleKind, RuleLook, RuleWidth, ScrollBarLook, resize_line_look, -}; +pub use paint::{HandleLook, MarkerLook, ResetMarkLook, ResizeLineLook, RuleKind, RuleLook, RuleWidth, ScrollBarLook, resize_line_look}; pub(crate) use paint::{min_thumb, scroll_bar_look}; pub use replacements::{DuplicateStyle, StyleReplacements}; pub use span::Span; diff --git a/crates/ui-panels/src/dialog/mod.rs b/crates/ui-panels/src/dialog/mod.rs index 4d00c4e13..d67772d4d 100644 --- a/crates/ui-panels/src/dialog/mod.rs +++ b/crates/ui-panels/src/dialog/mod.rs @@ -37,4 +37,3 @@ pub use serde_fields::{serde_fields, set_serde_field}; pub use stack::{DialogId, DialogStack, dialog_id}; pub use unsaved::{UnsavedAnswer, UnsavedChangesDialog, UnsavedChangesOutput}; pub use words::DialogWords; - diff --git a/crates/ui-panels/src/docking/group.rs b/crates/ui-panels/src/docking/group.rs index 99bc58121..9ad29c1e5 100644 --- a/crates/ui-panels/src/docking/group.rs +++ b/crates/ui-panels/src/docking/group.rs @@ -256,10 +256,8 @@ impl<'a, P: Clone + Hash + Send + Sync + 'static> DockGroup<'a, P> { /// The group named by `anchor` (one of its panels) with its `panels`, `active` showing. The group is named by the /// active panel's title. pub fn new(anchor: P, panels: &'a [PanelTitle], active: PanelKey) -> Self { - let props = ContainerProps::new() - .sizing(Sizing::Fill) - .header(HeaderRegion::new().fill(SurfaceKind::Background)) - .command_scope(DockCommands::SCOPE); + let props = + ContainerProps::new().sizing(Sizing::Fill).header(HeaderRegion::new().fill(SurfaceKind::Background)).command_scope(DockCommands::SCOPE); let title = panels.iter().find(|panel| panel.key == active).map(|panel| panel.title.clone()).unwrap_or_default(); DockGroup { common: Common::new(), diff --git a/crates/ui-panels/src/sections/footer.rs b/crates/ui-panels/src/sections/footer.rs index 7cf25f583..49b03b0f0 100644 --- a/crates/ui-panels/src/sections/footer.rs +++ b/crates/ui-panels/src/sections/footer.rs @@ -634,8 +634,7 @@ impl FooterBar { DialogRole::Destructive => Variant::DANGER, DialogRole::Cancel | DialogRole::Other => Variant::SECONDARY, }; - let mut widget = - Button::new(button.label.clone()).variant(variant).enabled(button.enabled).least_width(least); + let mut widget = Button::new(button.label.clone()).variant(variant).enabled(button.enabled).least_width(least); if column { widget = widget.sizing(Sizing::FillWidth); } diff --git a/crates/ui-panels/src/sections/mod.rs b/crates/ui-panels/src/sections/mod.rs index 9a477da36..84760feb1 100644 --- a/crates/ui-panels/src/sections/mod.rs +++ b/crates/ui-panels/src/sections/mod.rs @@ -12,9 +12,7 @@ mod words; // Panel. mod panel; -pub use footer::{ - DialogRole, DropAction, DropActionOutput, DropActionStyle, FooterAction, FooterBar, FooterButton, FooterDrop, FooterOutput, -}; +pub use footer::{DialogRole, DropAction, DropActionOutput, DropActionStyle, FooterAction, FooterBar, FooterButton, FooterDrop, FooterOutput}; pub use group_box::{GroupBox, GroupBoxStyle}; pub use section::{Section, SectionOutput, SectionStyle}; pub use stack::{SectionStack, SectionStackOutput, SectionStackStyle, StackRows, StackSlot}; diff --git a/crates/ui-patterns/src/patterns/dock/area.rs b/crates/ui-patterns/src/patterns/dock/area.rs index 46310dcfa..1052fbd34 100644 --- a/crates/ui-patterns/src/patterns/dock/area.rs +++ b/crates/ui-patterns/src/patterns/dock/area.rs @@ -3,7 +3,9 @@ use super::hide::{self, Shown}; use crate::contract::overlay::PlacementChange; -use crate::contract::{Bind, BindMut, BodyCx, Cx, Entry, NoValue, Outcome, Pad, Pointer as _, Props as _, ShowContainer as _, Sizing, WordSetCx as _}; +use crate::contract::{ + Bind, BindMut, BodyCx, Cx, Entry, NoValue, Outcome, Pad, Pointer as _, Props as _, ShowContainer as _, Sizing, WordSetCx as _, +}; use crate::docking::SplitFramesCx as _; use crate::docking::stack::{StackSection, StackSections, section_heights}; use crate::docking::tree::FrameRules; diff --git a/crates/ui-patterns/src/patterns/form_dialogs/save_for_web/options.rs b/crates/ui-patterns/src/patterns/form_dialogs/save_for_web/options.rs index bc524cb97..83b3c4f9d 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/save_for_web/options.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/save_for_web/options.rs @@ -332,10 +332,7 @@ fn metadata_row(ui: &mut Ui, words: &SaveForWebWords, options: &mut SaveForWebOp /// Image Size: Width and Height in pixels or percent, the Percent row and the Resample method. fn size_section(ui: &mut Ui, words: &SaveForWebWords, sizing: &SizingWords, units: &Units, link: &mut LinkedSize, resample: &mut Resample) { - let kinds = [ - Entry::new(UnitKind::Pixels, units.name(UnitKind::Pixels)), - Entry::new(UnitKind::Percent, units.name(UnitKind::Percent)), - ]; + let kinds = [Entry::new(UnitKind::Pixels, units.name(UnitKind::Pixels)), Entry::new(UnitKind::Percent, units.name(UnitKind::Percent))]; Section::fixed(words.image_size.clone()).id_salt("size").show(ui, |ui, _| { row(ui, &words.width, "width", |ui| { let range = link.width_range(); diff --git a/crates/ui-patterns/src/patterns/form_dialogs/sizing.rs b/crates/ui-patterns/src/patterns/form_dialogs/sizing.rs index 7e54cfa18..a076310f1 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/sizing.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/sizing.rs @@ -333,8 +333,7 @@ impl Kit { pub(super) fn new(ui: &Ui) -> Self { let env = Env::of(ui); let units = env.units(); - let entries = - |kinds: &[UnitKind]| -> Vec> { kinds.iter().map(|kind| Entry::new(*kind, units.name(*kind))).collect() }; + let entries = |kinds: &[UnitKind]| -> Vec> { kinds.iter().map(|kind| Entry::new(*kind, units.name(*kind))).collect() }; let lengths = entries(&LENGTH_UNITS); let mut widths = lengths.clone(); widths.extend(entries(&[UnitKind::Columns])); diff --git a/crates/ui-patterns/src/patterns/form_dialogs/sizing/canvas.rs b/crates/ui-patterns/src/patterns/form_dialogs/sizing/canvas.rs index 08f633dfb..75a9475fe 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/sizing/canvas.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/sizing/canvas.rs @@ -4,13 +4,13 @@ use super::{CanvasExtension, Kit, LinkedSize, SizeForm, SizingOutput, set_size_j use crate::choice::Checkbox; use crate::contract::{Bind, Props as _, Show as _, ShowContainer as _}; use crate::dialog::{DialogId, DialogResult, DialogStack, FieldRefusal, StackDialog, dialog_id}; +use crate::display::Text; use crate::form::Field; use crate::pickers::{Anchor9, ReferencePoint, Select}; -use crate::display::Text; use crate::runtime::env::{ColumnSize, Label, UnitKind}; use crate::sections::Section; -use craft_theme::variant::Tone; use craft_behavior::PixelSize; +use craft_theme::variant::Tone; use egui::Ui; use serde_json::json; @@ -195,8 +195,7 @@ impl<'a> CanvasSize<'a> { sized_section(ui, "new", &words.new_size, kit.file_size(now, bytes_per_pixel), kit.tone_of(now), |ui| { kit.refusal(ui, now); kit.sides(ui, &mut state.size); - let check = - Checkbox::new(Bind::given(state.size.is_relative())).label(words.relative.clone()).id_salt("relative").show(ui); + let check = Checkbox::new(Bind::given(state.size.is_relative())).label(words.relative.clone()).id_salt("relative").show(ui); if let Some(on) = check.value().copied() { state.size.relative(on); } diff --git a/crates/ui-patterns/src/patterns/presets/picker/stories.rs b/crates/ui-patterns/src/patterns/presets/picker/stories.rs index 9c5692377..d33a6edde 100644 --- a/crates/ui-patterns/src/patterns/presets/picker/stories.rs +++ b/crates/ui-patterns/src/patterns/presets/picker/stories.rs @@ -45,7 +45,9 @@ fn preset_picker_chip(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { let (swatch, state) = data.value("chip", (Some(TEAL), PresetState::::new())); let mut output = None; Bar::new("Brush options", BarKind::Options).show(ui, |ui, _| { - output = Some(PresetPicker::new("Swatch", Bind::bound(&mut *swatch), &rows, Bind::bound(&mut *state)).field(PickerField::Chip).caption("20").show(ui)); + output = Some( + PresetPicker::new("Swatch", Bind::bound(&mut *swatch), &rows, Bind::bound(&mut *state)).field(PickerField::Chip).caption("20").show(ui), + ); }); output.map(StoryOutput::from).unwrap_or_default() } diff --git a/crates/ui-shell/src/shell/app_shell.rs b/crates/ui-shell/src/shell/app_shell.rs index d7718edc6..d2af1c8ca 100644 --- a/crates/ui-shell/src/shell/app_shell.rs +++ b/crates/ui-shell/src/shell/app_shell.rs @@ -14,8 +14,8 @@ use super::screen_mode::{ScreenMode, ScreenModeCommands, ScreenModeFollow}; use super::words::ShellWords; use crate::contract::overlay::Resize; use crate::contract::{ - Bind, BodyCx, BodyLayout, Common, Component, Container, ContainerProps, Cx, Mount, NoValue, Outcome, PaneEdge, Props as _, Remember as _, Role, ShellPane, - ShowContainer as _, Sizing, + Bind, BodyCx, BodyLayout, Common, Component, Container, ContainerProps, Cx, Mount, NoValue, Outcome, PaneEdge, Props as _, Remember as _, Role, + ShellPane, ShowContainer as _, Sizing, }; use crate::notices::ToastStack; use crate::runtime::commands::{CommandAccess as _, CommandSet as _}; diff --git a/crates/ui-widgets/src/bars/constraint_fields.rs b/crates/ui-widgets/src/bars/constraint_fields.rs index c8c1b00e4..c0dffc57e 100644 --- a/crates/ui-widgets/src/bars/constraint_fields.rs +++ b/crates/ui-widgets/src/bars/constraint_fields.rs @@ -259,29 +259,26 @@ impl Cells<'_> { low.min(high)..=low.max(high) }); let mut edited = None; - Field::new(cell.caption.clone()).id_salt(cell.key).enabled(cell.enabled).side(SideLabel::new().scrub(true)).show( - ui, - |ui, _| { - let mut field = NumberField::new(cell.caption.clone(), Bind::given(Some(shown))).range(range.clone()).scrub_by_label(); - if let Some(c) = conversion { - field = if units.is_some() { - // Fixed Size with the host's units: typed text may carry any unit, read through the document. - // Its right-click is the unit menu, so the field opens no edit menu of its own. - let reader = Env::of(ui).units().document_reader(c.unit, c.extent, c.pixels_per_inch, c.points_per_inch); - field.codec(NumberCodec::new(reader, *c.unit.decimals().end())).own_context_menu() - } else { - field.unit_kind(c.unit) - }; - } - let out = field.show(ui); - edited = out.value().copied().flatten(); - if let Some(s) = units { - let entries: Vec> = s.units.iter().map(|entry| entry.clone().checked(entry.value() == Some(&s.unit))).collect(); - let menu = Menu::context(cell.caption.clone(), &out.response).values().pick(ui, &entries); - *unit_picked = unit_picked.or(menu.picked); - } - }, - ); + Field::new(cell.caption.clone()).id_salt(cell.key).enabled(cell.enabled).side(SideLabel::new().scrub(true)).show(ui, |ui, _| { + let mut field = NumberField::new(cell.caption.clone(), Bind::given(Some(shown))).range(range.clone()).scrub_by_label(); + if let Some(c) = conversion { + field = if units.is_some() { + // Fixed Size with the host's units: typed text may carry any unit, read through the document. + // Its right-click is the unit menu, so the field opens no edit menu of its own. + let reader = Env::of(ui).units().document_reader(c.unit, c.extent, c.pixels_per_inch, c.points_per_inch); + field.codec(NumberCodec::new(reader, *c.unit.decimals().end())).own_context_menu() + } else { + field.unit_kind(c.unit) + }; + } + let out = field.show(ui); + edited = out.value().copied().flatten(); + if let Some(s) = units { + let entries: Vec> = s.units.iter().map(|entry| entry.clone().checked(entry.value() == Some(&s.unit))).collect(); + let menu = Menu::context(cell.caption.clone(), &out.response).values().pick(ui, &entries); + *unit_picked = unit_picked.or(menu.picked); + } + }); let edited = edited?; let Some(c) = conversion else { return Some(edited) }; // A field that shows a rounded value commits the rounded value when it is left: that is no change. diff --git a/crates/ui-widgets/src/bars/stories.rs b/crates/ui-widgets/src/bars/stories.rs index 96be78c5e..7a36caff6 100644 --- a/crates/ui-widgets/src/bars/stories.rs +++ b/crates/ui-widgets/src/bars/stories.rs @@ -56,8 +56,7 @@ fn bar_options(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { BarHome::new("Home", Bind::bound(&mut home)).show(ui); BarTool::new(IconId::new("brush"), "Brush").show(ui); Field::new("Size").show(ui, |ui, _| NumberField::new("Size", Bind::bound(&mut size)).range(1.0..=5000.0).show(ui)); - Field::new("Opacity") - .show(ui, |ui, _| NumberField::new("Opacity", Bind::bound(&mut opacity)).range(1.0..=100.0).show(ui)); + Field::new("Opacity").show(ui, |ui, _| NumberField::new("Opacity", Bind::bound(&mut opacity)).range(1.0..=100.0).show(ui)); Field::new("Mode").show(ui, |ui, _| Select::new("Mode", Bind::bound(&mut mode), &modes).show(ui)); Divider::vertical().show(ui); Checkbox::new(Bind::bound(&mut sample_all)).label("Sample All Layers").show(ui); diff --git a/crates/ui-widgets/src/list/row/paint.rs b/crates/ui-widgets/src/list/row/paint.rs index b68c65916..f1ccb50d7 100644 --- a/crates/ui-widgets/src/list/row/paint.rs +++ b/crates/ui-widgets/src/list/row/paint.rs @@ -59,7 +59,9 @@ impl ListRow<'_> { icon.color.get_or_insert(cx.resolve(&cx.style.trailing_icon.color)); ui.draw().icon(shape, &icon); } - TrailingFace::Icon(icon) => ui.face(key, IconButton::new(icon.clone()).focusable(false).enabled(*enabled).glyphs(GlyphRole::PanelRail)), + TrailingFace::Icon(icon) => { + ui.face(key, IconButton::new(icon.clone()).focusable(false).enabled(*enabled).glyphs(GlyphRole::PanelRail)) + } TrailingFace::Disclosure { open } => ui.face(key, Disclosure::new(Bind::given(*open)).node(false).enabled(*enabled)), TrailingFace::Strong(text) => { ui.draw().text(*slot, &trailing_run(text, true));