mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-18 10:42:32 +00:00
Dialog bodies: the content sits directly in the dialog body, which is already a stack, so fill-width children take the dialog's width; the Tabs dialog's Position column is as wide as its field and Alignment and Leader share the rest
This commit is contained in:
@@ -300,43 +300,41 @@ impl StackDialog for LayersOptionsDialog {
|
||||
let words = env.words::<LayersOptionsWords>();
|
||||
let list = env.words::<ListWords>();
|
||||
let shown = FormDialog::new(words.title.clone(), Bind::bound(&mut self.options)).show(ui, |ui, _, options| {
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
GroupBox::new(words.thumbnail_size.clone(), None).show(ui, |ui, _| {
|
||||
RadioGroup::new(words.thumbnail_size.clone(), Bind::bound(&mut options.thumbnail_size)).show(ui, |ui, cx| {
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
// Each size's sample is its option's label: a click on it picks the size, and the size's
|
||||
// name names the radio and is the sample's tooltip.
|
||||
for size in ThumbSize::ALL {
|
||||
let side = SideLabel::new().layout(FieldLayout::After);
|
||||
if size == ThumbSize::None {
|
||||
cx.labelled(ui, size, size.label(&list), side, Radio::new(size));
|
||||
} else {
|
||||
let sample = Picture::new(words.sample.clone(), SAMPLE_KEY, &sample_image).extent(PictureSize::Thumb(size));
|
||||
cx.labelled_with(ui, size, size.label(&list), side.kind(LabelKind::Hidden), Radio::new(size), sample);
|
||||
}
|
||||
GroupBox::new(words.thumbnail_size.clone(), None).show(ui, |ui, _| {
|
||||
RadioGroup::new(words.thumbnail_size.clone(), Bind::bound(&mut options.thumbnail_size)).show(ui, |ui, cx| {
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
// Each size's sample is its option's label: a click on it picks the size, and the size's
|
||||
// name names the radio and is the sample's tooltip.
|
||||
for size in ThumbSize::ALL {
|
||||
let side = SideLabel::new().layout(FieldLayout::After);
|
||||
if size == ThumbSize::None {
|
||||
cx.labelled(ui, size, size.label(&list), side, Radio::new(size));
|
||||
} else {
|
||||
let sample = Picture::new(words.sample.clone(), SAMPLE_KEY, &sample_image).extent(PictureSize::Thumb(size));
|
||||
cx.labelled_with(ui, size, size.label(&list), side.kind(LabelKind::Hidden), Radio::new(size), sample);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
GroupBox::new(words.thumbnail_contents.clone(), None).show(ui, |ui, _| {
|
||||
RadioGroup::new(words.thumbnail_contents.clone(), Bind::bound(&mut options.thumbnail_contents)).show(ui, |ui, _| {
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
Radio::new(ThumbContents::LayerBounds).label(words.layer_bounds.clone()).show(ui);
|
||||
Radio::new(ThumbContents::EntireDocument).label(words.entire_document.clone()).show(ui);
|
||||
});
|
||||
});
|
||||
});
|
||||
let switches = [
|
||||
(&words.default_masks, &mut options.use_default_masks_on_fill_layers),
|
||||
(&words.expand_new_effects, &mut options.expand_new_effects),
|
||||
(&words.add_copy, &mut options.add_copy_to_copied_layers_and_groups),
|
||||
(&words.preview_on_canvas, &mut options.preview_on_canvas_when_reordering),
|
||||
(&words.mask_badges, &mut options.show_layer_mask_badges),
|
||||
];
|
||||
for (label, value) in switches {
|
||||
Checkbox::new(Bind::bound(value)).label(label.clone()).show(ui);
|
||||
}
|
||||
});
|
||||
GroupBox::new(words.thumbnail_contents.clone(), None).show(ui, |ui, _| {
|
||||
RadioGroup::new(words.thumbnail_contents.clone(), Bind::bound(&mut options.thumbnail_contents)).show(ui, |ui, _| {
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
Radio::new(ThumbContents::LayerBounds).label(words.layer_bounds.clone()).show(ui);
|
||||
Radio::new(ThumbContents::EntireDocument).label(words.entire_document.clone()).show(ui);
|
||||
});
|
||||
});
|
||||
});
|
||||
let switches = [
|
||||
(&words.default_masks, &mut options.use_default_masks_on_fill_layers),
|
||||
(&words.expand_new_effects, &mut options.expand_new_effects),
|
||||
(&words.add_copy, &mut options.add_copy_to_copied_layers_and_groups),
|
||||
(&words.preview_on_canvas, &mut options.preview_on_canvas_when_reordering),
|
||||
(&words.mask_badges, &mut options.show_layer_mask_badges),
|
||||
];
|
||||
for (label, value) in switches {
|
||||
Checkbox::new(Bind::bound(value)).label(label.clone()).show(ui);
|
||||
}
|
||||
true
|
||||
});
|
||||
match (shown.accepted, shown.closed) {
|
||||
|
||||
@@ -16,7 +16,7 @@ use craft_ui::contract::{
|
||||
use craft_ui::dialog::{Dialog, DialogId, DialogResult, DialogStack, StackDialog, dialog_id};
|
||||
use craft_ui::display::{Shade, Text};
|
||||
use craft_ui::fonts::FontRef;
|
||||
use craft_ui::layout_components::{Row, Stack};
|
||||
use craft_ui::layout_components::Row;
|
||||
use craft_ui::notices::{Notice, NoticeLayout};
|
||||
use craft_ui::primitives::{DocRun, DocText, Draw, HAlign, PaintShape, StrokeWidth, TextureCache};
|
||||
use craft_ui::runtime::env::Env;
|
||||
@@ -518,56 +518,54 @@ impl StackDialog for SignaturePadDialog {
|
||||
let SignaturePadDialog { draft, scan, open, decoding, error, .. } = self;
|
||||
let decoding = decoding.is_some();
|
||||
let shown = Dialog::new(title.clone()).opened(Bind::bound(open)).buttons(buttons).show(ui, |ui, _| {
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
let mut tabs = vec![
|
||||
Entry::new(SignatureTab::Type, words.type_tab.clone()),
|
||||
Entry::new(SignatureTab::Draw, words.draw_tab.clone()),
|
||||
Entry::new(SignatureTab::Image, words.image_tab.clone()),
|
||||
];
|
||||
if scan.is_some() {
|
||||
tabs.push(Entry::new(SignatureTab::Scan, words.scan_tab.clone()));
|
||||
let mut tabs = vec![
|
||||
Entry::new(SignatureTab::Type, words.type_tab.clone()),
|
||||
Entry::new(SignatureTab::Draw, words.draw_tab.clone()),
|
||||
Entry::new(SignatureTab::Image, words.image_tab.clone()),
|
||||
];
|
||||
if scan.is_some() {
|
||||
tabs.push(Entry::new(SignatureTab::Scan, words.scan_tab.clone()));
|
||||
}
|
||||
Segmented::new(title.clone(), Bind::bound(&mut draft.tab), &tabs).show(ui);
|
||||
match draft.tab {
|
||||
SignatureTab::Type => {
|
||||
TextField::new(words.type_hint.clone(), Bind::bound(&mut draft.text))
|
||||
.placeholder(words.type_hint.clone())
|
||||
.limit(MAX_SIGNATURE_CHARS)
|
||||
.show(ui);
|
||||
DrawPad::typed(draft.text.clone(), &draft.text).show(ui);
|
||||
}
|
||||
Segmented::new(title.clone(), Bind::bound(&mut draft.tab), &tabs).show(ui);
|
||||
match draft.tab {
|
||||
SignatureTab::Type => {
|
||||
TextField::new(words.type_hint.clone(), Bind::bound(&mut draft.text))
|
||||
.placeholder(words.type_hint.clone())
|
||||
.limit(MAX_SIGNATURE_CHARS)
|
||||
.show(ui);
|
||||
DrawPad::typed(draft.text.clone(), &draft.text).show(ui);
|
||||
SignatureTab::Draw => {
|
||||
DrawPad::new(words.draw_tab.clone(), Bind::bound(&mut draft.strokes)).show(ui);
|
||||
}
|
||||
SignatureTab::Image => {
|
||||
Text::new(words.image_hint.clone()).shade(Shade::Muted).show(ui);
|
||||
if clicked(&Button::new(words.browse.clone()).icon(craft_behavior::IconId::new("folder")).loading(decoding).show(ui)) {
|
||||
browse = true;
|
||||
}
|
||||
SignatureTab::Draw => {
|
||||
DrawPad::new(words.draw_tab.clone(), Bind::bound(&mut draft.strokes)).show(ui);
|
||||
if let Some(error) = *error {
|
||||
let word = match error {
|
||||
PickError::Unreadable => &words.image_failed,
|
||||
PickError::TooLarge => &words.image_too_large,
|
||||
};
|
||||
Notice::new(Tone::Bad, word.clone()).layout(NoticeLayout::Inline).show(ui);
|
||||
}
|
||||
SignatureTab::Image => {
|
||||
Text::new(words.image_hint.clone()).shade(Shade::Muted).show(ui);
|
||||
if clicked(&Button::new(words.browse.clone()).icon(craft_behavior::IconId::new("folder")).loading(decoding).show(ui)) {
|
||||
browse = true;
|
||||
}
|
||||
if let Some(error) = *error {
|
||||
let word = match error {
|
||||
PickError::Unreadable => &words.image_failed,
|
||||
PickError::TooLarge => &words.image_too_large,
|
||||
};
|
||||
Notice::new(Tone::Bad, word.clone()).layout(NoticeLayout::Inline).show(ui);
|
||||
}
|
||||
DrawPad::image(words.image_tab.clone(), draft.image.as_ref()).show(ui);
|
||||
}
|
||||
SignatureTab::Scan => {
|
||||
if let Some(tab) = scan.as_mut() {
|
||||
tab(ui, draft);
|
||||
}
|
||||
DrawPad::image(words.image_tab.clone(), draft.image.as_ref()).show(ui);
|
||||
}
|
||||
SignatureTab::Scan => {
|
||||
if let Some(tab) = scan.as_mut() {
|
||||
tab(ui, draft);
|
||||
}
|
||||
}
|
||||
Row::new().show(ui, |ui, _| {
|
||||
if draft.tab == SignatureTab::Draw && clicked(&Button::new(words.undo.clone()).enabled(!draft.strokes.is_empty()).show(ui)) {
|
||||
draft.undo_stroke();
|
||||
}
|
||||
if clicked(&Button::new(words.clear.clone()).show(ui)) {
|
||||
draft.clear();
|
||||
*error = None;
|
||||
}
|
||||
});
|
||||
}
|
||||
Row::new().show(ui, |ui, _| {
|
||||
if draft.tab == SignatureTab::Draw && clicked(&Button::new(words.undo.clone()).enabled(!draft.strokes.is_empty()).show(ui)) {
|
||||
draft.undo_stroke();
|
||||
}
|
||||
if clicked(&Button::new(words.clear.clone()).show(ui)) {
|
||||
draft.clear();
|
||||
*error = None;
|
||||
}
|
||||
});
|
||||
});
|
||||
if browse && let Some(host) = &host {
|
||||
|
||||
@@ -8,7 +8,6 @@ use craft_ui::choice::Checkbox;
|
||||
use craft_ui::contract::{Bind, CollectionEvent, Entry, Props as _, Show as _, ShowCollection as _, ShowContainer as _, Trigger, clicked};
|
||||
use craft_ui::dialog::{Dialog, DialogId, DialogResult, DialogStack, StackDialog, dialog_id};
|
||||
use craft_ui::display::Text;
|
||||
use craft_ui::layout_components::Stack;
|
||||
use craft_ui::menu::Menu;
|
||||
use craft_ui::pickers::Select;
|
||||
use craft_ui::runtime::env::{Env, Label};
|
||||
@@ -251,100 +250,98 @@ impl StackDialog for FindReplaceDialog {
|
||||
let close_at = buttons.len() - 1;
|
||||
|
||||
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 = [
|
||||
(FindTab::Find, words.find_tab.as_str().to_owned()),
|
||||
(FindTab::Replace, words.replace_tab.as_str().to_owned()),
|
||||
(FindTab::GoTo, words.go_to_tab.as_str().to_owned()),
|
||||
];
|
||||
let source = keyed(&tabs[..], |tab: &(FindTab, String)| tab.0).with_text(|tab| Cow::Borrowed(tab.1.as_str()));
|
||||
let strip = TabStrip::new(words.title.clone()).kind(TabKind::Text).shown(tab).natural_height(true);
|
||||
let out = strip.show_items(ui, &source, &mut |key, _| {
|
||||
Tab::new(tabs.iter().find(|tab| tab.0 == *key).map_or_else(String::new, |tab| tab.1.clone()))
|
||||
});
|
||||
for event in out.response.events {
|
||||
if let CollectionEvent::Selection(SelectionChange::Set(keys)) = event
|
||||
&& let Some(chosen) = keys.last()
|
||||
{
|
||||
next_tab = *chosen;
|
||||
}
|
||||
if word {
|
||||
let tabs = [
|
||||
(FindTab::Find, words.find_tab.as_str().to_owned()),
|
||||
(FindTab::Replace, words.replace_tab.as_str().to_owned()),
|
||||
(FindTab::GoTo, words.go_to_tab.as_str().to_owned()),
|
||||
];
|
||||
let source = keyed(&tabs[..], |tab: &(FindTab, String)| tab.0).with_text(|tab| Cow::Borrowed(tab.1.as_str()));
|
||||
let strip = TabStrip::new(words.title.clone()).kind(TabKind::Text).shown(tab).natural_height(true);
|
||||
let out = strip.show_items(ui, &source, &mut |key, _| {
|
||||
Tab::new(tabs.iter().find(|tab| tab.0 == *key).map_or_else(String::new, |tab| tab.1.clone()))
|
||||
});
|
||||
for event in out.response.events {
|
||||
if let CollectionEvent::Selection(SelectionChange::Set(keys)) = event
|
||||
&& let Some(chosen) = keys.last()
|
||||
{
|
||||
next_tab = *chosen;
|
||||
}
|
||||
}
|
||||
if tab == FindTab::GoTo {
|
||||
Text::new(words.go_to_what.clone()).show(ui);
|
||||
let entries: Vec<Entry<usize>> = kinds.iter().enumerate().map(|(at, kind)| Entry::new(at, kind.clone())).collect();
|
||||
let edit = Select::new(words.go_to_what.clone(), Bind::given(go_kind.min(kinds.len().saturating_sub(1))), &entries).show(ui);
|
||||
if let Some(value) = edit.events.value() {
|
||||
go_kind = *value;
|
||||
}
|
||||
let edit = TextField::new(words.go_to.clone(), Bind::given(target.clone())).show(ui);
|
||||
if let Some(value) = edit.events.value() {
|
||||
target.clone_from(value);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if tab == FindTab::GoTo {
|
||||
Text::new(words.go_to_what.clone()).show(ui);
|
||||
let entries: Vec<Entry<usize>> = kinds.iter().enumerate().map(|(at, kind)| Entry::new(at, kind.clone())).collect();
|
||||
let edit = Select::new(words.go_to_what.clone(), Bind::given(go_kind.min(kinds.len().saturating_sub(1))), &entries).show(ui);
|
||||
if let Some(value) = edit.events.value() {
|
||||
go_kind = *value;
|
||||
}
|
||||
let edit = TextField::new(words.go_to.clone(), Bind::given(target.clone())).show(ui);
|
||||
if let Some(value) = edit.events.value() {
|
||||
target.clone_from(value);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Text::new(words.find_what.clone()).show(ui);
|
||||
let mut field = TextField::new(words.find_what.clone(), Bind::given(query.clone()));
|
||||
if let Some((Field::Find, code)) = &pending {
|
||||
Text::new(words.find_what.clone()).show(ui);
|
||||
let mut field = TextField::new(words.find_what.clone(), Bind::given(query.clone()));
|
||||
if let Some((Field::Find, code)) = &pending {
|
||||
field = field.replace_selection(code.clone());
|
||||
}
|
||||
let edit = field.show(ui);
|
||||
if edit.response.has_focus() {
|
||||
last_field = Field::Find;
|
||||
}
|
||||
if let Some(value) = edit.events.value() {
|
||||
query.clone_from(value);
|
||||
}
|
||||
submitted |= edit.submitted;
|
||||
if tab == FindTab::Replace {
|
||||
Text::new(words.replace_with.clone()).show(ui);
|
||||
let mut field = TextField::new(words.replace_with.clone(), Bind::given(with.clone()));
|
||||
if let Some((Field::With, code)) = &pending {
|
||||
field = field.replace_selection(code.clone());
|
||||
}
|
||||
let edit = field.show(ui);
|
||||
if edit.response.has_focus() {
|
||||
last_field = Field::Find;
|
||||
last_field = Field::With;
|
||||
}
|
||||
if let Some(value) = edit.events.value() {
|
||||
query.clone_from(value);
|
||||
}
|
||||
submitted |= edit.submitted;
|
||||
if tab == FindTab::Replace {
|
||||
Text::new(words.replace_with.clone()).show(ui);
|
||||
let mut field = TextField::new(words.replace_with.clone(), Bind::given(with.clone()));
|
||||
if let Some((Field::With, code)) = &pending {
|
||||
field = field.replace_selection(code.clone());
|
||||
}
|
||||
let edit = field.show(ui);
|
||||
if edit.response.has_focus() {
|
||||
last_field = Field::With;
|
||||
}
|
||||
if let Some(value) = edit.events.value() {
|
||||
with.clone_from(value);
|
||||
}
|
||||
with.clone_from(value);
|
||||
}
|
||||
}
|
||||
|
||||
let check = |ui: &mut Ui, label: &Label, value: &mut bool, enabled: bool| {
|
||||
Checkbox::new(Bind::bound(value)).label(label.clone()).enabled(enabled).show(ui);
|
||||
};
|
||||
if !word {
|
||||
check(ui, &words.match_case.clone(), &mut options.match_case, true);
|
||||
check(ui, &words.whole_words.clone(), &mut options.whole_word, true);
|
||||
return;
|
||||
}
|
||||
if clicked(&Button::new(words.search_options.clone()).show(ui)) {
|
||||
more = !more;
|
||||
}
|
||||
if !more {
|
||||
return;
|
||||
}
|
||||
// Word greys the case, word and ignore options out while wildcards are on.
|
||||
let free = !options.wildcards || options.regex;
|
||||
let no_regex = !options.regex;
|
||||
check(ui, &words.match_case.clone(), &mut options.match_case, free);
|
||||
check(ui, &words.whole_words.clone(), &mut options.whole_word, free);
|
||||
check(ui, &words.use_wildcards.clone(), &mut options.wildcards, no_regex);
|
||||
check(ui, &words.match_prefix.clone(), &mut options.prefix, free);
|
||||
check(ui, &words.match_suffix.clone(), &mut options.suffix, free);
|
||||
check(ui, &words.ignore_punctuation.clone(), &mut options.ignore_punctuation, free);
|
||||
check(ui, &words.ignore_space.clone(), &mut options.ignore_space, free);
|
||||
check(ui, &words.regular_expressions.clone(), &mut options.regex, true);
|
||||
let entries = special_entries(&words, tab == FindTab::Replace);
|
||||
let button = Button::new(words.special.clone()).show(ui);
|
||||
if let Some(code) = Menu::new(words.special.clone()).opened_by(&button, Trigger::Press).pick(ui, &entries).picked {
|
||||
let field = if last_field == Field::With && tab == FindTab::Replace { Field::With } else { Field::Find };
|
||||
picked_code = Some((field, code.to_owned()));
|
||||
}
|
||||
});
|
||||
let check = |ui: &mut Ui, label: &Label, value: &mut bool, enabled: bool| {
|
||||
Checkbox::new(Bind::bound(value)).label(label.clone()).enabled(enabled).show(ui);
|
||||
};
|
||||
if !word {
|
||||
check(ui, &words.match_case.clone(), &mut options.match_case, true);
|
||||
check(ui, &words.whole_words.clone(), &mut options.whole_word, true);
|
||||
return;
|
||||
}
|
||||
if clicked(&Button::new(words.search_options.clone()).show(ui)) {
|
||||
more = !more;
|
||||
}
|
||||
if !more {
|
||||
return;
|
||||
}
|
||||
// Word greys the case, word and ignore options out while wildcards are on.
|
||||
let free = !options.wildcards || options.regex;
|
||||
let no_regex = !options.regex;
|
||||
check(ui, &words.match_case.clone(), &mut options.match_case, free);
|
||||
check(ui, &words.whole_words.clone(), &mut options.whole_word, free);
|
||||
check(ui, &words.use_wildcards.clone(), &mut options.wildcards, no_regex);
|
||||
check(ui, &words.match_prefix.clone(), &mut options.prefix, free);
|
||||
check(ui, &words.match_suffix.clone(), &mut options.suffix, free);
|
||||
check(ui, &words.ignore_punctuation.clone(), &mut options.ignore_punctuation, free);
|
||||
check(ui, &words.ignore_space.clone(), &mut options.ignore_space, free);
|
||||
check(ui, &words.regular_expressions.clone(), &mut options.regex, true);
|
||||
let entries = special_entries(&words, tab == FindTab::Replace);
|
||||
let button = Button::new(words.special.clone()).show(ui);
|
||||
if let Some(code) = Menu::new(words.special.clone()).opened_by(&button, Trigger::Press).pick(ui, &entries).picked {
|
||||
let field = if last_field == Field::With && tab == FindTab::Replace { Field::With } else { Field::Find };
|
||||
picked_code = Some((field, code.to_owned()));
|
||||
}
|
||||
if !message.is_empty() {
|
||||
Text::new(message.clone()).show(ui);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ use craft_ui::contract::{
|
||||
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::Stack;
|
||||
use craft_ui::list::{List, ListRow};
|
||||
use craft_ui::notices::{Notice, NoticeLayout};
|
||||
use craft_ui::runtime::env::Env;
|
||||
@@ -238,52 +237,49 @@ impl CheckSpellingDialog {
|
||||
.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, _| {
|
||||
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::FillWidth)
|
||||
.surface(SurfaceKind::Sunken)
|
||||
.pad(Pad::Control)
|
||||
.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 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::FillWidth)
|
||||
.surface(SurfaceKind::Sunken)
|
||||
.pad(Pad::Control)
|
||||
.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, picked } = shown.output;
|
||||
let button_press = picked.and_then(|at| actions.get(at.checked_sub(1)?)).map(|(_, which)| *which);
|
||||
|
||||
@@ -18,7 +18,7 @@ use craft_ui::contract::{
|
||||
};
|
||||
use craft_ui::dialog::{Dialog, DialogId, DialogResult, DialogStack, StackDialog, dialog_id};
|
||||
use craft_ui::form::Field;
|
||||
use craft_ui::layout_components::{Row, Stack};
|
||||
use craft_ui::layout_components::Row;
|
||||
use craft_ui::list::ListRow;
|
||||
use craft_ui::pickers::Select;
|
||||
use craft_ui::runtime::env::{Env, Units};
|
||||
@@ -270,15 +270,13 @@ enum CellEdit {
|
||||
|
||||
impl TabStopsDialog {
|
||||
fn body(&mut self, ui: &mut Ui, words: &TabStopsWords, units: &Units) {
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
self.default_row(ui, words);
|
||||
self.table(ui, words, units);
|
||||
self.buttons(ui, words);
|
||||
if !self.cleared.is_empty() {
|
||||
let positions: Vec<String> = self.cleared.iter().map(|gone| self.text(units, *gone)).collect();
|
||||
craft_ui::display::Text::new(format!("{} {}", words.to_be_cleared.as_str(), positions.join(", "))).show(ui);
|
||||
}
|
||||
});
|
||||
self.default_row(ui, words);
|
||||
self.table(ui, words, units);
|
||||
self.buttons(ui, words);
|
||||
if !self.cleared.is_empty() {
|
||||
let positions: Vec<String> = self.cleared.iter().map(|gone| self.text(units, *gone)).collect();
|
||||
craft_ui::display::Text::new(format!("{} {}", words.to_be_cleared.as_str(), positions.join(", "))).show(ui);
|
||||
}
|
||||
}
|
||||
|
||||
/// `points` as the number in the unit with its suffix.
|
||||
@@ -307,7 +305,7 @@ impl TabStopsDialog {
|
||||
/// selection change moves the selected stop.
|
||||
fn table(&mut self, ui: &mut Ui, words: &TabStopsWords, units: &Units) {
|
||||
let columns = vec![
|
||||
ColumnSpec::new(POSITION, words.position_column.clone(), ColumnWidth::fill(1.0)),
|
||||
ColumnSpec::new(POSITION, words.position_column.clone(), ColumnWidth::Content),
|
||||
ColumnSpec::new(ALIGNMENT, words.alignment.clone(), ColumnWidth::fill(1.0)),
|
||||
ColumnSpec::new(LEADER, words.leader.clone(), ColumnWidth::fill(1.0)),
|
||||
];
|
||||
|
||||
@@ -4,7 +4,6 @@ use super::modal::ModalDragStrip;
|
||||
use super::{BlockingOverlay, Dialog, DialogFrame};
|
||||
use crate::choice::Checkbox;
|
||||
use crate::contract::{Bind, Props as _, Show as _, ShowContainer as _};
|
||||
use crate::layout_components::Stack;
|
||||
use crate::runtime::focus::Initial;
|
||||
use crate::sections::{DialogRole, FooterButton};
|
||||
use crate::testing::{Drive, Fixture, StoryData, StoryOutput, story};
|
||||
@@ -14,10 +13,8 @@ use egui::Ui;
|
||||
#[doc(hidden)]
|
||||
pub fn body(ui: &mut Ui, checks: &mut [bool; 2]) {
|
||||
let [snap, rulers] = checks;
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
Checkbox::new(Bind::bound(snap)).label("Snap to grid").show(ui);
|
||||
Checkbox::new(Bind::bound(rulers)).label("Show rulers").show(ui);
|
||||
});
|
||||
Checkbox::new(Bind::bound(snap)).label("Snap to grid").show(ui);
|
||||
Checkbox::new(Bind::bound(rulers)).label("Show rulers").show(ui);
|
||||
}
|
||||
|
||||
/// The drive of the shells with a close action: a click on it.
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::choice::Checkbox;
|
||||
use crate::contract::{Bind, Props as _, Show as _, ShowContainer as _};
|
||||
use crate::dialog::Dialog;
|
||||
use crate::display::Text;
|
||||
use crate::layout_components::{Grid, Stack};
|
||||
use crate::layout_components::Grid;
|
||||
use crate::runtime::env::WindowKey;
|
||||
use crate::shell::{CanvasPanel, Slot};
|
||||
use crate::testing::{Drive, StoryData, StoryOutput, stage, story};
|
||||
@@ -77,10 +77,8 @@ fn shell_region(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
/// What the story dialogs hold: two check boxes whose values the story keeps between passes.
|
||||
fn dialog_body(ui: &mut Ui, checks: &mut [bool; 2]) {
|
||||
let [snap, rulers] = checks;
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
Checkbox::new(Bind::bound(snap)).label("Snap to grid").show(ui);
|
||||
Checkbox::new(Bind::bound(rulers)).label("Show rulers").show(ui);
|
||||
});
|
||||
Checkbox::new(Bind::bound(snap)).label("Snap to grid").show(ui);
|
||||
Checkbox::new(Bind::bound(rulers)).label("Show rulers").show(ui);
|
||||
}
|
||||
|
||||
/// Two embedded regions side by side, each with its own open dialog: a dialog opened in a region is placed in it, its
|
||||
|
||||
Reference in New Issue
Block a user