Bars: the trailing group follows commit and cancel; parts back on their old rows

TransformBar pins Reset warp, its rule and the mode switch after commit
and cancel. The annotation toolbar puts its colour and width on a second
row, and the crop bar shows Delete Cropped Pixels and Fill on the bar.
Bar::vertical goes: the vertical tool strip is a rail.
This commit is contained in:
aiongg
2026-11-12 14:32:40 +00:00
parent c427e539c3
commit d9e2f6e4f2
5 changed files with 79 additions and 97 deletions
+15 -2
View File
@@ -3,12 +3,13 @@
use super::bar_words::CropBarWords;
use super::menus::{CropOptionsMenu, CropOverlayMenu};
use super::options::{
CROP_RATIOS, CROP_SIZES, CropLength, CropPresetChoice, CropRatio, CropSettings, CropSizeFields, CropUserPreset, FIELD_MAX, LENGTH_MIN,
CROP_RATIOS, CROP_SIZES, CropFill, CropLength, CropPresetChoice, CropRatio, CropSettings, CropSizeFields, CropUserPreset, FIELD_MAX, LENGTH_MIN,
RATIO_DECIMALS, RATIO_MAX, RATIO_STEP, ResolutionUnit,
};
use super::session::CropDocument;
use craft_behavior::{EditEvent, EditEvents, IconId, NumberCodec};
use craft_ui::buttons::{Button, IconButton, ToggleButton};
use craft_ui::choice::Checkbox;
use craft_ui::contract::{
Bind, BodyCx, Entry, LabelKind, NoValue, Outcome, Props as _, Remember as _, Show as _, ShowContainer as _, SideLabel, Sizing, clicked,
};
@@ -74,7 +75,8 @@ impl Outcome for CropBarOutput {
/// presets, Front Image, a rule, New Crop Preset…, Delete Crop Preset…); the W and H ratio fields (0 to 99,999 with 3
/// decimals) with the swap button between them, or in W × H × Resolution mode the W, H and Resolution fields with
/// the px/in or px/cm select; Clear; the Angle field; the Straighten toggle (pressed while armed); the overlay menu
/// ([`CropOverlayMenu`]); the gear popover ([`CropOptionsMenu`]).
/// ([`CropOverlayMenu`]); the gear popover ([`CropOptionsMenu`]); the Delete Cropped Pixels check box; Fill and its
/// select.
/// - W and H keep their lengths with the unit they were entered in ([`CropLength`]); a cleared field is unset.
/// - A scrub or a step of a ratio field refits live; Escape puts the ratio back.
/// - Delete Crop Preset… is disabled when no user preset is given; New Crop Preset… when [`CropSettings::preset_name`]
@@ -135,6 +137,17 @@ impl<'a> CropBar<'a> {
report.straighten |= toggle.value().is_some();
CropOverlayMenu::new(settings).show(ui);
report.pick_color = CropOptionsMenu::new(settings).show(ui).pick_color;
Checkbox::new(Bind::bound(&mut settings.delete_pixels)).label(words.delete_pixels.clone()).show(ui);
let fills = [
Entry::new(CropFill::Background, words.fill_background.clone()),
Entry::new(CropFill::ContentAware, words.fill_content_aware.clone()),
];
Field::new(words.fill_name.clone()).id_salt("fill").sizing(Sizing::Content).show(ui, |ui, _| {
let pick = Select::new(words.fill_name.clone(), Bind::given(settings.fill), &fills).show(ui);
if let Some(fill) = pick.value().copied() {
settings.fill = fill;
}
});
});
let changed = *settings != before;
CropBarOutput {
+4 -24
View File
@@ -2,7 +2,7 @@
//! ([`CropOptionsMenu`]).
use super::bar_words::CropBarWords;
use super::options::{CropFill, CropSettings};
use super::options::CropSettings;
use craft_behavior::geometry::crop::{CropGuide, GuideShow};
use craft_behavior::{IconId, Mixed};
use craft_keymap::{Chord, Key, Mods, Platform};
@@ -10,13 +10,12 @@ use craft_ui::buttons::IconButton;
use craft_ui::canvas::{CropShield, ShieldColor};
use craft_ui::choice::{Checkbox, Radio, RadioGroup, Swatch};
use craft_ui::contract::{
Bind, Entry, FieldLayout, NoValue, Outcome, PopupKind, Props as _, Remember as _, Show as _, ShowContainer as _, SideLabel, Trigger, clicked,
Bind, FieldLayout, NoValue, Outcome, PopupKind, Props as _, Remember as _, Show as _, ShowContainer as _, SideLabel, Trigger, clicked,
};
use craft_ui::display::Divider;
use craft_ui::form::{Field, SliderField};
use craft_ui::layout_components::Row;
use craft_ui::menu::{Menu, MenuItem};
use craft_ui::pickers::Select;
use craft_ui::popover::Popover;
use craft_ui::runtime::env::{Env, UnitKind};
use craft_ui::runtime::requests::ColorRequest;
@@ -164,9 +163,8 @@ struct Open(bool);
/// The gear popover: an icon button named "Set additional Crop options" that opens a [`Popover`] of form rows: Use
/// Classic Mode (shortcut text P), Show Cropped Area (H; shown on and disabled in Classic Mode), Auto Center Preview
/// (disabled in Classic Mode), Enable Crop Shield, the colour (Match Canvas, or Custom… with its swatch), Opacity (0 to
/// 100 %) and Auto Adjust Opacity, then Delete Cropped Pixels and the Fill select. The colour rows, Opacity and Auto
/// Adjust Opacity are disabled with the shield off. The popover stays open on clicks inside and closes on a click
/// outside, Escape or the button.
/// 100 %) and Auto Adjust Opacity. The colour rows, Opacity and Auto Adjust Opacity are disabled with the shield off.
/// The popover stays open on clicks inside and closes on a click outside, Escape or the button.
#[must_use = "show the menu with `show`"]
#[derive(craft_ui::contract::Pattern, craft_ui::contract::Props)]
pub struct CropOptionsMenu<'a> {
@@ -268,24 +266,6 @@ impl<'a> CropOptionsMenu<'a> {
SideLabel::new().layout(FieldLayout::After),
Checkbox::new(Bind::bound(&mut shield.auto_adjust)).enabled(on),
);
Divider::horizontal().show(ui);
cx.labelled(
ui,
"delete",
words.delete_pixels.clone(),
SideLabel::new().layout(FieldLayout::After),
Checkbox::new(Bind::bound(&mut settings.delete_pixels)),
);
let fills = [
Entry::new(CropFill::Background, words.fill_background.clone()),
Entry::new(CropFill::ContentAware, words.fill_content_aware.clone()),
];
Field::new(words.fill_name.clone()).show(ui, |ui, _| {
let pick = Select::new(words.fill_name.clone(), Bind::given(settings.fill), &fills).show(ui);
if let Some(fill) = pick.value().copied() {
settings.fill = fill;
}
});
});
button
});
+22 -16
View File
@@ -78,10 +78,11 @@ impl<W> Outcome for TransformBarOutput<W> {
/// phase.
///
/// - Box phase, in Tab order: the [`TransformFields`] strip (reference point, X, Y, W, link, H, angle, H and V skew,
/// interpolation), the Show Reference Point check, the app's [`extra`](Self::extra) group, the Free Transform / Warp
/// switch (an icon button, pressed in the Warp phase), then cancel and commit at the reading end.
/// - Warp phase: the app's [`warp_fields`](Self::warp_fields) group in place of the fields, Reset warp and the
/// switch, then cancel and commit.
/// interpolation), the Show Reference Point check and the app's [`extra`](Self::extra) group; then, pinned at the
/// reading end, cancel, commit, a rule and the Free Transform / Warp switch (an icon button, pressed in the Warp
/// phase).
/// - Warp phase: the app's [`warp_fields`](Self::warp_fields) group in place of the fields; then cancel, commit, Reset
/// warp, a rule and the switch.
/// - [`groups`](Self::groups) narrows the strip; [`mode_switch`](Self::mode_switch) hides the switch (Content-Aware
/// Scale).
/// - Every control is an ordinary focusable control. The bar never changes the session: it reports
@@ -167,7 +168,20 @@ impl<'a, W: TransformWarp> TransformBar<'a, W> {
let mut edits: Vec<TransformEdit<W>> = Vec::new();
let mut reset_warp = false;
let mut unit_picked = None;
let shown = Bar::new(label.clone(), BarKind::Options).commit_cancel(commit.clone(), cancel.clone()).show(ui, |ui, cx| {
let mut switched = false;
// Reset warp and the mode switch stay in view after commit and cancel while the fields scroll.
let trailing = |ui: &mut Ui| {
if warping {
let reset = IconButton::new(IconId::new("undo")).label(words.reset_warp.clone()).show(ui);
reset_warp = clicked(&reset);
}
if mode_switch {
Divider::vertical().show(ui);
let switch = IconButton::new(IconId::new("grid")).label(words.switch_warp.clone()).selected(warping).show(ui);
switched = clicked(&switch);
}
};
let shown = Bar::new(label.clone(), BarKind::Options).commit_cancel(commit.clone(), cancel.clone()).trailing(trailing).show(ui, |ui, cx| {
let current = match settings.reborrow().read(cx) {
Some(Mixed::Same(held)) => held,
_ => TransformSettings::default(),
@@ -203,21 +217,13 @@ impl<'a, W: TransformWarp> TransformBar<'a, W> {
slot.show(ui);
}
}
if warping {
let reset = IconButton::new(IconId::new("undo")).label(words.reset_warp.clone()).show(ui);
reset_warp = clicked(&reset);
}
if mode_switch {
Divider::vertical().show(ui);
let switch = IconButton::new(IconId::new("grid")).label(words.switch_warp.clone()).selected(warping).show(ui);
if clicked(&switch) {
edits.push(if warping { TransformEdit::LeaveWarp } else { TransformEdit::WarpRequested });
}
}
if next != current {
let _ = settings.reborrow().write(cx, &EditEvent::set(Mixed::Same(current), next, name.clone(), None));
}
});
if switched {
edits.push(if warping { TransformEdit::LeaveWarp } else { TransformEdit::WarpRequested });
}
TransformBarOutput {
response: shown.output.response.clone(),
edits,
+21 -14
View File
@@ -19,6 +19,8 @@ use crate::annotate::{AnnotationGroup, AnnotationKind, AnnotationTool};
const WIDTH_RANGE: std::ops::RangeInclusive<f64> = 1.0..=12.0;
/// The most decimals the width field shows.
const WIDTH_DECIMALS: usize = 1;
/// The bar's rows: the tools, then the colour and width.
const TWO_ROWS: std::num::NonZeroU8 = std::num::NonZeroU8::MIN.saturating_add(1);
/// What [`AnnotationToolbar::show`] reports.
#[derive(Debug)]
@@ -68,29 +70,34 @@ impl<'a> AnnotationToolbar<'a> {
.enumerate()
.map(|(n, group)| ToolSlot::new(n as SlotId, group.tools().iter().map(|&tool| RailTool::new(tool, AnnotateCommand::of(tool))).collect()))
.collect();
let bar = Bar::new(words.toolbar.clone(), BarKind::Tool).show(ui, |ui, body| {
// The tool buttons on the first row, the colour well and the width on the second.
let bar = Bar::new(words.toolbar.clone(), BarKind::Tool).rows(TWO_ROWS).show(ui, |ui, body| {
let last = body.memory::<LastUsed<AnnotationTool>>().clone();
let current = annotate.tool;
let out =
FlyoutButton::new(&select, &AnnotationTool::Select).label(words.select.clone()).selected(current == AnnotationTool::Select).show(ui);
if let Some(tool) = out.select {
annotate.tool = tool;
}
for (slot, group) in slots.iter().zip(AnnotationGroup::ALL) {
let tools: Vec<&RailTool<AnnotationTool>> = slot.tools.iter().collect();
let shown = shown_tool(&current, slot.id, &tools, &last, |_| true).map_or(current, |tool| tool.id);
let out = FlyoutButton::new(&slot.tools, &shown)
.label(words.group(group).to_owned())
.selected(slot.tools.iter().any(|tool| tool.id == current))
Row::new().show(ui, |ui, _| {
let out = FlyoutButton::new(&select, &AnnotationTool::Select)
.label(words.select.clone())
.selected(current == AnnotationTool::Select)
.show(ui);
if let Some(tool) = out.select {
annotate.tool = tool;
}
}
for (slot, group) in slots.iter().zip(AnnotationGroup::ALL) {
let tools: Vec<&RailTool<AnnotationTool>> = slot.tools.iter().collect();
let shown = shown_tool(&current, slot.id, &tools, &last, |_| true).map_or(current, |tool| tool.id);
let out = FlyoutButton::new(&slot.tools, &shown)
.label(words.group(group).to_owned())
.selected(slot.tools.iter().any(|tool| tool.id == current))
.show(ui);
if let Some(tool) = out.select {
annotate.tool = tool;
}
}
});
if let Some(next) = remembered(&slots, &annotate.tool, &last) {
*body.memory::<LastUsed<AnnotationTool>>() = next;
}
style_controls(ui, body, annotate, &words);
Row::new().show(ui, |ui, _| style_controls(ui, body, annotate, &words));
});
let changed = before != (annotate.tool, annotate.color, annotate.highlight_color, annotate.width);
AnnotationToolbarOutput { response: bar.output.response, changed }
+17 -41
View File
@@ -73,12 +73,12 @@ impl Outcome for BarOutput {
}
/// A bar over a chrome surface whose body holds the members in reading order at the small control size. They are
/// one roving group. The bar is as tall as its tallest member plus the control padding. A horizontal bar takes the
/// width it is offered and no more height than that; a vertical bar sizes to its content. A bar of one row lays its
/// body out as a row; a bar of several rows, or a vertical one, as a stack whose rows the caller makes with `Row`.
/// The body scrolls along the row axis (along y for a vertical bar), so a member past the edge is reached by Tab
/// and revealed. A bar with `commit_cancel` ends with a cancel and a commit button in its end region, outside the
/// scroll; they run `BarCommands`.
/// one roving group. The bar is as tall as its tallest member plus the control padding, and takes the width it is
/// offered. A bar of one row lays its body out as a row; a bar of several rows as a stack whose rows the caller makes
/// with `Row`. A row too long for the bar first narrows its selects and elidable text, then scrolls, so a member past
/// the edge is reached by Tab and revealed. A rule between groups of members is a `Divider::vertical()`. A bar with
/// `commit_cancel` ends with a cancel and a commit button in its end region, outside the scroll; they run
/// `BarCommands`.
#[derive(crate::contract::Component)]
#[component(container)]
pub struct Bar<'a> {
@@ -87,8 +87,6 @@ pub struct Bar<'a> {
#[container]
props: ContainerProps,
kind: BarKind,
rows: NonZeroU8,
vertical: bool,
commit_cancel: Option<(Label, Label)>,
committed: bool,
cancelled: bool,
@@ -116,32 +114,16 @@ impl<'a> Bar<'a> {
if kind == BarKind::Status {
props = props.live(Politeness::Polite);
}
Bar {
common: Common::new(),
props,
kind,
rows: NonZeroU8::MIN,
vertical: false,
commit_cancel: None,
committed: false,
cancelled: false,
trailing: None,
}
.label(label)
Bar { common: Common::new(), props, kind, commit_cancel: None, committed: false, cancelled: false, trailing: None }.label(label)
}
/// Sets the number of rows the body holds.
#[must_use]
pub fn rows(mut self, rows: NonZeroU8) -> Self {
self.rows = rows;
self.lay_out()
}
/// Lays the body out along the vertical axis.
#[must_use]
pub fn vertical(mut self) -> Self {
self.vertical = true;
self.lay_out()
if rows.get() > 1 {
self.props = self.props.layout(BodyLayout::stack());
}
self
}
/// Ends the bar with a cancel and a commit button named `cancel` and `commit`. They run `BarCommands::Cancel`
@@ -154,20 +136,13 @@ impl<'a> Bar<'a> {
}
/// Ends the bar with a group of controls that stays at the reading end, outside the scroll, while the members
/// before it scroll. The group sits before the commit and cancel buttons.
/// before it scroll. The group sits after the cancel and commit buttons.
#[must_use]
pub fn trailing(mut self, group: impl FnMut(&mut Ui) + 'a) -> Self {
self.trailing = Some(Box::new(group));
self.props = self.props.end(EndRegion::new());
self
}
fn lay_out(mut self) -> Self {
let layout = if self.vertical || self.rows.get() > 1 { BodyLayout::stack() } else { BodyLayout::row() };
let scroll = if self.vertical { Scroll::vertical() } else { Scroll::horizontal() };
self.props = self.props.layout(layout).sizing(if self.vertical { Sizing::Content } else { Sizing::FillWidth }).scroll(scroll);
self
}
}
impl Component for Bar<'_> {
@@ -227,13 +202,14 @@ impl Component for Bar<'_> {
}
impl Container for Bar<'_> {
/// The trailing group, then the cancel button and the commit button at the reading end.
/// The cancel button and the commit button, then the trailing group.
fn end(&mut self, ui: &mut Ui, _: &mut BodyCx<'_>) {
if let Some((commit, cancel)) = &self.commit_cancel {
IconButton::command(IconId::new("ban"), BarCommands::Cancel).label(cancel.clone()).show(ui);
IconButton::command(IconId::new("check"), BarCommands::Commit).label(commit.clone()).show(ui);
}
if let Some(group) = &mut self.trailing {
group(ui);
}
let Some((commit, cancel)) = &self.commit_cancel else { return };
IconButton::command(IconId::new("ban"), BarCommands::Cancel).label(cancel.clone()).show(ui);
IconButton::command(IconId::new("check"), BarCommands::Commit).label(commit.clone()).show(ui);
}
}