mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-30 18:27:00 +01:00
WIP fw-app-2: partial framework follow-ups (Codex stopped: usage limit / killed); not reviewed, not merged
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9b2438f5e0
commit
97285bdddd
14 files changed
+212
-10
No files matched your search
@@ -307,6 +307,7 @@ pub struct ParagraphAnswer {
|
||||
/// - Keys: Enter is OK, Esc Cancel.
|
||||
#[derive(craft_ui::contract::Pattern)]
|
||||
pub struct ParagraphDialog {
|
||||
key: Option<String>,
|
||||
format: ParagraphFormat,
|
||||
unit: DocUnit,
|
||||
word: bool,
|
||||
@@ -319,9 +320,17 @@ pub struct ParagraphDialog {
|
||||
}
|
||||
|
||||
impl ParagraphDialog {
|
||||
/// Associates the host's result, including cancellation, with this command key.
|
||||
#[must_use]
|
||||
pub fn key(mut self, key: String) -> Self {
|
||||
self.key = Some(key);
|
||||
self
|
||||
}
|
||||
|
||||
/// A dialog editing `format`, with lengths in inches.
|
||||
pub fn new(format: ParagraphFormat) -> Self {
|
||||
ParagraphDialog {
|
||||
key: None,
|
||||
opened: format.clone(),
|
||||
format,
|
||||
unit: DocUnit::new(UnitKind::Inches, UnitKind::POINTS_PER_INCH),
|
||||
@@ -903,6 +912,10 @@ impl ParagraphDialog {
|
||||
impl StackDialog for ParagraphDialog {
|
||||
type Result = ParagraphAnswer;
|
||||
|
||||
fn key(&self) -> Option<&str> {
|
||||
self.key.as_deref()
|
||||
}
|
||||
|
||||
fn id(&self) -> DialogId {
|
||||
dialog_id("paragraph")
|
||||
}
|
||||
|
||||
@@ -261,6 +261,7 @@ struct FindFields {
|
||||
/// ("All done. We made 3 replacements.").
|
||||
#[derive(Debug, craft_ui::contract::Pattern)]
|
||||
pub struct FindReplaceDialog {
|
||||
key: Option<String>,
|
||||
query: String,
|
||||
with: String,
|
||||
options: FindOptions,
|
||||
@@ -286,9 +287,17 @@ pub struct FindReplaceDialog {
|
||||
}
|
||||
|
||||
impl FindReplaceDialog {
|
||||
/// Associates the host's result, including cancellation, with this command key.
|
||||
#[must_use]
|
||||
pub fn key(mut self, key: String) -> Self {
|
||||
self.key = Some(key);
|
||||
self
|
||||
}
|
||||
|
||||
/// A dialog opened on `tab` with `query` in Find what.
|
||||
pub fn new(query: impl Into<String>, tab: FindTab) -> Self {
|
||||
FindReplaceDialog {
|
||||
key: None,
|
||||
query: query.into(),
|
||||
with: String::new(),
|
||||
options: FindOptions::default(),
|
||||
@@ -433,6 +442,10 @@ impl FindReplaceDialog {
|
||||
impl StackDialog for FindReplaceDialog {
|
||||
type Result = ();
|
||||
|
||||
fn key(&self) -> Option<&str> {
|
||||
self.key.as_deref()
|
||||
}
|
||||
|
||||
fn id(&self) -> DialogId {
|
||||
dialog_id("find-replace")
|
||||
}
|
||||
|
||||
@@ -322,6 +322,7 @@ const REMOVE: usize = 2;
|
||||
/// - Keys: Enter is OK unless a field owns it, Escape is Cancel. Remove Link shows while a link is edited.
|
||||
#[derive(Clone, Debug, PartialEq, craft_ui::contract::Pattern)]
|
||||
pub struct HyperlinkDialog {
|
||||
key: Option<String>,
|
||||
given: Given,
|
||||
form: Form,
|
||||
open: bool,
|
||||
@@ -393,11 +394,19 @@ impl HyperlinkParts {
|
||||
}
|
||||
|
||||
impl HyperlinkDialog {
|
||||
/// Associates the host's result, including cancellation, with this command key.
|
||||
#[must_use]
|
||||
pub fn key(mut self, key: String) -> Self {
|
||||
self.key = Some(key);
|
||||
self
|
||||
}
|
||||
|
||||
/// The dialog over what the selection holds; `text` is the selected text shown in Text to display (`None` hides
|
||||
/// the field: a shape's click action).
|
||||
pub fn new(current: CurrentLink, text: Option<String>) -> Self {
|
||||
let form = Form::of(¤t, text.as_deref());
|
||||
HyperlinkDialog {
|
||||
key: None,
|
||||
given: Given { current, text, groups: Vec::new(), highlight: false, seed: form.clone() },
|
||||
form,
|
||||
open: true,
|
||||
@@ -431,7 +440,7 @@ impl HyperlinkDialog {
|
||||
|
||||
/// Shows the dialog.
|
||||
pub fn show(&mut self, ui: &mut Ui) -> HyperlinkOutput {
|
||||
let HyperlinkDialog { given, form, open, parts, hold, held } = self;
|
||||
let HyperlinkDialog { given, form, open, parts, hold, held, .. } = self;
|
||||
let env = Env::of(ui);
|
||||
let words = env.words::<HyperlinkWords>();
|
||||
let common = env.words::<CommonWords>();
|
||||
@@ -670,6 +679,10 @@ impl HyperlinkDialog {
|
||||
impl StackDialog for HyperlinkDialog {
|
||||
type Result = HyperlinkAnswer;
|
||||
|
||||
fn key(&self) -> Option<&str> {
|
||||
self.key.as_deref()
|
||||
}
|
||||
|
||||
/// The dialog's visible fields for automation.
|
||||
fn json_fields(&self) -> Option<serde_json::Value> {
|
||||
serde_fields(&self.fields())
|
||||
|
||||
@@ -216,6 +216,7 @@ pub enum SpellingScope {
|
||||
/// - Automation fields: `word` and `count` (read only), `changeTo`, and `allLayers` under [`SpellingScope::Layers`].
|
||||
#[derive(Clone, Debug, PartialEq, craft_ui::contract::Pattern)]
|
||||
pub struct CheckSpellingDialog {
|
||||
key: Option<String>,
|
||||
items: Vec<SpellingItem>,
|
||||
index: usize,
|
||||
/// Ignore All words for this check.
|
||||
@@ -230,6 +231,13 @@ pub struct CheckSpellingDialog {
|
||||
}
|
||||
|
||||
impl CheckSpellingDialog {
|
||||
/// Associates the host's result, including cancellation, with this command key.
|
||||
#[must_use]
|
||||
pub fn key(mut self, key: String) -> Self {
|
||||
self.key = Some(key);
|
||||
self
|
||||
}
|
||||
|
||||
/// Chooses the check's scope; Document hides and refuses the allLayers field.
|
||||
#[must_use]
|
||||
pub fn scope(mut self, scope: SpellingScope) -> Self {
|
||||
@@ -270,6 +278,7 @@ impl CheckSpellingDialog {
|
||||
pub fn new(items: Vec<SpellingItem>) -> Self {
|
||||
let change_to = items.first().and_then(|i| i.suggestions.first()).cloned().unwrap_or_default();
|
||||
CheckSpellingDialog {
|
||||
key: None,
|
||||
items,
|
||||
index: 0,
|
||||
ignored: Vec::new(),
|
||||
@@ -461,6 +470,10 @@ impl CheckSpellingDialog {
|
||||
impl StackDialog for CheckSpellingDialog {
|
||||
type Result = ();
|
||||
|
||||
fn key(&self) -> Option<&str> {
|
||||
self.key.as_deref()
|
||||
}
|
||||
|
||||
/// Whether the document stays editable behind the dialog.
|
||||
fn modeless(&self) -> bool {
|
||||
self.modeless
|
||||
|
||||
@@ -111,6 +111,7 @@ pub enum TabStopsParts {
|
||||
/// - Keys: Enter is OK unless a field owns it, Escape is Cancel.
|
||||
#[derive(craft_ui::contract::Pattern)]
|
||||
pub struct TabStopsDialog {
|
||||
key: Option<String>,
|
||||
stops: Vec<TabStop>,
|
||||
/// The positions the paragraph's stops began at: one that no stop holds any more is cleared in the result.
|
||||
basis: Vec<f32>,
|
||||
@@ -130,6 +131,13 @@ pub struct TabStopsDialog {
|
||||
}
|
||||
|
||||
impl TabStopsDialog {
|
||||
/// Associates the host's result, including cancellation, with this command key.
|
||||
#[must_use]
|
||||
pub fn key(mut self, key: String) -> Self {
|
||||
self.key = Some(key);
|
||||
self
|
||||
}
|
||||
|
||||
/// Chooses the dialog's parts; Basic uses the text-box ruler's alignments without leaders.
|
||||
#[must_use]
|
||||
pub fn parts(mut self, parts: TabStopsParts) -> Self {
|
||||
@@ -142,6 +150,7 @@ impl TabStopsDialog {
|
||||
stops.retain(|stop| stop.position.is_finite());
|
||||
stops.truncate(MAX_STOPS);
|
||||
TabStopsDialog {
|
||||
key: None,
|
||||
basis: stops.iter().map(|stop| stop.position).collect(),
|
||||
stops,
|
||||
cleared: Vec::new(),
|
||||
@@ -355,6 +364,10 @@ impl TabStopsDialog {
|
||||
impl StackDialog for TabStopsDialog {
|
||||
type Result = TabStopsResult;
|
||||
|
||||
fn key(&self) -> Option<&str> {
|
||||
self.key.as_deref()
|
||||
}
|
||||
|
||||
/// The stops, default interval and selected index for automation.
|
||||
fn json_fields(&self) -> Option<serde_json::Value> {
|
||||
serde_fields(&self.fields())
|
||||
|
||||
@@ -66,3 +66,44 @@ fn a_mixed_contextual_spacing_box_clicked_is_on_in_the_answer() {
|
||||
let answer = dialog.borrow_mut().take_ok().expect("OK filed its answer");
|
||||
assert_eq!(answer.format.contextual_spacing, Some(Some(true)), "the answer carries the box");
|
||||
}
|
||||
|
||||
/// The command key follows the host's result path even on cancellation, which has no typed answer to carry it.
|
||||
#[trial]
|
||||
fn text_dialog_results_keep_the_opt_in_command_key_on_cancel_and_accept() {
|
||||
use craft_text::ui::hyperlink::{CurrentLink, HyperlinkDialog};
|
||||
use craft_text::ui::spelling::CheckSpellingDialog;
|
||||
use craft_text::ui::tabs_dialog::TabStopsDialog;
|
||||
use craft_ui::dialog::{DialogHost, DialogResult, StackDialog};
|
||||
|
||||
fn canceled<D: StackDialog>(plain: D, keyed: D, ctx: &egui::Context, expected: &str) {
|
||||
let mut host = DialogHost::new();
|
||||
host.open(plain);
|
||||
assert!(host.cancel::<D>(ctx));
|
||||
let (result, key) = host.take_keyed::<D>().expect("the cancellation is retained");
|
||||
assert!(matches!(result, DialogResult::Cancel));
|
||||
assert!(key.is_none(), "existing callers stay unkeyed");
|
||||
host.open(keyed);
|
||||
assert!(host.cancel::<D>(ctx));
|
||||
let (result, key) = host.take_keyed::<D>().expect("the keyed cancellation is retained");
|
||||
assert!(matches!(result, DialogResult::Cancel));
|
||||
assert_eq!(key.as_deref(), Some(expected));
|
||||
}
|
||||
|
||||
let ctx = egui::Context::default();
|
||||
let key = String::from("text-command");
|
||||
canceled(ParagraphDialog::new(ParagraphFormat::default()), ParagraphDialog::new(ParagraphFormat::default()).key(key.clone()), &ctx, &key);
|
||||
canceled(TabStopsDialog::new(Vec::new(), 36.0), TabStopsDialog::new(Vec::new(), 36.0).key(key.clone()), &ctx, &key);
|
||||
canceled(HyperlinkDialog::new(CurrentLink::None, None), HyperlinkDialog::new(CurrentLink::None, None).key(key.clone()), &ctx, &key);
|
||||
canceled(CheckSpellingDialog::new(Vec::new()), CheckSpellingDialog::new(Vec::new()).key(key.clone()), &ctx, &key);
|
||||
#[cfg(feature = "find")]
|
||||
{
|
||||
use craft_text::ui::find::{FindReplaceDialog, FindTab};
|
||||
canceled(FindReplaceDialog::new("", FindTab::Find), FindReplaceDialog::new("", FindTab::Find).key(key.clone()), &ctx, &key);
|
||||
}
|
||||
let mut host = DialogHost::new();
|
||||
host.open(ParagraphDialog::new(ParagraphFormat::default()).key(key.clone()));
|
||||
assert!(host.confirm::<ParagraphDialog>(&ctx));
|
||||
let (result, accepted_key) = host.take_keyed::<ParagraphDialog>().expect("the acceptance is retained");
|
||||
assert!(matches!(result, DialogResult::Ok(_)));
|
||||
assert_eq!(accepted_key.as_deref(), Some(key.as_str()));
|
||||
}
|
||||
@@ -16,7 +16,7 @@ use crate::primitives::IconSpec;
|
||||
use crate::runtime::env::{Env, Label};
|
||||
use crate::tabs::{Tab, TabKind, TabStrip};
|
||||
use crate::text::TextField;
|
||||
use crate::tile_grid::{CaptionPlace, GridEvent, Tile, TileGrid, TileGroup};
|
||||
use crate::tile_grid::{CaptionPlace, GlyphLayout, GridEvent, Tile, TileGrid, TileGroup};
|
||||
use craft_behavior::{DisplayOrder, EditEvent, ItemSource, Mixed, Selection, SelectionChange, keyed};
|
||||
use craft_i18n::matcher::Matcher;
|
||||
use egui::{Response, Ui};
|
||||
@@ -42,12 +42,15 @@ pub struct IconPickerItem<K> {
|
||||
/// The cell shows this text instead of an icon; search also matches the glyph.
|
||||
#[prop(into)]
|
||||
pub glyph: Option<String>,
|
||||
/// The glyph cell's layout; square unless a wider text face is requested.
|
||||
#[prop]
|
||||
pub glyph_layout: GlyphLayout,
|
||||
}
|
||||
|
||||
impl<K> IconPickerItem<K> {
|
||||
/// A cell that picks `key`, named `label`, found by no other words.
|
||||
pub fn new(key: K, label: impl Into<String>) -> Self {
|
||||
Self { key, label: label.into(), keywords: Vec::new(), icon: None, glyph: None }
|
||||
Self { key, label: label.into(), keywords: Vec::new(), icon: None, glyph: None, glyph_layout: GlyphLayout::default() }
|
||||
}
|
||||
|
||||
/// Whether the name, glyph or a keyword matches `matcher`.
|
||||
@@ -289,7 +292,7 @@ impl<'a, K: Clone + Eq + Hash + Send + Sync + 'static> IconPicker<'a, K> {
|
||||
.empty(empty.cloned().unwrap_or_else(|| words.icon_no_match.clone()))
|
||||
.show_items(ui, &source, &mut |at, _| {
|
||||
let item = source.items[*at];
|
||||
let tile = Tile::new(item.label.clone());
|
||||
let tile = Tile::new(item.label.clone()).glyph_layout(item.glyph_layout);
|
||||
match (&item.glyph, &item.icon) {
|
||||
(Some(glyph), _) => tile.glyph(glyph.clone()),
|
||||
(None, Some(icon)) => tile.icon(icon.clone()),
|
||||
|
||||
@@ -6,6 +6,7 @@ use crate::contract::{Bind, Props as _, Show as _, ShowContainer as _};
|
||||
use crate::layout_components::Stack;
|
||||
use crate::popover::Popover;
|
||||
use crate::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use crate::tile_grid::GlyphLayout;
|
||||
use craft_behavior::IconId;
|
||||
use egui::Ui;
|
||||
|
||||
@@ -76,6 +77,20 @@ fn icon_picker_glyphs(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
opened_picker(ui, data, &groups, IconPickerSearch::Field)
|
||||
}
|
||||
|
||||
/// Wide text faces, including the selected and unavailable picker states.
|
||||
#[story(IconPicker<'static, u8>, covers = [], drive = Drive::Never)]
|
||||
fn icon_picker_wide_glyphs(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let groups = vec![IconPickerGroup::new(
|
||||
"Sequences",
|
||||
vec![
|
||||
IconPickerItem::new(1, "Decimal sequence").glyph("1. 2. 3.").glyph_layout(GlyphLayout::Wide),
|
||||
IconPickerItem::new(2, "Letter sequence").glyph("a. b. c.").glyph_layout(GlyphLayout::Wide),
|
||||
IconPickerItem::new(3, "Numeral sequence").glyph("i. ii. iii.").glyph_layout(GlyphLayout::Wide),
|
||||
],
|
||||
)];
|
||||
opened_picker(ui, data, &groups, IconPickerSearch::None)
|
||||
}
|
||||
|
||||
/// A picker whose host supplies the context without a search field.
|
||||
#[story(IconPicker<'static, u8>, covers = [], drive = Drive::Never)]
|
||||
fn icon_picker_without_search(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
|
||||
@@ -615,7 +615,7 @@ impl<'a, K: Clone + Eq + Hash + Send + Sync + 'static> TileGrid<'a, K> {
|
||||
let around = style.around.get(self.caption, self.detail_line);
|
||||
// A card never outgrows the grid: in a column narrower than a card the card takes the column.
|
||||
let mut side = self.picture_side(&style, item, around).min(width - 2.0 * spacing.inset - around.size().x).max(1.0);
|
||||
let aspect = if self.aspect.is_finite() && self.aspect > 0.0 { self.aspect } else { 1.0 };
|
||||
let aspect = self.picture_aspect(item, around);
|
||||
let tail_height = self.items.row_height.of(cx);
|
||||
let groups = self.shown_groups();
|
||||
let rule = if self.justified { ColumnRule::Zoom } else { self.column_rule };
|
||||
@@ -702,6 +702,17 @@ impl<'a, K: Clone + Eq + Hash + Send + Sync + 'static> TileGrid<'a, K> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Content cells preserve the measured picture's shape as well as its width.
|
||||
fn picture_aspect(&self, item: Option<Vec2>, around: Around) -> f32 {
|
||||
if let Some(item) = item.filter(|_| self.content_cells) {
|
||||
let picture = item - around.size();
|
||||
if picture.x > 0.0 && picture.y > 0.0 {
|
||||
return picture.x / picture.y;
|
||||
}
|
||||
}
|
||||
if self.aspect.is_finite() && self.aspect > 0.0 { self.aspect } else { 1.0 }
|
||||
}
|
||||
|
||||
/// The row that holds the lead while the grid has focus, when the grid has an arrangement.
|
||||
fn lead_slot(&self, cx: &Cx<'_, Self>) -> Option<Slot> {
|
||||
if !cx.is_focused() {
|
||||
@@ -1228,8 +1239,8 @@ impl<K: Clone + Eq + Hash + Send + Sync + 'static> Collection for TileGrid<'_, K
|
||||
/// The width of the requested card columns, their gaps and the content inset.
|
||||
fn ideal_width(&self, item: Option<Vec2>, _rows: usize, cx: &StyleCx<'_>) -> f32 {
|
||||
let style = GridSizes::of(cx, self.card, self.card_text, self.items.row_height, self.regular_card_padding, self.action_place);
|
||||
let aspect = if self.aspect.is_finite() && self.aspect > 0.0 { self.aspect } else { 1.0 };
|
||||
let around = style.around.get(self.caption, self.detail_line);
|
||||
let aspect = self.picture_aspect(item, around);
|
||||
let card = style.card(self.picture_side(&style, item, around), aspect, around).x;
|
||||
// At least one card: in a narrower column the cards shrink, and the grid would measure shorter than it shows
|
||||
// in the wider column it is given.
|
||||
|
||||
@@ -21,7 +21,7 @@ pub use fit::fit_columns;
|
||||
pub use grid::{ColumnRule, GridEvent, GridZoom, GroupHeads, RatingKeys, TileGrid, TileGridOutput, TileGridStyle};
|
||||
pub use layout::{Around, ArrangeSpacing, GridLayout, TailRow, TileArrangement, TileGroup, TileRow, Tiling, arrange, aspects_of};
|
||||
pub use slider::{ThumbnailSlider, ThumbnailSliderStyle, TileZoom, ZoomStep};
|
||||
pub use tile::{StackLook, Tile, TileActionPlace, TileOutput, TilePartEvent, TileStyle};
|
||||
pub use tile::{GlyphLayout, StackLook, Tile, TileActionPlace, TileOutput, TilePartEvent, TileStyle};
|
||||
pub use words::TileWords;
|
||||
|
||||
/// Where a tile's caption goes.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
//! Stories of `Tile` and `ThumbnailSlider`.
|
||||
|
||||
use super::{
|
||||
BadgeKind, BadgeSlot, BadgeVisibility, CaptionPlace, CardText, StackLook, ThumbnailSlider, Tile, TileBadge, TileFlag, TileMark, TilePartEvent,
|
||||
TileStatus, TileZoom,
|
||||
BadgeKind, BadgeSlot, BadgeVisibility, CaptionPlace, CardText, GlyphLayout, StackLook, ThumbnailSlider, Tile, TileBadge, TileFlag, TileMark,
|
||||
TilePartEvent, TileStatus, TileZoom,
|
||||
};
|
||||
use crate::contract::{Props as _, Show as _, Validity};
|
||||
use crate::list::{ThumbAspect, ToggleState};
|
||||
@@ -45,6 +45,14 @@ fn tile_glyphs(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
Tile::new("Unavailable triangle").glyph("▲").enabled(false).show(ui).into()
|
||||
}
|
||||
|
||||
/// Wide glyph cells fit multi-character faces and keep their resolved state ink.
|
||||
#[story(Tile<'static>, covers = [], drive = Drive::Never)]
|
||||
fn tile_wide_glyphs(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
Tile::new("Decimal sequence").glyph("1. 2. 3.").glyph_layout(GlyphLayout::Wide).show(ui);
|
||||
Tile::new("Selected letters").glyph("a. b. c.").glyph_layout(GlyphLayout::Wide).selected(true).show(ui);
|
||||
Tile::new("Unavailable numerals").glyph("i. ii. iii.").glyph_layout(GlyphLayout::Wide).enabled(false).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(Tile<'static>, covers = [LongText], drive = Drive::Never)]
|
||||
fn tile_long_text(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
Tile::new("IMG_20261101_123456_a_name_much_longer_than_the_tile_is_wide.jpeg").show(ui).into()
|
||||
|
||||
@@ -63,6 +63,17 @@ pub enum TileActionPlace {
|
||||
Band,
|
||||
}
|
||||
|
||||
/// How a text glyph sizes its cell.
|
||||
#[non_exhaustive]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
||||
pub enum GlyphLayout {
|
||||
/// A square cell, like an icon.
|
||||
#[default]
|
||||
Square,
|
||||
/// A cell as wide as the text needs, retaining at least the usual icon height and width.
|
||||
Wide,
|
||||
}
|
||||
|
||||
/// How a stacked tile shows its stack.
|
||||
#[non_exhaustive]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
@@ -470,6 +481,9 @@ pub struct Tile<'a> {
|
||||
picture: Option<Picture<'a>>,
|
||||
icon: Option<IconSpec<'static>>,
|
||||
glyph: Option<String>,
|
||||
/// The glyph's cell shape; wide cells fit the text at the usual icon height.
|
||||
#[prop]
|
||||
glyph_layout: GlyphLayout,
|
||||
badges: Vec<TileBadge>,
|
||||
marks: Vec<TileMark>,
|
||||
pills: Vec<TileBadge>,
|
||||
@@ -523,6 +537,7 @@ impl<'a> Tile<'a> {
|
||||
folder: false,
|
||||
icon: None,
|
||||
glyph: None,
|
||||
glyph_layout: GlyphLayout::default(),
|
||||
renaming: false,
|
||||
check: None,
|
||||
action_place: TileActionPlace::Corner,
|
||||
@@ -971,6 +986,14 @@ impl Component for Tile<'_> {
|
||||
(_, Proposal::Min) => sizes.thumbs[0],
|
||||
(_, _) => sizes.thumbs[1],
|
||||
};
|
||||
if self.glyph_layout == GlyphLayout::Wide
|
||||
&& let Some(glyph) = &self.glyph
|
||||
{
|
||||
let text = cx.layout_at(&TextRun::new(glyph).role(cx.style.glyph.role), f32::INFINITY).size();
|
||||
let natural = Vec2::splat(side).max(text);
|
||||
let width = cx.room.map_or(natural.x + column, |room| room.min(natural.x + column));
|
||||
return Vec2::new(width, natural.y + caption);
|
||||
}
|
||||
let width = cx.room.map_or(side + column, |room| room.min(side + column));
|
||||
Vec2::new(width, ((width - column).max(0.0) / ratio) + caption)
|
||||
}
|
||||
|
||||
@@ -44,3 +44,39 @@ fn the_category_row_filters_the_grid_and_search_stays_inside_it() {
|
||||
fixture.click(&all).settle();
|
||||
assert!(!shows(&fixture, "Move"), "the search still applies under All");
|
||||
}
|
||||
|
||||
/// A wide face must survive both the tile's measurement and the grid's cell fitting without being elided or
|
||||
/// becoming a tall square. The default keeps the compact cells used by symbol pickers.
|
||||
#[trial]
|
||||
fn wide_glyph_cells_fit_the_text_without_growing_into_squares() {
|
||||
use craft_ui::tile_grid::GlyphLayout;
|
||||
use egui::Vec2;
|
||||
|
||||
const GLYPH: &str = "1. 2. 3.";
|
||||
let shown = |layout| {
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let groups = [IconPickerGroup::new(
|
||||
"",
|
||||
vec![
|
||||
IconPickerItem::new(1u8, "Sequence").glyph(GLYPH).glyph_layout(layout),
|
||||
IconPickerItem::new(2u8, "Alternative").glyph("a. b. c.").glyph_layout(layout),
|
||||
],
|
||||
)];
|
||||
IconPicker::new("Sequences", Bind::given(Some(1)), &groups).search(craft_ui::pickers::IconPickerSearch::None).show(ui);
|
||||
});
|
||||
fixture.room(Vec2::new(600.0, 400.0)).settle();
|
||||
fixture
|
||||
};
|
||||
let square = shown(GlyphLayout::Square);
|
||||
let wide = shown(GlyphLayout::Wide);
|
||||
let cell = wide.by_label("Sequence").expect("the wide tile is accessible").rect;
|
||||
let compact = square.by_label("Sequence").expect("the default tile is accessible").rect;
|
||||
assert!(cell.width() > compact.width(), "the wide face gets more room than a square glyph");
|
||||
assert!(cell.width() > cell.height(), "the grid preserves the wide face's measured shape");
|
||||
assert!((cell.height() - compact.height()).abs() < 0.5, "widening does not make the row taller");
|
||||
let text = wide.texts().iter().find(|painted| painted.text == GLYPH).expect("the glyph is painted");
|
||||
assert!(!text.elided, "the full sequence fits");
|
||||
assert!(cell.contains_rect(text.rect), "the glyph stays inside its cell");
|
||||
let next = wide.by_label("Alternative").expect("the adjacent tile is accessible").rect;
|
||||
assert!(!cell.intersects(next), "neighbouring cells do not overlap");
|
||||
}
|
||||
+1
-1
@@ -83,7 +83,7 @@ Rules of the host:
|
||||
- `cancel::<D>()` closes a dialog from outside as Escape would, and `StackDialog::cancelled` lets it release what it holds.
|
||||
- `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.
|
||||
- `take_keyed` returns the result with `StackDialog::key`, so a Cancel still names the command it answers. `ParagraphDialog`, `TabStopsDialog`, `HyperlinkDialog`, `CheckSpellingDialog` and `FindReplaceDialog` opt in with `.key(String)`; without it their results remain unkeyed. The key does not change a dialog's identity or modality.
|
||||
- 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 closing extra button accepts the values and names itself in `ParamResult::button`; OK and automation confirmation leave `button` empty. `ParamResult::tab` is the accepted tab (zero without tabs), preserved while a held answer waits for settlement. Confirmation queries the dialog scope's current framework text drafts, so a custom field's invalid draft holds automation as well as OK and Enter. Hiding a row or writing its value retires only that row's drafts before the next confirmation, including custom controls and companion fields; reset and close retire the scope's drafts. These operations preserve drafts owned by other rows and sibling dialogs.
|
||||
- A `HostedParamDialog::accept_stays_open` form holds OK for the host and withdraws a successful answer, leaving the values ready for another OK. A refusal still shows its reason. `HostedParamDialog::modeless` uses the host's modality mechanism and a modeless dialog layer.
|
||||
|
||||
Reference in new issue
Block a user