mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-25 20:14:31 +01:00
fw sync: PageRangeChoices::Line, ParamDialog::caption_column, Param::short_slider (Slider/SliderField::short)
Trials line_page_range_options_stand_on_one_line_with_no_page_count, a_caption_column_puts_a_group_caption_beside_its_group_and_lines_the_controls_up, a_short_slider_row_is_as_wide_as_its_content. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
8 files changed
+175
-16
No files matched your search
@@ -252,6 +252,9 @@ pub enum PageRangeChoices {
|
||||
/// All pages, Selected pages and From and To, with no Subset (its own row, [`PageRangeOptions::subset_select`],
|
||||
/// stands elsewhere in the dialog).
|
||||
SelectedFromTo,
|
||||
/// Acrobat's rows on one line, as production's Background and Watermark dialogs show them: All pages, Pages from
|
||||
/// and to, then the Subset, with no page count after the range.
|
||||
Line,
|
||||
}
|
||||
|
||||
impl PageRangeChoices {
|
||||
@@ -267,7 +270,12 @@ impl PageRangeChoices {
|
||||
|
||||
/// Whether the rows end with the Subset list.
|
||||
fn subset(self) -> bool {
|
||||
matches!(self, PageRangeChoices::Acrobat | PageRangeChoices::Current | PageRangeChoices::Selection)
|
||||
matches!(self, PageRangeChoices::Acrobat | PageRangeChoices::Current | PageRangeChoices::Selection | PageRangeChoices::Line)
|
||||
}
|
||||
|
||||
/// Whether every option stands on one line.
|
||||
fn line(self) -> bool {
|
||||
self == PageRangeChoices::Line
|
||||
}
|
||||
}
|
||||
|
||||
@@ -368,6 +376,10 @@ impl PageRangeOptions {
|
||||
Entry::new(Subset::Odd, words.odd_only.clone()),
|
||||
];
|
||||
let mut subset = None;
|
||||
// One line ([`PageRangeChoices::Line`]): the subset ends the line in a document dialog and elsewhere, and the
|
||||
// range shows no page count.
|
||||
let line = choices.line();
|
||||
let subset_inline = inline || line;
|
||||
let mut pick_subset = |ui: &mut Ui| {
|
||||
let picked = Select::new(words.subset.clone(), Bind::given(range.subset), &entries).show(ui);
|
||||
if let Some(chosen) = picked.value().copied() {
|
||||
@@ -383,8 +395,9 @@ impl PageRangeOptions {
|
||||
if choices.selection() {
|
||||
cx.labelled(ui, "selection", words.selection.clone(), after.clone(), Radio::new(PageScope::Selection));
|
||||
}
|
||||
// Two themed fields don't fit beside the radio in a narrow panel: "to" and its field wrap together.
|
||||
Row::new().wrap(true).show(ui, |ui, _| {
|
||||
// Two themed fields don't fit beside the radio in a narrow panel: "to" and its field wrap together. One
|
||||
// line keeps them on it, as production's does: the dialog takes the line's width.
|
||||
Row::new().wrap(!line).show(ui, |ui, _| {
|
||||
cx.labelled(ui, "range", words.pages_from.clone(), after.clone(), Radio::new(PageScope::Range));
|
||||
let field = |label: &Label, shown: usize| {
|
||||
NumberField::new(label.clone(), Bind::given(Some(shown as f64)))
|
||||
@@ -395,12 +408,12 @@ impl PageRangeOptions {
|
||||
Row::new().show(ui, |ui, _| {
|
||||
Text::new(words.to.clone()).show(ui);
|
||||
to = whole(&field(&words.to, shown_to).show(ui).edit, shown_to);
|
||||
if inline {
|
||||
if inline && !line {
|
||||
let count = env.format().integer(last as u64);
|
||||
Text::new(words.of_count.fill(&[("count", count.as_str())])).show(ui);
|
||||
}
|
||||
});
|
||||
if inline && choices.subset() {
|
||||
if subset_inline && choices.subset() {
|
||||
Row::new().show(ui, |ui, _| {
|
||||
Text::new(words.subset.clone()).show(ui);
|
||||
pick_subset(ui);
|
||||
@@ -409,7 +422,11 @@ impl PageRangeOptions {
|
||||
});
|
||||
};
|
||||
// The radio buttons stack, in a document dialog as elsewhere: production's Pages group is a column.
|
||||
Stack::new().show(ui, |ui, _| body(ui));
|
||||
if line {
|
||||
Row::new().show(ui, |ui, _| body(ui));
|
||||
} else {
|
||||
Stack::new().show(ui, |ui, _| body(ui));
|
||||
}
|
||||
});
|
||||
if let Some(scope) = group.output.value().copied() {
|
||||
next.scope = scope;
|
||||
@@ -421,7 +438,7 @@ impl PageRangeOptions {
|
||||
if let Some(value) = to {
|
||||
next.to = Some(value);
|
||||
}
|
||||
if choices.subset() && !inline {
|
||||
if choices.subset() && !subset_inline {
|
||||
Field::new(words.subset.clone()).show(ui, |ui, _| pick_subset(ui));
|
||||
}
|
||||
if let Some(chosen) = subset {
|
||||
|
||||
@@ -118,3 +118,59 @@ fn the_page_range_options_of_a_document_dialog_stack_under_their_heading_and_cou
|
||||
assert!(fixture.texts().iter().any(|run| run.text == "of 12"), "the range ends in the page count");
|
||||
assert!(fixture.by_label("Subset").is_none(), "this arrangement has no Subset");
|
||||
}
|
||||
|
||||
/// Production's Background and Watermark dialogs put the page range options on one line: All pages, Pages from and
|
||||
/// to, then the Subset, with no page count after the range.
|
||||
#[trial]
|
||||
fn line_page_range_options_stand_on_one_line_with_no_page_count() {
|
||||
use craft_ui::patterns::form_dialogs::{ParamDialog, ParamLayout};
|
||||
let mut fixture = Fixture::new(|ui| {
|
||||
let mut fields = DialogFields::new();
|
||||
ParamDialog::new("range", "Add Background", vec![PageRangeOptions::param("range", "Page Range Options", 3, 0, PageRangeChoices::Line)])
|
||||
.layout(ParamLayout::Document)
|
||||
.values(Bind::bound(&mut fields))
|
||||
.show(ui);
|
||||
});
|
||||
fixture.room(egui::vec2(1100.0, 700.0));
|
||||
fixture.settle();
|
||||
let at = |name: &str| fixture.by_label(name).unwrap_or_else(|| panic!("{name:?} is shown")).rect;
|
||||
let (all, from, subset) = (at("All pages"), at("Pages from"), at("Subset"));
|
||||
for (name, rect) in [("Pages from", from), ("Subset", subset)] {
|
||||
assert!((rect.center().y - all.center().y).abs() < 4.0, "{name} {rect:?} stands on the line of All pages {all:?}");
|
||||
}
|
||||
assert!(all.max.x <= from.min.x && from.max.x <= subset.min.x, "in reading order: {all:?} {from:?} {subset:?}");
|
||||
assert!(!fixture.texts().iter().any(|run| run.text == "of 3"), "the range shows no page count");
|
||||
}
|
||||
|
||||
/// Production's Rotate Pages lines its captions up in one column with the controls after it: the Pages: caption
|
||||
/// stands beside the page range group, not over it, and the group's options start where the Direction: list does.
|
||||
/// Without the column the group's caption heads it.
|
||||
#[trial]
|
||||
fn a_caption_column_puts_a_group_caption_beside_its_group_and_lines_the_controls_up() {
|
||||
use craft_ui::patterns::form_dialogs::{ParamDialog, ParamKind, ParamLayout};
|
||||
let shown = |column: bool| {
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let mut fields = DialogFields::new();
|
||||
let direction =
|
||||
ParamKind::choice(vec![("90".into(), "Clockwise 90 degrees".into()), ("180".into(), "180 degrees".into())], Some("90".into()));
|
||||
let rows = vec![
|
||||
Param::new("direction", "Direction:", direction),
|
||||
PageRangeOptions::param("pages", "Pages:", 12, 2, PageRangeChoices::SelectedFromTo),
|
||||
];
|
||||
ParamDialog::new("range", "Rotate", rows).layout(ParamLayout::Document).caption_column(column).values(Bind::bound(&mut fields)).show(ui);
|
||||
});
|
||||
fixture.room(egui::vec2(1100.0, 700.0));
|
||||
fixture.settle();
|
||||
let caption = fixture.texts().iter().find(|run| run.text.starts_with("Pages") && !run.text.contains("from")).map(|run| run.rect);
|
||||
let caption =
|
||||
caption.unwrap_or_else(|| panic!("the Pages caption shows: {:?}", fixture.texts().iter().map(|run| &run.text).collect::<Vec<_>>()));
|
||||
let all = fixture.by_label("All pages").expect("All pages shows").rect;
|
||||
let direction = fixture.by_label("Direction:").or_else(|| fixture.by_label("Direction")).expect("the Direction list shows").rect;
|
||||
(caption, all, direction)
|
||||
};
|
||||
let (caption, all, direction) = shown(true);
|
||||
assert!(caption.max.x <= all.min.x && caption.min.y >= all.min.y - 4.0, "the caption {caption:?} stands beside the group {all:?}");
|
||||
assert!((all.min.x - direction.min.x).abs() <= 2.0, "the group {all:?} starts where the Direction list {direction:?} does");
|
||||
let (caption, all, _) = shown(false);
|
||||
assert!(caption.max.y <= all.min.y + 1.0, "without the column the caption {caption:?} heads the group {all:?}");
|
||||
}
|
||||
@@ -40,7 +40,7 @@ use crate::runtime::overlay::CloseReason;
|
||||
use crate::runtime::words::CommonWords;
|
||||
use crate::sections::{DialogRole, FooterButton};
|
||||
|
||||
use crate::contract::LabelScheme;
|
||||
use crate::contract::{CaptionColumn, LabelScheme};
|
||||
use craft_theme::Srgba;
|
||||
use craft_theme::variant::Tone;
|
||||
use egui::{Context, Pos2, Rect, Response, Ui};
|
||||
@@ -351,6 +351,12 @@ pub struct ParamDialog<'a> {
|
||||
/// How the rows, the preview pane and the buttons are arranged.
|
||||
#[prop]
|
||||
layout: Option<ParamLayout>,
|
||||
/// In a document dialog ([`ParamLayout::Document`]), the captions share one column at the row start and the
|
||||
/// controls line up after it, a group of controls (a custom row) with its caption beside it rather than over it:
|
||||
/// production's Rotate Pages (Direction:, Pages: and Rotate: in a column). Off by default: each caption is as
|
||||
/// wide as its text, and a group row's caption heads it ([`CaptionColumn`]).
|
||||
#[prop]
|
||||
caption_column: bool,
|
||||
/// Whether the title row has a close action.
|
||||
#[prop]
|
||||
closable: bool,
|
||||
@@ -464,6 +470,7 @@ impl<'a> ParamDialog<'a> {
|
||||
collection_body: false,
|
||||
reset_to: None,
|
||||
layout: None,
|
||||
caption_column: false,
|
||||
closable: true,
|
||||
close_unchanged: false,
|
||||
previews: false,
|
||||
@@ -577,6 +584,7 @@ impl<'a> ParamDialog<'a> {
|
||||
collection_body,
|
||||
reset_to,
|
||||
layout,
|
||||
caption_column,
|
||||
closable,
|
||||
close_unchanged,
|
||||
previews,
|
||||
@@ -697,6 +705,7 @@ impl<'a> ParamDialog<'a> {
|
||||
// A tabbed document dialog (Document Properties) is an aligned form: no colons, one caption column, the
|
||||
// controls filling the rest of the row.
|
||||
labels: if layout == ParamLayout::Document && !tabs.is_empty() { Some(LabelScheme::Inspector) } else { layout.labels() },
|
||||
caption_column: caption_column && layout == ParamLayout::Document,
|
||||
canvas,
|
||||
read_only,
|
||||
};
|
||||
@@ -974,6 +983,8 @@ struct DialogRows<'p> {
|
||||
sliders: SliderFieldLayout,
|
||||
/// The label scheme the layout sets for the rows.
|
||||
labels: Option<LabelScheme>,
|
||||
/// The rows' captions share one column ([`ParamDialog::caption_column`]).
|
||||
caption_column: bool,
|
||||
canvas: Option<egui::Id>,
|
||||
/// The dialog shows values only.
|
||||
read_only: bool,
|
||||
@@ -995,6 +1006,15 @@ impl DialogRows<'_> {
|
||||
if let Some(canvas) = self.canvas {
|
||||
rows = rows.canvas(canvas);
|
||||
}
|
||||
if self.caption_column {
|
||||
return crate::runtime::env::with_env(
|
||||
ui,
|
||||
|scope| {
|
||||
scope.values.set(CaptionColumn::SHARED);
|
||||
},
|
||||
|ui| rows.show(ui),
|
||||
);
|
||||
}
|
||||
rows.show(ui)
|
||||
}
|
||||
|
||||
|
||||
@@ -481,6 +481,8 @@ pub(crate) struct RowOptions {
|
||||
eyedropper_armed: bool,
|
||||
full_width: bool,
|
||||
beside_next: bool,
|
||||
/// A range row's slider is short and its number field content-wide ([`Param::short_slider`]).
|
||||
short_slider: bool,
|
||||
/// A radio row's options stand in one row with no caption ([`Param::options_in_row`]).
|
||||
options_in_row: bool,
|
||||
/// A radio row's options stand in a column with no caption, in a document dialog too ([`Param::stacked_options`]).
|
||||
@@ -970,6 +972,15 @@ impl Param {
|
||||
self
|
||||
}
|
||||
|
||||
/// For a [`ParamKind::Range`] row: the slider asks for a short field's length and the number field is as wide as
|
||||
/// its widest value, so the row takes its content's width rather than the form's (production's Opacity). Other
|
||||
/// kinds and a popup slider are unchanged.
|
||||
#[must_use]
|
||||
pub fn short_slider(mut self) -> Self {
|
||||
self.options.get_or_insert_default().short_slider = true;
|
||||
self
|
||||
}
|
||||
|
||||
/// For a [`ParamKind::Radio`] row: the options stand side by side in one row, with no caption over them; the label
|
||||
/// still names the group for assistive technology. Other kinds are unchanged.
|
||||
#[must_use]
|
||||
@@ -1188,6 +1199,11 @@ impl RowOptions {
|
||||
self.full_width
|
||||
}
|
||||
|
||||
/// Whether a range row's slider is short.
|
||||
pub(crate) fn short_slider(&self) -> bool {
|
||||
self.short_slider
|
||||
}
|
||||
|
||||
/// Whether a radio row's options stand in one row with no caption.
|
||||
pub(crate) fn options_in_row(&self) -> bool {
|
||||
self.options_in_row
|
||||
|
||||
@@ -13,8 +13,8 @@ use super::words::ParamWords;
|
||||
use crate::buttons::{Button, ToggleButton};
|
||||
use crate::choice::{Checkbox, Radio, RadioGroup, Swatch};
|
||||
use crate::contract::{
|
||||
Bind, BodyCx, CanvasGesture, Entry, FieldLayout, LabelScheme, NoValue, Outcome, Pad, Props as _, Remember as _, Sampler as _, Show as _,
|
||||
ShowContainer as _, SideLabel, Sizing, TooltipSpec, clicked,
|
||||
Bind, BodyCx, CanvasGesture, CaptionColumn, Entry, FieldLayout, LabelScheme, NoValue, Outcome, Pad, Props as _, Remember as _, Sampler as _,
|
||||
Show as _, ShowContainer as _, SideLabel, Sizing, TooltipSpec, clicked,
|
||||
};
|
||||
use crate::display::Text;
|
||||
use crate::form::{Field, FieldGroup, SliderField, SliderFieldLayout};
|
||||
@@ -352,8 +352,14 @@ impl Line<'_> {
|
||||
return;
|
||||
}
|
||||
let mut field = Field::new(self.name.clone()).id_salt(self.key).enabled(self.enabled);
|
||||
// In a document dialog a custom row is a group of controls (page range options, say): its name heads it.
|
||||
if matches!(self.param.kind, ParamKind::Custom(_)) && Env::of(ui).view().get::<LabelScheme>() == LabelScheme::Inline {
|
||||
// In a document dialog a custom row is a group of controls (page range options, say): its name heads it, unless
|
||||
// the captions share a column ([`CaptionColumn`]), where it stands beside the group as every caption does.
|
||||
let env = Env::of(ui);
|
||||
let view = env.view();
|
||||
if matches!(self.param.kind, ParamKind::Custom(_))
|
||||
&& view.get::<LabelScheme>() == LabelScheme::Inline
|
||||
&& !view.get::<CaptionColumn>().shared()
|
||||
{
|
||||
field = field.layout(FieldLayout::Above);
|
||||
}
|
||||
if self.compact {
|
||||
@@ -596,8 +602,12 @@ impl<'p> Pass<'p> {
|
||||
return;
|
||||
}
|
||||
let layout = self.sliders;
|
||||
let short = options.short_slider();
|
||||
let mut show = |ui: &mut Ui| {
|
||||
let mut slider = SliderField::new(line.name.clone(), Bind::given(value), range.clone()).scale(scale).layout(layout);
|
||||
if short {
|
||||
slider = slider.short(true).field_sizing(Sizing::Content);
|
||||
}
|
||||
if let Some(places) = places {
|
||||
slider = slider.step(10f64.powi(-(places as i32)));
|
||||
}
|
||||
@@ -619,6 +629,8 @@ impl<'p> Pass<'p> {
|
||||
};
|
||||
match layout {
|
||||
SliderFieldLayout::Stacked => show(ui),
|
||||
// A short row is as wide as its content, as a row in a shared line is.
|
||||
_ if short => Line { compact: true, name: line.name.clone(), ..*line }.show(ui, show),
|
||||
_ => line.show(ui, show),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -721,3 +721,27 @@ fn a_text_row_that_selects_on_focus_is_replaced_by_typing() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Production's Opacity row: a short slider and a number field as wide as its value, the row as wide as its content.
|
||||
/// An unmarked range row's slider takes the room the form offers.
|
||||
#[trial]
|
||||
fn a_short_slider_row_is_as_wide_as_its_content() {
|
||||
let widths = |short: bool| {
|
||||
let row = Param::new("opacity", "Opacity", ParamKind::range(0.0, 100.0, 100.0, Default::default())).decimals(1);
|
||||
let params = vec![if short { row.short_slider() } else { row }];
|
||||
let values = Rc::new(RefCell::new(DialogFields::new()));
|
||||
let shown = values.clone();
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let _ = ParamRows::new("Form", ¶ms, Bind::bound(&mut *shown.borrow_mut())).labels(LabelScheme::Inline).show(ui);
|
||||
});
|
||||
fixture.room(egui::vec2(800.0, 400.0));
|
||||
fixture.settle();
|
||||
let slider = fixture.by_role(Role::SLIDER).first().map(|slider| slider.rect.width());
|
||||
let field = fixture.by_role(Role::SPIN_BUTTON).first().map(|field| field.rect.width());
|
||||
(slider.unwrap_or(f32::NAN), field.unwrap_or(f32::NAN))
|
||||
};
|
||||
let ((long, wide), (short, narrow)) = (widths(false), widths(true));
|
||||
assert!(long > 300.0, "an unmarked slider fills the row: {long}");
|
||||
assert!(short < 120.0 && short > 40.0, "a short slider is about a short field long: {short}");
|
||||
assert!(narrow <= wide, "the short row's number field ({narrow}) is no wider than the unmarked one's ({wide})");
|
||||
}
|
||||
@@ -96,6 +96,10 @@ pub struct SliderField<'a> {
|
||||
/// row, the Color panel's channels) instead of the number cell, and the slider takes the room it leaves.
|
||||
#[prop]
|
||||
field_sizing: Option<Sizing>,
|
||||
/// The slider asks for a short length ([`Slider::short`]): with a content-sized number field, the line is as wide as
|
||||
/// a short field and the number, as production's Opacity, not the room it is offered.
|
||||
#[prop]
|
||||
short: bool,
|
||||
/// The number field's width from this pass's measure (its `Proposal::Ideal` call, which runs before `paint`).
|
||||
field_width: f32,
|
||||
/// The field's range alert of this pass, which `finish` reports.
|
||||
@@ -151,6 +155,7 @@ impl<'a> SliderField<'a> {
|
||||
track_face: None,
|
||||
thumb: SliderThumb::Round,
|
||||
field_sizing: None,
|
||||
short: false,
|
||||
field_width: 0.0,
|
||||
out_of_range: None,
|
||||
}
|
||||
@@ -171,6 +176,7 @@ impl<'a> SliderField<'a> {
|
||||
thumb: self.thumb,
|
||||
reset: self.value.reset_value().copied(),
|
||||
field_sizing: self.field_sizing,
|
||||
short: self.short,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -189,6 +195,7 @@ struct Look {
|
||||
/// The reset value of the composite's own binding, which both children restore on a double click.
|
||||
reset: Option<f64>,
|
||||
field_sizing: Option<Sizing>,
|
||||
short: bool,
|
||||
}
|
||||
|
||||
/// The composite's check, which its children check their values with.
|
||||
@@ -214,7 +221,7 @@ impl Look {
|
||||
if let Some(check) = check {
|
||||
bind = bind.check_with(check, BindCheck::validity);
|
||||
}
|
||||
let slider = Slider::new(bind, self.range.clone()).scale(self.scale).fill(self.fill).thumb(self.thumb).label(name.clone());
|
||||
let slider = Slider::new(bind, self.range.clone()).scale(self.scale).fill(self.fill).thumb(self.thumb).short(self.short).label(name.clone());
|
||||
let slider = match face {
|
||||
Some(face) => slider.track_face(face),
|
||||
None => slider,
|
||||
@@ -298,8 +305,9 @@ impl Component for SliderField<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// A short slider keeps to its own length; otherwise the line takes the width it is offered.
|
||||
fn fills(&self) -> Option<craft_behavior::Axis> {
|
||||
Some(craft_behavior::Axis::X)
|
||||
(!self.short).then_some(craft_behavior::Axis::X)
|
||||
}
|
||||
|
||||
fn sense(&self) -> Sense {
|
||||
|
||||
@@ -96,6 +96,11 @@ pub struct Slider<'a> {
|
||||
track_face: Option<TrackFace<'a>>,
|
||||
/// The kept part of the range, its ends drawn across the track ([`Slider::trim`]).
|
||||
trim: Option<(f64, f64)>,
|
||||
/// The track asks for a short field's length (`size.length.short`) in place of a track's (`size.length.track`):
|
||||
/// a slider beside a number in a document dialog's line, as production's Opacity.
|
||||
#[style_key]
|
||||
#[prop]
|
||||
short: bool,
|
||||
}
|
||||
|
||||
/// The shape of a slider's thumb.
|
||||
@@ -129,6 +134,7 @@ impl<'a> Slider<'a> {
|
||||
value_text: None,
|
||||
track_face: None,
|
||||
trim: None,
|
||||
short: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,9 +191,9 @@ impl Component for Slider<'_> {
|
||||
type Style = SliderStyle;
|
||||
type Output = EditResponse<f64>;
|
||||
|
||||
fn style(cx: &StyleCx<'_>, _: SliderStyleKey) -> SliderStyle {
|
||||
fn style(cx: &StyleCx<'_>, key: SliderStyleKey) -> SliderStyle {
|
||||
let control = cx.control();
|
||||
let length = cx.tokens.size.length.track;
|
||||
let length = if key.short { cx.tokens.size.length.short } else { cx.tokens.size.length.track };
|
||||
SliderStyle {
|
||||
// Where a row shrinks it, the track narrows down to a square of the control's height.
|
||||
metrics: Metrics::new().min_size(Vec2::new(length, control.height)).least_width(control.height),
|
||||
|
||||
Reference in new issue
Block a user