mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-16 23:24:24 +00:00
Side button columns in the dialogs that had them (K16)
FindReplace, Hyperlink, Paragraph, Check Spelling, Marker, the Contour editor, ListManager and ParamDialog with a preview put their buttons in the side column. FormDialog takes extra footer buttons (ResetFooter::extra, ResetPick::Extra) in place of hand-made buttons in footer_extra; ParamDialog's Preview check box sits under the buttons. FileListPicker's buttons stand beside the list through Stack::footer_beside, one width.
This commit is contained in:
@@ -10,7 +10,7 @@ use craft_ui::contract::{
|
||||
};
|
||||
use craft_ui::display::{Shade, Text};
|
||||
use craft_ui::form::Field;
|
||||
use craft_ui::layout_components::{Row, Stack};
|
||||
use craft_ui::layout_components::Stack;
|
||||
use craft_ui::list::{List, ListRow};
|
||||
use craft_ui::pickers::Select;
|
||||
use craft_ui::runtime::env::{Env, Label};
|
||||
@@ -121,8 +121,8 @@ impl Outcome for FileListPickerOutput {
|
||||
/// Photoshop's Load Files into Stack file list, after PhotoCraft's port of it.
|
||||
///
|
||||
/// The user sees "Use:" with Files and Folder (when [`folder_mode`](Self::folder_mode) is on), the list (one row per
|
||||
/// file showing its name, the full path as tooltip, and the app's info line under the name when given) and the buttons
|
||||
/// under it: Browse… (an open-many picker in Files mode, a folder picker in Folder mode, both through `host.files()`),
|
||||
/// file showing its name, the full path as tooltip, and the app's info line under the name when given) and a column of
|
||||
/// buttons beside it, one width: Browse… (an open-many picker in Files mode, a folder picker in Folder mode, both through `host.files()`),
|
||||
/// Remove (with a row selected), Add Open Files (when the app passed open documents with a path) and Sort By Name (more
|
||||
/// than one file; sorts by name ignoring case). In Folder mode the list shows the folder's files the app passes and has
|
||||
/// no selection.
|
||||
@@ -202,9 +202,9 @@ impl<'a> FileListPicker<'a> {
|
||||
};
|
||||
let folder = now.mode == FileListMode::Folder;
|
||||
let (mut browse, mut remove, mut add_open, mut sort) = (false, false, false, false);
|
||||
Row::new().show(ui, |ui, _| {
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
let button = |ui: &mut Ui, label: &Label, key: &'static str, enabled: bool| {
|
||||
clicked(&Button::new(label.clone()).enabled(enabled).id_salt(key).show(ui))
|
||||
clicked(&Button::new(label.clone()).enabled(enabled).fill_width(true).id_salt(key).show(ui))
|
||||
};
|
||||
browse = button(ui, &words.browse, "browse", true);
|
||||
remove = button(ui, &words.remove, "remove", !folder && now.selected.is_some());
|
||||
@@ -233,6 +233,7 @@ impl<'a> FileListPicker<'a> {
|
||||
}
|
||||
pass.finish(cx, label.as_str());
|
||||
})
|
||||
.footer_beside()
|
||||
.show(ui, |ui, cx| {
|
||||
let mut pass = pass.borrow_mut();
|
||||
let now = pass.load(cx);
|
||||
|
||||
@@ -11,6 +11,7 @@ use craft_ui::patterns::form_dialogs::FormDialog;
|
||||
use craft_ui::pickers::Select;
|
||||
use craft_ui::runtime::env::Env;
|
||||
use craft_ui::runtime::focus::{self, FocusTarget};
|
||||
use craft_ui::sections::{DialogRole, FooterButton};
|
||||
use craft_ui::text::TextField;
|
||||
use egui::Ui;
|
||||
|
||||
@@ -117,19 +118,14 @@ impl StackDialog for ContourEditorDialog {
|
||||
fn show(&mut self, ui: &mut Ui, _: &DialogStack) -> Option<DialogResult<Contour>> {
|
||||
let words = Env::of(ui).words::<ContourWords>();
|
||||
let before = self.draft.contour.clone();
|
||||
let extra = Cell::new(None::<Extra>);
|
||||
let extras = [(Extra::Load, &words.load), (Extra::Save, &words.save), (Extra::New, &words.new)];
|
||||
let named = Cell::new(false);
|
||||
let focus_name = std::mem::take(&mut self.focus_name);
|
||||
let sampler = self.sampler.clone();
|
||||
let shown = FormDialog::new(words.editor.clone(), Bind::bound(&mut self.draft))
|
||||
.outer_gesture(true)
|
||||
.footer_extra(|ui| {
|
||||
for (which, label) in [(Extra::Load, &words.load), (Extra::Save, &words.save), (Extra::New, &words.new)] {
|
||||
if clicked(&Button::new(label.clone()).show(ui)) {
|
||||
extra.set(Some(which));
|
||||
}
|
||||
}
|
||||
})
|
||||
.extra_buttons(extras.iter().map(|(_, label)| FooterButton::new((*label).clone(), DialogRole::Other)))
|
||||
.shaped(|dialog| dialog.side_buttons(true))
|
||||
.show(ui, |ui, _, draft| {
|
||||
FieldGroup::new(words.preset.clone()).show(ui, |ui, _| {
|
||||
Field::new(words.preset.clone()).show(ui, |ui, _| {
|
||||
@@ -192,7 +188,8 @@ impl StackDialog for ContourEditorDialog {
|
||||
self.draft.contour.clone_from(&new);
|
||||
self.action = Some(ContourAction::New(new));
|
||||
}
|
||||
match extra.get() {
|
||||
let extra = shown.picked.and_then(|at| extras.get(at.checked_sub(2)?)).map(|(which, _)| *which);
|
||||
match extra {
|
||||
Some(Extra::Load) => self.action = Some(ContourAction::Load),
|
||||
Some(Extra::Save) => self.action = Some(ContourAction::Save),
|
||||
Some(Extra::New) if self.draft.naming.is_none() => {
|
||||
|
||||
@@ -600,6 +600,7 @@ impl StackDialog for ParagraphDialog {
|
||||
FooterButton::new(words.tabs.clone(), DialogRole::Other),
|
||||
];
|
||||
let shown = Dialog::new(words.title.clone())
|
||||
.side_buttons(true)
|
||||
.buttons(buttons)
|
||||
.settle_buttons(|_, buttons| {
|
||||
for (at, button) in buttons.iter_mut().enumerate() {
|
||||
|
||||
@@ -250,7 +250,7 @@ impl StackDialog for FindReplaceDialog {
|
||||
buttons.push(FooterButton::new(words.close_button.clone(), DialogRole::Cancel));
|
||||
let close_at = buttons.len() - 1;
|
||||
|
||||
let shown = Dialog::new(words.title.clone()).modeless().buttons(buttons).show(ui, |ui, _| {
|
||||
let shown = Dialog::new(words.title.clone()).modeless().side_buttons(true).buttons(buttons).show(ui, |ui, _| {
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
if word {
|
||||
let tabs = [
|
||||
|
||||
@@ -345,11 +345,13 @@ impl HyperlinkDialog {
|
||||
if editing {
|
||||
buttons.push(FooterButton::new(words.remove.clone(), DialogRole::Destructive));
|
||||
}
|
||||
let dialog = Dialog::new(title).buttons(buttons).initial_focus(Initial::Default).opened(Bind::bound(open)).settle_buttons(|_, buttons| {
|
||||
if let Some(accept) = buttons.get_mut(OK) {
|
||||
accept.set_enabled(valid.get());
|
||||
}
|
||||
});
|
||||
let dialog = Dialog::new(title).side_buttons(true).buttons(buttons).initial_focus(Initial::Default).opened(Bind::bound(open)).settle_buttons(
|
||||
|_, buttons| {
|
||||
if let Some(accept) = buttons.get_mut(OK) {
|
||||
accept.set_enabled(valid.get());
|
||||
}
|
||||
},
|
||||
);
|
||||
let given_ref = &*given;
|
||||
let shown = dialog.show(ui, |ui, _| {
|
||||
body(ui, given_ref, form, &words);
|
||||
|
||||
@@ -23,15 +23,14 @@ use std::ops::Range;
|
||||
use craft_behavior::{Selection, SelectionChange, keyed};
|
||||
use craft_host::Section;
|
||||
use craft_theme::variant::Tone;
|
||||
use craft_ui::buttons::Button;
|
||||
use craft_ui::choice::Checkbox;
|
||||
use craft_ui::contract::{
|
||||
Bind, CollectionEvent, NoValue, Outcome, Props as _, SelectMode, Show as _, ShowCollection as _, ShowContainer as _, Sizing, clicked,
|
||||
Bind, CollectionEvent, NoValue, Outcome, Props as _, SelectMode, Show as _, ShowCollection as _, ShowContainer as _, Sizing,
|
||||
};
|
||||
use craft_ui::dialog::{Dialog, DialogId, DialogOutput, DialogResult, DialogStack, StackDialog, dialog_id};
|
||||
use craft_ui::display::Text;
|
||||
use craft_ui::form::Field;
|
||||
use craft_ui::layout_components::{Row, Stack};
|
||||
use craft_ui::layout_components::Stack;
|
||||
use craft_ui::list::{List, ListRow};
|
||||
use craft_ui::notices::{Notice, NoticeLayout};
|
||||
use craft_ui::runtime::env::Env;
|
||||
@@ -65,7 +64,7 @@ craft_ui::words! {
|
||||
/// How many suggestions the app asks [`Dictionary::suggest`](crate::spell::Dictionary::suggest) for.
|
||||
pub const SUGGESTION_COUNT: usize = 8;
|
||||
|
||||
/// A button of the right-hand column that the dialog or the app acts on.
|
||||
/// A button of the side column, or a body change, that the dialog or the app acts on.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum Press {
|
||||
Ignore,
|
||||
@@ -161,8 +160,8 @@ impl Outcome for SpellingOutput {
|
||||
|
||||
/// Edit › Check Spelling. Photoshop's layout: at the left, "Not in Dictionary:" with the word (read only),
|
||||
/// "Change To:" (a text field, opening with the first suggestion), "Suggestions:" (a list), Check All Layers, and
|
||||
/// "Spell check complete." once the list is empty; at the right, the buttons Ignore, Ignore All, Change, Change All
|
||||
/// and Add, disabled when the list is empty, and Done in the footer.
|
||||
/// "Spell check complete." once the list is empty; at the right, a column of Done and the buttons Ignore, Ignore All,
|
||||
/// Change, Change All and Add, which are disabled when the list is empty.
|
||||
///
|
||||
/// - A click on a suggestion puts it in Change To; a double click or Enter also changes.
|
||||
/// - Enter is Done unless Change To has focus; Escape and the close action are Done too (nothing to undo: every
|
||||
@@ -225,75 +224,68 @@ impl CheckSpellingDialog {
|
||||
let item = self.items.get(self.index).cloned();
|
||||
let has_item = item.is_some();
|
||||
let body_press = Cell::new(None::<Press>);
|
||||
let button_press = Cell::new(None::<Press>);
|
||||
let CheckSpellingDialog { change_to, all_layers, open, .. } = self;
|
||||
|
||||
let dialog = Dialog::new(words.title.clone()).buttons([FooterButton::new(words.done.clone(), DialogRole::Accept)]).opened(Bind::bound(open));
|
||||
let actions = [
|
||||
(&words.ignore, Press::Ignore),
|
||||
(&words.ignore_all, Press::IgnoreAll),
|
||||
(&words.change, Press::Change),
|
||||
(&words.change_all, Press::ChangeAll),
|
||||
(&words.add, Press::Add),
|
||||
];
|
||||
let buttons = std::iter::once(FooterButton::new(words.done.clone(), DialogRole::Accept))
|
||||
.chain(actions.iter().map(|(label, _)| FooterButton::new((*label).clone(), DialogRole::Other).stays_open(true).enabled(has_item)));
|
||||
let dialog = Dialog::new(words.title.clone()).side_buttons(true).buttons(buttons).opened(Bind::bound(open));
|
||||
let shown = dialog.show(ui, |ui, _| {
|
||||
Row::new().show(ui, |ui, _| {
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
let word = item.as_ref().map_or_else(String::new, |i| i.word.clone());
|
||||
Field::new(words.not_in_dictionary.clone()).id_salt("word").show(ui, |ui, _| {
|
||||
TextField::new(words.not_in_dictionary.clone(), Bind::given(word.clone())).enabled(false).show(ui);
|
||||
});
|
||||
Field::new(words.change_to.clone()).id_salt("change-to").show(ui, |ui, _| {
|
||||
TextField::new(words.change_to.clone(), Bind::bound(&mut *change_to)).enabled(has_item).show(ui);
|
||||
});
|
||||
Text::new(words.suggestions.clone()).show(ui);
|
||||
let suggestions: &[String] = item.as_ref().map_or(&[], |i| i.suggestions.as_slice());
|
||||
let positions: Vec<usize> = (0..suggestions.len()).collect();
|
||||
let source = keyed(&positions, |at: &usize| *at);
|
||||
let mut selection =
|
||||
suggestions.iter().position(|s| s.as_str() == change_to.as_str()).map_or_else(Selection::default, Selection::single);
|
||||
let events = List::new(words.suggestions.clone())
|
||||
.select(SelectMode::Single)
|
||||
.sizing(Sizing::Content)
|
||||
.natural_height(true)
|
||||
.selection(Bind::bound(&mut selection))
|
||||
.show_items(ui, &source, &mut |at, _| ListRow::new(suggestions[*at].clone()))
|
||||
.events;
|
||||
for event in events {
|
||||
match event {
|
||||
CollectionEvent::Selection(SelectionChange::Set(rows)) => {
|
||||
if let Some(row) = rows.last() {
|
||||
change_to.clone_from(&suggestions[*row]);
|
||||
}
|
||||
}
|
||||
CollectionEvent::Activate(row) => {
|
||||
change_to.clone_from(&suggestions[row]);
|
||||
body_press.set(Some(Press::Change));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let before = *all_layers;
|
||||
Checkbox::new(Bind::bound(&mut *all_layers)).label(words.all_layers.clone()).show(ui);
|
||||
if *all_layers != before {
|
||||
body_press.set(Some(Press::Relist));
|
||||
}
|
||||
if !has_item {
|
||||
Notice::new(Tone::Neutral, words.complete.clone()).layout(NoticeLayout::Centred).show(ui);
|
||||
}
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
let word = item.as_ref().map_or_else(String::new, |i| i.word.clone());
|
||||
Field::new(words.not_in_dictionary.clone()).id_salt("word").show(ui, |ui, _| {
|
||||
TextField::new(words.not_in_dictionary.clone(), Bind::given(word.clone())).enabled(false).show(ui);
|
||||
});
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
let buttons = [
|
||||
(&words.ignore, Press::Ignore),
|
||||
(&words.ignore_all, Press::IgnoreAll),
|
||||
(&words.change, Press::Change),
|
||||
(&words.change_all, Press::ChangeAll),
|
||||
(&words.add, Press::Add),
|
||||
];
|
||||
for (label, which) in buttons {
|
||||
if clicked(&Button::new(label.clone()).enabled(has_item).show(ui)) {
|
||||
button_press.set(Some(which));
|
||||
}
|
||||
}
|
||||
Field::new(words.change_to.clone()).id_salt("change-to").show(ui, |ui, _| {
|
||||
TextField::new(words.change_to.clone(), Bind::bound(&mut *change_to)).enabled(has_item).show(ui);
|
||||
});
|
||||
Text::new(words.suggestions.clone()).show(ui);
|
||||
let suggestions: &[String] = item.as_ref().map_or(&[], |i| i.suggestions.as_slice());
|
||||
let positions: Vec<usize> = (0..suggestions.len()).collect();
|
||||
let source = keyed(&positions, |at: &usize| *at);
|
||||
let mut selection =
|
||||
suggestions.iter().position(|s| s.as_str() == change_to.as_str()).map_or_else(Selection::default, Selection::single);
|
||||
let events = List::new(words.suggestions.clone())
|
||||
.select(SelectMode::Single)
|
||||
.sizing(Sizing::Content)
|
||||
.natural_height(true)
|
||||
.selection(Bind::bound(&mut selection))
|
||||
.show_items(ui, &source, &mut |at, _| ListRow::new(suggestions[*at].clone()))
|
||||
.events;
|
||||
for event in events {
|
||||
match event {
|
||||
CollectionEvent::Selection(SelectionChange::Set(rows)) => {
|
||||
if let Some(row) = rows.last() {
|
||||
change_to.clone_from(&suggestions[*row]);
|
||||
}
|
||||
}
|
||||
CollectionEvent::Activate(row) => {
|
||||
change_to.clone_from(&suggestions[row]);
|
||||
body_press.set(Some(Press::Change));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let before = *all_layers;
|
||||
Checkbox::new(Bind::bound(&mut *all_layers)).label(words.all_layers.clone()).show(ui);
|
||||
if *all_layers != before {
|
||||
body_press.set(Some(Press::Relist));
|
||||
}
|
||||
if !has_item {
|
||||
Notice::new(Tone::Neutral, words.complete.clone()).layout(NoticeLayout::Centred).show(ui);
|
||||
}
|
||||
});
|
||||
});
|
||||
let DialogOutput { response, closed, .. } = shown.output;
|
||||
let DialogOutput { response, closed, picked } = shown.output;
|
||||
let button_press = picked.and_then(|at| actions.get(at.checked_sub(1)?)).map(|(_, which)| *which);
|
||||
|
||||
match body_press.get().or(button_press.get()) {
|
||||
match body_press.get().or(button_press) {
|
||||
Some(Press::Ignore) => {
|
||||
self.index = (self.index + 1).min(self.items.len());
|
||||
self.change_to = self.items.get(self.index).and_then(|i| i.suggestions.first()).cloned().unwrap_or_default();
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
//! The Marker dialog: the draft it edits, its result and the dialog itself.
|
||||
|
||||
use std::cell::Cell;
|
||||
|
||||
use craft_ui::buttons::Button;
|
||||
use craft_ui::choice::{RadioGroup, Swatch};
|
||||
use craft_ui::contract::{Bind, Outcome as _, Show as _, ShowContainer as _, clicked};
|
||||
use craft_ui::contract::{Bind, Outcome as _, Show as _, ShowContainer as _};
|
||||
use craft_ui::dialog::{DialogId, DialogResult, DialogStack, StackDialog, dialog_id};
|
||||
use craft_ui::form::{Field, FieldGroup};
|
||||
use craft_ui::layout_components::Row;
|
||||
use craft_ui::patterns::form_dialogs::FormDialog;
|
||||
use craft_ui::runtime::env::Env;
|
||||
use craft_ui::runtime::focus::{self, FocusTarget};
|
||||
use craft_ui::sections::{DialogRole, FooterButton};
|
||||
use craft_ui::text::TextField;
|
||||
use egui::{Color32, Ui};
|
||||
|
||||
@@ -112,16 +110,11 @@ impl StackDialog for MarkerDialog {
|
||||
let env = Env::of(ui);
|
||||
let words = env.words::<MarkerWords>();
|
||||
let format = self.format;
|
||||
let picked = Cell::new(None::<Extra>);
|
||||
let extras = [(Extra::Delete, &words.delete), (Extra::Previous, &words.previous), (Extra::Next, &words.next)];
|
||||
let shown = FormDialog::new(words.title.clone(), Bind::bound(&mut self.draft))
|
||||
.outer_gesture(true)
|
||||
.footer_extra(|ui| {
|
||||
for (extra, label) in [(Extra::Delete, &words.delete), (Extra::Previous, &words.previous), (Extra::Next, &words.next)] {
|
||||
if clicked(&Button::new(label.clone()).show(ui)) {
|
||||
picked.set(Some(extra));
|
||||
}
|
||||
}
|
||||
})
|
||||
.extra_buttons(extras.iter().map(|(_, label)| FooterButton::new((*label).clone(), DialogRole::Other)))
|
||||
.shaped(|dialog| dialog.side_buttons(true))
|
||||
.show(ui, |ui, form, draft| {
|
||||
let first = form.first();
|
||||
let timeline_words = Env::of(ui).words::<TimelineWords>();
|
||||
@@ -158,7 +151,7 @@ impl StackDialog for MarkerDialog {
|
||||
true
|
||||
});
|
||||
let answer = |action| Some(DialogResult::Ok(MarkerDialogResult { marker: self.id, action }));
|
||||
if let Some(extra) = picked.get() {
|
||||
if let Some((extra, _)) = shown.picked.and_then(|at| extras.get(at.checked_sub(2)?)) {
|
||||
return match extra {
|
||||
Extra::Delete => answer(MarkerDialogAction::Delete),
|
||||
Extra::Previous => answer(MarkerDialogAction::SaveAndPrevious(self.draft.clone())),
|
||||
|
||||
@@ -30,6 +30,8 @@ use egui::load::SizedTexture;
|
||||
use egui::{Response, Ui};
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::cell::Cell;
|
||||
use std::rc::Rc;
|
||||
|
||||
#[cfg(feature = "testing")]
|
||||
mod stories;
|
||||
@@ -46,7 +48,7 @@ craft_ui::words! {
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
pub enum ParamLayout {
|
||||
/// The preview pane to the right of the rows, under the Preview check box and the zoom row.
|
||||
/// The preview pane to the right of the rows, under the zoom row.
|
||||
#[default]
|
||||
Beside,
|
||||
/// The preview pane under the rows.
|
||||
@@ -76,18 +78,15 @@ impl ParamResult {
|
||||
}
|
||||
}
|
||||
|
||||
/// What a parameter dialog keeps while it is open: the Preview check box and the view of the preview pane.
|
||||
#[derive(Clone)]
|
||||
/// What a parameter dialog keeps while it is open: the view of the preview pane.
|
||||
#[derive(Clone, Default)]
|
||||
struct Live {
|
||||
on: bool,
|
||||
view: PreviewView,
|
||||
}
|
||||
|
||||
impl Default for Live {
|
||||
fn default() -> Self {
|
||||
Live { on: true, view: PreviewView::default() }
|
||||
}
|
||||
}
|
||||
/// What the footer of a dialog with a preview keeps while it is open: the Preview check box is off.
|
||||
#[derive(Clone, Default)]
|
||||
struct PreviewOff(bool);
|
||||
|
||||
/// What a parameter dialog reports.
|
||||
#[derive(Debug)]
|
||||
@@ -124,7 +123,8 @@ impl Outcome for ParamDialogOutput {
|
||||
/// - Values: the `values` binding holds them; without one the dialog keeps its own between passes. The first pass
|
||||
/// fills the parameters' defaults and, with `remember`, the values saved by [`ParamResult::remember`].
|
||||
/// - Preview: the host renders from the reported values while `preview_on` and hands the picture to `preview`. Drag
|
||||
/// pans the picture, the zoom buttons scale it.
|
||||
/// pans the picture, the zoom buttons scale it. A dialog with a preview has its buttons in a column beside the
|
||||
/// body, with the Preview check box and the footer extra under them.
|
||||
/// - 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)]
|
||||
@@ -297,9 +297,9 @@ impl<'a> ParamDialog<'a> {
|
||||
layout,
|
||||
closable,
|
||||
preview,
|
||||
footer_extra,
|
||||
mut footer_extra,
|
||||
below,
|
||||
shaped,
|
||||
mut shaped,
|
||||
answers,
|
||||
} = self;
|
||||
let words = Env::of(ui).words::<ParamDialogWords>();
|
||||
@@ -334,6 +334,28 @@ impl<'a> ParamDialog<'a> {
|
||||
if let Some(open) = open {
|
||||
form = form.opened(open);
|
||||
}
|
||||
// With a preview the buttons stand beside the body, and the Preview check box and the extras under them.
|
||||
let preview_on = Rc::new(Cell::new(false));
|
||||
if preview.is_some() {
|
||||
let (on, label) = (Rc::clone(&preview_on), words.preview.clone());
|
||||
let mut extra = footer_extra.take();
|
||||
let caller = shaped.take();
|
||||
form = form.shaped(move |dialog| {
|
||||
let dialog = dialog.side_buttons(true).footer(move |ui, cx| {
|
||||
let mut value = !cx.bar().memory::<PreviewOff>().0;
|
||||
Checkbox::new(Bind::bound(&mut value)).label(label.clone()).show(ui);
|
||||
cx.bar().memory::<PreviewOff>().0 = !value;
|
||||
on.set(value);
|
||||
if let Some(FooterExtra(extra)) = extra.as_mut() {
|
||||
extra(ui);
|
||||
}
|
||||
});
|
||||
match caller {
|
||||
Some(Shaped(shape)) => shape(dialog),
|
||||
None => dialog,
|
||||
}
|
||||
});
|
||||
}
|
||||
if let Some(FooterExtra(extra)) = footer_extra {
|
||||
form = form.footer_extra(extra);
|
||||
}
|
||||
@@ -396,7 +418,7 @@ impl<'a> ParamDialog<'a> {
|
||||
result,
|
||||
rows,
|
||||
values: shown.value,
|
||||
preview_on: preview.is_some() && live.on,
|
||||
preview_on: preview.is_some() && preview_on.get(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -418,6 +440,8 @@ pub enum ResetPick {
|
||||
Reset,
|
||||
/// The second button while Alt is not held: the dialog closes without an answer.
|
||||
Cancel,
|
||||
/// The extra button at this index in the order [`extra`](ResetFooter::extra) was given.
|
||||
Extra(usize),
|
||||
}
|
||||
|
||||
/// The two footer buttons of a dialog whose Cancel turns into Reset while Alt is held. Reset restores the values from
|
||||
@@ -440,6 +464,7 @@ pub struct ResetFooter {
|
||||
resetting: bool,
|
||||
cancel: Label,
|
||||
reset: Label,
|
||||
extra: Vec<FooterButton>,
|
||||
}
|
||||
|
||||
impl ResetFooter {
|
||||
@@ -451,9 +476,17 @@ impl ResetFooter {
|
||||
resetting: alt_resets && crate::runtime::pointer::frame(ui.ctx()).mods.alt,
|
||||
cancel: cancel.unwrap_or_else(|| env.words::<CommonWords>().cancel.clone()),
|
||||
reset: env.words::<ParamDialogWords>().reset.clone(),
|
||||
extra: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Buttons after the second one, which [`install`](ResetFooter::install) gives the dialog with the two.
|
||||
#[must_use]
|
||||
pub fn extra(mut self, buttons: impl IntoIterator<Item = FooterButton>) -> Self {
|
||||
self.extra = buttons.into_iter().collect();
|
||||
self
|
||||
}
|
||||
|
||||
/// Whether the second button is Reset in this pass.
|
||||
pub fn resetting(&self) -> bool {
|
||||
self.resetting
|
||||
@@ -487,7 +520,7 @@ impl ResetFooter {
|
||||
let pick = self.clone();
|
||||
let settle = self.clone();
|
||||
dialog
|
||||
.buttons(self.buttons(accept, false))
|
||||
.buttons(self.buttons(accept, false).into_iter().chain(self.extra.iter().cloned()))
|
||||
.settle_buttons(move |cx, buttons| {
|
||||
let footing = *cx.memory::<Footing>();
|
||||
settle.settle(buttons, footing.changed);
|
||||
@@ -496,7 +529,7 @@ impl ResetFooter {
|
||||
}
|
||||
})
|
||||
.on_pick(move |button, cx| {
|
||||
if pick.resetting() && button.role() == DialogRole::Other {
|
||||
if pick.resetting() && button.role() == DialogRole::Other && *button.label() == pick.reset {
|
||||
restore(cx);
|
||||
crate::runtime::frame::request_repaint(cx.memory.ctx());
|
||||
}
|
||||
@@ -513,15 +546,15 @@ impl ResetFooter {
|
||||
pub fn pick(&self, picked: Option<usize>) -> Option<ResetPick> {
|
||||
match picked? {
|
||||
0 => Some(ResetPick::Accept),
|
||||
_ if self.resetting => Some(ResetPick::Reset),
|
||||
_ => Some(ResetPick::Cancel),
|
||||
1 if self.resetting => Some(ResetPick::Reset),
|
||||
1 => Some(ResetPick::Cancel),
|
||||
at => Some(ResetPick::Extra(at - 2)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The Preview check box, the zoom row and the pane.
|
||||
/// The zoom row and the pane.
|
||||
fn show_preview(ui: &mut Ui, words: &ParamDialogWords, texture: &SizedTexture, live: &mut Live) {
|
||||
Checkbox::new(Bind::bound(&mut live.on)).label(words.preview.clone()).show(ui);
|
||||
let zoom = PreviewZoom::new(&live.view).show(ui);
|
||||
let pane = PreviewPane::new(words.preview.clone(), *texture, &live.view).show(ui);
|
||||
live.view = zoom.view.or(pane.view).unwrap_or(pane.shown);
|
||||
|
||||
@@ -88,7 +88,8 @@ pub struct FormOutput<V> {
|
||||
pub response: Response,
|
||||
/// How the dialog closed in this pass; `None` while it stays open.
|
||||
pub closed: Option<CloseReason>,
|
||||
/// The index of the footer button picked in this pass, in the order `ResetFooter::buttons` gives them.
|
||||
/// The index of the footer button picked in this pass, in the order `ResetFooter::buttons` gives them, then the
|
||||
/// [`extra_buttons`](FormDialog::extra_buttons) from 2 on.
|
||||
pub picked: Option<usize>,
|
||||
/// The value, the pass the dialog closed as OK while it could be accepted.
|
||||
pub accepted: Option<V>,
|
||||
@@ -130,6 +131,7 @@ pub struct FormDialog<'a, V: Value + Default> {
|
||||
closable: bool,
|
||||
accept_stays_open: bool,
|
||||
footer_extra: Option<FooterExtraFn<'a>>,
|
||||
extra_buttons: Vec<FooterButton>,
|
||||
shaped: Option<Box<dyn FnOnce(Dialog<'a>) -> Dialog<'a> + 'a>>,
|
||||
answers: Vec<HostAnswer>,
|
||||
reset_with: Option<ResetWithFn<'a, V>>,
|
||||
@@ -154,6 +156,7 @@ impl<'a, V: Value + Default> FormDialog<'a, V> {
|
||||
closable: true,
|
||||
accept_stays_open: false,
|
||||
footer_extra: None,
|
||||
extra_buttons: Vec::new(),
|
||||
shaped: None,
|
||||
answers: Vec::new(),
|
||||
reset_with: None,
|
||||
@@ -233,6 +236,13 @@ impl<'a, V: Value + Default> FormDialog<'a, V> {
|
||||
self
|
||||
}
|
||||
|
||||
/// Footer buttons after OK and Cancel, which keep the dialog open: the caller acts on
|
||||
/// [`FormOutput::picked`].
|
||||
pub fn extra_buttons(mut self, buttons: impl IntoIterator<Item = FooterButton>) -> Self {
|
||||
self.extra_buttons = buttons.into_iter().map(|button| button.stays_open(true)).collect();
|
||||
self
|
||||
}
|
||||
|
||||
/// Changes the built [`Dialog`] before it shows, for the settings this type has no setter for.
|
||||
pub fn shaped(mut self, shape: impl FnOnce(Dialog<'a>) -> Dialog<'a> + 'a) -> Self {
|
||||
self.shaped = Some(Box::new(shape));
|
||||
@@ -275,6 +285,7 @@ impl<'a, V: Value + Default> FormDialog<'a, V> {
|
||||
closable,
|
||||
accept_stays_open,
|
||||
footer_extra,
|
||||
extra_buttons,
|
||||
shaped,
|
||||
mut answers,
|
||||
reset_with,
|
||||
@@ -285,7 +296,7 @@ impl<'a, V: Value + Default> FormDialog<'a, V> {
|
||||
let name: Arc<str> = title.as_str().into();
|
||||
let bind = Rc::new(RefCell::new(bind));
|
||||
|
||||
let reset = ResetFooter::new(ui, cancel_label, alt_resets);
|
||||
let reset = ResetFooter::new(ui, cancel_label, alt_resets).extra(extra_buttons);
|
||||
let mut accept =
|
||||
FooterButton::new(ok_label.unwrap_or_else(|| common.ok.clone()), DialogRole::Accept).enabled(ok_enabled).stays_open(accept_stays_open);
|
||||
if let (false, Some(reason)) = (ok_enabled, &ok_reason) {
|
||||
|
||||
@@ -261,8 +261,8 @@ fn is_enabled(action: &ListManagerAction, entries: &[ListManagerEntry], folder:
|
||||
/// box also filters the rows to the names that match it.
|
||||
/// - Keys: Up and Down in the box or the list move the selection, Enter and a double click run the first action when
|
||||
/// it is enabled, Delete in the list runs the `delete` action, Escape cancels.
|
||||
/// - Actions are the footer's buttons, in the given order, with Cancel last. The app replaces `entries` between
|
||||
/// passes; the name box keeps its text.
|
||||
/// - Actions are the buttons in a column beside the list: the first action, Cancel, then the other actions in the
|
||||
/// given order. The app replaces `entries` between passes; the name box keeps its text.
|
||||
#[must_use = "show the dialog with `show`"]
|
||||
#[derive(crate::contract::Pattern, crate::contract::Props)]
|
||||
pub struct ListManager<'a> {
|
||||
@@ -334,13 +334,15 @@ impl<'a> ListManager<'a> {
|
||||
})
|
||||
.collect();
|
||||
buttons.push(FooterButton::new(common.cancel.clone(), DialogRole::Cancel));
|
||||
let mut dialog = Dialog::new(title.clone()).collection_body().close_on_enter(false).buttons(buttons).settle_buttons(move |cx, buttons| {
|
||||
let folder = cx.env.folder();
|
||||
let typed = cx.memory::<Session>().name.clone();
|
||||
for (button, action) in buttons.iter_mut().zip(actions) {
|
||||
button.set_enabled(is_enabled(action, entries, &folder, &typed));
|
||||
}
|
||||
});
|
||||
let mut dialog = Dialog::new(title.clone()).collection_body().close_on_enter(false).side_buttons(true).buttons(buttons).settle_buttons(
|
||||
move |cx, buttons| {
|
||||
let folder = cx.env.folder();
|
||||
let typed = cx.memory::<Session>().name.clone();
|
||||
for (button, action) in buttons.iter_mut().zip(actions) {
|
||||
button.set_enabled(is_enabled(action, entries, &folder, &typed));
|
||||
}
|
||||
},
|
||||
);
|
||||
if let Some(open) = open {
|
||||
dialog = dialog.opened(open);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
//! lays its children out (6.3).
|
||||
|
||||
use crate::contract::{
|
||||
Access, BodyCx, Common, Component, Container, ContainerProps, Cx, FooterRegion, Gap, HeaderRegion, Pad, Role, Scroll, Sizing, ThemeScope,
|
||||
Access, BodyCx, Common, Component, Container, ContainerProps, Cx, EndRegion, FooterPlace, FooterRegion, Gap, HeaderRegion, Pad, Role, Scroll,
|
||||
Sizing, ThemeScope,
|
||||
};
|
||||
use crate::layout::{BodyLayout, RowAlign};
|
||||
use crate::style::{ComponentStyle, StyleCx};
|
||||
@@ -217,6 +218,15 @@ impl<'a> Stack<'a> {
|
||||
self.footer = Some(Box::new(content));
|
||||
self
|
||||
}
|
||||
|
||||
/// The footer stands in a column at the end edge, beside the body and at its top, as wide as its widest child;
|
||||
/// a child that fills the width (`Button::fill_width`) takes that width. Set it after [`footer`](Stack::footer).
|
||||
#[must_use]
|
||||
pub fn footer_beside(mut self) -> Self {
|
||||
self.props.end = Some(EndRegion::new());
|
||||
self.props = self.props.footer(FooterRegion::new().place(FooterPlace::EndTop));
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Stack<'_> {
|
||||
|
||||
Reference in New Issue
Block a user