mirror of
https://github.com/storytold/deckcraft.git
synced 2026-12-02 02:36:14 -06:00
symbol dialog: the framework IconPicker with its natural height
The Symbol dialog shows its picker in a dialog body that scrolls, so the picker takes its natural height (IconPicker::natural_height, fw a787c30e9) instead of a hand-built TileGrid standing in for the framework control. no_collection_shares_a_scrolling_body passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
f923daba0f
commit
320d98f8f3
@@ -1,33 +1,50 @@
|
||||
use craft::behavior::keyed;
|
||||
use craft::ui::contract::{ActivateOn, Bind, CollectionEvent, SelectMode, ShowCollection as _};
|
||||
use craft::ui::contract::Bind;
|
||||
use craft::ui::dialog::DialogHost;
|
||||
use craft::ui::patterns::form_dialogs::{DialogFields, HostedParamDialog, Param, ParamDialog, ParamLayout, ParamResult};
|
||||
use craft::ui::tile_grid::{CaptionPlace, Tile, TileGrid, TileGroup};
|
||||
use craft::ui::pickers::{IconPicker, IconPickerGroup, IconPickerGroups, IconPickerItem, IconPickerSearch};
|
||||
use egui::Context;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::SlideApp;
|
||||
|
||||
const GROUPS: [(&str, &str); 6] = [
|
||||
("Punctuation", "–—‘’“”…•·§¶†‡‰′″‹›«»¡¿"),
|
||||
("Currency", "$€£¥¢₹₩₽₺₿"),
|
||||
("Math", "±×÷≠≈≤≥∞√∑∏∫∂∆∇∈∉∩∪⊂⊃∀∃¬∧∨⇒⇔°′"),
|
||||
("Greek", "αβγδεζηθικλμνξοπρστυφχψωΓΔΘΛΞΠΣΦΨΩ"),
|
||||
("Arrows", "←↑→↓↔↕⇐⇑⇒⇓↖↗↘↙⟵⟶"),
|
||||
("Shapes", "■□▪▫▲△▶▷▼▽◀◁◆◇○●◎★☆✓✔✗✘♠♣♥♦"),
|
||||
];
|
||||
|
||||
/// Opens a modeless symbol palette that inserts at the text caret.
|
||||
pub(crate) fn open(_app: &SlideApp, ctx: &Context, _params: &Value) -> HostedParamDialog {
|
||||
let groups: Vec<_> = [
|
||||
("Punctuation", "–—‘’“”…•·§¶†‡‰′″‹›«»¡¿"),
|
||||
("Currency", "$€£¥¢₹₩₽₺₿"),
|
||||
("Math", "±×÷≠≈≤≥∞√∑∏∫∂∆∇∈∉∩∪⊂⊃∀∃¬∧∨⇒⇔°′"),
|
||||
("Greek", "αβγδεζηθικλμνξοπρστυφχψωΓΔΘΛΞΠΣΦΨΩ"),
|
||||
("Arrows", "←↑→↓↔↕⇐⇑⇒⇓↖↗↘↙⟵⟶"),
|
||||
("Shapes", "■□▪▫▲△▶▷▼▽◀◁◆◇○●◎★☆✓✔✗✘♠♣♥♦"),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(name, characters)| {
|
||||
IconPickerGroup::new(
|
||||
name,
|
||||
characters
|
||||
.chars()
|
||||
.map(|character| {
|
||||
let glyph = character.to_string();
|
||||
IconPickerItem::new(glyph.clone(), glyph.clone()).glyph(glyph)
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
HostedParamDialog::new(ctx, "symbol", DialogFields::new(), move |fields| {
|
||||
let groups = groups.clone();
|
||||
let params = vec![
|
||||
Param::read_only_text("instructions", "", "Click a symbol to insert it at the insertion point.").full_width(),
|
||||
Param::custom("symbol", "Symbols", move |ui, _, cx| {
|
||||
let (response, picked) = palette(ui);
|
||||
if let Some(symbol) = picked {
|
||||
let out = IconPicker::new("Symbols", Bind::given(None::<String>), &groups)
|
||||
.group_display(IconPickerGroups::Headings)
|
||||
.natural_height(true)
|
||||
.search(IconPickerSearch::None)
|
||||
.show(ui);
|
||||
if let Some(symbol) = out.picked {
|
||||
cx.request_action(symbol);
|
||||
}
|
||||
response
|
||||
out.response
|
||||
})
|
||||
.full_width(),
|
||||
];
|
||||
@@ -40,37 +57,6 @@ pub(crate) fn open(_app: &SlideApp, ctx: &Context, _params: &Value) -> HostedPar
|
||||
.modeless()
|
||||
}
|
||||
|
||||
/// Shows every group's symbols under its heading, at the grid's full height: the dialog's body scrolls them, as the
|
||||
/// palette is a document row of that body. Returns the grid's response and the symbol clicked this pass.
|
||||
fn palette(ui: &mut egui::Ui) -> (egui::Response, Option<String>) {
|
||||
let mut symbols = Vec::new();
|
||||
let mut named = Vec::new();
|
||||
for (name, characters) in GROUPS {
|
||||
let start = symbols.len();
|
||||
symbols.extend(characters.chars().map(String::from));
|
||||
named.push((start, symbols.len() - start, name));
|
||||
}
|
||||
// The heading rows are keyed after the cells, whose keys are their positions.
|
||||
let groups: Vec<TileGroup<usize>> =
|
||||
named.iter().enumerate().map(|(at, (start, count, name))| TileGroup::new(symbols.len() + at, *start, *count, *name)).collect();
|
||||
let cells: Vec<usize> = (0..symbols.len()).collect();
|
||||
let source = keyed(&cells, |at| *at).with_text(|at| symbols[*at].clone().into());
|
||||
let out = TileGrid::<usize>::new("Symbols")
|
||||
.natural_height(true)
|
||||
.select(SelectMode::Single)
|
||||
.activate(ActivateOn::Click)
|
||||
.caption(CaptionPlace::None)
|
||||
.content_cells()
|
||||
.slow_click_rename(false)
|
||||
.groups(&groups)
|
||||
.show_items(ui, &source, &mut |at, _| Tile::new(symbols[*at].clone()).glyph(symbols[*at].clone()));
|
||||
let picked = out.response.events.iter().find_map(|event| match event {
|
||||
CollectionEvent::Activate(at) => symbols.get(*at).cloned(),
|
||||
_ => None,
|
||||
});
|
||||
(out.response.response, picked)
|
||||
}
|
||||
|
||||
/// Completes the palette's Close action without editing text.
|
||||
pub(crate) fn finish(_app: &mut SlideApp, _result: &ParamResult, _host: &mut DialogHost) -> Result<(), String> {
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user