mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 00:57:26 +00:00
pdf-dialogs-w1: net change of 3 commits
- pdf-dialogs-w1: written by an agent - pdf-dialogs-w1: finished by an agent - pdf-dialogs-w1: review fixes (review-1)
This commit is contained in:
@@ -7,25 +7,30 @@ use crate::runtime::requests::{ColorRequest, EyedropperRequest, HostAnswer, List
|
||||
|
||||
use super::form::{FormDialog, FormDialogWords};
|
||||
use super::host_requests::HostRequests;
|
||||
use super::param::{Param, ParamKind, open_fields, set_color_field};
|
||||
use super::param::{Param, ParamKind, edited_rows, open_fields, set_color_field};
|
||||
use super::preview::{PagerStep, PaneOverlay, PanePager, PreviewPane, PreviewState, PreviewView, PreviewZoom};
|
||||
|
||||
use super::rows::{ParamRows, ParamRowsOutput};
|
||||
|
||||
use crate::contract::{Bind, BodyCx, CanvasGesture, NoValue, Outcome, Remember as _, Sampler as _, SaveKey, Show as _, ShowContainer as _};
|
||||
use crate::contract::{
|
||||
Bind, BodyCx, CanvasGesture, CollectionEvent, NoValue, Outcome, Remember as _, Sampler as _, SaveKey, Show as _, ShowCollection as _,
|
||||
ShowContainer as _,
|
||||
};
|
||||
|
||||
use crate::dialog::{Alert, Dialog, DialogId, DialogResult, DialogStack, FieldRefusal, FooterHooks, HeldAnswer, HeldOk, StackDialog, dialog_id};
|
||||
|
||||
use crate::display::{Shade, Text};
|
||||
use crate::form::SliderFieldLayout;
|
||||
use crate::layout::RowAlign;
|
||||
use crate::layout_components::{Row, Stack};
|
||||
use crate::notices::{Notice, NoticeLayout};
|
||||
use crate::style::DataColor;
|
||||
use crate::tabs::{Tab, TabKind, TabStrip};
|
||||
|
||||
use crate::primitives::ContentPainterCx;
|
||||
use crate::runtime::env::{Env, Label};
|
||||
use crate::text::RangeAlert;
|
||||
use craft_behavior::CanvasTransform;
|
||||
use craft_behavior::{CanvasTransform, DisplayOrder, EditEvent, ItemSource, Mixed, SelectionChange};
|
||||
|
||||
use crate::runtime::memory::MemoryStage;
|
||||
|
||||
@@ -103,18 +108,54 @@ pub struct ParamTab {
|
||||
impl ParamTab {
|
||||
/// A tab titled `title` with the rows `params`.
|
||||
pub fn new(title: impl Into<Label>, params: Vec<Param>) -> Self {
|
||||
let _ = (title, params);
|
||||
todo!("DG-C1")
|
||||
ParamTab { title: title.into(), params, note: None, read_only: false }
|
||||
}
|
||||
|
||||
/// The tab as a read-only one, with `note` above its rows.
|
||||
#[must_use]
|
||||
pub fn read_only(self, note: Option<Label>) -> Self {
|
||||
let _ = note;
|
||||
todo!("DG-C1")
|
||||
ParamTab { note, read_only: true, ..self }
|
||||
}
|
||||
}
|
||||
|
||||
/// The tab titles of a tabbed dialog as an item source, keyed by position.
|
||||
struct Titles<'t>(&'t [ParamTab]);
|
||||
|
||||
impl DisplayOrder<usize> for Titles<'_> {
|
||||
fn len(&self) -> usize {
|
||||
self.0.len()
|
||||
}
|
||||
|
||||
fn key(&self, at: usize) -> usize {
|
||||
at
|
||||
}
|
||||
|
||||
fn index_of(&self, key: &usize) -> Option<usize> {
|
||||
(*key < self.0.len()).then_some(*key)
|
||||
}
|
||||
|
||||
fn text(&self, at: usize) -> Option<Cow<'_, str>> {
|
||||
self.0.get(at).map(|tab| Cow::Borrowed(tab.title.as_str()))
|
||||
}
|
||||
}
|
||||
|
||||
impl ItemSource<usize> for Titles<'_> {}
|
||||
|
||||
/// The tab a tabbed dialog without a `tab` binding shows while it is open.
|
||||
#[derive(Clone, Default)]
|
||||
struct OpenTab(usize);
|
||||
|
||||
/// The shared rows, then the rows of every tab: their values open, validate and answer together, whichever tab shows.
|
||||
/// The rows of a read-only tab are disabled here, so automation cannot set what the user cannot edit.
|
||||
fn every_param<'p>(params: Cow<'p, [Param]>, tabs: &[ParamTab]) -> Cow<'p, [Param]> {
|
||||
if tabs.is_empty() {
|
||||
return params;
|
||||
}
|
||||
let mut every = params.into_owned();
|
||||
every.extend(tabs.iter().flat_map(|tab| tab.params.iter().cloned().map(move |param| if tab.read_only { param.disabled() } else { param })));
|
||||
Cow::Owned(every)
|
||||
}
|
||||
|
||||
/// Where a tabbed dialog's own `params` go.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
@@ -216,7 +257,13 @@ impl Outcome for ParamDialogOutput {
|
||||
/// (the Preview check box held down). Drag pans the picture, the zoom buttons scale it. The
|
||||
/// [`layout`](ParamDialog::layout) places the pane and the buttons.
|
||||
/// - Footer: [`extra_buttons`](ParamDialog::extra_buttons) keep the dialog open and come back as
|
||||
/// `ParamDialogOutput::action`; [`footer_note`](ParamDialog::footer_note) is a muted line at the start edge.
|
||||
/// `ParamDialogOutput::action`, the one action channel a custom row's `CustomContext::request_action` reports in
|
||||
/// too; [`footer_note`](ParamDialog::footer_note) is a muted line at the start edge.
|
||||
/// - Tabs: with [`tabs`](ParamDialog::tabs) a `TabStrip` shows the tab titles and the shown tab's rows; the dialog's
|
||||
/// own `params` are the shared rows, above the strip or under the tab's rows ([`SharedRows`]). Every tab's values
|
||||
/// open, validate and answer together. The `tab` binding says which tab shows.
|
||||
/// - Read-only: [`read_only`](ParamDialog::read_only) shows the values without controls, has one button and no Alt
|
||||
/// reset, and answers with no values whichever way it closes.
|
||||
/// - A command form is a dialog with no preview and no remember key.
|
||||
#[must_use = "show the dialog with `show`"]
|
||||
#[derive(crate::contract::Pattern, crate::contract::Props)]
|
||||
@@ -492,7 +539,7 @@ impl<'a> ParamDialog<'a> {
|
||||
params,
|
||||
tabs,
|
||||
shared_rows,
|
||||
tab,
|
||||
mut tab,
|
||||
read_only,
|
||||
title_note,
|
||||
bound,
|
||||
@@ -514,7 +561,7 @@ impl<'a> ParamDialog<'a> {
|
||||
preview_on,
|
||||
preview,
|
||||
preview_pager,
|
||||
preview_overlay,
|
||||
mut preview_overlay,
|
||||
preview_tint,
|
||||
click_centres,
|
||||
canvas,
|
||||
@@ -531,11 +578,16 @@ impl<'a> ParamDialog<'a> {
|
||||
centre,
|
||||
preview_colors,
|
||||
} = self;
|
||||
// P3(pdf-dialogs-w1): DG-C3, DG-C12, CM-C28 — the writer draws these; the stub only reads them.
|
||||
let _ = (tabs, shared_rows, tab, read_only, title_note, preview_pager, preview_overlay, preview_tint);
|
||||
let preview_label = Env::of(ui).words::<FormDialogWords>().preview.clone();
|
||||
let env = Env::of(ui);
|
||||
let preview_label = env.words::<FormDialogWords>().preview.clone();
|
||||
// A read-only dialog has one button, so there is no second one for Alt to turn into Reset.
|
||||
let alt_resets = alt_resets && !read_only;
|
||||
// The footer `FormDialog` builds for this pass, made the same way, so its `pick` reads `FormOutput::picked`.
|
||||
let footer = ResetFooter::new(ui, cancel_label.clone(), alt_resets);
|
||||
let tabbed = !tabs.is_empty();
|
||||
let every = every_param(Cow::Borrowed(&*params), &tabs);
|
||||
let read_only_ok =
|
||||
read_only.then(|| FooterButton::new(ok_label.clone().unwrap_or_else(|| env.words::<CommonWords>().ok.clone()), DialogRole::Accept));
|
||||
|
||||
let mut form = match bound {
|
||||
Some(bind) => FormDialog::new(title.clone(), bind),
|
||||
@@ -546,7 +598,8 @@ impl<'a> ParamDialog<'a> {
|
||||
.alt_resets(alt_resets)
|
||||
.outer_gesture(outer_gesture)
|
||||
.history(history)
|
||||
.collection_body(collection_body)
|
||||
// The tab strip is a collection in the body, as a browse list is.
|
||||
.collection_body(collection_body || tabbed)
|
||||
.closable(closable)
|
||||
.accept_stays_open(hold)
|
||||
.answers(answers);
|
||||
@@ -588,33 +641,57 @@ impl<'a> ParamDialog<'a> {
|
||||
Text::new(note.clone()).shade(Shade::Muted).show(ui);
|
||||
});
|
||||
}
|
||||
if let Some(Shaped(shape)) = shaped {
|
||||
form = form.shaped(shape);
|
||||
// `FormDialog` has one slot for `Dialog` settings: the read-only footer, then the title note, then the caller's
|
||||
// shape, last so it can still change what the dialog set itself.
|
||||
if read_only_ok.is_some() || title_note.is_some() || shaped.is_some() {
|
||||
form = form.shaped(move |mut dialog| {
|
||||
if let Some(ok) = read_only_ok {
|
||||
dialog = dialog.buttons([ok]);
|
||||
}
|
||||
if let Some(note) = title_note {
|
||||
dialog = dialog.title_note(note);
|
||||
}
|
||||
if let Some(Shaped(shape)) = shaped {
|
||||
dialog = shape(dialog);
|
||||
}
|
||||
dialog
|
||||
});
|
||||
}
|
||||
|
||||
let mut live = Live::default();
|
||||
let mut rows = None;
|
||||
let mut shown_preview = ShownPreview::default();
|
||||
let mut latest = None::<DialogFields>;
|
||||
let body = DialogRows {
|
||||
title: &title,
|
||||
shared: ¶ms,
|
||||
tabs: &tabs,
|
||||
place: shared_rows,
|
||||
patterns: &patterns,
|
||||
preview_colors: &preview_colors,
|
||||
sliders: layout.sliders(),
|
||||
canvas,
|
||||
read_only,
|
||||
};
|
||||
let shown = form.show(ui, |ui, cx, values| {
|
||||
if cx.first() && !host_opened {
|
||||
let saved = remember.as_ref().and_then(|key| cx.saved::<Option<DialogFields>>(key).clone());
|
||||
Self::open_values(¶ms, &patterns, saved.as_ref(), values);
|
||||
Self::open_values(&every, &patterns, saved.as_ref(), values);
|
||||
}
|
||||
for answer in cx.take_answers() {
|
||||
let answered = match &answer {
|
||||
HostAnswer::Color { key, .. } | HostAnswer::Eyedropper { key, .. } | HostAnswer::Path { key, .. } => {
|
||||
params.iter().find(|param| param.key == *key)
|
||||
every.iter().find(|param| param.key == *key)
|
||||
}
|
||||
HostAnswer::Listing { .. } => None,
|
||||
};
|
||||
let held = answered.and_then(|param| values.get(¶m.key).cloned());
|
||||
match answer {
|
||||
HostAnswer::Color { key, color } | HostAnswer::Eyedropper { key, color } => set_color_field(¶ms, values, &key, color),
|
||||
HostAnswer::Color { key, color } | HostAnswer::Eyedropper { key, color } => set_color_field(&every, values, &key, color),
|
||||
HostAnswer::Path { key, path } => values.set(&key, FieldValue::Text(path.to_string_lossy().into_owned())),
|
||||
HostAnswer::Listing { key, files } => {
|
||||
let files = files.into_iter().map(|file| FieldValue::Text(file.to_string_lossy().into_owned())).collect();
|
||||
if let Some(param) = params.iter().find(|param| param.key == key) {
|
||||
if let Some(param) = every.iter().find(|param| param.key == key) {
|
||||
values.set(param.folder_files_key(), FieldValue::List(files));
|
||||
}
|
||||
}
|
||||
@@ -636,37 +713,45 @@ impl<'a> ParamDialog<'a> {
|
||||
cx.request_close_as(CloseReason::Activated);
|
||||
}
|
||||
live = cx.memory::<Live>().clone();
|
||||
// P3(pdf-dialogs-w1): DG-C12 — only a `Ready` preview has a picture to centre on.
|
||||
// Only a `Ready` preview has a picture to centre on.
|
||||
if let (Some(point), Some(PreviewState::Ready(texture))) = (centre, &preview) {
|
||||
live.view = live.view.centred_on(point, texture.size);
|
||||
}
|
||||
let mut show_rows = |ui: &mut Ui, values: &mut DialogFields| {
|
||||
let mut shown = ParamRows::new(title.clone(), ¶ms, Bind::bound(values))
|
||||
.patterns(&patterns)
|
||||
.preview_colors(&preview_colors)
|
||||
.sliders(layout.sliders());
|
||||
if let Some(canvas) = canvas {
|
||||
shown = shown.canvas(canvas);
|
||||
}
|
||||
rows = Some(shown.show(ui));
|
||||
// The `tab` binding, when there is one, says which tab shows; the dialog's memory does otherwise.
|
||||
let last = tabs.len().saturating_sub(1);
|
||||
let bound_tab = match tab.as_mut().map(|bind| bind.reborrow().read(&mut **cx)) {
|
||||
Some(Some(Mixed::Same(at))) => Some(at),
|
||||
_ => None,
|
||||
};
|
||||
let held_tab = bound_tab.unwrap_or_else(|| cx.memory::<OpenTab>().0).min(last);
|
||||
let mut shown_tab = held_tab;
|
||||
let mut show_rows = |ui: &mut Ui, values: &mut DialogFields| rows = body.show(ui, &mut shown_tab, values);
|
||||
// A measuring run paints nothing, so it leaves the overlay, which runs once, to the real run.
|
||||
let overlay = if crate::runtime::measure::active(ui.ctx()) { None } else { preview_overlay.take() };
|
||||
let mut extras = PaneExtras { pager: preview_pager.clone(), overlay, tint: preview_tint };
|
||||
match (&preview, layout) {
|
||||
(Some(texture), ParamLayout::Beside) => {
|
||||
(Some(state), ParamLayout::Beside) => {
|
||||
Row::new().show(ui, |ui, _| {
|
||||
show_rows(ui, values);
|
||||
Stack::new()
|
||||
.show(ui, |ui, _| shown_preview = show_preview(ui, &preview_label, texture, click_centres, ZoomRow::Above, &mut live));
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
shown_preview = show_preview(ui, &preview_label, state, &mut extras, click_centres, ZoomRow::Above, &mut live);
|
||||
});
|
||||
});
|
||||
}
|
||||
(Some(texture), layout) => {
|
||||
(Some(state), layout) => {
|
||||
let zoom = if layout == ParamLayout::Stacked { ZoomRow::Below } else { ZoomRow::Above };
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
show_rows(ui, values);
|
||||
shown_preview = show_preview(ui, &preview_label, texture, click_centres, zoom, &mut live);
|
||||
shown_preview = show_preview(ui, &preview_label, state, &mut extras, click_centres, zoom, &mut live);
|
||||
});
|
||||
}
|
||||
(None, _) => show_rows(ui, values),
|
||||
}
|
||||
if let Some(bind) = tab.as_mut().filter(|_| bound_tab != Some(shown_tab)) {
|
||||
let event = EditEvent::set(bound_tab.map_or(Mixed::Mixed, Mixed::Same), shown_tab, title.as_str().into(), None);
|
||||
let _ = bind.reborrow().write(&mut **cx, &event);
|
||||
}
|
||||
cx.memory::<OpenTab>().0 = shown_tab;
|
||||
// The host's refusal of the held OK stays until a value changes.
|
||||
if let Some((reason, _)) = refusal.as_ref().filter(|(_, refused)| *refused == *values) {
|
||||
Notice::new(Tone::Bad, reason.clone()).layout(NoticeLayout::Inline).show(ui);
|
||||
@@ -681,13 +766,19 @@ impl<'a> ParamDialog<'a> {
|
||||
|
||||
// `picked` is this pass's press: a second pass of the frame has none, so a press is reported once.
|
||||
let pick = footer.pick(shown.picked);
|
||||
let action = match pick {
|
||||
let pressed = match pick {
|
||||
Some(ResetPick::Extra(at)) => extra_buttons.get(at).map(|(id, _)| id.clone()),
|
||||
_ => None,
|
||||
};
|
||||
// Footer and row buttons share one channel. The rows' own slot is emptied, so a host that absorbs the rows
|
||||
// files the press once.
|
||||
let action = rows.as_mut().and_then(|rows: &mut ParamRowsOutput| rows.action.take()).or(pressed);
|
||||
let closed = shown.closed.is_some();
|
||||
let (result, held) = match (shown.accepted, pick, latest) {
|
||||
(Some(fields), _, _) => (Some(Self::result(key, ¶ms, remember, fields)), None),
|
||||
(None, Some(ResetPick::Accept), Some(fields)) if hold => (None, Some(Self::result(key, ¶ms, remember, fields))),
|
||||
// A read-only dialog answers with no values, whichever way it closes.
|
||||
_ if read_only => (closed.then(|| Self::result(key, &every, None, DialogFields::new())), None),
|
||||
(Some(fields), _, _) => (Some(Self::result(key, &every, remember, fields)), None),
|
||||
(None, Some(ResetPick::Accept), Some(fields)) if hold => (None, Some(Self::result(key, &every, remember, fields))),
|
||||
_ => (None, None),
|
||||
};
|
||||
ParamDialogOutput {
|
||||
@@ -700,7 +791,7 @@ impl<'a> ParamDialog<'a> {
|
||||
comparing: shown.comparing,
|
||||
preview_click: shown_preview.clicked,
|
||||
action,
|
||||
preview_step: None, // P3(pdf-dialogs-w1): DG-C12
|
||||
preview_step: shown_preview.step,
|
||||
held,
|
||||
preview_centre: shown_preview.centre,
|
||||
}
|
||||
@@ -837,6 +928,91 @@ impl ResetFooter {
|
||||
}
|
||||
}
|
||||
|
||||
/// The rows a dialog shows: its own rows and, in a tabbed dialog, its tabs, all drawn the same way.
|
||||
struct DialogRows<'p> {
|
||||
/// The dialog's title, which names its own rows and its tab strip.
|
||||
title: &'p Label,
|
||||
/// The dialog's own rows: the shared rows of a tabbed dialog.
|
||||
shared: &'p [Param],
|
||||
tabs: &'p [ParamTab],
|
||||
place: SharedRows,
|
||||
patterns: &'p [PresetRow<String>],
|
||||
preview_colors: &'p [(String, Srgba)],
|
||||
sliders: SliderFieldLayout,
|
||||
canvas: Option<egui::Id>,
|
||||
/// The dialog shows values only.
|
||||
read_only: bool,
|
||||
}
|
||||
|
||||
impl DialogRows<'_> {
|
||||
/// The rows `params` over `values`, their group named `label`; `read_only` for the rows of a read-only tab.
|
||||
fn group(&self, ui: &mut Ui, label: &Label, params: &[Param], read_only: bool, values: &mut DialogFields) -> ParamRowsOutput {
|
||||
let mut rows = ParamRows::new(label.clone(), params, Bind::bound(values))
|
||||
.patterns(self.patterns)
|
||||
.preview_colors(self.preview_colors)
|
||||
.sliders(self.sliders)
|
||||
.read_only(self.read_only || read_only);
|
||||
if let Some(canvas) = self.canvas {
|
||||
rows = rows.canvas(canvas);
|
||||
}
|
||||
rows.show(ui)
|
||||
}
|
||||
|
||||
/// The body's rows. A tabbed dialog shows its shared rows where `place` puts them, the tab strip (with more than one
|
||||
/// tab), whose pick moves `shown`, and the rows of the tab `shown` under its note. One output for all the rows drawn.
|
||||
fn show(&self, ui: &mut Ui, shown: &mut usize, values: &mut DialogFields) -> Option<ParamRowsOutput> {
|
||||
let (title, shared, tabs) = (self.title, self.shared, self.tabs);
|
||||
if tabs.is_empty() {
|
||||
return Some(self.group(ui, title, shared, false, values));
|
||||
}
|
||||
let mut out = None;
|
||||
if self.place == SharedRows::Above && !shared.is_empty() {
|
||||
merge_rows(&mut out, self.group(ui, title, shared, false, values));
|
||||
}
|
||||
if tabs.len() > 1 {
|
||||
let last = tabs.len() - 1;
|
||||
let strip = TabStrip::new(title.clone())
|
||||
.kind(TabKind::Text)
|
||||
.shown(*shown)
|
||||
.show_items(ui, &Titles(tabs), &mut |key, _| Tab::new(tabs.get(*key).map_or_else(Label::default, |tab| tab.title.clone())));
|
||||
for event in strip.response.events {
|
||||
if let CollectionEvent::Selection(SelectionChange::Set(keys)) = event
|
||||
&& let Some(key) = keys.into_iter().last()
|
||||
{
|
||||
*shown = key.min(last);
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(tab) = tabs.get(*shown) {
|
||||
if let Some(note) = tab.note.as_ref().filter(|_| tab.read_only) {
|
||||
Notice::new(Tone::Info, note.clone()).layout(NoticeLayout::Inline).show(ui);
|
||||
}
|
||||
merge_rows(&mut out, self.group(ui, &tab.title, &tab.params, tab.read_only, values));
|
||||
}
|
||||
if self.place == SharedRows::Below && !shared.is_empty() {
|
||||
merge_rows(&mut out, self.group(ui, title, shared, false, values));
|
||||
}
|
||||
out
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds `next`, the output of rows shown after those of `out`, to `out`.
|
||||
fn merge_rows(out: &mut Option<ParamRowsOutput>, next: ParamRowsOutput) {
|
||||
*out = Some(match out.take() {
|
||||
Some(earlier) => earlier.merged(next),
|
||||
None => next,
|
||||
});
|
||||
}
|
||||
|
||||
/// What a dialog's preview pane shows beside its picture: the pager row under it, the host's drawing over the picture
|
||||
/// and the tint.
|
||||
struct PaneExtras<'p> {
|
||||
pager: Option<PanePager>,
|
||||
/// Taken by the run that paints: it runs once.
|
||||
overlay: Option<PaneOverlay<'p>>,
|
||||
tint: Option<DataColor>,
|
||||
}
|
||||
|
||||
/// What the preview pane reported in a pass.
|
||||
#[derive(Clone, Copy, Default)]
|
||||
struct ShownPreview {
|
||||
@@ -844,6 +1020,8 @@ struct ShownPreview {
|
||||
clicked: Option<Pos2>,
|
||||
/// The picture point at the centre of the view the pane drew.
|
||||
centre: Option<Pos2>,
|
||||
/// The step a press on the pager made.
|
||||
step: Option<PagerStep>,
|
||||
}
|
||||
|
||||
/// Where the zoom row stands: over the preview pane or under it.
|
||||
@@ -853,18 +1031,35 @@ enum ZoomRow {
|
||||
Below,
|
||||
}
|
||||
|
||||
/// The zoom row and the pane.
|
||||
fn show_preview(ui: &mut Ui, label: &Label, state: &PreviewState, click_centres: bool, zoom_row: ZoomRow, live: &mut Live) -> ShownPreview {
|
||||
let above = (zoom_row == ZoomRow::Above).then(|| PreviewZoom::new(&live.view).show(ui));
|
||||
// P3(pdf-dialogs-w1): DG-C12 — the pane takes the state; the zoom row and the centre follow `Ready` in the writer's version.
|
||||
let pane = PreviewPane::state(label.clone(), state.clone(), &live.view).click_centres(click_centres).show(ui);
|
||||
let below = (zoom_row == ZoomRow::Below).then(|| PreviewZoom::new(&live.view).show(ui));
|
||||
let centre = match state {
|
||||
PreviewState::Ready(texture) => Some(pane.shown.centre(texture.size)),
|
||||
/// The pane, the zoom row where `zoom_row` puts it and the pager centred under them. Only a `Ready` picture has a zoom
|
||||
/// row and a centre: a pending or failed preview has nothing to zoom.
|
||||
fn show_preview(
|
||||
ui: &mut Ui,
|
||||
label: &Label,
|
||||
state: &PreviewState,
|
||||
extras: &mut PaneExtras<'_>,
|
||||
click_centres: bool,
|
||||
zoom_row: ZoomRow,
|
||||
live: &mut Live,
|
||||
) -> ShownPreview {
|
||||
let picture = match state {
|
||||
PreviewState::Ready(texture) => Some(texture.size),
|
||||
PreviewState::Pending(_) | PreviewState::Failed(_) => None,
|
||||
};
|
||||
live.view = above.or(below).and_then(|zoom| zoom.view).or(pane.view).unwrap_or(pane.shown);
|
||||
ShownPreview { clicked: pane.clicked, centre }
|
||||
let above = (picture.is_some() && zoom_row == ZoomRow::Above).then(|| PreviewZoom::new(&live.view).show(ui));
|
||||
let mut pane = PreviewPane::state(label.clone(), state.clone(), &live.view).click_centres(click_centres);
|
||||
if let Some(tint) = extras.tint {
|
||||
pane = pane.tint(tint);
|
||||
}
|
||||
// `ParamDialog::show` leaves no overlay in a measuring run, which paints nothing.
|
||||
if let Some(overlay) = extras.overlay.take() {
|
||||
pane = pane.overlay(overlay.into_paint());
|
||||
}
|
||||
let pane = pane.show(ui);
|
||||
let below = (picture.is_some() && zoom_row == ZoomRow::Below).then(|| PreviewZoom::new(&live.view).show(ui));
|
||||
let step = extras.pager.as_ref().and_then(|pager| Row::new().align(RowAlign::Center).show(ui, |ui, _| pager.clone().show(ui)).inner.flatten());
|
||||
live.view = above.or(below).and_then(|zoom| zoom.view).or(pane.view).unwrap_or(pane.shown.clone());
|
||||
ShownPreview { clicked: pane.clicked, centre: picture.map(|size| pane.shown.centre(size)), step }
|
||||
}
|
||||
|
||||
/// Builds the dialog over the host-owned values of a [`HostedParamDialog`] for one pass.
|
||||
@@ -906,6 +1101,14 @@ pub struct HostedParamDialog {
|
||||
preview_on: bool,
|
||||
/// The preview picture the host last gave (`set_preview`).
|
||||
picture: Option<PreviewState>,
|
||||
/// The pager row under the preview pane the host last gave (`set_preview_pager`).
|
||||
pager: Option<PanePager>,
|
||||
/// The host's drawing over the preview picture (`set_preview_overlay`).
|
||||
overlay: Option<SharedOverlay>,
|
||||
/// The tint of the preview picture (`set_preview_tint`).
|
||||
tint: Option<DataColor>,
|
||||
/// The tab a tabbed dialog shows: bound to the dialog's `tab` prop, so the host sets it before a pass.
|
||||
tab: usize,
|
||||
/// What the dialog showed in its last pass.
|
||||
shown: ShownState,
|
||||
/// Whether OK files its answer for the host instead of closing ([`held_ok`](HostedParamDialog::held_ok)).
|
||||
@@ -935,8 +1138,8 @@ impl HostedParamDialog {
|
||||
build: impl for<'b> Fn(&'b mut DialogFields) -> ParamDialog<'b> + Send + 'static,
|
||||
) -> Self {
|
||||
let key = key.into();
|
||||
let ParamDialog { params, remember, patterns, previews, .. } = build(&mut fields);
|
||||
let (params, patterns) = (params.into_owned(), patterns.into_owned());
|
||||
let ParamDialog { params, tabs, remember, patterns, previews, .. } = build(&mut fields);
|
||||
let (params, patterns) = (every_param(params, &tabs).into_owned(), patterns.into_owned());
|
||||
let saved = remember.and_then(|key| MemoryStage::peek_saved::<Option<DialogFields>>(ctx, &key));
|
||||
ParamDialog::open_values(¶ms, &patterns, saved.as_ref(), &mut fields);
|
||||
let id = dialog_id(key.as_str());
|
||||
@@ -952,6 +1155,10 @@ impl HostedParamDialog {
|
||||
previews,
|
||||
preview_on: true,
|
||||
picture: None,
|
||||
pager: None,
|
||||
overlay: None,
|
||||
tint: None,
|
||||
tab: 0,
|
||||
shown: ShownState::default(),
|
||||
hold: false,
|
||||
held: HeldAnswer::new(),
|
||||
@@ -1024,44 +1231,40 @@ impl HostedParamDialog {
|
||||
|
||||
/// Sets the pager row under the preview pane from the next pass on; `None` shows none.
|
||||
pub fn set_preview_pager(&mut self, pager: Option<PanePager>) {
|
||||
let _ = pager;
|
||||
todo!("DG-C13")
|
||||
self.pager = pager;
|
||||
}
|
||||
|
||||
/// Sets the host's drawing over the preview picture from the next pass on; `None` draws none.
|
||||
pub fn set_preview_overlay(&mut self, overlay: Option<SharedOverlay>) {
|
||||
let _ = overlay;
|
||||
todo!("DG-C13")
|
||||
self.overlay = overlay;
|
||||
}
|
||||
|
||||
/// Sets the tint that multiplies the `Ready` preview picture's colours from the next pass on; `None` shows it
|
||||
/// untinted.
|
||||
pub fn set_preview_tint(&mut self, tint: Option<DataColor>) {
|
||||
let _ = tint;
|
||||
todo!("DG-C13")
|
||||
self.tint = tint;
|
||||
}
|
||||
|
||||
/// The step the preview pager took, once.
|
||||
pub fn take_preview_step(&mut self) -> Option<PagerStep> {
|
||||
todo!("DG-C13")
|
||||
self.requests.take_preview_step()
|
||||
}
|
||||
|
||||
/// Opens the dialog on the tab `tab` of a tabbed dialog ([`ParamDialog::tabs`]).
|
||||
#[must_use]
|
||||
pub fn tab(self, tab: usize) -> Self {
|
||||
let _ = tab;
|
||||
todo!("DG-C4")
|
||||
pub fn tab(mut self, tab: usize) -> Self {
|
||||
self.tab = tab;
|
||||
self
|
||||
}
|
||||
|
||||
/// Shows the tab `tab` from the next pass on.
|
||||
pub fn set_tab(&mut self, tab: usize) {
|
||||
let _ = tab;
|
||||
todo!("DG-C4")
|
||||
self.tab = tab;
|
||||
}
|
||||
|
||||
/// The tab shown in the last pass.
|
||||
/// The tab shown in the last pass; before the first pass, the tab it opens on.
|
||||
pub fn shown_tab(&self) -> usize {
|
||||
todo!("DG-C4")
|
||||
self.tab
|
||||
}
|
||||
|
||||
/// Whether the dialog previews and its Preview check box is on: the host renders the preview while it is. The box
|
||||
@@ -1115,7 +1318,8 @@ impl HostedParamDialog {
|
||||
self.requests.take_action()
|
||||
}
|
||||
|
||||
/// The row keys an edit changed since the last take.
|
||||
/// The row keys an edit changed since the last take: an edit in a row or a set through automation. The host's own
|
||||
/// [`set_field`](HostedParamDialog::set_field), its answers and Reset are no edit of a row.
|
||||
pub fn take_edited(&mut self) -> Vec<String> {
|
||||
self.requests.take_edited()
|
||||
}
|
||||
@@ -1282,10 +1486,19 @@ impl StackDialog for HostedParamDialog {
|
||||
if self.held.is_waiting() {
|
||||
dialog = dialog.ok_enabled(false);
|
||||
}
|
||||
// P3(pdf-dialogs-w1): DG-C12 — the state is no longer `Copy`.
|
||||
if let Some(picture) = self.picture.clone() {
|
||||
dialog = dialog.preview(picture);
|
||||
}
|
||||
if let Some(pager) = self.pager.clone() {
|
||||
dialog = dialog.preview_pager(pager);
|
||||
}
|
||||
if let Some(overlay) = self.overlay.clone() {
|
||||
dialog = dialog.preview_overlay(move |cx, transform, rect| overlay(cx, transform, rect));
|
||||
}
|
||||
if let Some(tint) = self.tint {
|
||||
dialog = dialog.preview_tint(tint);
|
||||
}
|
||||
dialog = dialog.tab(Bind::bound(&mut self.tab));
|
||||
let alert_title = dialog.alert_title.clone().unwrap_or_else(|| dialog.title.clone());
|
||||
let shown = dialog.show(ui);
|
||||
if let Some(mut rows) = shown.rows {
|
||||
@@ -1301,6 +1514,9 @@ impl StackDialog for HostedParamDialog {
|
||||
if let Some(action) = shown.action {
|
||||
self.requests.request_action(action);
|
||||
}
|
||||
if let Some(step) = shown.preview_step {
|
||||
self.requests.request_preview_step(step);
|
||||
}
|
||||
self.shown = ShownState { comparing: shown.comparing, centre: shown.preview_centre };
|
||||
if self.held.refusal().is_some_and(|(_, refused)| refused.fields != self.fields) {
|
||||
self.held.clear_refusal();
|
||||
@@ -1341,12 +1557,17 @@ impl StackDialog for HostedParamDialog {
|
||||
if self.held.is_waiting() {
|
||||
return None;
|
||||
}
|
||||
let ParamDialog { key, params, remember, ok_enabled, .. } = (self.build)(&mut self.fields);
|
||||
let ParamDialog { key, params, tabs, remember, ok_enabled, read_only, .. } = (self.build)(&mut self.fields);
|
||||
if !ok_enabled {
|
||||
return None;
|
||||
}
|
||||
let params = params.into_owned();
|
||||
let mut result = ParamDialog::result(key, ¶ms, remember, self.fields.clone());
|
||||
let params = every_param(params, &tabs).into_owned();
|
||||
// A read-only dialog answers with no values, as its OK does.
|
||||
let mut result = if read_only {
|
||||
ParamDialog::result(key, ¶ms, None, DialogFields::new())
|
||||
} else {
|
||||
ParamDialog::result(key, ¶ms, remember, self.fields.clone())
|
||||
};
|
||||
if self.hold {
|
||||
self.file_held(result);
|
||||
return None;
|
||||
@@ -1363,7 +1584,11 @@ impl StackDialog for HostedParamDialog {
|
||||
/// Keeps `value` when the row `field` names (a parameter or its unit choice) is shown, takes input, and takes
|
||||
/// the value ([`set_param_field`]).
|
||||
fn set_json_field(&mut self, _: &Context, field: &str, value: Value) -> Result<(), String> {
|
||||
let params = (self.build)(&mut self.fields).params.into_owned();
|
||||
let ParamDialog { params, tabs, read_only, .. } = (self.build)(&mut self.fields);
|
||||
if read_only {
|
||||
return Err(FieldRefusal::Inactive.message(field));
|
||||
}
|
||||
let params = every_param(params, &tabs).into_owned();
|
||||
let before = self.fields.clone();
|
||||
set_param_field(¶ms, &mut self.fields, field, value)?;
|
||||
for param in params.iter().filter(|param| matches!(param.kind, ParamKind::Files { .. })) {
|
||||
@@ -1371,6 +1596,7 @@ impl StackDialog for HostedParamDialog {
|
||||
self.requests.request_listing(request);
|
||||
}
|
||||
}
|
||||
self.requests.request_edited(edited_rows(¶ms, &before, &self.fields));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
//! Stories of `ParamDialog`.
|
||||
|
||||
use super::{HostedParamDialog, ParamDialog, ParamLayout};
|
||||
use super::{HostedParamDialog, ParamDialog, ParamLayout, ParamTab, SharedRows};
|
||||
use crate::contract::Bind;
|
||||
use crate::dialog::StackDialog as _;
|
||||
use crate::dialog::stories::hosted_with;
|
||||
use crate::patterns::form_dialogs::PreviewState;
|
||||
use crate::patterns::form_dialogs::{DialogFields, Param};
|
||||
use crate::primitives::TextureCache;
|
||||
use crate::patterns::form_dialogs::{DialogFields, Param, ParamKind};
|
||||
use crate::patterns::form_dialogs::{PagerUnit, PanePager, PreviewState};
|
||||
use crate::primitives::{ContentPainterCx, StrokeWidth, TextureCache};
|
||||
use crate::runtime::env::Label;
|
||||
use crate::style::DataColor;
|
||||
use crate::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::load::SizedTexture;
|
||||
use egui::{Color32, ColorImage, Ui, Vec2};
|
||||
use egui::{Color32, ColorImage, Rect, Stroke, Ui, Vec2};
|
||||
|
||||
const SPEC: &str = r#"{"radius":0.1..1000=1,"method":"spin|zoom","smooth":bool}"#;
|
||||
|
||||
@@ -36,7 +37,6 @@ fn blur_story(ui: &mut Ui, data: &mut StoryData, preview: bool, layout: ParamLay
|
||||
let layout = *data.choice("layout", layout, &LAYOUTS);
|
||||
let comparing = *data.value("comparing", false);
|
||||
let dialog = ParamDialog::new("blur", "Blur", Param::parse_list(SPEC)).opened(Bind::bound(data.value("open", true))).history(true).layout(layout);
|
||||
// P3(pdf-dialogs-w1): DG-C12 — the preview takes a `PreviewState`.
|
||||
let dialog = if preview { dialog.previews(true).preview(PreviewState::Ready(picture(ui, comparing))) } else { dialog };
|
||||
let shown = dialog.show(ui);
|
||||
*data.value("comparing", false) = shown.comparing;
|
||||
@@ -115,3 +115,94 @@ fn hosted_param_dialog_with_a_refused_ok(ui: &mut Ui, data: &mut StoryData) -> S
|
||||
fn command_form(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
ParamDialog::command("fit-image", "Fit Image", Param::parse_list(COMMAND_SPEC)).opened(Bind::bound(data.value("open", true))).show(ui).into()
|
||||
}
|
||||
|
||||
/// The rows of the tabbed stories' first tab.
|
||||
const GENERAL_SPEC: &str = r#"{"language":"english|german|french","deskew":bool,"resolution":72..600=300}"#;
|
||||
/// The rows of the tabbed stories' second tab.
|
||||
const OUTPUT_SPEC: &str = r#"{"layer":"text|image","keepOriginal":bool}"#;
|
||||
|
||||
/// The editable tabs of the tabbed stories.
|
||||
fn tabs() -> Vec<ParamTab> {
|
||||
vec![ParamTab::new("General", Param::parse_list(GENERAL_SPEC)), ParamTab::new("Output", Param::parse_list(OUTPUT_SPEC))]
|
||||
}
|
||||
|
||||
/// A tabbed dialog over `tabs`, with `shared` as its own rows, open while the story's `open` value is on.
|
||||
fn tabbed(data: &mut StoryData, tabs: Vec<ParamTab>, shared: Vec<Param>) -> ParamDialog<'_> {
|
||||
ParamDialog::new("ocr", "Recognize Text", shared).tabs(tabs).opened(Bind::bound(data.value("open", true)))
|
||||
}
|
||||
|
||||
/// Editable tabs: the strip shows the titles and the shown tab's rows; the values of both tabs answer at OK.
|
||||
#[story(ParamDialog<'static>, covers = [], drive = Drive::Never)]
|
||||
fn param_dialog_tabs(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
tabbed(data, tabs(), Vec::new()).show(ui).into()
|
||||
}
|
||||
|
||||
/// A read-only tab, shown first: its values without controls under an informational note.
|
||||
#[story(ParamDialog<'static>, covers = [], drive = Drive::Never)]
|
||||
fn param_dialog_tabs_read_only_note(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let document = vec![
|
||||
Param::read_only_text("producer", "Producer", "PdfCraft"),
|
||||
Param::read_only_text("version", "PDF Version", "1.7"),
|
||||
Param::new("tagged", "Tagged", ParamKind::bool(true)),
|
||||
];
|
||||
let note = Label::from("These values come from the file and cannot be changed here.");
|
||||
let mut all = vec![ParamTab::new("Document", document).read_only(Some(note))];
|
||||
all.extend(tabs());
|
||||
tabbed(data, all, Vec::new()).show(ui).into()
|
||||
}
|
||||
|
||||
/// Shared rows under the shown tab's rows.
|
||||
#[story(ParamDialog<'static>, covers = [], drive = Drive::Never)]
|
||||
fn param_dialog_shared_rows_below(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let shared = Param::parse_list(r#"{"allPages":bool}"#);
|
||||
tabbed(data, tabs(), shared).shared_rows(SharedRows::Below).show(ui).into()
|
||||
}
|
||||
|
||||
/// The preview pager of the pending and tinted stories: page 2 of 5.
|
||||
fn pager() -> PanePager {
|
||||
PanePager { shown: 2, count: 5, shown_label: None, back: true, next: true, unit: PagerUnit::Page }
|
||||
}
|
||||
|
||||
/// The host's drawing over the preview picture: the picture's edge in the surface's ink.
|
||||
fn outline(cx: &ContentPainterCx, rect: Rect) {
|
||||
let stroke = Stroke::new(cx.stroke_width(StrokeWidth::Thin), cx.ink());
|
||||
let [top_left, top_right, bottom_right, bottom_left] = [rect.left_top(), rect.right_top(), rect.right_bottom(), rect.left_bottom()];
|
||||
for edge in [[top_left, top_right], [top_right, bottom_right], [bottom_right, bottom_left], [bottom_left, top_left]] {
|
||||
cx.painter.line_segment(edge, stroke);
|
||||
}
|
||||
}
|
||||
|
||||
/// A preview the host is still rendering: the well's progress line, with the pager under the pane and the host's
|
||||
/// overlay given for when the picture comes.
|
||||
#[story(ParamDialog<'static>, covers = [], drive = Drive::Never)]
|
||||
fn param_dialog_preview_pending(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
ParamDialog::new("ocr", "Recognize Text", Param::parse_list(GENERAL_SPEC))
|
||||
.opened(Bind::bound(data.value("open", true)))
|
||||
.previews(true)
|
||||
.preview(PreviewState::Pending(Some(0.4)))
|
||||
.preview_pager(pager())
|
||||
.preview_overlay(|cx, _, rect| outline(cx, rect))
|
||||
.show(ui)
|
||||
.into()
|
||||
}
|
||||
|
||||
/// A tinted preview: the picture's colours multiplied by the tint, with the pager and the overlay.
|
||||
#[story(ParamDialog<'static>, covers = [], drive = Drive::Never)]
|
||||
fn param_dialog_preview_tinted(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let picture = picture(ui, false);
|
||||
ParamDialog::new("ocr", "Recognize Text", Param::parse_list(GENERAL_SPEC))
|
||||
.opened(Bind::bound(data.value("open", true)))
|
||||
.previews(true)
|
||||
.preview(PreviewState::Ready(picture))
|
||||
.preview_pager(pager())
|
||||
.preview_overlay(|cx, _, rect| outline(cx, rect))
|
||||
.preview_tint(DataColor::new(Color32::from_rgb(0x9c, 0xc2, 0xe6)))
|
||||
.show(ui)
|
||||
.into()
|
||||
}
|
||||
|
||||
/// A muted note after the title.
|
||||
#[story(ParamDialog<'static>, covers = [], drive = Drive::Never)]
|
||||
fn param_dialog_title_note(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
ParamDialog::new("blur", "Blur", Param::parse_list(SPEC)).opened(Bind::bound(data.value("open", true))).title_note("Layer 1").show(ui).into()
|
||||
}
|
||||
|
||||
@@ -26,8 +26,9 @@ impl<O> PreviewRequest<O> {
|
||||
}
|
||||
|
||||
/// The requests of parameter rows that the host answers: the colour picker, the file dialog, the eyedropper and a
|
||||
/// folder listing, the click on a dialog's preview picture (an eyedropper there samples it) and a footer or row button
|
||||
/// that keeps the dialog open. A hosted dialog embeds one, feeds it each pass's rows with [`absorb`](HostRequests::absorb)
|
||||
/// folder listing, the click on a dialog's preview picture (an eyedropper there samples it), a step of its preview
|
||||
/// pager, a footer or row button that keeps the dialog open (one action channel: footer and row ids share one
|
||||
/// namespace) and the rows an edit changed. A hosted dialog embeds one, feeds it each pass's rows with [`absorb`](HostRequests::absorb)
|
||||
/// and offers the `take_*` methods to its host. A request stays until it is taken; a newer one of the same kind
|
||||
/// replaces it. It also keeps the colours a child picker previews in the dialog's colour rows
|
||||
/// ([`preview_color`](HostRequests::preview_color)).
|
||||
@@ -39,6 +40,9 @@ pub struct HostRequests {
|
||||
listing: Option<ListingRequest>,
|
||||
preview_click: Option<Pos2>,
|
||||
action: Option<String>,
|
||||
preview_step: Option<PagerStep>,
|
||||
/// The keys of the rows an edit changed since the last take, each once.
|
||||
edited: Vec<String>,
|
||||
/// The previewed colour of each colour row a child picker edits, by row key; one entry per key.
|
||||
previews: Vec<(String, Srgba)>,
|
||||
answers: Vec<HostAnswer>,
|
||||
@@ -64,6 +68,10 @@ impl HostRequests {
|
||||
if let Some(request) = rows.listing.take() {
|
||||
self.request_listing(request);
|
||||
}
|
||||
if let Some(id) = rows.action.take() {
|
||||
self.request_action(id);
|
||||
}
|
||||
self.request_edited(std::mem::take(&mut rows.edited));
|
||||
}
|
||||
|
||||
/// Files a colour request; it replaces one not taken yet.
|
||||
@@ -130,13 +138,15 @@ impl HostRequests {
|
||||
|
||||
/// Moves the requests and answers of `other` in; its requests replace the ones not taken yet.
|
||||
pub fn extend(&mut self, other: HostRequests) {
|
||||
let HostRequests { color, path, eyedropper, listing, preview_click, action, previews, answers } = other;
|
||||
let HostRequests { color, path, eyedropper, listing, preview_click, action, preview_step, edited, previews, answers } = other;
|
||||
self.color = color.or(self.color.take());
|
||||
self.path = path.or(self.path.take());
|
||||
self.eyedropper = eyedropper.or(self.eyedropper.take());
|
||||
self.listing = listing.or(self.listing.take());
|
||||
self.preview_click = preview_click.or(self.preview_click.take());
|
||||
self.action = action.or(self.action.take());
|
||||
self.preview_step = preview_step.or(self.preview_step.take());
|
||||
self.request_edited(edited);
|
||||
for (key, color) in previews {
|
||||
self.preview_color(key, Some(color));
|
||||
}
|
||||
@@ -153,20 +163,28 @@ impl HostRequests {
|
||||
self.action.take()
|
||||
}
|
||||
|
||||
/// Files the keys of rows an edit changed; a key not taken yet is kept once.
|
||||
pub fn request_edited(&mut self, keys: impl IntoIterator<Item = String>) {
|
||||
for key in keys {
|
||||
if !self.edited.contains(&key) {
|
||||
self.edited.push(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The row keys an edit changed since the last take.
|
||||
pub fn take_edited(&mut self) -> Vec<String> {
|
||||
todo!("DG-C13")
|
||||
std::mem::take(&mut self.edited)
|
||||
}
|
||||
|
||||
/// Files a step of the preview pager; it replaces one not taken yet.
|
||||
pub fn request_preview_step(&mut self, step: PagerStep) {
|
||||
let _ = step;
|
||||
todo!("DG-C13")
|
||||
self.preview_step = Some(step);
|
||||
}
|
||||
|
||||
/// The step of the preview pager, once.
|
||||
pub fn take_preview_step(&mut self) -> Option<PagerStep> {
|
||||
todo!("DG-C13")
|
||||
self.preview_step.take()
|
||||
}
|
||||
|
||||
/// Files a request for the files of a folder; it replaces one not taken yet.
|
||||
|
||||
@@ -79,7 +79,7 @@ pub use guides::{
|
||||
GuideLayoutPreset, GuideLayoutResult, GuideLayoutValues, GuideLength, GuideRect, GuideTarget, GuideUnits, HostedGuideLayoutDialog,
|
||||
HostedNewGuideDialog, NEW_GUIDE_COLOR_KEY, NewGuideDialog, NewGuideOutput, NewGuideValues,
|
||||
};
|
||||
pub use properties::{HostedPropertiesDialog, PropertiesDialog, PropertiesOutput, PropertiesTab, PropertyRow};
|
||||
pub use properties::{PropertiesDialog, PropertiesOutput, PropertiesTab, PropertyRow};
|
||||
|
||||
// canvas-navigator-a
|
||||
mod navigator_options;
|
||||
|
||||
@@ -391,12 +391,13 @@ pub struct CustomContext {
|
||||
canvas: Option<egui::Id>,
|
||||
eyedropper: Option<EyedropperRequest>,
|
||||
sampling: bool,
|
||||
action: Option<String>,
|
||||
}
|
||||
|
||||
impl CustomContext {
|
||||
/// The context of a row labelled `title`.
|
||||
pub(crate) fn new(title: Label, canvas: Option<egui::Id>) -> Self {
|
||||
CustomContext { title, request: None, canvas, eyedropper: None, sampling: false }
|
||||
CustomContext { title, request: None, canvas, eyedropper: None, sampling: false, action: None }
|
||||
}
|
||||
|
||||
/// Arms the host's eyedropper for the colour under `request.key`, as a colour row's dropper toggle does.
|
||||
@@ -424,8 +425,12 @@ impl CustomContext {
|
||||
/// Asks the host to act on `id`: a custom row's button. The request is reported once, in the pass of the press
|
||||
/// (`ParamRowsOutput::action`).
|
||||
pub fn request_action(&mut self, id: impl Into<String>) {
|
||||
let _ = id;
|
||||
todo!("DG-C7")
|
||||
self.action = Some(id.into());
|
||||
}
|
||||
|
||||
/// The action the row asked for, once.
|
||||
pub(crate) fn take_action(&mut self) -> Option<String> {
|
||||
self.action.take()
|
||||
}
|
||||
|
||||
/// The dropper the row armed, once.
|
||||
@@ -480,6 +485,10 @@ pub(crate) struct RowOptions {
|
||||
units: Option<UnitChoices>,
|
||||
/// The ids of the options a choice row shows disabled.
|
||||
disabled_options: Vec<String>,
|
||||
/// Why an option of `disabled_options` is disabled, by option id ([`Param::disabled_option`]).
|
||||
disabled_reasons: Vec<(String, Label)>,
|
||||
/// The description of an option of a choice or radio row, by option id ([`Param::option_description`]).
|
||||
option_descriptions: Vec<(String, Label)>,
|
||||
/// The row's select has a search field.
|
||||
searchable: bool,
|
||||
/// The keys a change of the row's value removes ([`Param::resets`]).
|
||||
@@ -611,22 +620,42 @@ impl Param {
|
||||
|
||||
/// Shows `text` as the description of the option `id` of a choice or radio row.
|
||||
#[must_use]
|
||||
pub fn option_description(self, id: impl Into<String>, text: impl Into<Label>) -> Self {
|
||||
let _ = (id, text);
|
||||
todo!("PO-P12")
|
||||
pub fn option_description(mut self, id: impl Into<String>, text: impl Into<Label>) -> Self {
|
||||
keyed_text(&mut self.options.get_or_insert_default().option_descriptions, id.into(), text.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Shows the option `id` disabled, with `reason` as its tooltip.
|
||||
/// Shows the option `id` disabled, with `reason` as its tooltip. It joins the options
|
||||
/// [`disabled_options`](Param::disabled_options) lists, so automation refuses it as it refuses those.
|
||||
#[must_use]
|
||||
pub fn disabled_option(self, id: impl Into<String>, reason: impl Into<Label>) -> Self {
|
||||
let _ = (id, reason);
|
||||
todo!("PO-P12")
|
||||
pub fn disabled_option(mut self, id: impl Into<String>, reason: impl Into<Label>) -> Self {
|
||||
let options = self.options.get_or_insert_default();
|
||||
let id = id.into();
|
||||
if !options.disabled_options.contains(&id) {
|
||||
options.disabled_options.push(id.clone());
|
||||
}
|
||||
keyed_text(&mut options.disabled_reasons, id, reason.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// The description of the option `id` of a choice or radio row ([`option_description`](Param::option_description)).
|
||||
pub(crate) fn option_description_text(&self, id: &str) -> Option<&Label> {
|
||||
self.options.as_deref()?.option_descriptions.iter().find(|(held, _)| held == id).map(|(_, text)| text)
|
||||
}
|
||||
|
||||
/// Why the option `id` is disabled, while it is ([`disabled_option`](Param::disabled_option)).
|
||||
pub(crate) fn disabled_reason(&self, id: &str) -> Option<&Label> {
|
||||
if self.option_enabled(id) {
|
||||
return None;
|
||||
}
|
||||
self.options.as_deref()?.disabled_reasons.iter().find(|(held, _)| held == id).map(|(_, reason)| reason)
|
||||
}
|
||||
|
||||
/// The row never takes input: it is shown disabled.
|
||||
#[must_use]
|
||||
pub fn disabled(self) -> Self {
|
||||
todo!("CM-C29")
|
||||
pub fn disabled(mut self) -> Self {
|
||||
self.enable = Enable::Off;
|
||||
self
|
||||
}
|
||||
|
||||
/// Gives a choice row's select a search field.
|
||||
@@ -974,13 +1003,11 @@ impl Param {
|
||||
|
||||
/// Whether the row is shown with `fields`.
|
||||
pub fn visible(&self, fields: &DialogFields) -> bool {
|
||||
// P3(pdf-dialogs-w1): PO-P13
|
||||
self.visible_when.iter().all(|(key, value)| fields.get(key) == Some(value))
|
||||
}
|
||||
|
||||
/// Whether the row takes input with `fields`.
|
||||
pub fn enabled(&self, fields: &DialogFields) -> bool {
|
||||
// P3(pdf-dialogs-w1): CM-C29
|
||||
match &self.enable {
|
||||
Enable::Always => true,
|
||||
Enable::When(key, values) => fields.get(key).is_some_and(|held| values.contains(held)),
|
||||
@@ -1080,6 +1107,28 @@ pub fn set_color_field(params: &[Param], fields: &mut DialogFields, key: &str, c
|
||||
}
|
||||
}
|
||||
|
||||
/// The keys of the rows of `params` whose values differ between `before` and `after`: a row's own key, its unit key, a
|
||||
/// custom row's companions or a Files row's folder and mode. Every record of the rows an edit changed reads this rule.
|
||||
pub(crate) fn edited_rows(params: &[Param], before: &DialogFields, after: &DialogFields) -> Vec<String> {
|
||||
let differs = |key: &str| before.get(key) != after.get(key);
|
||||
params
|
||||
.iter()
|
||||
.filter(|param| {
|
||||
differs(¶m.key)
|
||||
|| param.unit_key().is_some_and(|key| differs(key))
|
||||
|| matches!(¶m.kind, ParamKind::Custom(row) if row.companions.iter().any(|key| differs(key)))
|
||||
|| (matches!(param.kind, ParamKind::Files { .. }) && (differs(¶m.folder_key()) || differs(¶m.use_folder_key())))
|
||||
})
|
||||
.map(|param| param.key.clone())
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Sets `text` as the one text of `id` in `texts`.
|
||||
fn keyed_text(texts: &mut Vec<(String, Label)>, id: String, text: Label) {
|
||||
texts.retain(|(held, _)| *held != id);
|
||||
texts.push((id, text));
|
||||
}
|
||||
|
||||
/// Fills the keys `params` have defaults for and `fields` lack, and takes the opening snapshot.
|
||||
pub fn open_fields(params: &[Param], fields: &mut DialogFields) {
|
||||
fill_defaults(params, fields);
|
||||
|
||||
@@ -1,19 +1,13 @@
|
||||
//! `PropertiesDialog`: an object's properties as tabs of label and value rows, with text, number and check rows to
|
||||
//! edit and read-only rows to read.
|
||||
|
||||
use super::{DialogFields, FormDialog, Param, ParamDialog, ParamRows, ParamRowsOutput, SharedRows, open_fields};
|
||||
use crate::contract::{Bind, CollectionEvent, NoValue, Outcome, Remember as _, Show as _, ShowCollection as _};
|
||||
use crate::dialog::{DialogId, DialogResult, DialogStack, StackDialog, dialog_id};
|
||||
use super::{DialogFields, Param, ParamDialog, ParamRowsOutput, ParamTab, SharedRows};
|
||||
use crate::contract::{Bind, NoValue, Outcome, Show as _};
|
||||
use crate::display::Text;
|
||||
use crate::runtime::env::{Env, Label};
|
||||
use crate::runtime::env::Label;
|
||||
use crate::runtime::overlay::CloseReason;
|
||||
use crate::runtime::words::CommonWords;
|
||||
use crate::sections::{DialogRole, FooterButton};
|
||||
use crate::tabs::{Tab, TabKind, TabStrip};
|
||||
use craft_behavior::{DisplayOrder, ItemSource, SelectionChange};
|
||||
use egui::{Response, Ui};
|
||||
use std::borrow::Cow;
|
||||
use std::cell::RefCell;
|
||||
|
||||
#[cfg(feature = "testing")]
|
||||
mod stories;
|
||||
@@ -68,63 +62,45 @@ pub struct PropertiesTab {
|
||||
pub title: Label,
|
||||
/// The rows under it.
|
||||
pub rows: Vec<PropertyRow>,
|
||||
/// A note shown above the rows of a read-only tab.
|
||||
pub note: Option<Label>,
|
||||
/// Whether the rows show their values without controls.
|
||||
pub read_only: bool,
|
||||
}
|
||||
|
||||
impl PropertiesTab {
|
||||
/// A tab titled `title` with `rows`.
|
||||
pub fn new(title: impl Into<Label>, rows: Vec<PropertyRow>) -> Self {
|
||||
PropertiesTab { title: title.into(), rows }
|
||||
PropertiesTab { title: title.into(), rows, note: None, read_only: false }
|
||||
}
|
||||
|
||||
/// The tab as a read-only one, with `note` above its rows.
|
||||
#[must_use]
|
||||
pub fn read_only(self, note: Option<Label>) -> Self {
|
||||
let _ = note;
|
||||
todo!("DG-C5")
|
||||
PropertiesTab { note, read_only: true, ..self }
|
||||
}
|
||||
|
||||
/// The parameters the rows are: a value is a read-only text row, a heading is a section.
|
||||
fn params(&self, at: usize) -> Vec<Param> {
|
||||
self.rows
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(row, entry)| match entry {
|
||||
PropertyRow::Value { label, text } => Param::read_only_text(format!("properties.{at}.{row}"), label.clone(), text.clone()),
|
||||
PropertyRow::Field(param) => (**param).clone(),
|
||||
PropertyRow::Heading(label) => Param::section(label.clone()),
|
||||
PropertyRow::Space => Param::custom(format!("properties.{at}.{row}"), Label::Empty, |ui, _, _| Text::new(Label::Empty).show(ui)),
|
||||
})
|
||||
.collect()
|
||||
/// The tab as a tab of a [`ParamDialog`]; `at` keys the rows that hold no value of their own.
|
||||
fn param_tab(&self, at: usize) -> ParamTab {
|
||||
let tab = ParamTab::new(self.title.clone(), params(&self.rows, &format!("properties.{at}")));
|
||||
if self.read_only { tab.read_only(self.note.clone()) } else { tab }
|
||||
}
|
||||
}
|
||||
|
||||
/// The tab titles as an item source, keyed by position.
|
||||
struct Titles<'t>(&'t [PropertiesTab]);
|
||||
|
||||
impl DisplayOrder<usize> for Titles<'_> {
|
||||
fn len(&self) -> usize {
|
||||
self.0.len()
|
||||
}
|
||||
|
||||
fn key(&self, at: usize) -> usize {
|
||||
at
|
||||
}
|
||||
|
||||
fn index_of(&self, key: &usize) -> Option<usize> {
|
||||
(*key < self.0.len()).then_some(*key)
|
||||
}
|
||||
|
||||
fn text(&self, at: usize) -> Option<Cow<'_, str>> {
|
||||
self.0.get(at).map(|tab| Cow::Borrowed(tab.title.as_str()))
|
||||
}
|
||||
/// The parameters `rows` are: a value is a read-only text row, a heading is a section. The rows that hold no value of
|
||||
/// their own are keyed `{prefix}.{row}`.
|
||||
fn params(rows: &[PropertyRow], prefix: &str) -> Vec<Param> {
|
||||
rows.iter()
|
||||
.enumerate()
|
||||
.map(|(row, entry)| match entry {
|
||||
PropertyRow::Value { label, text } => Param::read_only_text(format!("{prefix}.{row}"), label.clone(), text.clone()),
|
||||
PropertyRow::Field(param) => (**param).clone(),
|
||||
PropertyRow::Heading(label) => Param::section(label.clone()),
|
||||
PropertyRow::Space => Param::custom(format!("{prefix}.{row}"), Label::Empty, |ui, _, _| Text::new(Label::Empty).show(ui)),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
impl ItemSource<usize> for Titles<'_> {}
|
||||
|
||||
/// The tab the dialog shows while it is open.
|
||||
#[derive(Clone, Default)]
|
||||
struct OpenTab(usize);
|
||||
|
||||
/// What a properties dialog reports.
|
||||
#[derive(Debug)]
|
||||
#[non_exhaustive]
|
||||
@@ -137,7 +113,7 @@ pub struct PropertiesOutput {
|
||||
pub result: Option<DialogFields>,
|
||||
/// The rows' output of this pass; `None` when the dialog is closed.
|
||||
pub rows: Option<ParamRowsOutput>,
|
||||
/// The id of the extra footer button pressed this pass (`PropertiesDialog::extra_buttons`).
|
||||
/// The id of the extra footer button or custom row button pressed this pass (`PropertiesDialog::extra_buttons`).
|
||||
pub action: Option<String>,
|
||||
}
|
||||
|
||||
@@ -149,15 +125,16 @@ impl Outcome for PropertiesOutput {
|
||||
}
|
||||
}
|
||||
|
||||
/// A properties dialog: a `TabStrip` over the tabs (none with one tab) and the rows of the shown tab as one
|
||||
/// `ParamRows` over the values of all of them.
|
||||
/// A properties dialog: a builder over a tabbed [`ParamDialog`] ([`into_param_dialog`](PropertiesDialog::into_param_dialog)),
|
||||
/// a `TabStrip` over the tabs (none with one tab) and the rows of the shown tab over the values of all of them.
|
||||
///
|
||||
/// - Keys: Tab walks the rows of the shown tab, arrows on the strip switch tabs, Enter is OK, Escape cancels.
|
||||
/// - Read-only: the dialog has one button, and every row shows its value without a control; whichever way it closes
|
||||
/// it answers with empty values.
|
||||
/// it answers with empty values. A [`PropertiesTab::read_only`] tab shows its values only, under its note.
|
||||
/// - Values: the `values` binding holds them; the first pass fills the rows' defaults for keys it lacks. Alt turns
|
||||
/// Cancel into Reset, which restores the values from when the dialog opened.
|
||||
/// - Tab: the shown tab is kept while the dialog is open.
|
||||
/// - Shared rows: the [`shared`](PropertiesDialog::shared) rows show with every tab, where `shared_rows` puts them.
|
||||
/// - Tab: the `tab` binding says which tab shows; without it the shown tab is kept while the dialog is open.
|
||||
#[must_use = "show the dialog with `show`"]
|
||||
#[derive(crate::contract::Pattern, crate::contract::Props)]
|
||||
pub struct PropertiesDialog<'a> {
|
||||
@@ -204,119 +181,41 @@ impl<'a> PropertiesDialog<'a> {
|
||||
}
|
||||
|
||||
/// The dialog as a tabbed [`ParamDialog`] over the same values.
|
||||
///
|
||||
/// A host owns a properties dialog as it owns any parameter dialog:
|
||||
///
|
||||
/// ```ignore
|
||||
/// host.open(HostedParamDialog::new(ctx, "file.properties", DialogFields::new(), move |fields| {
|
||||
/// PropertiesDialog::new("file.properties", "Properties", tabs.clone(), Bind::bound(fields)).into_param_dialog()
|
||||
/// }));
|
||||
/// ```
|
||||
pub fn into_param_dialog(self) -> ParamDialog<'a> {
|
||||
todo!("DG-C5")
|
||||
let PropertiesDialog { key, title, tabs, values, read_only, open, tab, extra_buttons, shared, shared_rows } = self;
|
||||
let tabs: Vec<ParamTab> = tabs.iter().enumerate().map(|(at, tab)| tab.param_tab(at)).collect();
|
||||
let mut dialog = ParamDialog::new(key, title, params(&shared, "properties.shared"))
|
||||
.tabs(tabs)
|
||||
.shared_rows(shared_rows)
|
||||
.read_only(read_only)
|
||||
.values(values)
|
||||
.extra_buttons(extra_buttons);
|
||||
if let Some(open) = open {
|
||||
dialog = dialog.opened(open);
|
||||
}
|
||||
if let Some(tab) = tab {
|
||||
dialog = dialog.tab(tab);
|
||||
}
|
||||
dialog
|
||||
}
|
||||
|
||||
/// Shows the dialog.
|
||||
pub fn show(self, ui: &mut Ui) -> PropertiesOutput {
|
||||
// P3(pdf-dialogs-w1): DG-C5 — the writer builds `show` on `into_param_dialog`.
|
||||
let PropertiesDialog { key, title, tabs, values, read_only, open, tab, extra_buttons, shared, shared_rows } = self;
|
||||
let _ = (key, tab, extra_buttons, shared, shared_rows);
|
||||
let env = Env::of(ui);
|
||||
let common = env.words::<CommonWords>();
|
||||
let per_tab: Vec<Vec<Param>> = tabs.iter().enumerate().map(|(at, tab)| tab.params(at)).collect();
|
||||
let mut dialog = FormDialog::new(title.clone(), values).collection_body(true);
|
||||
if read_only {
|
||||
let ok = FooterButton::new(common.ok.clone(), DialogRole::Accept);
|
||||
dialog = dialog.alt_resets(false).shaped(move |dialog| dialog.buttons([ok]));
|
||||
}
|
||||
if let Some(open) = open {
|
||||
dialog = dialog.opened(open);
|
||||
}
|
||||
let rows = RefCell::new(None::<ParamRowsOutput>);
|
||||
let shown = dialog.show(ui, |ui, form, fields| {
|
||||
if form.first() {
|
||||
let all: Vec<Param> = per_tab.iter().flatten().cloned().collect();
|
||||
open_fields(&all, fields);
|
||||
}
|
||||
let last = tabs.len().saturating_sub(1);
|
||||
let mut current = form.memory::<OpenTab>().0.min(last);
|
||||
if tabs.len() > 1 {
|
||||
let strip = TabStrip::new(title.clone())
|
||||
.kind(TabKind::Text)
|
||||
.shown(current)
|
||||
.show_items(ui, &Titles(&tabs), &mut |key, _| Tab::new(tabs[*key].title.clone()));
|
||||
for event in strip.response.events {
|
||||
if let CollectionEvent::Selection(SelectionChange::Set(keys)) = event
|
||||
&& let Some(key) = keys.into_iter().last()
|
||||
{
|
||||
current = key.min(last);
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(params) = per_tab.get(current) {
|
||||
*rows.borrow_mut() = Some(ParamRows::new(title.clone(), params, Bind::bound(&mut *fields)).read_only(read_only).show(ui));
|
||||
}
|
||||
form.memory::<OpenTab>().0 = current;
|
||||
true
|
||||
});
|
||||
let result = match shown.closed {
|
||||
Some(_) if read_only => Some(DialogFields::new()),
|
||||
_ => shown.accepted,
|
||||
};
|
||||
let shown = self.into_param_dialog().show(ui);
|
||||
PropertiesOutput {
|
||||
response: shown.response,
|
||||
closed: shown.closed,
|
||||
result,
|
||||
rows: rows.into_inner(),
|
||||
action: None, /* P3(pdf-dialogs-w1): DG-C5 */
|
||||
result: shown.result.map(|result| result.fields),
|
||||
rows: shown.rows,
|
||||
action: shown.action,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Builds the dialog over the host-owned values of a [`HostedPropertiesDialog`] for one pass.
|
||||
type Build = dyn for<'b> Fn(Bind<'b, DialogFields>) -> PropertiesDialog<'b> + Send;
|
||||
|
||||
/// A hosted properties dialog: the `DialogHost` owns the values, and `build` makes the dialog over them each pass.
|
||||
/// It answers with the edited values at OK, and with empty values when the dialog is read-only.
|
||||
///
|
||||
/// ```ignore
|
||||
/// host.open(HostedPropertiesDialog::new("file.properties", DialogFields::new(), move |values| {
|
||||
/// PropertiesDialog::new("Properties", tabs.clone(), values)
|
||||
/// }));
|
||||
/// ```
|
||||
pub struct HostedPropertiesDialog {
|
||||
id: DialogId,
|
||||
key: String,
|
||||
fields: DialogFields,
|
||||
build: Box<Build>,
|
||||
}
|
||||
|
||||
impl HostedPropertiesDialog {
|
||||
/// A dialog for `key` opening with `fields`; `build` makes it over the values.
|
||||
pub fn new(
|
||||
key: impl Into<String>,
|
||||
fields: DialogFields,
|
||||
build: impl for<'b> Fn(Bind<'b, DialogFields>) -> PropertiesDialog<'b> + Send + 'static,
|
||||
) -> Self {
|
||||
let key = key.into();
|
||||
HostedPropertiesDialog { id: dialog_id(key.as_str()), key, fields, build: Box::new(build) }
|
||||
}
|
||||
|
||||
/// The values the dialog shows.
|
||||
pub fn fields(&self) -> &DialogFields {
|
||||
&self.fields
|
||||
}
|
||||
}
|
||||
|
||||
impl StackDialog for HostedPropertiesDialog {
|
||||
type Result = DialogFields;
|
||||
|
||||
fn id(&self) -> DialogId {
|
||||
self.id
|
||||
}
|
||||
|
||||
fn show(&mut self, ui: &mut Ui, _: &DialogStack) -> Option<DialogResult<DialogFields>> {
|
||||
let shown = (self.build)(Bind::bound(&mut self.fields)).show(ui);
|
||||
match (shown.result, shown.closed) {
|
||||
(Some(result), _) => Some(DialogResult::Ok(result)),
|
||||
(None, Some(_)) => Some(DialogResult::Cancel),
|
||||
(None, None) => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn key(&self) -> Option<&str> {
|
||||
Some(&self.key)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
use super::{PropertiesDialog, PropertiesTab, PropertyRow};
|
||||
use crate::contract::Bind;
|
||||
use crate::patterns::form_dialogs::{DialogFields, Param, ParamKind};
|
||||
use crate::patterns::form_dialogs::{DialogFields, Param, ParamKind, SharedRows};
|
||||
use crate::runtime::env::Label;
|
||||
use crate::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
|
||||
@@ -22,18 +23,50 @@ fn tabs() -> Vec<PropertiesTab> {
|
||||
]
|
||||
}
|
||||
|
||||
/// A properties dialog over `tabs`, open while the story's `open` value is on, so the gallery can close and reopen it.
|
||||
/// The story's `values` are copied out for the pass and written back after it, as one story value is borrowed at a time.
|
||||
fn shown(
|
||||
ui: &mut Ui,
|
||||
data: &mut StoryData,
|
||||
tabs: Vec<PropertiesTab>,
|
||||
configure: impl for<'a> FnOnce(PropertiesDialog<'a>) -> PropertiesDialog<'a>,
|
||||
) -> StoryOutput {
|
||||
let mut values = data.value("values", DialogFields::new()).clone();
|
||||
let output = {
|
||||
let dialog = PropertiesDialog::new("properties", "Properties", tabs, Bind::bound(&mut values)).opened(Bind::bound(data.value("open", true)));
|
||||
configure(dialog).show(ui)
|
||||
};
|
||||
*data.value("values", DialogFields::new()) = values;
|
||||
output.into()
|
||||
}
|
||||
|
||||
#[story(PropertiesDialog<'static>, covers = [], drive = Drive::Never)]
|
||||
fn properties_dialog(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let read_only = *data.value("read_only", false);
|
||||
let values = data.value("values", DialogFields::new());
|
||||
// P3(pdf-dialogs-w1): DG-C5 — the key is the new first argument.
|
||||
PropertiesDialog::new("properties", "Properties", tabs(), Bind::bound(values)).read_only(read_only).opened(Bind::given(true)).show(ui).into()
|
||||
shown(ui, data, tabs(), |dialog| dialog.read_only(read_only))
|
||||
}
|
||||
|
||||
#[story(PropertiesDialog<'static>, covers = [], drive = Drive::Never)]
|
||||
fn properties_dialog_read_only(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let read_only = *data.value("read_only", true);
|
||||
let values = data.value("values", DialogFields::new());
|
||||
// P3(pdf-dialogs-w1): DG-C5 — the key is the new first argument.
|
||||
PropertiesDialog::new("properties", "Properties", tabs(), Bind::bound(values)).read_only(read_only).opened(Bind::given(true)).show(ui).into()
|
||||
shown(ui, data, tabs(), |dialog| dialog.read_only(read_only))
|
||||
}
|
||||
|
||||
/// The editable tabs and a read-only one, shown first, whose values come from the file under a note.
|
||||
#[story(PropertiesDialog<'static>, covers = [], drive = Drive::Never)]
|
||||
fn properties_dialog_tabs(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let note = Label::from("Set by the application that made the file.");
|
||||
let file = PropertiesTab::new("File", vec![PropertyRow::value("Producer", "PdfCraft"), PropertyRow::value("PDF Version", "1.7")]).read_only(Some(note));
|
||||
let mut all = vec![file];
|
||||
all.extend(tabs());
|
||||
shown(ui, data, all, |dialog| dialog)
|
||||
}
|
||||
|
||||
/// Rows shown with every tab, under the tab's rows, and an extra footer button.
|
||||
#[story(PropertiesDialog<'static>, covers = [], drive = Drive::Never)]
|
||||
fn properties_dialog_extras(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let shared = vec![PropertyRow::field(Param::new("applyAll", "Apply to all pages", ParamKind::bool(false)))];
|
||||
shown(ui, data, tabs(), |dialog| {
|
||||
dialog.shared(shared).shared_rows(SharedRows::Below).extra_buttons(vec![("metadata".to_owned(), Label::from("Additional Metadata…"))])
|
||||
})
|
||||
}
|
||||
|
||||
@@ -7,13 +7,14 @@ use crate::patterns::presets::{PresetKind, PresetPicker, PresetRow};
|
||||
use crate::runtime::commands::{CommandState, Commands as _};
|
||||
use crate::runtime::requests::{ColorRequest, EyedropperRequest, ListingRequest, PathRequest};
|
||||
|
||||
use super::param::{CustomContext, Param, ParamKind, fill_defaults, path_list, rounded};
|
||||
use super::param::{CustomContext, Param, ParamKind, edited_rows, fill_defaults, path_list, rounded};
|
||||
use super::path_row::PathRow;
|
||||
use super::words::ParamWords;
|
||||
use crate::buttons::{Button, ToggleButton};
|
||||
use crate::choice::{Checkbox, Radio, RadioGroup, Swatch};
|
||||
use crate::contract::{
|
||||
Bind, BodyCx, CanvasGesture, Entry, NoValue, Outcome, Props as _, Remember as _, Sampler as _, Show as _, ShowContainer as _, clicked,
|
||||
Bind, BodyCx, CanvasGesture, Entry, FieldLayout, NoValue, Outcome, Props as _, Remember as _, Sampler as _, Show as _, ShowContainer as _,
|
||||
SideLabel, TooltipSpec, clicked,
|
||||
};
|
||||
use crate::form::{Field, FieldGroup, SliderField, SliderFieldLayout};
|
||||
|
||||
@@ -76,6 +77,32 @@ pub struct ParamRowsOutput {
|
||||
pub out_of_range: Option<RangeAlert>,
|
||||
/// The id a custom row's button asked the host to act on this pass (`CustomContext::request_action`).
|
||||
pub action: Option<String>,
|
||||
/// The keys of the rows whose values an edit of this pass changed; defaults the pass fills in are no edit.
|
||||
pub edited: Vec<String>,
|
||||
}
|
||||
|
||||
impl ParamRowsOutput {
|
||||
/// This output and `later`'s, of rows shown after these in the same pass over the same values: the later rows'
|
||||
/// values and requests win, and the edited rows of both are kept.
|
||||
pub(crate) fn merged(mut self, later: ParamRowsOutput) -> ParamRowsOutput {
|
||||
let ParamRowsOutput { response, changed, values, pick_color, path, eyedropper, listing, out_of_range, action, edited } = later;
|
||||
self.response = self.response.union(response);
|
||||
self.changed |= changed;
|
||||
// The later rows read the values the earlier ones wrote, so theirs are the values after both.
|
||||
self.values = values.or(self.values);
|
||||
self.pick_color = pick_color.or(self.pick_color);
|
||||
self.path = path.or(self.path);
|
||||
self.eyedropper = eyedropper.or(self.eyedropper);
|
||||
self.listing = listing.or(self.listing);
|
||||
self.out_of_range = out_of_range.or(self.out_of_range);
|
||||
self.action = action.or(self.action);
|
||||
for key in edited {
|
||||
if !self.edited.contains(&key) {
|
||||
self.edited.push(key);
|
||||
}
|
||||
}
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Outcome for ParamRowsOutput {
|
||||
@@ -91,7 +118,7 @@ impl Outcome for ParamRowsOutput {
|
||||
///
|
||||
/// - **Values.** They live in the caller's [`DialogFields`] binding; a missing key shows its parameter's default,
|
||||
/// which the pass writes. The host keeps its own history of the values and its own Reset.
|
||||
/// - **Rows.** A row is shown while its `visible_when` holds and takes input while its `enabled_when` holds. A
|
||||
/// - **Rows.** A row is shown while every `visible_when` condition holds and takes input while its `enable` rule allows. A
|
||||
/// [`Param::section`] opens a section, a bold title under a rule, whose body is the rows up to the next section.
|
||||
/// A range row is a slider and its number field beside the row's label, or stacked under the label
|
||||
/// ([`sliders`](ParamRows::sliders)).
|
||||
@@ -183,6 +210,7 @@ impl<'a> ParamRows<'a> {
|
||||
pass.sliders = sliders;
|
||||
let mut changed = false;
|
||||
let mut values = None;
|
||||
let mut edited = Vec::new();
|
||||
let mut group = |ui: &mut Ui| {
|
||||
FieldGroup::new(label.clone()).show(ui, |ui, cx| {
|
||||
let before = match fields.reborrow().read(cx) {
|
||||
@@ -205,6 +233,7 @@ impl<'a> ParamRows<'a> {
|
||||
}
|
||||
*cx.keep::<Memo>() = pass.memo.clone();
|
||||
changed = pass.work != filled;
|
||||
edited = if changed { edited_rows(params, &filled, &pass.work) } else { Vec::new() };
|
||||
values = (pass.work != before).then(|| pass.work.clone());
|
||||
if let Some(after) = &values {
|
||||
let event = EditEvent::set(Mixed::Same(before), after.clone(), name.clone(), None);
|
||||
@@ -217,19 +246,12 @@ impl<'a> ParamRows<'a> {
|
||||
})
|
||||
};
|
||||
let shown = if read_only { with_env(ui, |scope| scope.read_only = Some(true), group) } else { group(ui) };
|
||||
let (pick_color, path, eyedropper, listing, out_of_range) =
|
||||
if read_only { Default::default() } else { (pass.color, pass.path, pass.eyedropper, pass.listing, pass.out_of_range) };
|
||||
ParamRowsOutput {
|
||||
response: shown.output,
|
||||
changed,
|
||||
values,
|
||||
pick_color,
|
||||
path,
|
||||
eyedropper,
|
||||
listing,
|
||||
out_of_range,
|
||||
action: None, /* P3(pdf-dialogs-w1): DG-C8 */
|
||||
}
|
||||
let (pick_color, path, eyedropper, listing, out_of_range, action) = if read_only {
|
||||
Default::default()
|
||||
} else {
|
||||
(pass.color, pass.path, pass.eyedropper, pass.listing, pass.out_of_range, pass.action)
|
||||
};
|
||||
ParamRowsOutput { response: shown.output, changed, values, pick_color, path, eyedropper, listing, out_of_range, action, edited }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,6 +287,8 @@ struct Pass<'p> {
|
||||
listing: Option<ListingRequest>,
|
||||
/// The range alert of the number row that clamped a typed value; one a pass is the most a user can cause.
|
||||
out_of_range: Option<RangeAlert>,
|
||||
/// The id a custom row's button asked the host to act on.
|
||||
action: Option<String>,
|
||||
/// An eyedropper row is armed.
|
||||
sampling: bool,
|
||||
/// The patterns a pattern row offers.
|
||||
@@ -319,6 +343,7 @@ impl<'p> Pass<'p> {
|
||||
eyedropper: None,
|
||||
listing: None,
|
||||
out_of_range: None,
|
||||
action: None,
|
||||
sampling: false,
|
||||
patterns,
|
||||
canvas,
|
||||
@@ -338,6 +363,7 @@ impl<'p> Pass<'p> {
|
||||
self.eyedropper = None;
|
||||
self.listing = None;
|
||||
self.out_of_range = None;
|
||||
self.action = None;
|
||||
self.sampling = false;
|
||||
}
|
||||
|
||||
@@ -575,8 +601,7 @@ impl<'p> Pass<'p> {
|
||||
|
||||
fn choice(&mut self, ui: &mut Ui, line: &Line<'_>, options: &[(String, Label)]) {
|
||||
let value = self.work.text(line.key).map(str::to_owned).or_else(|| line.param.kind.default_value().and_then(text_of)).unwrap_or_default();
|
||||
let entries: Vec<Entry<String>> =
|
||||
options.iter().map(|(id, label)| Entry::new(id.clone(), label.clone()).enabled(line.param.option_enabled(id))).collect();
|
||||
let entries: Vec<Entry<String>> = options.iter().map(|(id, label)| option_entry(line.param, id, label)).collect();
|
||||
let searchable = line.param.option().searchable();
|
||||
line.show(ui, |ui| {
|
||||
let mut select = Select::new(line.name.clone(), Bind::given(value.clone()), &entries);
|
||||
@@ -690,9 +715,21 @@ impl<'p> Pass<'p> {
|
||||
group = group.tooltip(tip.clone());
|
||||
}
|
||||
let group = group.show(ui, |ui, _| {
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
Stack::new().show(ui, |ui, cx| {
|
||||
for (id, label) in options {
|
||||
Radio::new(id.clone()).label(label.clone()).enabled(line.param.option_enabled(id) && line.enabled).show(ui);
|
||||
let mut radio = Radio::new(id.clone()).enabled(line.param.option_enabled(id) && line.enabled);
|
||||
if let Some(reason) = line.param.disabled_reason(id) {
|
||||
radio = radio.tooltip(TooltipSpec::new(reason.clone()).disabled_text(reason.clone()));
|
||||
}
|
||||
match line.param.option_description_text(id) {
|
||||
Some(text) => {
|
||||
let side = SideLabel::new().layout(FieldLayout::After).detail(text.clone());
|
||||
cx.labelled(ui, id.as_str(), label.clone(), side, radio);
|
||||
}
|
||||
None => {
|
||||
radio.label(label.clone()).show(ui);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -912,6 +949,9 @@ impl<'p> Pass<'p> {
|
||||
self.memo.armed = Some(request.key.clone());
|
||||
self.eyedropper = Some(request);
|
||||
}
|
||||
if let Some(action) = context.take_action() {
|
||||
self.action = Some(action);
|
||||
}
|
||||
self.sampling |= context.is_sampling();
|
||||
}
|
||||
}
|
||||
@@ -924,6 +964,18 @@ fn read_only_text(ui: &mut Ui, line: &Line<'_>, text: &Label) {
|
||||
});
|
||||
}
|
||||
|
||||
/// The entry of the option `id` of a choice row: disabled with its reason when it has one, and with its description.
|
||||
fn option_entry(param: &Param, id: &str, label: &Label) -> Entry<String> {
|
||||
let mut entry = Entry::new(id.to_owned(), label.clone()).enabled(param.option_enabled(id));
|
||||
if let Some(reason) = param.disabled_reason(id) {
|
||||
entry = entry.disabled_reason(reason.clone());
|
||||
}
|
||||
if let Some(text) = param.option_description_text(id) {
|
||||
entry = entry.description(text.clone());
|
||||
}
|
||||
entry
|
||||
}
|
||||
|
||||
/// The mode entries of a Blend row's `modes`, in menu order.
|
||||
fn blend_key_entries(modes: &[(BlendKeyEntry<String>, Label)]) -> Vec<BlendKeyEntry<String>> {
|
||||
modes.iter().map(|(entry, _)| entry.clone()).collect()
|
||||
|
||||
@@ -74,6 +74,42 @@ fn param_rows(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
ParamRows::new("Filter", ¶ms, Bind::bound(fields)).patterns(&patterns).show(ui).into()
|
||||
}
|
||||
|
||||
/// Rows that never take input (`Param::disabled`): shown greyed out whatever the other rows hold.
|
||||
#[story(ParamRows<'static>, covers = [], drive = Drive::Never)]
|
||||
fn param_rows_enable_off(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let params = vec![
|
||||
Param::new("searchable", "Make Searchable", ParamKind::bool(true)),
|
||||
Param::new("engine", "Engine", ParamKind::choice(vec![("builtin".to_owned(), "Built-in".into())], None)).disabled(),
|
||||
Param::new("dpi", "Resolution", ParamKind::int(Some(72), Some(600), 300)).disabled(),
|
||||
];
|
||||
let fields = data.value("fields", DialogFields::new());
|
||||
ParamRows::new("Recognize Text", ¶ms, Bind::bound(fields)).show(ui).into()
|
||||
}
|
||||
|
||||
/// Options with descriptions and a disabled option with its reason, on a Choice row and a Radio row.
|
||||
#[story(ParamRows<'static>, covers = [], drive = Drive::Never)]
|
||||
fn param_rows_option_descriptions(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let modes = || {
|
||||
vec![
|
||||
("fast".to_owned(), "Fast".into()),
|
||||
("accurate".to_owned(), "Accurate".into()),
|
||||
("cloud".to_owned(), "Cloud".into()),
|
||||
]
|
||||
};
|
||||
let described = |param: Param| {
|
||||
param
|
||||
.option_description("fast", "Lower accuracy, finishes in seconds")
|
||||
.option_description("accurate", "Best for scanned books and small print")
|
||||
.disabled_option("cloud", "Needs a network connection")
|
||||
};
|
||||
let params = vec![
|
||||
described(Param::new("engine", "Engine", ParamKind::choice(modes(), Some("fast".to_owned())))),
|
||||
described(Param::new("quality", "Quality", ParamKind::radio(modes(), Some("accurate".to_owned())))),
|
||||
];
|
||||
let fields = data.value("fields", DialogFields::new());
|
||||
ParamRows::new("Recognize Text", ¶ms, Bind::bound(fields)).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(ParamRows<'static>, covers = [], drive = Drive::Never)]
|
||||
fn param_rows_read_only(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let params = params();
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
//! `ParamDialog` and `HostedParamDialog`: the dialog's own undo history, the Preview box's hold-to-compare, Enter in
|
||||
//! a multi-line row and on a focused Cancel, Alt+Reset to `reset_to`, the held OK, reopening under the same key, the
|
||||
//! request slots, disabled options and the remembered values a row refuses.
|
||||
//! request slots and the rows an edit changed, disabled options and the remembered values a row refuses.
|
||||
|
||||
use craft_ui::buttons::Button;
|
||||
use craft_ui::contract::{Bind, Outcome as _, Role, SaveKey, Show as _, clicked};
|
||||
use craft_ui::dialog::{DialogHost, DialogResult, HeldOk, dialog_id};
|
||||
use craft_ui::patterns::form_dialogs::{
|
||||
DialogFields, FieldValue, HostedParamDialog, Param, ParamDialog, ParamKind, ParamLayout, ParamResult, PreviewState,
|
||||
DialogFields, FieldValue, HostedParamDialog, PagerStep, PanePager, Param, ParamDialog, ParamKind, ParamLayout, ParamResult, PreviewState,
|
||||
};
|
||||
use craft_ui::patterns::presets::PresetRow;
|
||||
use craft_ui::runtime::env::Label;
|
||||
@@ -60,7 +60,7 @@ fn holding_the_preview_box_compares_and_the_release_toggles_it() {
|
||||
let out = seen.clone();
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let picture = SizedTexture::new(TextureId::default(), vec2(64.0, 48.0));
|
||||
let shown = ParamDialog::new("blur", "Blur", Param::parse_list(SPEC)).previews(true).preview(PreviewState::Ready(picture)).show(ui); // P3(pdf-dialogs-w1): DG-C12
|
||||
let shown = ParamDialog::new("blur", "Blur", Param::parse_list(SPEC)).previews(true).preview(PreviewState::Ready(picture)).show(ui);
|
||||
out.set((shown.preview_on, shown.comparing));
|
||||
});
|
||||
fixture.settle();
|
||||
@@ -82,7 +82,7 @@ fn holding_the_preview_box_compares_and_the_release_toggles_it() {
|
||||
fn laid_out(layout: ParamLayout) -> [egui::Rect; 4] {
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let picture = SizedTexture::new(TextureId::default(), vec2(64.0, 48.0));
|
||||
ParamDialog::new("blur", "Blur", Param::parse_list(SPEC)).previews(true).preview(PreviewState::Ready(picture)).layout(layout).show(ui); // P3(pdf-dialogs-w1): DG-C12
|
||||
ParamDialog::new("blur", "Blur", Param::parse_list(SPEC)).previews(true).preview(PreviewState::Ready(picture)).layout(layout).show(ui);
|
||||
});
|
||||
fixture.settle();
|
||||
let slider = fixture.by_role(Role::SLIDER).into_iter().next().expect("the radius row has a slider");
|
||||
@@ -279,11 +279,20 @@ fn a_hosted_dialog_reopened_under_the_same_key_opens() {
|
||||
assert!(matches!(*answered.borrow(), Some(DialogResult::Ok(_))), "the reopened dialog answers OK");
|
||||
}
|
||||
|
||||
/// A dialog with a files row and two footer buttons that keep it open.
|
||||
/// A previewing dialog with a files row, a custom row whose button asks for the `reload` action and two footer
|
||||
/// buttons that keep it open.
|
||||
fn stack_dialog(fields: &mut DialogFields) -> ParamDialog<'_> {
|
||||
ParamDialog::new("stack", "Load Files into Stack", vec![Param::files("sources", "Source Files").folder_mode(true)])
|
||||
let reload = Param::custom("reload", "Reload Sources", |ui, _, cx| {
|
||||
let shown = Button::new("Reload Sources").show(ui);
|
||||
if clicked(&shown) {
|
||||
cx.request_action("reload");
|
||||
}
|
||||
shown.response().clone()
|
||||
});
|
||||
ParamDialog::new("stack", "Load Files into Stack", vec![Param::files("sources", "Source Files").folder_mode(true), reload])
|
||||
.values(Bind::bound(fields))
|
||||
.extra_buttons(vec![("load".to_owned(), Label::from("Load…")), ("save".to_owned(), Label::from("Save…"))])
|
||||
.previews(true)
|
||||
}
|
||||
|
||||
/// The `{files, folder, useFolder}` value of a files row that lists `folder`.
|
||||
@@ -291,24 +300,40 @@ fn folder_value(folder: &str) -> serde_json::Value {
|
||||
json!({ "files": [], "folder": folder, "useFolder": true })
|
||||
}
|
||||
|
||||
// A footer button that keeps the dialog open is reported once by its id, in a frame that runs twice too; a folder
|
||||
// listing is asked for once; `cancel_requests` drops both.
|
||||
// A footer button and a custom row's button that keep the dialog open are reported once by their id on the one
|
||||
// action channel, and a press on the preview pager once as its step, in a frame that runs twice too; a folder listing
|
||||
// is asked for once; `cancel_requests` drops them all.
|
||||
#[trial]
|
||||
fn a_hosted_dialogs_new_requests_come_once_and_a_cancel_drops_them() {
|
||||
let (host, twice) = (Rc::new(RefCell::new(DialogHost::new())), Rc::new(Cell::new(false)));
|
||||
let mut fixture = host_fixture(&host, &twice);
|
||||
host.borrow_mut().open(HostedParamDialog::new(fixture.ctx(), "stack", DialogFields::new(), stack_dialog));
|
||||
let picture = SizedTexture::new(TextureId::default(), vec2(64.0, 48.0));
|
||||
let pager = PanePager { shown: 1, count: 3, back: false, next: true, ..PanePager::default() };
|
||||
on_dialog(&host, |dialog| {
|
||||
dialog.set_preview(Some(PreviewState::Ready(picture)));
|
||||
dialog.set_preview_pager(Some(pager));
|
||||
});
|
||||
fixture.idle(10);
|
||||
let press_twice = |fixture: &mut Fixture, label: &str| {
|
||||
let target = fixture.by_label(label).unwrap_or_else(|| panic!("the {label} button"));
|
||||
twice.set(true);
|
||||
fixture.click(&target);
|
||||
assert_eq!(fixture.passes(), 2, "the frame ran a second pass");
|
||||
twice.set(false);
|
||||
fixture.idle(4);
|
||||
};
|
||||
|
||||
let save = fixture.by_label("Save…").expect("the Save… button");
|
||||
twice.set(true);
|
||||
fixture.click(&save);
|
||||
twice.set(false);
|
||||
fixture.idle(4);
|
||||
// P3(pdf-dialogs-w1): DG-C9
|
||||
assert_eq!(on_dialog(&host, HostedParamDialog::take_action).flatten().as_deref(), Some("save"), "the press is reported by its id");
|
||||
assert_eq!(on_dialog(&host, HostedParamDialog::take_action).flatten(), None, "the press is reported once");
|
||||
press_twice(&mut fixture, "Save…");
|
||||
assert_eq!(on_dialog(&host, HostedParamDialog::take_action).flatten().as_deref(), Some("save"), "the footer press is reported by its id");
|
||||
assert_eq!(on_dialog(&host, HostedParamDialog::take_action).flatten(), None, "the footer press is reported once");
|
||||
assert!(host.borrow().is_open::<HostedParamDialog>(), "the button keeps the dialog open");
|
||||
press_twice(&mut fixture, "Reload Sources");
|
||||
assert_eq!(on_dialog(&host, HostedParamDialog::take_action).flatten().as_deref(), Some("reload"), "the row's press is reported by its id");
|
||||
assert_eq!(on_dialog(&host, HostedParamDialog::take_action).flatten(), None, "the row's press is reported once");
|
||||
press_twice(&mut fixture, "Next");
|
||||
assert_eq!(on_dialog(&host, HostedParamDialog::take_preview_step).flatten(), Some(PagerStep::Next), "the pager press is its step");
|
||||
assert_eq!(on_dialog(&host, HostedParamDialog::take_preview_step).flatten(), None, "the step is reported once");
|
||||
|
||||
let ctx = fixture.ctx().clone();
|
||||
host.borrow_mut().set_json_field(&ctx, dialog_id("stack"), "sources", folder_value("/photos/shoot")).expect("the files row takes a folder");
|
||||
@@ -319,13 +344,42 @@ fn a_hosted_dialogs_new_requests_come_once_and_a_cancel_drops_them() {
|
||||
|
||||
let load = fixture.by_label("Load…").expect("the Load… button");
|
||||
fixture.click(&load).idle(2);
|
||||
let next = fixture.by_label("Next").expect("the pager's Next button");
|
||||
fixture.click(&next).idle(2);
|
||||
host.borrow_mut().set_json_field(&ctx, dialog_id("stack"), "sources", folder_value("/photos/other")).expect("the files row takes a folder");
|
||||
fixture.idle(4);
|
||||
on_dialog(&host, HostedParamDialog::cancel_requests);
|
||||
assert_eq!(on_dialog(&host, HostedParamDialog::take_action).flatten(), None, "a cancel drops the footer press"); // P3(pdf-dialogs-w1): DG-C9
|
||||
assert_eq!(on_dialog(&host, HostedParamDialog::take_action).flatten(), None, "a cancel drops the footer press");
|
||||
assert_eq!(on_dialog(&host, HostedParamDialog::take_preview_step).flatten(), None, "a cancel drops the pager step");
|
||||
assert_eq!(on_dialog(&host, HostedParamDialog::take_listing).flatten(), None, "a cancel drops the listing request");
|
||||
}
|
||||
|
||||
// An edit of a row reports its key once, in a frame that runs twice too, and a set through automation reports its
|
||||
// key; passes with no edit report none.
|
||||
#[trial]
|
||||
fn a_hosted_dialog_reports_the_rows_an_edit_changed_once() {
|
||||
let (host, twice) = (Rc::new(RefCell::new(DialogHost::new())), Rc::new(Cell::new(false)));
|
||||
let mut fixture = host_fixture(&host, &twice);
|
||||
host.borrow_mut().open(HostedParamDialog::new(fixture.ctx(), "blur", DialogFields::new(), blur));
|
||||
fixture.idle(10);
|
||||
let edited = || on_dialog(&host, HostedParamDialog::take_edited).unwrap_or_default();
|
||||
assert_eq!(edited(), Vec::<String>::new(), "opening and passes with no edit report none");
|
||||
|
||||
let smooth = fixture.by_label("Smooth").expect("the smooth row has a check box");
|
||||
twice.set(true);
|
||||
fixture.click(&smooth);
|
||||
assert_eq!(fixture.passes(), 2, "the frame ran a second pass");
|
||||
twice.set(false);
|
||||
fixture.idle(4);
|
||||
assert_eq!(edited(), ["smooth"], "the edit reports its row");
|
||||
fixture.idle(4);
|
||||
assert_eq!(edited(), Vec::<String>::new(), "the edit is reported once");
|
||||
|
||||
let ctx = fixture.ctx().clone();
|
||||
host.borrow_mut().set_json_field(&ctx, dialog_id("blur"), "radius", json!(40)).expect("the radius row takes a number");
|
||||
assert_eq!(edited(), ["radius"], "a set through automation reports its row");
|
||||
}
|
||||
|
||||
/// A dialog with a radio row whose second option is disabled.
|
||||
fn brush_tip(fields: &mut DialogFields) -> ParamDialog<'_> {
|
||||
let options = vec![("round".to_owned(), Label::from("Round")), ("square".to_owned(), Label::from("Square"))];
|
||||
@@ -513,13 +567,13 @@ fn a_preview_that_centres_on_clicks_passes_a_press_on_the_canvas_under_it() {
|
||||
fixture.idle(4);
|
||||
press(&mut fixture);
|
||||
assert_eq!(presses.get(), 0, "no pane yet: the modal layer blocks the press");
|
||||
on_dialog(&host, |dialog| dialog.set_preview(Some(PreviewState::Ready(picture)))); // P3(pdf-dialogs-w1): DG-C12
|
||||
on_dialog(&host, |dialog| dialog.set_preview(Some(PreviewState::Ready(picture))));
|
||||
fixture.idle(4);
|
||||
press(&mut fixture);
|
||||
assert_eq!(presses.get(), 1, "with the pane shown the press reaches the canvas");
|
||||
|
||||
host.borrow_mut().open(HostedParamDialog::new(fixture.ctx(), "blur", DialogFields::new(), locating(id, false)));
|
||||
on_dialog(&host, |dialog| dialog.set_preview(Some(PreviewState::Ready(picture)))); // P3(pdf-dialogs-w1): DG-C12
|
||||
on_dialog(&host, |dialog| dialog.set_preview(Some(PreviewState::Ready(picture))));
|
||||
fixture.idle(4);
|
||||
press(&mut fixture);
|
||||
assert_eq!(presses.get(), 1, "a pane that does not centre on clicks leaves the press blocked");
|
||||
|
||||
@@ -7,6 +7,7 @@ mod export;
|
||||
mod files;
|
||||
mod hosted;
|
||||
mod new_document;
|
||||
mod param_tabs;
|
||||
mod params;
|
||||
mod password;
|
||||
mod preview;
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
//! A tabbed `ParamDialog` hosted in a `DialogHost`: every tab's values open, validate and answer together, the hosted
|
||||
//! dialog opens on its tab and the host moves it, and a read-only tab shows its values without a control.
|
||||
|
||||
use craft_ui::contract::Bind;
|
||||
use craft_ui::dialog::{DialogHost, DialogResult, dialog_id};
|
||||
use craft_ui::patterns::form_dialogs::{DialogFields, FieldValue, HostedParamDialog, Param, ParamDialog, ParamKind, ParamTab};
|
||||
use craft_ui::runtime::env::Label;
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
use egui::Vec2;
|
||||
use serde_json::json;
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::rc::Rc;
|
||||
|
||||
/// The note above the read-only tab's rows.
|
||||
const NOTE: &str = "Fonts are listed as the file embeds them.";
|
||||
|
||||
/// A Document Properties dialog with three tabs; the last is read-only.
|
||||
fn properties(fields: &mut DialogFields) -> ParamDialog<'_> {
|
||||
let tabs = vec![
|
||||
ParamTab::new("Description", vec![Param::new("title", "Title", ParamKind::text(""))]),
|
||||
ParamTab::new("Security", vec![Param::new("level", "Level", ParamKind::int(Some(0), Some(3), 1))]),
|
||||
ParamTab::new("Fonts", vec![Param::new("fonts", "Embedded Fonts", ParamKind::text("Serif"))]).read_only(Some(Label::from(NOTE))),
|
||||
];
|
||||
ParamDialog::new("properties", "Document Properties", Vec::<Param>::new()).tabs(tabs).values(Bind::bound(fields))
|
||||
}
|
||||
|
||||
/// `act` on the open `HostedParamDialog`; `None` when none is open.
|
||||
fn on_dialog<T>(host: &Rc<RefCell<DialogHost>>, act: impl FnOnce(&mut HostedParamDialog) -> T) -> Option<T> {
|
||||
host.borrow_mut().get_mut::<HostedParamDialog>().map(act)
|
||||
}
|
||||
|
||||
// A value in a tab that is not shown opens with its default, is checked by its row when the host sets it and comes
|
||||
// back at OK; the hosted dialog opens on its `tab`, `set_tab` and a press on the strip move it (once, in a frame that
|
||||
// runs twice), and the read-only tab shows its note and its value and takes no typing.
|
||||
#[trial]
|
||||
fn a_tabbed_dialog_answers_every_tabs_values_and_opens_on_its_tab() {
|
||||
let (host, twice) = (Rc::new(RefCell::new(DialogHost::new())), Rc::new(Cell::new(false)));
|
||||
let (shown, again) = (Rc::clone(&host), Rc::clone(&twice));
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
shown.borrow_mut().run(ui);
|
||||
if again.get() && ui.ctx().current_pass_index() == 0 {
|
||||
ui.ctx().request_discard("the frame runs twice");
|
||||
}
|
||||
});
|
||||
fixture.room(Vec2::new(1200.0, 900.0));
|
||||
let ctx = fixture.ctx().clone();
|
||||
let opening = DialogFields::from_pairs([("level", FieldValue::Int(2))]);
|
||||
host.borrow_mut().open(HostedParamDialog::new(&ctx, "properties", opening, properties).tab(1));
|
||||
assert_eq!(on_dialog(&host, |dialog| dialog.shown_tab()), Some(1), "the dialog opens on its tab");
|
||||
|
||||
// Before any pass: the hidden tabs' rows opened with their defaults and take or refuse a set as shown rows do.
|
||||
let id = dialog_id("properties");
|
||||
let listed = host.borrow().open_dialogs().into_iter().find(|dialog| dialog.id == id).and_then(|dialog| dialog.fields);
|
||||
let listed = listed.expect("the dialog lists its fields");
|
||||
assert_eq!((listed["level"].as_i64(), listed["fonts"].clone()), (Some(2), json!("Serif")), "every tab's values open: {listed}");
|
||||
assert_eq!(host.borrow_mut().set_json_field(&ctx, id, "title", json!("Report")), Ok(()), "a hidden tab's row takes a value");
|
||||
assert!(host.borrow_mut().set_json_field(&ctx, id, "level", json!(9)).is_err(), "a row checks a value past its range");
|
||||
assert!(host.borrow_mut().set_json_field(&ctx, id, "fonts", json!("Sans")).is_err(), "automation is refused a read-only tab's row");
|
||||
|
||||
fixture.idle(6);
|
||||
assert!(fixture.by_label("Level").is_some(), "the opening tab's rows show");
|
||||
assert!(fixture.by_label("Title").is_none(), "another tab's rows do not");
|
||||
|
||||
on_dialog(&host, |dialog| dialog.set_tab(0));
|
||||
fixture.idle(4);
|
||||
let title = fixture.by_label("Title").expect("set_tab shows the first tab's rows");
|
||||
assert_eq!(fixture.tree().value_of(title.node), Some("Report"), "the value set while hidden shows");
|
||||
assert_eq!(on_dialog(&host, |dialog| dialog.shown_tab()), Some(0));
|
||||
|
||||
let fonts = fixture.by_label("Fonts").expect("the strip has the Fonts tab");
|
||||
twice.set(true);
|
||||
fixture.click(&fonts);
|
||||
assert_eq!(fixture.passes(), 2, "the frame ran a second pass");
|
||||
twice.set(false);
|
||||
fixture.idle(4);
|
||||
assert_eq!(on_dialog(&host, |dialog| dialog.shown_tab()), Some(2), "a press on the strip shows its tab");
|
||||
assert!(fixture.by_label(NOTE).is_some(), "the read-only tab shows its note");
|
||||
let field = fixture.by_label("Embedded Fonts").expect("the read-only row shows");
|
||||
assert_eq!(fixture.tree().value_of(field.node), Some("Serif"), "the read-only row shows its value");
|
||||
fixture.click(&field).settle();
|
||||
fixture.type_text("Sans").settle();
|
||||
let held = on_dialog(&host, |dialog| dialog.fields().text("fonts").map(str::to_owned)).flatten();
|
||||
assert_eq!(held.as_deref(), Some("Serif"), "the read-only row takes no typing");
|
||||
|
||||
let ok = fixture.by_label("OK").expect("the OK button");
|
||||
fixture.click(&ok).idle(4);
|
||||
let answered = host.borrow_mut().take_keyed::<HostedParamDialog>().map(|(result, _)| result).and_then(DialogResult::ok);
|
||||
let fields = answered.expect("OK answers").fields;
|
||||
assert_eq!(fields.text("title"), Some("Report"), "a tab not shown at OK answers its value");
|
||||
assert_eq!(fields.int("level"), Some(2), "the opening value of another tab answers");
|
||||
assert_eq!(fields.text("fonts"), Some("Serif"), "the read-only tab answers its value");
|
||||
}
|
||||
@@ -105,6 +105,39 @@ fn rows_follow_their_predicates_and_carry_their_tooltip() {
|
||||
assert!(fixture.tree().is_disabled_key(detail.node), "disabled for the third value");
|
||||
}
|
||||
|
||||
// A row with two `visible_when` conditions is there only while both hold: the second call adds a condition, not
|
||||
// replaces the first. A `disabled` row takes no input whatever the fields hold, from a click or from automation.
|
||||
#[trial]
|
||||
fn a_row_with_two_visible_conditions_needs_both_and_a_disabled_row_takes_no_input() {
|
||||
let params = vec![
|
||||
Param::new("custom", "Custom", ParamKind::bool(false)),
|
||||
Param::new("advanced", "Advanced", ParamKind::bool(false)),
|
||||
Param::new("quality", "Quality", ParamKind::int(Some(0), Some(12), 8)).visible_when("custom", true).visible_when("advanced", true),
|
||||
Param::new("locked", "Locked", ParamKind::bool(false)).disabled(),
|
||||
];
|
||||
let values = Rc::new(RefCell::new(DialogFields::new()));
|
||||
let mut fixture = rows(params.clone(), &values);
|
||||
let click = |fixture: &mut Fixture, label: &str| {
|
||||
let target = fixture.by_label(label).unwrap_or_else(|| panic!("the {label} row"));
|
||||
fixture.click(&target).settle();
|
||||
};
|
||||
assert!(fixture.by_label("Quality").is_none(), "hidden while neither condition holds");
|
||||
click(&mut fixture, "Custom");
|
||||
assert!(fixture.by_label("Quality").is_none(), "the first condition alone keeps the row hidden");
|
||||
click(&mut fixture, "Advanced");
|
||||
assert!(fixture.by_label("Quality").is_some(), "shown once both hold");
|
||||
click(&mut fixture, "Custom");
|
||||
assert!(fixture.by_label("Quality").is_none(), "the second condition alone keeps the row hidden");
|
||||
|
||||
let locked = fixture.by_label("Locked").expect("a disabled row shows");
|
||||
assert!(fixture.tree().is_disabled_key(locked.node), "a disabled row is a disabled node");
|
||||
fixture.click(&locked).settle();
|
||||
assert_ne!(values.borrow().bool("locked"), Some(true), "a click on a disabled row changes nothing");
|
||||
let mut fields = values.borrow().clone();
|
||||
assert!(set_param_field(¶ms, &mut fields, "locked", json!(true)).is_err(), "automation is refused a disabled row");
|
||||
assert_ne!(fields.bool("locked"), Some(true), "the refused value is not set");
|
||||
}
|
||||
|
||||
// A row that resets its dependents removes them when its value changes, from the row or from automation before any
|
||||
// pass; the value it already holds keeps them.
|
||||
#[trial]
|
||||
|
||||
+3
-2
@@ -84,7 +84,8 @@ Rules of the host:
|
||||
- `get`, `get_mut` and `confirm::<D>()` reach the open dialog's value, so a script or a test sets fields and answers OK as a user would.
|
||||
- Automation that doesn't know the dialog's type goes by id. `open_dialogs` lists the open dialogs with their `StackDialog::json_fields`; `set_json_field(ctx, id, field, value)` sets one as the user would (a prompt's answer is its `choice` field, one it has an enabled button for); `confirm_by_id` and `cancel_by_id` close it. A dialog type opts in by implementing `json_fields` and `set_json_field`; `HostedParamDialog`, `StandardPrompt` and `UnsavedChangesDialog` do. `craft_automation::dialogs` runs `ui.dialog.set`, `ui.dialog.confirm` and `ui.dialog.cancel` on a host and lists its dialogs for `ui.inspect`, so an app's control channel needs no code per dialog type.
|
||||
- `take_keyed` returns the result with `StackDialog::key`, so a Cancel still names the command it answers.
|
||||
- A hosted form owns what its dialog edits. What the dialog asks of the app while open (a preview, a path, a colour, a link) waits on the hosted value until the app takes it, and the app answers through the hosted value's methods. The hosted forms: `HostedParamDialog`, `HostedFormatOptions`, `HostedImageSize`, `HostedCanvasSize`, `HostedExportAs`, `HostedSaveForWeb`, `HostedAbout`, `HostedNewDocument`, `HostedGuideLayoutDialog`, `HostedNewGuideDialog`, `HostedPropertiesDialog` (ui-patterns), `HostedAlert` (ui-panels), `HostedLayerStyle` and `HostedAdjustDialog<V, E>` around any adjustment editor (craft-imaging).
|
||||
- A hosted form owns what its dialog edits. What the dialog asks of the app while open (a preview, a path, a colour, a link) waits on the hosted value until the app takes it, and the app answers through the hosted value's methods. The hosted forms: `HostedParamDialog`, `HostedFormatOptions`, `HostedImageSize`, `HostedCanvasSize`, `HostedExportAs`, `HostedSaveForWeb`, `HostedAbout`, `HostedNewDocument`, `HostedGuideLayoutDialog`, `HostedNewGuideDialog` (ui-patterns), `HostedAlert` (ui-panels), `HostedLayerStyle` and `HostedAdjustDialog<V, E>` around any adjustment editor (craft-imaging). A properties dialog is hosted as a `HostedParamDialog` over `PropertiesDialog::into_param_dialog()`. A footer button or a custom row's button that keeps a hosted form open comes back once, by its id, from `take_action`. Footer and row ids share that one channel.
|
||||
- A `ParamDialog` with `tabs` shows a tab strip and the rows of the shown tab. Its own `params` are the shared rows, above the strip or under the tab's rows (`SharedRows`). Every tab's values open, are checked and answer together, whichever tab shows. A `ParamTab::read_only` tab shows its values without controls, under its note. A `read_only` dialog has only OK, no Alt reset, and answers with no values.
|
||||
- While the host runs its dialogs, or inside a `with` closure, `BodyCx::dialogs` returns `None`. A dialog that the host runs opens children through its own `DialogHost` value.
|
||||
|
||||
## DialogStack
|
||||
@@ -107,4 +108,4 @@ Rules of the host:
|
||||
|
||||
`dont_show_again` adds a check box. The answer is a `PromptAnswer`: its `choice` (`PromptChoice::Proceed`, `Alternate` or `Cancel`), `skip` (the box was ticked and the choice is Proceed; the app stores it) and the `tag` the app attached to say which question it answers.
|
||||
|
||||
`Alert` is a notice with one OK. `UnsavedChangesDialog` asks Save, Don't Save or Cancel for one document and answers an `UnsavedAnswer`. `RecoveryDialog` offers to recover documents an earlier run autosaved, and answers a `RecoveryAnswer`.
|
||||
`Alert` is a notice with one OK. `UnsavedChangesDialog` asks Save, Don't Save or Cancel for one document and answers an `UnsavedAnswer`. `RecoveryDialog` offers to recover documents an earlier run autosaved, and answers a `RecoveryChoice`: a `RecoveryAnswer` and whether to apply it to every document still waiting.
|
||||
|
||||
@@ -181,21 +181,21 @@ name = "PropertiesDialog"
|
||||
old = "craft_ui::dialog::properties::PropertiesDialog"
|
||||
new = "craft_ui::patterns::form_dialogs::PropertiesDialog"
|
||||
status = "moved"
|
||||
note = "A `FormDialog<DialogFields>`: `PropertiesDialog::new(title, tabs, Bind<DialogFields>)` with `.read_only(bool)`; `show(ui) -> PropertiesOutput { response, closed, result, rows }`. The tab is kept while the dialog is open; Alt turns Cancel into Reset."
|
||||
note = "A builder over a tabbed `ParamDialog`: `PropertiesDialog::new(key, title, tabs, Bind<DialogFields>)` with `.read_only(bool)`; `show(ui) -> PropertiesOutput { response, closed, result, rows, action }` is `into_param_dialog().show(ui)`. Without a `tab` binding the tab is kept while the dialog is open; Alt turns Cancel into Reset unless the dialog is read-only."
|
||||
|
||||
[[type]]
|
||||
name = "PropertiesOutput"
|
||||
old = ""
|
||||
new = "craft_ui::patterns::form_dialogs::PropertiesOutput"
|
||||
status = "replaced"
|
||||
note = "`result` is the edited values at OK, or empty values when the dialog is read-only."
|
||||
note = "`result` is the edited values at OK, or empty values when the dialog is read-only; `action` is the id of the extra footer button or custom row button pressed this pass."
|
||||
|
||||
[[type]]
|
||||
name = "PropertiesTab"
|
||||
old = "craft_ui::dialog::properties::PropertiesTab"
|
||||
new = "craft_ui::patterns::form_dialogs::PropertiesTab"
|
||||
status = "moved"
|
||||
note = "`PropertiesTab::new(title: impl Into<Label>, rows)`."
|
||||
note = "`PropertiesTab::new(title: impl Into<Label>, rows)`; `PropertiesTab::read_only(note: Option<Label>)` shows the tab's values without controls, under the note."
|
||||
|
||||
[[type]]
|
||||
name = "PropertyRow"
|
||||
@@ -207,12 +207,12 @@ note = "`Value { label, text }` and `Heading(Label)` as before, `Field(Box<Param
|
||||
[[setter]]
|
||||
type = "PropertiesDialog"
|
||||
old = "new(key, title, tabs)"
|
||||
new = "new(title, tabs, Bind<DialogFields>)"
|
||||
new = "new(key, title, tabs, Bind<DialogFields>)"
|
||||
|
||||
[[setter]]
|
||||
type = "PropertiesDialog"
|
||||
old = "values(DialogFields)"
|
||||
new = "new(title, tabs, Bind<DialogFields>)"
|
||||
new = "new(key, title, tabs, Bind<DialogFields>)"
|
||||
note = "The values are the binding passed to `new`."
|
||||
|
||||
[[setter]]
|
||||
@@ -220,6 +220,12 @@ type = "PropertiesDialog"
|
||||
old = "width(Width)"
|
||||
new = ""
|
||||
|
||||
[[setter]]
|
||||
type = "PropertiesDialog"
|
||||
old = ""
|
||||
new = "tab(Bind<usize>) / extra_buttons(Vec<(String, Label)>) / shared(Vec<PropertyRow>) / shared_rows(SharedRows) / into_param_dialog()"
|
||||
note = "New: the shown tab's binding; footer buttons that keep the dialog open, reported as `PropertiesOutput::action`; rows shown with every tab, above the strip or under the tab's rows; the tabbed `ParamDialog` the builder makes, which a `HostedParamDialog` owns."
|
||||
|
||||
[[setter]]
|
||||
type = "GuideLayoutDialog"
|
||||
old = "artboards(Vec<GuideRect>)"
|
||||
@@ -234,6 +240,6 @@ new = "error(Label)"
|
||||
[[type]]
|
||||
name = "HostedPropertiesDialog"
|
||||
old = ""
|
||||
new = "craft_ui::patterns::form_dialogs::HostedPropertiesDialog"
|
||||
status = "replaced"
|
||||
note = "The `StackDialog` form of `PropertiesDialog`: the `DialogHost` owns the `DialogFields` and `build` makes the dialog over them each pass; it answers `DialogFields`."
|
||||
new = ""
|
||||
status = "removed"
|
||||
note = "Replaced by `HostedParamDialog`: `HostedParamDialog::new(ctx, key, fields, move |fields| PropertiesDialog::new(key, title, tabs.clone(), Bind::bound(fields)).into_param_dialog())`. It answers a `ParamResult`, whose `fields` are the values."
|
||||
|
||||
@@ -12,7 +12,7 @@ name = "ParamDialog"
|
||||
old = "craft_ui::dialog::params::ParamDialog"
|
||||
new = "craft_ui::patterns::form_dialogs::ParamDialog"
|
||||
status = "moved"
|
||||
note = "A pattern: `ParamDialog::new(key, title, params)` with `show(ui) -> ParamDialogOutput { response, closed, result, rows, values, preview_on }`. A `DialogHost` owns it as `HostedParamDialog`, whose `build` closure makes the dialog over the host's values each pass."
|
||||
note = "A pattern: `ParamDialog::new(key, title, params)` with `show(ui) -> ParamDialogOutput { response, closed, result, rows, values, preview_on, comparing, preview_click, action, preview_step }`. A `DialogHost` owns it as `HostedParamDialog`, whose `build` closure makes the dialog over the host's values each pass."
|
||||
|
||||
[[type]]
|
||||
name = "HostedParamDialog"
|
||||
@@ -404,13 +404,37 @@ note = "The close action is named by the dialog title row; `closable(false)` rem
|
||||
type = "ParamDialog"
|
||||
old = "footer_extra(FnMut(&mut Ui) + Send + 'static)"
|
||||
new = ""
|
||||
note = "A footer line is `footer_note(impl Into<Label>)`; footer buttons that keep the dialog open are `extra_buttons(Vec<(String, Label)>)`, reported as `ParamDialogOutput::footer_action`."
|
||||
note = "A footer line is `footer_note(impl Into<Label>)`; footer buttons that keep the dialog open are `extra_buttons(Vec<(String, Label)>)`, reported as `ParamDialogOutput::action` (hosted: `HostedParamDialog::take_action`), the channel a custom row's `CustomContext::request_action` shares."
|
||||
|
||||
[[setter]]
|
||||
type = "ParamDialog"
|
||||
old = "preview(bool)"
|
||||
new = "preview(SizedTexture)"
|
||||
note = "The picture the pane shows; a dialog without one has no Preview check box. `set_preview_image` is the next pass's `preview`, `preview_on()` is `ParamDialogOutput::preview_on`."
|
||||
new = "previews(bool) / preview(PreviewState)"
|
||||
note = "`previews(true)` gives the Preview check box; `preview(PreviewState)` is what the pane shows: `Pending` (the progress line), `Failed` (its message) or `Ready(SizedTexture)` (the picture, with the zoom row). `set_preview_image` is the next pass's `preview` (hosted: `HostedParamDialog::set_preview(Option<PreviewState>)`), `preview_on()` is `ParamDialogOutput::preview_on`."
|
||||
|
||||
[[setter]]
|
||||
type = "ParamDialog"
|
||||
old = ""
|
||||
new = "preview_pager(PanePager) / preview_overlay(FnOnce(&ContentPainterCx, CanvasTransform, Rect)) / preview_tint(DataColor)"
|
||||
note = "New: the pager row centred under the pane, its step reported as `ParamDialogOutput::preview_step`; the host's drawing over a `Ready` picture; the tint that multiplies its colours. Hosted: `set_preview_pager(Option<PanePager>)`, `set_preview_overlay(Option<SharedOverlay>)`, `set_preview_tint(Option<DataColor>)` and `take_preview_step()`."
|
||||
|
||||
[[setter]]
|
||||
type = "ParamDialog"
|
||||
old = ""
|
||||
new = "tabs(Vec<ParamTab>) / shared_rows(SharedRows) / tab(Bind<usize>)"
|
||||
note = "New: a tab strip over the shown tab's rows; the dialog's own `params` are the shared rows, above the strip or below the tab's rows. Every tab's values open, are checked and answer together. Hosted: `HostedParamDialog::tab(usize)`, `set_tab(usize)`, `shown_tab()`."
|
||||
|
||||
[[setter]]
|
||||
type = "ParamDialog"
|
||||
old = ""
|
||||
new = "read_only(bool) / title_note(impl Into<Label>)"
|
||||
note = "New: `read_only` shows the values without controls, with an OK-only footer and no Alt reset, and answers with no values; `title_note` is passed to `Dialog::title_note`."
|
||||
|
||||
[[setter]]
|
||||
type = "HostedParamDialog"
|
||||
old = ""
|
||||
new = "take_action() / take_edited()"
|
||||
note = "New: the id of the footer or row button pressed, once; the row keys an edit changed since the last take."
|
||||
|
||||
[[setter]]
|
||||
type = "ParamDialog"
|
||||
@@ -504,7 +528,7 @@ new = "below(impl Fn(&mut Ui, &DialogFields))"
|
||||
type = "ParamDialog"
|
||||
old = "footer_extra(impl FnMut(&mut Ui))"
|
||||
new = ""
|
||||
note = "A footer line is `footer_note(impl Into<Label>)`; footer buttons that keep the dialog open are `extra_buttons(Vec<(String, Label)>)`, reported as `ParamDialogOutput::footer_action`."
|
||||
note = "A footer line is `footer_note(impl Into<Label>)`; footer buttons that keep the dialog open are `extra_buttons(Vec<(String, Label)>)`, reported as `ParamDialogOutput::action` (hosted: `HostedParamDialog::take_action`), the channel a custom row's `CustomContext::request_action` shares."
|
||||
|
||||
[[setter]]
|
||||
type = "ParamDialog"
|
||||
|
||||
Reference in New Issue
Block a user