mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-28 21:49:49 +00:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fbe5c3017a | ||
|
|
3b77539db2 | ||
|
|
98e71c1478 | ||
|
|
0483b212b7 | ||
|
|
06642d07c7 |
@@ -4,10 +4,10 @@
|
||||
"repository_id": 1408489772,
|
||||
"producer_workflow_id": 429734489,
|
||||
"producer_workflow_path": ".github/workflows/nightly.yml",
|
||||
"producer_tooling_revision": "main",
|
||||
"producer_workflow_ref": "storytold/craft-common-actions/.github/workflows/nightly-unsigned.yml@main",
|
||||
"producer_tooling_revision": "bf94b15b708089b95c4e2d1c978e66ecf1f2f4f3",
|
||||
"producer_workflow_ref": "storytold/craft-common-actions/.github/workflows/nightly-unsigned.yml@bf94b15b708089b95c4e2d1c978e66ecf1f2f4f3",
|
||||
"signer_workflow_path": ".github/workflows/nightly-sign.yml",
|
||||
"signer_tooling_revision": "main",
|
||||
"signer_tooling_revision": "bf94b15b708089b95c4e2d1c978e66ecf1f2f4f3",
|
||||
"release_branch": "nightly-signer",
|
||||
"manual_actors": [
|
||||
"bflatastic",
|
||||
|
||||
@@ -44,10 +44,10 @@ jobs:
|
||||
- name: Install the system libraries the GUI links
|
||||
run: sudo apt-get update && sudo apt-get install -y pkg-config libxkbcommon-dev libwayland-dev libx11-dev libxcursor-dev libxrandr-dev libxi-dev libgtk-3-dev libfontconfig1-dev libfreetype-dev
|
||||
- name: Check out craft-fonts
|
||||
uses: storytold/craft-common-actions/actions/checkout-craft-fonts@main
|
||||
uses: storytold/craft-common-actions/actions/checkout-craft-fonts@f5141455aac7b2eb4708aa259d8ffcdf10fde939
|
||||
with:
|
||||
ref: b076417b5880bd4154bd22f00695b1d28c6bea83
|
||||
- uses: storytold/craft-common-actions/actions/checkout-craft-i18n@main
|
||||
- uses: storytold/craft-common-actions/actions/checkout-craft-i18n@f5141455aac7b2eb4708aa259d8ffcdf10fde939
|
||||
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
|
||||
with:
|
||||
toolchain: stable
|
||||
@@ -128,10 +128,10 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Check out craft-fonts
|
||||
uses: storytold/craft-common-actions/actions/checkout-craft-fonts@main
|
||||
uses: storytold/craft-common-actions/actions/checkout-craft-fonts@f5141455aac7b2eb4708aa259d8ffcdf10fde939
|
||||
with:
|
||||
ref: b076417b5880bd4154bd22f00695b1d28c6bea83
|
||||
- uses: storytold/craft-common-actions/actions/checkout-craft-i18n@main
|
||||
- uses: storytold/craft-common-actions/actions/checkout-craft-i18n@f5141455aac7b2eb4708aa259d8ffcdf10fde939
|
||||
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
|
||||
with:
|
||||
toolchain: stable
|
||||
@@ -188,10 +188,10 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Check out craft-fonts
|
||||
uses: storytold/craft-common-actions/actions/checkout-craft-fonts@main
|
||||
uses: storytold/craft-common-actions/actions/checkout-craft-fonts@f5141455aac7b2eb4708aa259d8ffcdf10fde939
|
||||
with:
|
||||
ref: b076417b5880bd4154bd22f00695b1d28c6bea83
|
||||
- uses: storytold/craft-common-actions/actions/checkout-craft-i18n@main
|
||||
- uses: storytold/craft-common-actions/actions/checkout-craft-i18n@f5141455aac7b2eb4708aa259d8ffcdf10fde939
|
||||
- uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0
|
||||
with:
|
||||
toolchain: stable
|
||||
|
||||
@@ -34,9 +34,9 @@ jobs:
|
||||
checks: read
|
||||
attestations: write
|
||||
id-token: write
|
||||
uses: storytold/craft-common-actions/.github/workflows/nightly-release.yml@main
|
||||
uses: storytold/craft-common-actions/.github/workflows/nightly-release.yml@bf94b15b708089b95c4e2d1c978e66ecf1f2f4f3
|
||||
with:
|
||||
tooling-revision: main
|
||||
tooling-revision: bf94b15b708089b95c4e2d1c978e66ecf1f2f4f3
|
||||
app-name: wordcraft
|
||||
producer_run_id: ${{ inputs.producer_run_id }}
|
||||
producer_run_attempt: ${{ inputs.producer_run_attempt }}
|
||||
|
||||
@@ -22,9 +22,9 @@ jobs:
|
||||
actions: read
|
||||
attestations: write
|
||||
id-token: write
|
||||
uses: storytold/craft-common-actions/.github/workflows/nightly-unsigned.yml@main
|
||||
uses: storytold/craft-common-actions/.github/workflows/nightly-unsigned.yml@bf94b15b708089b95c4e2d1c978e66ecf1f2f4f3
|
||||
with:
|
||||
tooling-revision: main
|
||||
tooling-revision: bf94b15b708089b95c4e2d1c978e66ecf1f2f4f3
|
||||
app-name: wordcraft
|
||||
manual-actors: '["bflatastic","dylanmtaylor","echelon","FredApps","skylartaylor"]'
|
||||
craft-fonts-ref: b076417b5880bd4154bd22f00695b1d28c6bea83
|
||||
@@ -32,4 +32,3 @@ jobs:
|
||||
# craft-common-actions main commit that merged the exact-analysis admission (#371, after #370,
|
||||
# #369 and #364).
|
||||
platforms: '["windows-x86_64","linux-x86_64","macos-aarch64"]'
|
||||
linux-package-formats: '["deb","rpm","appimage","flatpak","oci","arch"]'
|
||||
|
||||
@@ -499,13 +499,6 @@ fn table_frame(ctx: &mut Ctx, t: &Table, avail: f32, depth: usize, style: Option
|
||||
(_, true) => avail - total - start_offset,
|
||||
(_, false) => start_offset,
|
||||
};
|
||||
// The reading view has no margin to hang a negative indent into: keep the table inside the column (#8020).
|
||||
// The clamp also pulls in an over-large positive indent. A table wider than the column keeps its start edge.
|
||||
let x = if ctx.opts.view == crate::ViewMode::Read {
|
||||
if total > avail { if rtl { avail - total } else { 0.0 } } else { x.clamp(0.0, avail - total) }
|
||||
} else {
|
||||
x
|
||||
};
|
||||
TableFrame { ncols, colx, acc, total, margins_def, tborders, rtl, x }
|
||||
}
|
||||
|
||||
|
||||
@@ -17824,36 +17824,3 @@ fn header_text_covers_the_whole_band_of_centred_and_right_lines() {
|
||||
assert!(hit(x + left - 60.0), "{align:?}: beyond 40pt left of the band the picture is hit");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reading_layout_keeps_a_negatively_indented_table_in_the_column() {
|
||||
crate::test_fonts();
|
||||
// #8020: a table indented left of the margin ran out of the column's start edge (right edge when mirrored).
|
||||
for (rtl, width, indent, align) in [
|
||||
(false, 300.0, -36.0, None),
|
||||
(true, 300.0, -36.0, None),
|
||||
(true, 400.0, -36.0, None),
|
||||
(false, 400.0, -36.0, None),
|
||||
(false, 300.0, -36.0, Some(Align::Center)),
|
||||
] {
|
||||
let mut d = Document::from_text("Before.");
|
||||
let mut t = Table::new(2, 4, width);
|
||||
t.props.indent = Some(indent);
|
||||
t.props.bidi_visual = rtl;
|
||||
t.props.align = align;
|
||||
d.insert_block(StoryRef::Body, &Path::top(1), wordcraft_doc::Block::Table(t)).unwrap();
|
||||
let opts = LayoutOptions { view: ViewMode::Read, web_width: 360.0, read_height: 600.0, ..Default::default() };
|
||||
let l = layout(&d, &mut LayoutCache::new(), &opts);
|
||||
let p = &l.pages[0];
|
||||
let cells: Vec<_> = p.items.iter().filter_map(|i| if let Placed::Cell { rect, .. } = i { Some(*rect) } else { None }).collect();
|
||||
let (left, right) = cells.iter().fold((f32::MAX, 0.0f32), |(l, r), c| (l.min(c.x), r.max(c.x + c.w)));
|
||||
assert!(right > left, "cells placed");
|
||||
// A table wider than the column keeps its start edge there; one that fits is inside at both edges.
|
||||
if !rtl || width <= 300.0 {
|
||||
assert!(left >= p.body.x - 0.5, "rtl {rtl} width {width}: left {left} vs column {}", p.body.x);
|
||||
}
|
||||
if rtl || width <= 300.0 {
|
||||
assert!(right <= p.body.x + p.body.w + 0.5, "rtl {rtl} width {width}: right {right} vs column {}", p.body.x + p.body.w);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,13 @@ pub(crate) use host::close_all;
|
||||
pub(crate) use mailings::{FilterRow, RecipientDraft, RecipientFilter, RecipientListDialog, hold_rows, merge_order, visible_recipients};
|
||||
pub(crate) use page_setup::PAPER_LABELS;
|
||||
|
||||
/// `max_rows` for a `TileGrid` that shows `rows` rows of `columns` tiles. The collection counts the cap in
|
||||
/// items (the tile `rows` in, not the grid row it is in), so a cap of `rows` shows one row; a cap past the item
|
||||
/// count adds blank rows, so it stops at `len`. lean: upstream fix in craft-libs `rows_height`, then drop this.
|
||||
pub(crate) fn tile_rows_cap(len: usize, columns: usize, rows: usize) -> u16 {
|
||||
u16::try_from(len.min(columns * rows)).unwrap_or(u16::MAX)
|
||||
}
|
||||
|
||||
/// Opens the dialog `name` for a script, a button or a command, with `params`; the module of the name reads what it
|
||||
/// needs of them. Returns the dialog's id, or `None` when no dialog opened (an unknown name, nothing to show, or a
|
||||
/// pane such as Restrict Editing).
|
||||
|
||||
@@ -6,9 +6,10 @@ use craft::ui::buttons::Button;
|
||||
use craft::ui::choice::{Radio, RadioGroup};
|
||||
use craft::ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _, clicked};
|
||||
use craft::ui::dialog::DialogId;
|
||||
use craft::ui::display::{Picture, PictureSize, Text};
|
||||
use craft::ui::display::{Picture, Text};
|
||||
use craft::ui::form::FieldGroup;
|
||||
use craft::ui::layout_components::Row;
|
||||
use craft::ui::list::{ThumbAspect, ThumbSize};
|
||||
use craft::ui::list::ThumbAspect;
|
||||
use craft::ui::patterns::form_dialogs::FormCx;
|
||||
use craft::ui::primitives::{ContentPainterCx, TextureCache};
|
||||
use craft::ui::runtime::env::Label;
|
||||
@@ -19,7 +20,7 @@ use wordcraft_doc::props::Align;
|
||||
|
||||
use super::dialogs_insert::symbol::SymbolRequest;
|
||||
use super::font::FontRequest;
|
||||
use super::host::{Asks, ChildAnswer, WordForm, captioned, open_form};
|
||||
use super::host::{Asks, ChildAnswer, WordForm, open_form};
|
||||
use crate::WordApp;
|
||||
|
||||
/// The alignments the dialog offers: `para.defineBullet`'s `align` and their names.
|
||||
@@ -182,7 +183,6 @@ impl DefineBulletForm {
|
||||
}
|
||||
},
|
||||
)
|
||||
.extent(PictureSize::Sample(ThumbSize::Large))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,8 +210,8 @@ impl WordForm for DefineBulletForm {
|
||||
});
|
||||
let entries: Vec<Entry<String>> = ALIGNMENTS.iter().map(|(k, n)| Entry::new((*k).to_string(), Label::from(tl!(n)))).collect();
|
||||
let current = if self.align.is_empty() { "left".to_string() } else { self.align.clone() };
|
||||
let group = captioned(ui, Label::from(tl!("Alignment:")), |name, ui| {
|
||||
RadioGroup::new(name, Bind::given(current.clone())).show(ui, |ui, _| {
|
||||
FieldGroup::new(Label::from(tl!("Alignment:"))).show(ui, |ui, _| {
|
||||
let group = RadioGroup::new(Label::from(tl!("Alignment:")), Bind::given(current.clone())).show(ui, |ui, _| {
|
||||
Row::new().show(ui, |ui, _| {
|
||||
for e in &entries {
|
||||
if let (Some(id), label) = (e.value(), e.label()) {
|
||||
@@ -219,12 +219,12 @@ impl WordForm for DefineBulletForm {
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
});
|
||||
if let Some(a) = group.output.value().cloned() {
|
||||
self.align = a;
|
||||
}
|
||||
});
|
||||
if let Some(a) = group.and_then(|g| g.output.value().cloned()) {
|
||||
self.align = a;
|
||||
}
|
||||
captioned(ui, Label::from(tl!("Preview")), |_, ui| {
|
||||
FieldGroup::new(Label::from(tl!("Preview"))).show(ui, |ui, _| {
|
||||
self.preview().show(ui);
|
||||
});
|
||||
self.ch.chars().count() == 1
|
||||
|
||||
@@ -4,11 +4,10 @@ use craft::text::ui::columns::{ColumnsApply, TextColumns, TextColumnsDialog};
|
||||
use craft::ui::choice::{Radio, RadioGroup};
|
||||
use craft::ui::contract::{Bind, FieldLayout, Props as _, Show as _, ShowContainer as _, SideLabel};
|
||||
use craft::ui::dialog::DialogId;
|
||||
use craft::ui::form::Field;
|
||||
use craft::ui::form::{Field, FieldGroup};
|
||||
use craft::ui::layout_components::Stack;
|
||||
use craft::ui::patterns::form_dialogs::FormCx;
|
||||
use craft::ui::runtime::env::Label;
|
||||
use craft::ui::sections::GroupBox;
|
||||
use craft::ui::text::NumberField;
|
||||
use egui::Ui;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -16,7 +15,7 @@ use serde_json::{Map, Value, json};
|
||||
|
||||
use super::{settled, word};
|
||||
use crate::WordApp;
|
||||
use crate::dialogs::host::{Asks, DialogHooks, Keyed, Settle, WordForm, captioned, open_with};
|
||||
use crate::dialogs::host::{Asks, DialogHooks, Keyed, Settle, WordForm, open_with};
|
||||
use crate::options::lengths;
|
||||
use crate::widgets::font_box::{CatalogRef, font_picker};
|
||||
|
||||
@@ -105,16 +104,14 @@ impl WordForm for DropCapForm {
|
||||
fn body(&mut self, ui: &mut Ui, _cx: &mut FormCx<'_, '_>, _asks: &mut Vec<Asks>) -> bool {
|
||||
let enabled = self.position != "none";
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
captioned(ui, word("Position"), |name, ui| {
|
||||
RadioGroup::new(name, Bind::bound(&mut self.position)).show(ui, |ui, _| {
|
||||
Stack::new().show(ui, |ui, cx| {
|
||||
for (at, (v, l)) in [("none", "None"), ("dropped", "Dropped"), ("margin", "In margin")].into_iter().enumerate() {
|
||||
cx.labelled(ui, at, word(l), SideLabel::new().layout(FieldLayout::After), Radio::new(v.to_string()));
|
||||
}
|
||||
});
|
||||
})
|
||||
RadioGroup::new(word("Position"), Bind::bound(&mut self.position)).show(ui, |ui, _| {
|
||||
Stack::new().show(ui, |ui, cx| {
|
||||
for (at, (v, l)) in [("none", "None"), ("dropped", "Dropped"), ("margin", "In margin")].into_iter().enumerate() {
|
||||
cx.labelled(ui, at, word(l), SideLabel::new().layout(FieldLayout::After), Radio::new(v.to_string()));
|
||||
}
|
||||
});
|
||||
});
|
||||
GroupBox::new(word("Options"), None).show(ui, |ui, _| {
|
||||
FieldGroup::new(word("Options")).show(ui, |ui, _| {
|
||||
if let Some(catalog) = self.catalog.get() {
|
||||
Field::new(word("Font:")).show(ui, |ui, _| {
|
||||
font_picker(word("Font:"), Bind::bound(&mut self.font), catalog, Bind::bound(&mut self.settings), &[], None)
|
||||
|
||||
@@ -4,23 +4,24 @@ use craft::behavior::{ColumnWidth, Selection, SelectionChange, keyed};
|
||||
use craft::font_manager::Catalog;
|
||||
use craft::font_manager::picker::FontPickerSettings;
|
||||
use craft::theme::Mode;
|
||||
use craft::ui::contract::{Bind, CollectionEvent, ColumnKey, ColumnSpec, SelectMode, Show as _, ShowCollection as _, ShowContainer as _};
|
||||
use craft::ui::contract::{Bind, CollectionEvent, ColumnKey, ColumnSpec, Props as _, SelectMode, Show as _, ShowCollection as _, ShowContainer as _};
|
||||
use craft::ui::dialog::{DialogId, DialogResult, DialogStack, HeldAnswer, HeldOk, StackDialog, dialog_id};
|
||||
use craft::ui::display::{Kbd, Text};
|
||||
use craft::ui::form::Field;
|
||||
use craft::ui::layout_components::Stack;
|
||||
use craft::ui::layout_components::{Row, Stack};
|
||||
use craft::ui::list::{ListRow, ThumbAspect, ThumbSize};
|
||||
use craft::ui::patterns::form_dialogs::{FormCx, FormDialog};
|
||||
use craft::ui::primitives::ContentPainterCx;
|
||||
use craft::ui::runtime::env::{Env, Label};
|
||||
use craft::ui::table::Table;
|
||||
use craft::ui::tabs::{Tab, TabKind, TabStrip};
|
||||
use craft::ui::text::TextField;
|
||||
use craft::ui::tile_grid::{CaptionPlace, Tile, TileGrid};
|
||||
use egui::Ui;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use super::{select_index, settled, text_field, word};
|
||||
use super::{select_index, settled, word};
|
||||
use crate::WordApp;
|
||||
use crate::dialogs::host::{DialogHooks, Settle, open_with};
|
||||
use crate::widgets::font_box::font_picker;
|
||||
@@ -37,6 +38,12 @@ pub struct RecentSymbol {
|
||||
pub font: String,
|
||||
}
|
||||
|
||||
/// Characters per row of the Symbols map (Word's grid is 16 wide).
|
||||
// lean: the cap assumes this many columns; read the laid-out count if the map becomes resizable.
|
||||
const GRID_COLUMNS: usize = 16;
|
||||
/// Rows of the Symbols map shown before it scrolls.
|
||||
const GRID_ROWS: usize = 8;
|
||||
|
||||
/// How many recent symbols are kept.
|
||||
pub const RECENT_SYMBOLS: usize = 20;
|
||||
|
||||
@@ -547,7 +554,7 @@ fn special_table(ui: &mut Ui, form: &mut SymbolForm) -> bool {
|
||||
let columns = vec![
|
||||
ColumnSpec::new(glyph.clone(), Label::Empty, ColumnWidth::fill(0.5)),
|
||||
ColumnSpec::new(name.clone(), word("Special Characters"), ColumnWidth::fill(2.0)),
|
||||
ColumnSpec::new(keys.clone(), word("Shortcut key:"), ColumnWidth::Controls(5.5)),
|
||||
ColumnSpec::new(keys.clone(), word("Shortcut key:"), ColumnWidth::fill(1.0)),
|
||||
];
|
||||
let positions: Vec<usize> = (0..SPECIAL.len()).collect();
|
||||
let source = keyed(&positions, |at: &usize| *at);
|
||||
@@ -623,7 +630,13 @@ fn symbol_page(ui: &mut Ui, form: &mut SymbolForm, catalog: Option<&Arc<Catalog>
|
||||
Text::new(Label::from(format!("U+{:04X}", c as u32))).show(ui);
|
||||
}
|
||||
let before = form.code.clone();
|
||||
text_field(ui, "symbol_code", &word("Character code:"), &mut form.code);
|
||||
let label = word("Character code:");
|
||||
Field::new(label.clone()).id_salt("symbol_code").show(ui, |ui, _| {
|
||||
Row::new().show(ui, |ui, _| {
|
||||
TextField::new(label.clone(), Bind::bound(&mut form.code)).show(ui);
|
||||
Text::new(word("from Unicode (hex)")).show(ui);
|
||||
});
|
||||
});
|
||||
if form.code != before {
|
||||
let code = form.code.clone();
|
||||
form.select_code(&code);
|
||||
@@ -633,14 +646,17 @@ fn symbol_page(ui: &mut Ui, form: &mut SymbolForm, catalog: Option<&Arc<Catalog>
|
||||
|
||||
/// The recently inserted symbols as one row of glyphs, each in its own font; a click picks one.
|
||||
fn recent_row(ui: &mut Ui, form: &mut SymbolForm, dark: bool) {
|
||||
// The heading shows while the row is empty too, as Word does; with symbols it labels the row.
|
||||
if form.recent.is_empty() {
|
||||
Text::new(word("Recently used symbols:")).show(ui);
|
||||
return;
|
||||
}
|
||||
let positions: Vec<usize> = (0..form.recent.len()).collect();
|
||||
let source = keyed(&positions, |at: &usize| *at);
|
||||
let events = {
|
||||
let mut events = Vec::new();
|
||||
Field::new(word("Recently used symbols:")).show(ui, |ui, _| {
|
||||
let recent = &form.recent;
|
||||
TileGrid::new(word("Recently used symbols:"))
|
||||
events = TileGrid::new(word("Recently used symbols:"))
|
||||
.thumb_size(ThumbSize::Medium)
|
||||
.select(SelectMode::Single)
|
||||
.caption(CaptionPlace::None)
|
||||
@@ -654,8 +670,8 @@ fn recent_row(ui: &mut Ui, form: &mut SymbolForm, dark: bool) {
|
||||
Tile::new(r.ch).thumb(ThumbAspect::SQUARE, move |cx, rect| paint_glyph(cx, rect, ch, &font, dark))
|
||||
})
|
||||
.response
|
||||
.events
|
||||
};
|
||||
.events;
|
||||
});
|
||||
for event in events {
|
||||
if let CollectionEvent::Selection { change: SelectionChange::Set(rows), .. } = event
|
||||
&& let Some(r) = rows.last().and_then(|i| form.recent.get(*i)).cloned()
|
||||
@@ -687,7 +703,8 @@ fn glyph_grid(ui: &mut Ui, form: &mut SymbolForm, dark: bool) -> bool {
|
||||
let mut grid = TileGrid::new(word("Symbols"))
|
||||
.thumb_size(ThumbSize::Medium)
|
||||
.select(SelectMode::Single)
|
||||
.max_rows(8)
|
||||
.max_rows(crate::dialogs::tile_rows_cap(form.chars.len(), GRID_COLUMNS, GRID_ROWS))
|
||||
.card_columns(GRID_COLUMNS)
|
||||
.caption(CaptionPlace::None)
|
||||
.selection(Bind::bound(&mut selection));
|
||||
if let Some(at) = reveal {
|
||||
|
||||
@@ -138,6 +138,43 @@ fn symbol_dialog_uses_compact_tile_grids() {
|
||||
assert!(recent.height() < 80.0, "recently used symbols row should be compact: {}", recent.height());
|
||||
}
|
||||
|
||||
fn h_recent(a: &mut WordApp) {
|
||||
remember_symbol(a, "©", "DejaVu Sans");
|
||||
}
|
||||
|
||||
/// #7972: the Symbols map shows rows of characters (not one strip), with the Recently used heading
|
||||
/// and the note that the code is Unicode hex.
|
||||
#[test]
|
||||
fn symbol_dialog_shows_the_map_in_rows() {
|
||||
use egui::accesskit::Role;
|
||||
let mut a = app();
|
||||
h_recent(&mut a);
|
||||
let mut h = testing::harness(a);
|
||||
crate::dialogs::open(h.state_mut(), "symbol", &json!({})).expect("symbol dialog opens");
|
||||
h.run_steps(3);
|
||||
assert_eq!(h.query_all_by_label("Recently used symbols:").count(), 1, "the heading is the row's one name");
|
||||
h.get_by_role_and_label(Role::ListBox, "Recently used symbols:");
|
||||
let map = h.get_by_role_and_label(Role::ListBox, "Symbols").rect();
|
||||
let tile = h.query_all_by_label("A").map(|n| n.rect()).find(|r| map.contains_rect(*r)).expect("a tile in the map");
|
||||
assert!(map.height() > 3.0 * tile.height(), "the map is several rows tall: {} vs a tile {}", map.height(), tile.height());
|
||||
h.get_by_label("from Unicode (hex)");
|
||||
}
|
||||
|
||||
/// #7973: Insert Diagram offers every layout in its grid, not the first row of three.
|
||||
#[test]
|
||||
fn insert_diagram_dialog_shows_every_layout() {
|
||||
use egui::accesskit::Role;
|
||||
let mut h = testing::harness(app());
|
||||
crate::dialogs::open(h.state_mut(), "insertSmartArt", &json!({})).expect("the dialog opens");
|
||||
// The tiles' heights settle over a few passes.
|
||||
h.run_steps(10);
|
||||
let grid = h.get_by_role_and_label(Role::ListBox, "Layouts").rect();
|
||||
for layout in wordcraft_doc::smart_art::SmartArtLayout::ALL {
|
||||
let shown = h.query_all_by_label(layout.label()).any(|n| grid.contains(n.rect().center()));
|
||||
assert!(shown, "{} is shown in the grid", layout.label());
|
||||
}
|
||||
}
|
||||
|
||||
/// The Field dialog builds the field code from its options.
|
||||
#[test]
|
||||
fn field_dialog_builds_the_instruction() {
|
||||
|
||||
@@ -15,7 +15,7 @@ use egui::Ui;
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::WordApp;
|
||||
use crate::dialogs::host::{DialogHooks, labelled, open_form, open_form_with};
|
||||
use crate::dialogs::host::{DialogHooks, open_form, open_form_with};
|
||||
|
||||
mod page;
|
||||
pub(crate) mod print;
|
||||
@@ -92,23 +92,11 @@ pub(crate) fn points() -> LengthUnits {
|
||||
LengthUnits::new(UnitKind::Points, UnitKind::Points, 96.0)
|
||||
}
|
||||
|
||||
/// A whole-number field over `value` within `range`, with its caption; true when the user changed it.
|
||||
/// A whole-number field over `value` within `range`; true when the user changed it.
|
||||
pub(crate) fn count_field(ui: &mut Ui, label: &str, value: &mut u32, range: RangeInclusive<u32>, enabled: bool) -> bool {
|
||||
labelled(ui, label.to_string(), |name, ui| count_box(ui, name, value, range.clone(), enabled)).unwrap_or(false)
|
||||
}
|
||||
|
||||
/// `count_field` with no caption, named `label` for assistive technology: for a box that follows a radio carrying the
|
||||
/// same words ("Start at:").
|
||||
pub(crate) fn count_box(
|
||||
ui: &mut Ui,
|
||||
label: impl Into<craft::ui::runtime::env::Label>,
|
||||
value: &mut u32,
|
||||
range: RangeInclusive<u32>,
|
||||
enabled: bool,
|
||||
) -> bool {
|
||||
let was = f64::from(*value);
|
||||
let mut shown = Some(was);
|
||||
NumberField::new(label, Bind::bound(&mut shown)).range(f64::from(*range.start())..=f64::from(*range.end())).enabled(enabled).show(ui);
|
||||
NumberField::new(label.to_string(), Bind::bound(&mut shown)).range(f64::from(*range.start())..=f64::from(*range.end())).enabled(enabled).show(ui);
|
||||
match shown {
|
||||
Some(n) if n != was => {
|
||||
*value = (n.round().max(0.0) as u32).clamp(*range.start(), *range.end());
|
||||
@@ -128,10 +116,8 @@ pub(crate) fn length_field(ui: &mut Ui, label: &str, value: &mut f32, lengths: L
|
||||
let was = f64::from(*value);
|
||||
// The form takes the field's edit events, not a write into a copy that lives one pass: an edit that commits as the
|
||||
// dialog files its OK (Enter, or a click on OK) reaches the form in the pass that files it.
|
||||
let out = labelled(ui, label.to_string(), |name, ui| {
|
||||
NumberField::length(name, Bind::given(Some(was)), lengths).range(range.clone()).enabled(enabled).show(ui)
|
||||
});
|
||||
match out.as_ref().and_then(|out| edited(&out.edit.events)) {
|
||||
let out = NumberField::length(label.to_string(), Bind::given(Some(was)), lengths).range(range).enabled(enabled).show(ui);
|
||||
match edited(&out.edit.events) {
|
||||
Some(n) if n != was => {
|
||||
*value = n as f32;
|
||||
true
|
||||
@@ -143,8 +129,8 @@ pub(crate) fn length_field(ui: &mut Ui, label: &str, value: &mut f32, lengths: L
|
||||
/// A percentage field over `value`; true when the user changed it.
|
||||
pub(crate) fn percent_field(ui: &mut Ui, label: &str, value: &mut f32, range: RangeInclusive<f64>) -> bool {
|
||||
let was = f64::from(*value);
|
||||
let out = labelled(ui, label.to_string(), |name, ui| NumberField::new(name, Bind::given(Some(was))).range(range.clone()).unit("%").show(ui));
|
||||
match out.as_ref().and_then(|out| edited(&out.edit.events)) {
|
||||
let out = NumberField::new(label.to_string(), Bind::given(Some(was))).range(range).unit("%").show(ui);
|
||||
match edited(&out.edit.events) {
|
||||
Some(n) if n != was => {
|
||||
*value = n as f32;
|
||||
true
|
||||
@@ -165,16 +151,11 @@ pub(crate) fn named_field<K: NumberName + 'static>(
|
||||
enabled: bool,
|
||||
) {
|
||||
let presets = vec![Entry::new(NumberPick::Choice(name.0.id()), name.1.to_string()).checked(matches!(*value, NamedOr::Named(_)))];
|
||||
labelled(ui, label.to_string(), |name, ui| {
|
||||
{
|
||||
let field = NumberField::named(name, Bind::bound(&mut *value)).range(range.clone()).presets(&presets).enabled(enabled);
|
||||
match lengths {
|
||||
Some(lengths) => field.lengths(lengths),
|
||||
None => field,
|
||||
}
|
||||
}
|
||||
.show(ui)
|
||||
});
|
||||
let mut field = NumberField::named(label.to_string(), Bind::bound(value)).range(range).presets(&presets).enabled(enabled);
|
||||
if let Some(lengths) = lengths {
|
||||
field = field.lengths(lengths);
|
||||
}
|
||||
field.show(ui);
|
||||
}
|
||||
|
||||
/// The number a named field holds, 0 while it holds its name.
|
||||
|
||||
@@ -14,7 +14,7 @@ use serde_json::{Value, json};
|
||||
use wordcraft_engine::cmd::objects::fit_size;
|
||||
|
||||
use super::{DialogId, WordApp, length_field, percent_field, points};
|
||||
use crate::dialogs::host::{Asks, FormHost, WordForm, captioned, labelled};
|
||||
use crate::dialogs::host::{Asks, FormHost, WordForm};
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Size
|
||||
@@ -300,22 +300,14 @@ impl WordForm for PageNumbersForm {
|
||||
fn body(&mut self, ui: &mut Ui, _cx: &mut FormCx<'_, '_>, _asks: &mut Vec<Asks>) -> bool {
|
||||
let formats: Vec<Entry<String>> =
|
||||
crate::dialogs_notes::FORMATS.iter().map(|(v, l)| Entry::new((*v).to_string(), tl!(l).to_string())).collect();
|
||||
labelled(ui, tl!("Number format").to_string(), |name, ui| Select::new(name, Bind::bound(&mut self.format), &formats).show(ui));
|
||||
captioned(ui, tl!("Page numbering").to_string(), |name, ui| {
|
||||
RadioGroup::new(name, Bind::bound(&mut self.cont)).show(ui, |ui, _| {
|
||||
Stack::new().show(ui, |ui, cx| {
|
||||
cx.labelled(
|
||||
ui,
|
||||
0,
|
||||
Label::from(tl!("Continue from previous section")),
|
||||
SideLabel::new().layout(FieldLayout::After),
|
||||
Radio::new(true),
|
||||
);
|
||||
cx.labelled(ui, 1, Label::from(tl!("Start at:")), SideLabel::new().layout(FieldLayout::After), Radio::new(false));
|
||||
});
|
||||
})
|
||||
Select::new(tl!("Number format").to_string(), Bind::bound(&mut self.format), &formats).show(ui);
|
||||
RadioGroup::new(tl!("Page numbering").to_string(), Bind::bound(&mut self.cont)).show(ui, |ui, _| {
|
||||
Stack::new().show(ui, |ui, cx| {
|
||||
cx.labelled(ui, 0, Label::from(tl!("Continue from previous section")), SideLabel::new().layout(FieldLayout::After), Radio::new(true));
|
||||
cx.labelled(ui, 1, Label::from(tl!("Start at:")), SideLabel::new().layout(FieldLayout::After), Radio::new(false));
|
||||
});
|
||||
});
|
||||
super::count_box(ui, tl!("Start at:"), &mut self.start, 0..=100_000, !self.cont);
|
||||
super::count_field(ui, tl!("Start at:"), &mut self.start, 0..=100_000, !self.cont);
|
||||
true
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ use wordcraft_engine::cmd::mailings::{ENVELOPE_SIZES, LABEL_PRODUCTS};
|
||||
use wordcraft_geom::Region;
|
||||
|
||||
use crate::WordApp;
|
||||
use crate::dialogs::host::{Asks, WordForm, labelled, open_form};
|
||||
use crate::dialogs::host::{Asks, WordForm, open_form};
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Envelopes
|
||||
@@ -72,12 +72,10 @@ impl WordForm for EnvelopeForm {
|
||||
fn body(&mut self, ui: &mut egui::Ui, _cx: &mut FormCx<'_, '_>, _asks: &mut Vec<Asks>) -> bool {
|
||||
let sizes: Vec<Entry<usize>> =
|
||||
ENVELOPE_SIZES.iter().enumerate().map(|(i, (n, w, h))| Entry::new(i, envelope_label(n, *w, *h, &self.region))).collect();
|
||||
labelled(ui, tl!("Delivery address:"), |name, ui| TextField::new(name, Bind::bound(&mut self.delivery)).lines(4).show(ui));
|
||||
TextField::new(tl!("Delivery address:"), Bind::bound(&mut self.delivery)).lines(4).show(ui);
|
||||
Checkbox::new(Bind::bound(&mut self.omit_return)).label(tl!("Omit")).show(ui);
|
||||
labelled(ui, tl!("Return address:"), |name, ui| {
|
||||
TextField::new(name, Bind::bound(&mut self.ret)).lines(3).enabled(!self.omit_return).show(ui)
|
||||
});
|
||||
labelled(ui, tl!("Envelope size:"), |name, ui| Select::new(name, Bind::bound(&mut self.size), &sizes).show(ui));
|
||||
TextField::new(tl!("Return address:"), Bind::bound(&mut self.ret)).lines(3).enabled(!self.omit_return).show(ui);
|
||||
Select::new(tl!("Envelope size:"), Bind::bound(&mut self.size), &sizes).show(ui);
|
||||
self.ready()
|
||||
}
|
||||
fn commands(&self) -> Vec<(String, Value)> {
|
||||
@@ -204,9 +202,9 @@ impl WordForm for LabelsForm {
|
||||
Checkbox::new(Bind::bound(&mut self.recipients)).label(tl!("One label per recipient")).show(ui);
|
||||
}
|
||||
let per_recipient = self.has_recipients && self.recipients && !self.single;
|
||||
labelled(ui, tl!("Address:"), |name, ui| TextField::new(name, Bind::bound(&mut self.text)).lines(4).enabled(!per_recipient).show(ui));
|
||||
TextField::new(tl!("Address:"), Bind::bound(&mut self.text)).lines(4).enabled(!per_recipient).show(ui);
|
||||
let products: Vec<Entry<usize>> = (0..LABEL_PRODUCTS.len()).map(|i| Entry::new(i, product_label(i, &self.region))).collect();
|
||||
labelled(ui, tl!("Label:"), |name, ui| Select::new(name, Bind::bound(&mut self.product), &products).show(ui));
|
||||
Select::new(tl!("Label:"), Bind::bound(&mut self.product), &products).show(ui);
|
||||
let (rows, cols) = LABEL_PRODUCTS.get(self.product).map_or((1, 1), |p| (p.rows, p.cols));
|
||||
let mut single = self.single;
|
||||
let (mut row, mut col) = (self.row, self.col);
|
||||
@@ -218,17 +216,21 @@ impl WordForm for LabelsForm {
|
||||
Radio::new(1u8).label(tl!("Single label")).show(ui);
|
||||
});
|
||||
single = mode == 1;
|
||||
if let Some(Some(v)) = labelled(ui, tl!("Row:"), |name, ui| {
|
||||
NumberField::new(name, Bind::given(Some(row as f64))).range(1.0..=rows.max(1) as f64).enabled(single_on).show(ui)
|
||||
})
|
||||
.and_then(|out| out.value().copied())
|
||||
if let Some(Some(v)) = NumberField::new(tl!("Row:"), Bind::given(Some(row as f64)))
|
||||
.range(1.0..=rows.max(1) as f64)
|
||||
.enabled(single_on)
|
||||
.show(ui)
|
||||
.value()
|
||||
.copied()
|
||||
{
|
||||
row = v as usize;
|
||||
}
|
||||
if let Some(Some(v)) = labelled(ui, tl!("Column:"), |name, ui| {
|
||||
NumberField::new(name, Bind::given(Some(col as f64))).range(1.0..=cols.max(1) as f64).enabled(single_on).show(ui)
|
||||
})
|
||||
.and_then(|out| out.value().copied())
|
||||
if let Some(Some(v)) = NumberField::new(tl!("Column:"), Bind::given(Some(col as f64)))
|
||||
.range(1.0..=cols.max(1) as f64)
|
||||
.enabled(single_on)
|
||||
.show(ui)
|
||||
.value()
|
||||
.copied()
|
||||
{
|
||||
col = v as usize;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use super::{WordApp, count_field, named_field, number_or_zero, points};
|
||||
use crate::dialogs::host::{Asks, WordForm, labelled};
|
||||
use crate::dialogs::host::{Asks, WordForm};
|
||||
|
||||
/// The field's one name: a width that shares the text width out.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
@@ -96,7 +96,7 @@ impl WordForm for FormulaForm {
|
||||
});
|
||||
let functions: Vec<Entry<String>> = FORMULA_FUNCTIONS.iter().map(|n| Entry::new((*n).to_string(), (*n).to_string())).collect();
|
||||
let mut picked = String::new();
|
||||
labelled(ui, tl!("Paste function:").to_string(), |name, ui| Select::new(name, Bind::bound(&mut picked), &functions).show(ui));
|
||||
Select::new(tl!("Paste function:").to_string(), Bind::bound(&mut picked), &functions).show(ui);
|
||||
if !picked.is_empty() {
|
||||
self.paste(&picked);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ use serde_json::{Value, json};
|
||||
use wordcraft_doc::section::LineNumberRestart;
|
||||
|
||||
use super::{WordApp, count_field, length_field, named_field, number_or_zero, points};
|
||||
use crate::dialogs::host::{Asks, Filed, WordForm, captioned};
|
||||
use crate::dialogs::host::{Asks, Filed, WordForm};
|
||||
|
||||
/// The field's one name: no limit on consecutive hyphens.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
@@ -105,14 +105,12 @@ impl WordForm for LineNumbersForm {
|
||||
length_field(ui, tl!("From text:"), &mut self.distance, lengths, 0.0..=22.0 * 72.0, on && !self.auto_distance);
|
||||
count_field(ui, tl!("Count by:"), &mut self.count_by, 1..=100, on);
|
||||
let opts = [("restartPage", tl!("Restart Each Page")), ("restartSection", tl!("Restart Each Section")), ("continuous", tl!("Continuous"))];
|
||||
captioned(ui, tl!("Numbering:").to_string(), |name, ui| {
|
||||
RadioGroup::new(name, Bind::bound(&mut self.restart)).show(ui, |ui, _| {
|
||||
Stack::new().show(ui, |ui, cx| {
|
||||
for (at, (v, l)) in opts.iter().enumerate() {
|
||||
cx.labelled(ui, at, Label::from(*l), SideLabel::new().layout(FieldLayout::After), Radio::new((*v).to_string()));
|
||||
}
|
||||
});
|
||||
})
|
||||
RadioGroup::new(tl!("Numbering:").to_string(), Bind::bound(&mut self.restart)).show(ui, |ui, _| {
|
||||
Stack::new().show(ui, |ui, cx| {
|
||||
for (at, (v, l)) in opts.iter().enumerate() {
|
||||
cx.labelled(ui, at, Label::from(*l), SideLabel::new().layout(FieldLayout::After), Radio::new((*v).to_string()));
|
||||
}
|
||||
});
|
||||
});
|
||||
true
|
||||
}
|
||||
@@ -446,8 +444,6 @@ impl WordForm for LanguageForm {
|
||||
let which: Vec<usize> = (0..list.len()).collect();
|
||||
let source = keyed(which.as_slice(), |i: &usize| *i);
|
||||
let selection = at.map_or_else(|| Selection::new(Vec::new(), None, None), Selection::single);
|
||||
// A plain caption, not a `Field`: the list keeps its own accessible name (#7976).
|
||||
Text::new(Label::from(heading.to_string())).show(ui);
|
||||
let shown = List::<usize>::new(Label::from(heading.to_string()))
|
||||
.select(SelectMode::Single)
|
||||
.selection(Bind::given(selection))
|
||||
|
||||
@@ -22,7 +22,7 @@ use serde_json::{Value, json};
|
||||
use wordcraft_doc::section::NumFormat;
|
||||
use wordcraft_engine::cmd::lists::{LEVELS, caret_list, level_json, levels_of};
|
||||
|
||||
use super::dialogs_para::{color_row, pick, radios, radios_in_section, srgba, word};
|
||||
use super::dialogs_para::{color_row, pick, radios, srgba, word};
|
||||
use super::host::{Asks, ChildAnswer, WordForm, open_form};
|
||||
use crate::WordApp;
|
||||
use crate::colors::{AutoFace, ColorFieldEmpty, Palette};
|
||||
@@ -282,7 +282,7 @@ impl ListForm {
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
Text::new(word(tl!("Preview"))).show(ui);
|
||||
Picture::painter(word(tl!("Preview")), ThumbAspect::new(5, 3), preview(rows.clone(), level))
|
||||
.extent(PictureSize::Sample(ThumbSize::Large))
|
||||
.extent(PictureSize::Thumb(ThumbSize::Large))
|
||||
.show(ui);
|
||||
});
|
||||
});
|
||||
@@ -599,7 +599,7 @@ fn choose(ui: &mut Ui, salt: &'static str, label: Label, options: &[(&str, &str)
|
||||
/// A radio group over `options` setting `value`.
|
||||
fn choose_radio(ui: &mut Ui, label: Label, options: &[(&str, &str)], value: &mut String) {
|
||||
let current = index_of(options, value).unwrap_or(0);
|
||||
if let Some((v, _)) = radios_in_section(ui, label, &labels(options), current).and_then(|at| options.get(at)) {
|
||||
if let Some((v, _)) = radios(ui, label, &labels(options), current).and_then(|at| options.get(at)) {
|
||||
*value = v.to_string();
|
||||
}
|
||||
}
|
||||
@@ -829,12 +829,6 @@ mod tests {
|
||||
assert_eq!(h.state_mut().run("list.define", json!({})).unwrap(), json!({"pending": "defineList"}));
|
||||
h.run_steps(2);
|
||||
|
||||
// The sheet fills the Preview image's rect, which is larger than the 80 × 48 icon-side thumbnail it once
|
||||
// shrank to (#7977).
|
||||
let preview = egui_kittest::kittest::Queryable::get_by_role_and_label(&h, egui::accesskit::Role::Image, "Preview").rect();
|
||||
assert!(preview.width() > 80.0 && preview.height() > 48.0, "{theme}: the preview is {preview:?}");
|
||||
let is_sheet = |r: egui::Rect| (r.width() - preview.width()).abs() <= 2.0 && (r.height() - preview.height()).abs() <= 2.0;
|
||||
|
||||
let mut shapes = Vec::new();
|
||||
collect_shapes(&h.output().shapes, &mut shapes);
|
||||
|
||||
@@ -842,7 +836,11 @@ mod tests {
|
||||
let white_rects: Vec<_> = shapes
|
||||
.iter()
|
||||
.filter_map(|s| match s {
|
||||
egui::Shape::Rect(r) if r.fill == egui::Color32::WHITE && is_sheet(r.rect) => Some(r),
|
||||
egui::Shape::Rect(r)
|
||||
if r.fill == egui::Color32::WHITE && (r.rect.width() - 80.0).abs() <= 5.0 && (r.rect.height() - 48.0).abs() <= 5.0 =>
|
||||
{
|
||||
Some(r)
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
@@ -852,7 +850,13 @@ mod tests {
|
||||
let stroke_rects: Vec<_> = shapes
|
||||
.iter()
|
||||
.filter_map(|s| match s {
|
||||
egui::Shape::Rect(r) if r.stroke.color == egui::Color32::from_gray(160) && is_sheet(r.rect) => Some(r),
|
||||
egui::Shape::Rect(r)
|
||||
if r.stroke.color == egui::Color32::from_gray(160)
|
||||
&& (r.rect.width() - 80.0).abs() <= 5.0
|
||||
&& (r.rect.height() - 48.0).abs() <= 5.0 =>
|
||||
{
|
||||
Some(r)
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
|
||||
@@ -14,7 +14,6 @@ use craft::theme::Srgba;
|
||||
use craft::ui::choice::{Checkbox, Radio, RadioGroup};
|
||||
use craft::ui::contract::{Bind, CollectionEvent, Entry, FieldLayout, Props as _, Show as _, ShowCollection as _, ShowContainer as _, SideLabel};
|
||||
use craft::ui::dialog::DialogId;
|
||||
use craft::ui::display::Text;
|
||||
use craft::ui::form::Field;
|
||||
use craft::ui::layout_components::{Row, Stack};
|
||||
use craft::ui::patterns::form_dialogs::FormCx;
|
||||
@@ -26,7 +25,7 @@ use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Map, Value, json};
|
||||
use wordcraft_doc::props::{Border, BorderStyle, Borders, Rgb, TabAlign, TabLeader, TabStop};
|
||||
|
||||
use super::host::{Asks, ChildAnswer, DialogHooks, Keyed, Settle, WordForm, captioned, open_form, open_with};
|
||||
use super::host::{Asks, ChildAnswer, DialogHooks, Keyed, Settle, WordForm, open_form, open_with};
|
||||
use crate::WordApp;
|
||||
use crate::colors::{AutoFace, ColorFieldEmpty, Palette, color_field};
|
||||
use crate::options::unit_kind;
|
||||
@@ -61,23 +60,6 @@ pub(super) fn color_row(
|
||||
}
|
||||
}
|
||||
|
||||
/// `color_row` with `label` drawn beside it as plain text. Not a `Field`: its label scope would rename the split button
|
||||
/// "Color:" and drop the colour it speaks ("Color: Automatic").
|
||||
fn captioned_color_row(
|
||||
ui: &mut Ui,
|
||||
key: &'static str,
|
||||
label: Label,
|
||||
value: &mut String,
|
||||
empty: &ColorFieldEmpty,
|
||||
palette: &Palette,
|
||||
asks: &mut Vec<Asks>,
|
||||
) {
|
||||
Row::new().show(ui, |ui, _| {
|
||||
Text::new(label.clone()).show(ui);
|
||||
color_row(ui, key, &label, value, empty, palette, asks);
|
||||
});
|
||||
}
|
||||
|
||||
/// A drop-down over `labels` under `label`, showing entry `current` (empty while it is `None`). The index of the entry
|
||||
/// picked in this pass.
|
||||
pub(super) fn pick(ui: &mut Ui, salt: &'static str, label: Label, labels: &[Label], current: Option<usize>, enabled: bool) -> Option<usize> {
|
||||
@@ -90,18 +72,9 @@ pub(super) fn pick(ui: &mut Ui, salt: &'static str, label: Label, labels: &[Labe
|
||||
.flatten()
|
||||
}
|
||||
|
||||
/// A radio group over `labels` under a caption `label`, entry `current` chosen. The index chosen in this pass, when it
|
||||
/// is another one.
|
||||
/// A radio group over `labels` under `label`, entry `current` chosen. The index chosen in this pass, when it is
|
||||
/// another one.
|
||||
pub(super) fn radios(ui: &mut Ui, label: Label, labels: &[Label], current: usize) -> Option<usize> {
|
||||
captioned(ui, label.clone(), |_, ui| radio_set(ui, label.clone(), labels, current)).flatten()
|
||||
}
|
||||
|
||||
/// `radios` with no caption: for a group inside a section that already carries its title.
|
||||
pub(super) fn radios_in_section(ui: &mut Ui, label: Label, labels: &[Label], current: usize) -> Option<usize> {
|
||||
radio_set(ui, label, labels, current)
|
||||
}
|
||||
|
||||
fn radio_set(ui: &mut Ui, label: Label, labels: &[Label], current: usize) -> Option<usize> {
|
||||
let mut at = current;
|
||||
RadioGroup::new(label, Bind::bound(&mut at)).show(ui, |ui, cx| {
|
||||
for (i, text) in labels.iter().enumerate() {
|
||||
@@ -508,7 +481,7 @@ fn lines(ui: &mut Ui, key: &'static str, l: &mut LineForm, area: SampleArea, fil
|
||||
l.style = *style;
|
||||
}
|
||||
let automatic = ColorFieldEmpty::Automatic { label: word(tl!("Automatic")), value: "", face: AutoFace::One(srgba(Rgb(0, 0, 0))) };
|
||||
captioned_color_row(ui, key, word(tl!("Color:")), &mut l.color, &automatic, palette, asks);
|
||||
color_row(ui, key, &word(tl!("Color:")), &mut l.color, &automatic, palette, asks);
|
||||
let names: Vec<Label> = WIDTHS.iter().map(|w| word(crate::i18n::fmt(tl!("{n} pt"), &[("n", &w.to_string())]))).collect();
|
||||
let current = WIDTHS.iter().position(|w| *w == l.width);
|
||||
if let Some(width) = pick(ui, "width", word(tl!("Width:")), &names, current, true).and_then(|at| WIDTHS.get(at)) {
|
||||
@@ -567,7 +540,7 @@ impl WordForm for BordersForm {
|
||||
Self::apply_to(ui, &mut self.whole_doc, word(tl!("This section")), word(tl!("Whole document")));
|
||||
}
|
||||
_ => {
|
||||
captioned_color_row(ui, "fill", word(tl!("Fill")), &mut self.fill, &ColorFieldEmpty::NoColor, &palette, asks);
|
||||
color_row(ui, "fill", &word(tl!("Fill")), &mut self.fill, &ColorFieldEmpty::NoColor, &palette, asks);
|
||||
// The same sample as the Borders tab shows, without the lines and not editable.
|
||||
let mut none = BorderEdges::default();
|
||||
let area = if self.fill_to_text { SampleArea::Text } else { SampleArea::Paragraph };
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use craft::behavior::{Mixed, Selection, keyed};
|
||||
use craft::ui::contract::{Bind, Entry, SelectMode, Show as _, ShowCollection as _, ShowContainer as _};
|
||||
use craft::ui::dialog::DialogId;
|
||||
use craft::ui::display::Text;
|
||||
use craft::ui::form::Field;
|
||||
use craft::ui::list::{List, ListRow};
|
||||
use craft::ui::patterns::form_dialogs::FormCx;
|
||||
@@ -157,7 +156,6 @@ impl WordForm for CrossRefForm {
|
||||
let source = keyed(&which, |i: &usize| *i);
|
||||
let mut selection = self.selected.map_or_else(|| Selection::new(Vec::new(), None, None), Selection::single);
|
||||
let targets = &self.targets;
|
||||
Text::new(Label::from(tl!("For which item:").to_string())).show(ui);
|
||||
let _ = List::new(Label::from(tl!("For which item:").to_string()))
|
||||
.max_rows(8)
|
||||
.select(SelectMode::Single)
|
||||
|
||||
@@ -20,7 +20,7 @@ use wordcraft_engine::cmd::references::FieldCode;
|
||||
|
||||
use super::sample::{LEADERS, leader_char, sample_card};
|
||||
use crate::WordApp;
|
||||
use crate::dialogs::host::{Asks, Filed, WordForm, captioned, labelled, open_form};
|
||||
use crate::dialogs::host::{Asks, Filed, WordForm, open_form};
|
||||
|
||||
/// The tab leaders as drop-down entries (value, translated label).
|
||||
pub(super) fn leaders() -> Vec<Entry<String>> {
|
||||
@@ -104,21 +104,18 @@ impl WordForm for IndexForm {
|
||||
|
||||
fn body(&mut self, ui: &mut Ui, _cx: &mut FormCx<'_, '_>, asks: &mut Vec<Asks>) -> bool {
|
||||
sample_card(tl!("Preview"), self.sample_lines(), self.right_align, leader_char(&self.leader)).show(ui);
|
||||
let kind = captioned(ui, Label::from(tl!("Type:").to_string()), |name, ui| {
|
||||
RadioGroup::new(name, Bind::given(self.kind.clone())).show(ui, |ui, _| {
|
||||
Row::new().show(ui, |ui, _| {
|
||||
Radio::new("indented".to_string()).label(Label::from(tl!("Indented").to_string())).show(ui);
|
||||
Radio::new("runIn".to_string()).label(Label::from(tl!("Run-in").to_string())).show(ui);
|
||||
});
|
||||
})
|
||||
let kind = RadioGroup::new(Label::from(tl!("Type:").to_string()), Bind::given(self.kind.clone())).show(ui, |ui, _| {
|
||||
Row::new().show(ui, |ui, _| {
|
||||
Radio::new("indented".to_string()).label(Label::from(tl!("Indented").to_string())).show(ui);
|
||||
Radio::new("runIn".to_string()).label(Label::from(tl!("Run-in").to_string())).show(ui);
|
||||
});
|
||||
});
|
||||
if let Some(kind) = kind.and_then(|kind| kind.output.value().cloned()) {
|
||||
if let Some(kind) = kind.output.value().cloned() {
|
||||
self.kind = kind;
|
||||
}
|
||||
let columns = labelled(ui, Label::from(tl!("Columns:").to_string()), |name, ui| {
|
||||
NumberField::new(name, Bind::given(Some(f64::from(self.columns)))).range(1.0..=4.0).show(ui)
|
||||
});
|
||||
if let Some(Some(n)) = columns.and_then(|out| out.edit.value().cloned()) {
|
||||
let columns =
|
||||
NumberField::new(Label::from(tl!("Columns:").to_string()), Bind::given(Some(f64::from(self.columns)))).range(1.0..=4.0).show(ui);
|
||||
if let Some(Some(n)) = columns.edit.value().cloned() {
|
||||
self.columns = n.round().clamp(1.0, 4.0) as u32;
|
||||
}
|
||||
Checkbox::new(Bind::bound(&mut self.right_align)).label(Label::from(tl!("Page numbers at the right margin").to_string())).show(ui);
|
||||
|
||||
@@ -25,7 +25,6 @@ use craft::ui::list::{List, ListRow, ToggleCell, ToggleState};
|
||||
use craft::ui::notices::Notice;
|
||||
use craft::ui::runtime::env::Label;
|
||||
use craft::ui::sections::{DialogRole, FooterButton};
|
||||
use craft::ui::style::SurfaceKind;
|
||||
use craft::ui::tabs::{Tab, TabKind, TabStrip};
|
||||
use craft::ui::text::TextField;
|
||||
use egui::{Context, Ui};
|
||||
@@ -261,7 +260,6 @@ impl RibbonDialog {
|
||||
let rows = &self.tree;
|
||||
let out = List::new(word("Ribbon tabs"))
|
||||
.id(self.tree_id(ui))
|
||||
.surface(SurfaceKind::Frame)
|
||||
.tree(true)
|
||||
.select(SelectMode::Single)
|
||||
.columns(columns)
|
||||
@@ -405,7 +403,6 @@ fn pick(ui: &mut Ui, salt: &'static str, label: &str, rows: &[(String, String)],
|
||||
let mut selection = at.map_or_else(Selection::default, Selection::single);
|
||||
List::new(word(label))
|
||||
.id(ui.scope_id().with(salt))
|
||||
.surface(SurfaceKind::Frame)
|
||||
.select(SelectMode::Single)
|
||||
// The list scrolls its own rows, as main's fixed-height boxes did, so the dialog's body does not scroll it too.
|
||||
.max_rows(12)
|
||||
|
||||
@@ -321,7 +321,7 @@ fn layout_tiles(ui: &mut Ui, theme: &[Rgb], form: &mut SmartArtForm) -> bool {
|
||||
.card_columns(3)
|
||||
// Production's picker is three tile rows high and scrolls the rest; the cap also makes the grid the one owner
|
||||
// of its scroll inside the dialog's scrolling body.
|
||||
.max_rows(3)
|
||||
.max_rows(crate::dialogs::tile_rows_cap(shown.len(), 3, 3))
|
||||
.selection(Bind::given(Selection::single(current)))
|
||||
.show_items(ui, &keyed(&positions, |i| *i), &mut |key, _| {
|
||||
let layout = shown.get(*key).copied().unwrap_or_default();
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
use craft::ui::choice::{Radio, RadioGroup};
|
||||
use craft::ui::contract::{Bind, Props as _, Show as _, ShowContainer as _};
|
||||
use craft::ui::dialog::DialogId;
|
||||
use craft::ui::display::{Picture, PictureSize};
|
||||
use craft::ui::display::Picture;
|
||||
use craft::ui::form::{Field, FieldGroup};
|
||||
use craft::ui::layout_components::{Row, Stack};
|
||||
use craft::ui::list::{ThumbAspect, ThumbSize};
|
||||
use craft::ui::list::ThumbAspect;
|
||||
use craft::ui::patterns::form_dialogs::FormCx;
|
||||
use craft::ui::primitives::{ContentPainterCx, HAlign, PaintShape, StrokeColor, StrokeWidth, TextRun};
|
||||
use craft::ui::runtime::env::Label;
|
||||
@@ -17,7 +17,7 @@ use egui::{CornerRadius, Rect, Ui, pos2, vec2};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use super::host::{Asks, WordForm, captioned, open_form};
|
||||
use super::host::{Asks, WordForm, open_form};
|
||||
use crate::WordApp;
|
||||
|
||||
const PREVIEW_W: f32 = 110.0;
|
||||
@@ -81,27 +81,24 @@ impl EncloseForm {
|
||||
d.text(line, &TextRun::new(text.as_str()).role(role).align(HAlign::Center));
|
||||
});
|
||||
})
|
||||
.extent(PictureSize::Sample(ThumbSize::Large))
|
||||
}
|
||||
}
|
||||
|
||||
/// A radio group over `value` whose options are `(id, label)`.
|
||||
fn radios(ui: &mut Ui, name: &'static str, value: &mut String, options: &[(&'static str, &'static str)], enabled: bool, horizontal: bool) {
|
||||
let group = captioned(ui, Label::from(name), |name, ui| {
|
||||
RadioGroup::new(name, Bind::given(value.clone())).enabled(enabled).show(ui, |ui, _| {
|
||||
let items = |ui: &mut Ui| {
|
||||
for (id, label) in options {
|
||||
Radio::new((*id).to_string()).label(Label::from(tl!(*label))).enabled(enabled).show(ui);
|
||||
}
|
||||
};
|
||||
if horizontal {
|
||||
Row::new().show(ui, |ui, _| items(ui));
|
||||
} else {
|
||||
Stack::new().show(ui, |ui, _| items(ui));
|
||||
let group = RadioGroup::new(Label::from(name), Bind::given(value.clone())).enabled(enabled).show(ui, |ui, _| {
|
||||
let items = |ui: &mut Ui| {
|
||||
for (id, label) in options {
|
||||
Radio::new((*id).to_string()).label(Label::from(tl!(*label))).enabled(enabled).show(ui);
|
||||
}
|
||||
})
|
||||
};
|
||||
if horizontal {
|
||||
Row::new().show(ui, |ui, _| items(ui));
|
||||
} else {
|
||||
Stack::new().show(ui, |ui, _| items(ui));
|
||||
}
|
||||
});
|
||||
if let Some(v) = group.and_then(|g| g.output.value().cloned()) {
|
||||
if let Some(v) = group.output.value().cloned() {
|
||||
*value = v;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ use craft::ui::sections::Section;
|
||||
use craft::ui::style::TypeRole;
|
||||
use craft::ui::text::{NumberField, TextField};
|
||||
|
||||
use super::host::{Asks, WordForm, captioned, labelled, open_form};
|
||||
use super::host::{Asks, WordForm, open_form};
|
||||
|
||||
/// Opens the form dialog `name` when it is one of this file's: Table Properties (only with a table selection) or Custom
|
||||
/// Properties.
|
||||
@@ -49,16 +49,14 @@ fn flag(ui: &mut Ui, id: &'static str, label: String, value: &mut bool, enabled:
|
||||
|
||||
/// A radio group choosing one of `options` (key, label) into `value`.
|
||||
fn choose(ui: &mut Ui, id: &'static str, label: String, value: &mut String, options: &[(&str, String)]) {
|
||||
let chosen = captioned(ui, Label::from(label), |name, ui| {
|
||||
RadioGroup::new(name, Bind::given(value.clone())).id_salt(id).show(ui, |ui, _| {
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
for (key, text) in options {
|
||||
Radio::new((*key).to_string()).label(Label::from(text.clone())).show(ui);
|
||||
}
|
||||
});
|
||||
})
|
||||
let chosen = RadioGroup::new(Label::from(label), Bind::given(value.clone())).id_salt(id).show(ui, |ui, _| {
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
for (key, text) in options {
|
||||
Radio::new((*key).to_string()).label(Label::from(text.clone())).show(ui);
|
||||
}
|
||||
});
|
||||
});
|
||||
if let Some(next) = chosen.and_then(|c| c.output.value().cloned()) {
|
||||
if let Some(next) = chosen.output.value().cloned() {
|
||||
*value = next;
|
||||
}
|
||||
}
|
||||
@@ -242,21 +240,14 @@ impl WordForm for CustomPropertiesForm {
|
||||
let rows: Vec<String> = self.props.iter().map(|p| format!("{} = {}", p.name, p.value)).collect();
|
||||
let positions: Vec<usize> = (0..rows.len()).collect();
|
||||
let mut selection = if self.selected < rows.len() { Selection::single(self.selected) } else { Selection::default() };
|
||||
if rows.is_empty() {
|
||||
// lean: craft's `List` measures its `.empty()` text shorter than it draws it, so the dialog is a row short and
|
||||
// its footer is drawn over the last row (#7982). Show the text ourselves; drop this once craft-libs fixes
|
||||
// `List`. The same latent overlap may hit the other `.empty()` users: bookmarks.rs:112/268, macros.rs:71,
|
||||
// dialogs_refs/cross_ref.rs:165, dialogs_refs/sources.rs:311 and dialogs_review.rs:423.
|
||||
Text::new(Label::from(tl!("This document has no custom properties.").to_string())).shade(Shade::Muted).show(ui);
|
||||
} else {
|
||||
List::new(Label::from(tl!("Properties").to_string()))
|
||||
.id_salt("props")
|
||||
.max_rows(6)
|
||||
.select(SelectMode::Single)
|
||||
.allow_empty(true)
|
||||
.selection(Bind::bound(&mut selection))
|
||||
.show_items(ui, &keyed(&positions, |at| *at), &mut |at, _| ListRow::new(rows.get(*at).cloned().unwrap_or_default()));
|
||||
}
|
||||
List::new(Label::from(tl!("Properties").to_string()))
|
||||
.id_salt("props")
|
||||
.max_rows(6)
|
||||
.select(SelectMode::Single)
|
||||
.allow_empty(true)
|
||||
.empty(Label::from(tl!("This document has no custom properties.").to_string()))
|
||||
.selection(Bind::bound(&mut selection))
|
||||
.show_items(ui, &keyed(&positions, |at| *at), &mut |at, _| ListRow::new(rows.get(*at).cloned().unwrap_or_default()));
|
||||
if let Some(at) = selection.items.first().copied()
|
||||
&& at != self.selected
|
||||
{
|
||||
@@ -274,16 +265,15 @@ impl WordForm for CustomPropertiesForm {
|
||||
self.delete();
|
||||
}
|
||||
});
|
||||
let typed = labelled(ui, Label::from(tl!("Name:").to_string()), |name, ui| {
|
||||
TextField::new(name, Bind::given(self.name.clone())).id_salt("name").limit(wordcraft_engine::cmd::file::MAX_CUSTOM_NAME).show(ui)
|
||||
});
|
||||
if let Some(text) = typed.and_then(|out| out.value().cloned()) {
|
||||
let typed = TextField::new(Label::from(tl!("Name:").to_string()), Bind::given(self.name.clone()))
|
||||
.id_salt("name")
|
||||
.limit(wordcraft_engine::cmd::file::MAX_CUSTOM_NAME)
|
||||
.show(ui);
|
||||
if let Some(text) = typed.value().cloned() {
|
||||
self.name = text;
|
||||
}
|
||||
let typed = labelled(ui, Label::from(tl!("Value:").to_string()), |name, ui| {
|
||||
TextField::new(name, Bind::given(self.value.clone())).id_salt("value").show(ui)
|
||||
});
|
||||
if let Some(text) = typed.and_then(|out| out.value().cloned()) {
|
||||
let typed = TextField::new(Label::from(tl!("Value:").to_string()), Bind::given(self.value.clone())).id_salt("value").show(ui);
|
||||
if let Some(text) = typed.value().cloned() {
|
||||
self.value = text;
|
||||
}
|
||||
if !self.message.is_empty() {
|
||||
@@ -454,9 +444,11 @@ fn mixed_check(ui: &mut Ui, id: &'static str, label: String, key: &str, value: &
|
||||
/// A length field over points, shown in the interface unit of `units`, within `lo..=hi` points.
|
||||
fn length(ui: &mut Ui, id: &'static str, label: String, value: &mut f32, (lo, hi): (f32, f32), units: LengthUnits, enabled: bool) {
|
||||
let mut points = Some(f64::from(*value));
|
||||
labelled(ui, Label::from(label), |name, ui| {
|
||||
NumberField::length(name, Bind::bound(&mut points), units).id_salt(id).range(f64::from(lo)..=f64::from(hi)).enabled(enabled).show(ui)
|
||||
});
|
||||
NumberField::length(Label::from(label), Bind::bound(&mut points), units)
|
||||
.id_salt(id)
|
||||
.range(f64::from(lo)..=f64::from(hi))
|
||||
.enabled(enabled)
|
||||
.show(ui);
|
||||
if let Some(next) = points {
|
||||
*value = next as f32;
|
||||
}
|
||||
|
||||
@@ -7,9 +7,8 @@
|
||||
//! answer is inferred from side effects.
|
||||
|
||||
use craft::color_ui::ui::{ColorPickerDialog, ColorPickerTab};
|
||||
use craft::ui::contract::{Bind, FieldLayout, ShowContainer as _};
|
||||
use craft::ui::contract::Bind;
|
||||
use craft::ui::dialog::{ChildDialog, DialogId, DialogResult, DialogStack, HeldAnswer, HeldOk, StackDialog, dialog_id};
|
||||
use craft::ui::form::Field;
|
||||
use craft::ui::patterns::form_dialogs::{AboutTab, FormButtons, FormCx, FormDialog, HostedAbout};
|
||||
use craft::ui::runtime::env::Label;
|
||||
use craft::ui::sections::FooterButton;
|
||||
@@ -418,23 +417,6 @@ impl<F: WordForm> StackDialog for FormHost<F> {
|
||||
}
|
||||
}
|
||||
|
||||
/// `show` (given `label` to name its control, and the field's `Ui`) with `label` drawn beside the control. A text box,
|
||||
/// number box or drop-down names itself but draws no caption, so every bare one in a dialog goes through here
|
||||
/// (#7976). `None` when the field is not shown this pass.
|
||||
pub(crate) fn labelled<R>(ui: &mut Ui, label: impl Into<Label>, show: impl FnMut(Label, &mut Ui) -> R) -> Option<R> {
|
||||
field(ui, FieldLayout::Beside, label.into(), show)
|
||||
}
|
||||
|
||||
/// `labelled`, with the caption above the control: for a radio group or a preview, which has no box for a side label
|
||||
/// to sit against (#7976).
|
||||
pub(crate) fn captioned<R>(ui: &mut Ui, label: impl Into<Label>, show: impl FnMut(Label, &mut Ui) -> R) -> Option<R> {
|
||||
field(ui, FieldLayout::Above, label.into(), show)
|
||||
}
|
||||
|
||||
fn field<R>(ui: &mut Ui, layout: FieldLayout, label: Label, mut show: impl FnMut(Label, &mut Ui) -> R) -> Option<R> {
|
||||
Field::new(label.clone()).layout(layout).show(ui, |ui, _| show(label.clone(), ui)).inner
|
||||
}
|
||||
|
||||
/// Opens `form` as a dialog, over `parent` when there is one.
|
||||
pub(crate) fn open_form<F: WordForm>(app: &mut WordApp, parent: Option<DialogId>, form: F) -> DialogId {
|
||||
let id = open_node(app, parent, FormHost::new(form, parent));
|
||||
|
||||
@@ -22,7 +22,7 @@ use serde::Serialize;
|
||||
use serde_json::{Value, json};
|
||||
use wordcraft_engine::cmd::mailings::{FilterOp, FilterRule, SortKey};
|
||||
|
||||
use super::host::{DialogHooks, Settle, labelled, open_with};
|
||||
use super::host::{DialogHooks, Settle, open_with};
|
||||
use crate::WordApp;
|
||||
|
||||
/// The address parts Match Fields lists, with their keys in `mailings.matchFields`' `address`.
|
||||
@@ -376,7 +376,7 @@ fn recipient_body(ui: &mut egui::Ui, d: &mut RecipientDraft, editing: &mut bool,
|
||||
filter.only_merged = false;
|
||||
}
|
||||
Checkbox::new(Bind::bound(&mut filter.only_merged)).label(tl!("Show only records that will be merged")).enabled(order.is_some()).show(ui);
|
||||
labelled(ui, tl!("Find in list:"), |name, ui| TextField::search(name, Bind::bound(&mut filter.find)).show(ui));
|
||||
TextField::search(tl!("Find in list"), Bind::bound(&mut filter.find)).show(ui);
|
||||
// The rows the grid shows, by real index: edits and removes go to the right record.
|
||||
let fresh = visible_recipients(rows, order.as_deref(), &filter.find, filter.only_merged);
|
||||
// A press that ends a cell's edit (one on the row's Remove part) completes its click on release, a pass later: the
|
||||
@@ -394,7 +394,7 @@ fn recipient_body(ui: &mut egui::Ui, d: &mut RecipientDraft, editing: &mut bool,
|
||||
let columns = fields
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(j, f)| ColumnSpec::new(ColumnKey::index(j as u32), f.clone(), ColumnWidth::Controls(6.0)).removable(tl!("Remove field"), can_remove))
|
||||
.map(|(j, f)| ColumnSpec::new(ColumnKey::index(j as u32), f.clone(), ColumnWidth::fill(1.0)).removable(tl!("Remove field"), can_remove))
|
||||
.collect();
|
||||
// The dialog body scrolls, and a collection owns its own scroll: the grid shows this many records and scrolls
|
||||
// the rest itself.
|
||||
@@ -530,16 +530,11 @@ fn filter_section(ui: &mut egui::Ui, fields: &[String], filter: &mut RecipientFi
|
||||
let directions = [Entry::new(false, tl!("Ascending")), Entry::new(true, tl!("Descending"))];
|
||||
for (i, (field, desc)) in filter.sort.iter_mut().enumerate() {
|
||||
let label = tl!(if i == 0 { "Sort by" } else { "Then by" });
|
||||
if let Some(f) = labelled(ui, label, |name, ui| Select::new(name, Bind::given(field.clone()), &keys).id_salt(("sort", i)).show(ui))
|
||||
.and_then(|out| out.value().cloned())
|
||||
{
|
||||
if let Some(f) = Select::new(label, Bind::given(field.clone()), &keys).id_salt(("sort", i)).show(ui).value().cloned() {
|
||||
*field = f;
|
||||
}
|
||||
let has_field = !field.is_empty();
|
||||
if let Some(d) =
|
||||
labelled(ui, tl!("Order"), |name, ui| Select::new(name, Bind::given(*desc), &directions).id_salt(("dir", i)).enabled(has_field).show(ui))
|
||||
.and_then(|out| out.value().copied())
|
||||
{
|
||||
if let Some(d) = Select::new(tl!("Order"), Bind::given(*desc), &directions).id_salt(("dir", i)).enabled(has_field).show(ui).value().copied() {
|
||||
*desc = d;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ use craft::ui::text::{NumberField, TextField};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use super::host::{Asks, DialogHooks, FormHost, Settle, WordForm, captioned, labelled, open_form, open_form_with, open_with};
|
||||
use super::host::{Asks, DialogHooks, FormHost, Settle, WordForm, open_form, open_form_with, open_with};
|
||||
use super::mailings::ADDRESS_PARTS;
|
||||
use crate::WordApp;
|
||||
|
||||
@@ -115,7 +115,7 @@ impl WordForm for InsertMergeFieldForm {
|
||||
} else if let (Some(name), _) = pick_name(ui, tl!("Fields:"), &self.fields, &self.field) {
|
||||
self.field = name;
|
||||
}
|
||||
labelled(ui, tl!("Field:"), |name, ui| TextField::new(name, Bind::bound(&mut self.field)).show(ui));
|
||||
TextField::new(tl!("Field:"), Bind::bound(&mut self.field)).show(ui);
|
||||
!self.field.trim().is_empty()
|
||||
}
|
||||
fn commands(&self) -> Vec<(String, Value)> {
|
||||
@@ -209,7 +209,7 @@ impl WordForm for FindRecipientForm {
|
||||
Some(tl!("Find").into())
|
||||
}
|
||||
fn body(&mut self, ui: &mut egui::Ui, _cx: &mut FormCx<'_, '_>, _asks: &mut Vec<Asks>) -> bool {
|
||||
labelled(ui, tl!("Find:"), |name, ui| TextField::new(name, Bind::bound(&mut self.text)).show(ui));
|
||||
TextField::new(tl!("Find:"), Bind::bound(&mut self.text)).show(ui);
|
||||
!self.text.trim().is_empty()
|
||||
}
|
||||
fn commands(&self) -> Vec<(String, Value)> {
|
||||
@@ -261,12 +261,10 @@ impl WordForm for MergeRecordsForm {
|
||||
}
|
||||
fn body(&mut self, ui: &mut egui::Ui, _cx: &mut FormCx<'_, '_>, _asks: &mut Vec<Asks>) -> bool {
|
||||
let mut choice = self.choice;
|
||||
captioned(ui, tl!("Records"), |name, ui| {
|
||||
RadioGroup::new(name, Bind::bound(&mut choice)).show(ui, |ui, _| {
|
||||
Radio::new(0u8).label(tl!("All")).show(ui);
|
||||
Radio::new(1u8).label(tl!("Current record")).show(ui);
|
||||
Radio::new(2u8).label(tl!("From:")).show(ui);
|
||||
})
|
||||
RadioGroup::new(tl!("Records"), Bind::bound(&mut choice)).show(ui, |ui, _| {
|
||||
Radio::new(0u8).label(tl!("All")).show(ui);
|
||||
Radio::new(1u8).label(tl!("Current record")).show(ui);
|
||||
Radio::new(2u8).label(tl!("From:")).show(ui);
|
||||
});
|
||||
self.choice = choice;
|
||||
// Typing a number picks the range.
|
||||
@@ -346,19 +344,17 @@ impl WordForm for MergeRuleForm {
|
||||
}))
|
||||
.show(ui);
|
||||
if self.fields.is_empty() {
|
||||
labelled(ui, tl!("Field:"), |name, ui| TextField::new(name, Bind::bound(&mut self.field)).show(ui));
|
||||
TextField::new(tl!("Field:"), Bind::bound(&mut self.field)).show(ui);
|
||||
} else {
|
||||
let entries: Vec<Entry<String>> = self.fields.iter().map(|f| Entry::new(f.clone(), Label::from(f.clone()))).collect();
|
||||
if let Some(f) = labelled(ui, tl!("Field:"), |name, ui| Select::new(name, Bind::given(self.field.clone()), &entries).show(ui))
|
||||
.and_then(|out| out.value().cloned())
|
||||
{
|
||||
if let Some(f) = Select::new(tl!("Field:"), Bind::given(self.field.clone()), &entries).show(ui).value().cloned() {
|
||||
self.field = f;
|
||||
}
|
||||
}
|
||||
labelled(ui, tl!("Equals:"), |name, ui| TextField::new(name, Bind::bound(&mut self.value)).show(ui));
|
||||
TextField::new(tl!("Equals:"), Bind::bound(&mut self.value)).show(ui);
|
||||
if !skip {
|
||||
labelled(ui, tl!("Then insert:"), |name, ui| TextField::new(name, Bind::bound(&mut self.then)).show(ui));
|
||||
labelled(ui, tl!("Otherwise insert:"), |name, ui| TextField::new(name, Bind::bound(&mut self.els)).show(ui));
|
||||
TextField::new(tl!("Then insert:"), Bind::bound(&mut self.then)).show(ui);
|
||||
TextField::new(tl!("Otherwise insert:"), Bind::bound(&mut self.els)).show(ui);
|
||||
}
|
||||
self.params().is_some()
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use craft::ui::patterns::form_dialogs::FormCx;
|
||||
use craft::ui::runtime::env::Label;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::host::{Asks, WordForm, captioned, open_form};
|
||||
use super::host::{Asks, WordForm, open_form};
|
||||
use super::{Value, WordApp};
|
||||
use egui::Ui;
|
||||
use serde_json::json;
|
||||
@@ -69,15 +69,13 @@ impl WordForm for PasteSpecialForm {
|
||||
return true;
|
||||
}
|
||||
let formats = self.formats.clone();
|
||||
captioned(ui, Label::from(tl!("Paste as:")), |name, ui| {
|
||||
RadioGroup::new(name, Bind::bound(&mut self.choice)).show(ui, |ui, _| {
|
||||
Stack::new().show(ui, |ui, cx| {
|
||||
for (at, f) in formats.iter().enumerate() {
|
||||
let label = wordcraft_engine::cmd::paste::FORMATS.iter().find(|(id, _)| id == f).map(|(_, l)| *l).unwrap_or(f.as_str());
|
||||
cx.labelled(ui, at, Label::from(tl!(label).to_owned()), SideLabel::new().layout(FieldLayout::After), Radio::new(at));
|
||||
}
|
||||
});
|
||||
})
|
||||
RadioGroup::new(Label::from(tl!("Paste as:")), Bind::bound(&mut self.choice)).show(ui, |ui, _| {
|
||||
Stack::new().show(ui, |ui, cx| {
|
||||
for (at, f) in formats.iter().enumerate() {
|
||||
let label = wordcraft_engine::cmd::paste::FORMATS.iter().find(|(id, _)| id == f).map(|(_, l)| *l).unwrap_or(f.as_str());
|
||||
cx.labelled(ui, at, Label::from(tl!(label).to_owned()), SideLabel::new().layout(FieldLayout::After), Radio::new(at));
|
||||
}
|
||||
});
|
||||
});
|
||||
if let Some(f) = formats.get(self.choice) {
|
||||
Text::new(Label::from(tl!("Result"))).show(ui);
|
||||
|
||||
@@ -8,7 +8,7 @@ use craft::ui::contract::{
|
||||
Bind, CollectionEvent, ColumnSpec, Entry, Props as _, SelectMode, Show as _, ShowCollection as _, ShowContainer as _, TooltipSpec, clicked,
|
||||
};
|
||||
use craft::ui::dialog::{Dialog, DialogId, DialogResult, DialogStack, StackDialog, dialog_id};
|
||||
use craft::ui::display::{Picture, PictureSize, Shade, Text};
|
||||
use craft::ui::display::{Picture, Shade, Text};
|
||||
use craft::ui::form::Field;
|
||||
use craft::ui::list::{List, ListRow};
|
||||
use craft::ui::pickers::Select;
|
||||
@@ -183,7 +183,7 @@ impl ManageStylesDialog {
|
||||
if let Some((key, image)) = &self.preview {
|
||||
let image = image.clone();
|
||||
let make = move || image.clone();
|
||||
Picture::new(label(tl!("Preview")), self.made, &make).revision(key.styles).extent(PictureSize::DevicePixels).show(ui);
|
||||
Picture::new(label(tl!("Preview")), self.made, &make).revision(key.styles).show(ui);
|
||||
}
|
||||
Text::new(label(describe(&cur))).shade(Shade::Muted).show(ui);
|
||||
let style = self.selected.clone();
|
||||
|
||||
@@ -2284,75 +2284,6 @@ fn modal_dialog_with_open_popup_does_not_shake_on_inside_click_but_shakes_on_out
|
||||
assert!(h.ctx.data(|d| d.get_temp::<f64>(key2)).is_none(), "reopened dialog starts still");
|
||||
}
|
||||
|
||||
/// #7976: a text box, number box, drop-down or radio group has an accessible name but draws no caption of its own;
|
||||
/// the dialog must draw one beside or above it, or the field reads as a bare box.
|
||||
#[test]
|
||||
fn bare_fields_and_groups_draw_their_captions() {
|
||||
use egui::accesskit::Role;
|
||||
for (dialog, captions) in
|
||||
[("envelopes", &["Delivery address", "Return address", "Envelope size"][..]), ("dropCap", &["Position", "Lines to drop"][..])]
|
||||
{
|
||||
let mut h = app_harness(app_with("Lanterns"));
|
||||
h.state_mut().run("ui.dialog", json!({"name": dialog})).unwrap();
|
||||
h.run_steps(6);
|
||||
for caption in captions {
|
||||
let drawn = h.query_all(egui_kittest::kittest::By::new().role(Role::Label).label_contains(caption)).count();
|
||||
assert!(drawn > 0, "{dialog} draws no caption \"{caption}\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// #7976: a caption is drawn once. A group inside a titled section, or a box after a radio that says the same
|
||||
/// words, must not repeat them as a second caption.
|
||||
#[test]
|
||||
fn captions_are_not_drawn_twice() {
|
||||
use egui::accesskit::Role;
|
||||
for (dialog, caption) in
|
||||
[("trackChangesOptions", "Balloons"), ("trackChangesOptions", "Comments"), ("pageNumbers", "Start at"), ("tableSort", "My list has")]
|
||||
{
|
||||
let mut app = app_with("Lanterns");
|
||||
if dialog == "tableSort" {
|
||||
app.run("insert.table", json!({"rows": 3, "cols": 3})).unwrap();
|
||||
}
|
||||
let mut h = app_harness(app);
|
||||
h.state_mut().run("ui.dialog", json!({"name": dialog})).unwrap();
|
||||
h.run_steps(6);
|
||||
let drawn = h.query_all(egui_kittest::kittest::By::new().role(Role::Label).label_contains(caption)).count();
|
||||
assert!(drawn <= 1, "{dialog} draws \"{caption}\" {drawn} times");
|
||||
}
|
||||
}
|
||||
|
||||
/// #7977: a preview picture is drawn at a sample size, not at the icon side it takes by default.
|
||||
#[test]
|
||||
fn dialog_previews_are_drawn_larger_than_a_control() {
|
||||
use egui::accesskit::Role;
|
||||
for dialog in ["enclose", "defineBullet"] {
|
||||
let mut h = app_harness(app_with("Lanterns"));
|
||||
h.state_mut().run("ui.dialog", json!({"name": dialog})).unwrap();
|
||||
h.run_steps(6);
|
||||
let preview = h.get_by_role_and_label(Role::Image, "Preview").rect();
|
||||
let button = h.get_by_role_and_label(Role::Button, "Cancel").rect();
|
||||
assert!(
|
||||
preview.height() > 2.0 * button.height(),
|
||||
"{dialog}: the preview is {}pt high beside a {}pt button",
|
||||
preview.height(),
|
||||
button.height()
|
||||
);
|
||||
}
|
||||
}
|
||||
/// #7982: Custom Properties' hint wraps inside the dialog instead of running under the Cancel button.
|
||||
#[test]
|
||||
fn custom_properties_hint_does_not_run_under_the_buttons() {
|
||||
use egui::accesskit::Role;
|
||||
let mut h = app_harness(app_with("Lanterns"));
|
||||
h.state_mut().run("ui.dialog", json!({"name": "customProperties"})).unwrap();
|
||||
h.run_steps(6);
|
||||
let hint = h.get_by_label_contains("Text properties only").rect();
|
||||
let cancel = h.get_by_role_and_label(Role::Button, "Cancel").rect();
|
||||
let value = h.get_by_role_and_label(Role::TextInput, "Value:").rect();
|
||||
assert!(!hint.intersects(cancel) && !value.intersects(cancel), "the hint {hint:?} or Value {value:?} overlaps Cancel {cancel:?}");
|
||||
}
|
||||
|
||||
/// #7970: Cell Margins shows the table's points in the interface unit (0.19 cm, not 5.4 cm), and OK without
|
||||
/// an edit leaves the table's margins as they were.
|
||||
#[test]
|
||||
@@ -2458,37 +2389,3 @@ fn the_organizer_lists_are_framed() {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Part of #7981 and #7980: the lists of Customize Ribbon and its Quick Access Toolbar page have a visible
|
||||
/// frame, as before the port; without it an empty list is a blank patch.
|
||||
#[test]
|
||||
fn the_ribbon_customizer_lists_are_framed() {
|
||||
use egui::accesskit::Role;
|
||||
fn rects<'a>(shape: &'a egui::Shape, out: &mut Vec<&'a egui::epaint::RectShape>) {
|
||||
match shape {
|
||||
egui::Shape::Vec(inner) => inner.iter().for_each(|s| rects(s, out)),
|
||||
egui::Shape::Rect(r) => out.push(r),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
fn assert_framed(h: &egui_kittest::Harness<'_, WordApp>, label: &str) {
|
||||
let list = h.get_by_role_and_label(Role::List, label).rect();
|
||||
let mut seen = Vec::new();
|
||||
h.output().shapes.iter().for_each(|c| rects(&c.shape, &mut seen));
|
||||
assert!(
|
||||
seen.iter().any(|r| r.stroke.width > 0.0
|
||||
&& r.stroke.color.a() > 0
|
||||
&& r.rect.contains_rect(list.shrink(2.0))
|
||||
&& list.expand(2.0).contains_rect(r.rect)),
|
||||
"the list {label:?} {list:?} has a border"
|
||||
);
|
||||
}
|
||||
let mut h = app_harness(app_with(""));
|
||||
open_named(&mut h, "customizeRibbon", json!({}));
|
||||
assert_framed(&h, "Categories:");
|
||||
assert_framed(&h, "Commands:");
|
||||
assert_framed(&h, "Ribbon tabs");
|
||||
h.get_by_role_and_label(Role::Tab, "Quick Access Toolbar").click();
|
||||
h.run_steps(3);
|
||||
assert_framed(&h, "Quick Access Toolbar");
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ use wordcraft_doc::math::{MNode, MRun, parse_linear};
|
||||
use wordcraft_engine::math_gallery::{BUILT_INS, STRUCTURES, SYMBOL_SETS};
|
||||
|
||||
use crate::WordApp;
|
||||
use crate::previews::{MathSource, math_key, math_picture, math_thumbnails};
|
||||
use crate::previews::{MathSource, math_key, math_painter, math_picture, math_thumbnails};
|
||||
use crate::ribbon::common::menu_button;
|
||||
|
||||
/// What each structure button shows.
|
||||
@@ -155,10 +155,14 @@ fn math_menu_button(ui: &mut Ui, picture: &str, label: &str, body: impl FnMut(&m
|
||||
let _ = menu_button(ui, face, tl!(label).to_string(), None, body);
|
||||
}
|
||||
|
||||
/// The size a symbol is set at. The strip's tiles are 24 pt wide and the picture is fitted to them, so it reads at
|
||||
/// about 16 pt (11 pt drew a speck).
|
||||
const SYMBOL_PT: f32 = 22.0;
|
||||
|
||||
/// The picture source of one symbol, as a literal run.
|
||||
fn symbol_source(c: char, ink: Color32) -> MathSource {
|
||||
pub(crate) fn symbol_source(c: char, ink: Color32) -> MathSource {
|
||||
let nodes = vec![MNode::Run(MRun { text: c.to_string(), lit: true, ..Default::default() })];
|
||||
MathSource::new(nodes, false, 11.0, [1, 1], ink)
|
||||
MathSource::new(nodes, false, SYMBOL_PT, [1, 1], ink).fitted()
|
||||
}
|
||||
|
||||
/// A grid of rendered math tiles, `(name, picture key)` each over its own source, shaped as the sources are;
|
||||
@@ -222,13 +226,14 @@ fn symbols(ui: &mut Ui, app: &mut WordApp) {
|
||||
let ink = ink(ui);
|
||||
let thumbs = math_thumbnails(ui.ctx());
|
||||
let sources: Vec<MathSource> = all.iter().map(|c| symbol_source(*c, ink)).collect();
|
||||
let painters: Vec<_> = all.iter().zip(&sources).map(|(c, source)| math_painter(math_key(&format!("sym:{c}")), &thumbs, source)).collect();
|
||||
let items: Vec<GalleryItem<'_, char>> = all
|
||||
.iter()
|
||||
.zip(&sources)
|
||||
.map(|(c, source)| GalleryItem {
|
||||
.zip(&painters)
|
||||
.map(|(c, paint)| GalleryItem {
|
||||
key: *c,
|
||||
label: Label::from(symbol_tooltip(*c, &math_placeholder(ui, &c.to_string()))),
|
||||
face: GalleryFace::rendered(math_key(&format!("sym:{c}")), &thumbs, source),
|
||||
face: GalleryFace::Paint(paint),
|
||||
})
|
||||
.collect();
|
||||
let mut sets = |ui: &mut Ui| {
|
||||
|
||||
@@ -10,7 +10,10 @@ use std::sync::Arc;
|
||||
use craft::theme::Mode;
|
||||
use craft::ui::display::Picture;
|
||||
use craft::ui::list::ThumbAspect;
|
||||
use craft::ui::primitives::textures::{LoadedPicture, Revision, ThumbRender, ThumbRequest, ThumbSource, ThumbnailOptions, Thumbnails};
|
||||
use craft::ui::primitives::ContentPainterCx;
|
||||
use craft::ui::primitives::textures::{
|
||||
LoadedPicture, Priority, Revision, ThumbPaint, ThumbRender, ThumbRequest, ThumbSource, ThumbnailOptions, Thumbnails,
|
||||
};
|
||||
use craft::ui::runtime::env::Label;
|
||||
use egui::{Color32, ColorImage, Vec2};
|
||||
use wordcraft_doc::props::CharProps;
|
||||
@@ -163,19 +166,37 @@ pub(crate) fn dim(img: &mut ColorImage) {
|
||||
|
||||
/// Renders an equation off the frame for [`math_picture`]: the inputs of one tile, owned so the render job
|
||||
/// can run on a queue lane.
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct MathSource {
|
||||
nodes: Arc<wordcraft_doc::math::Arg>,
|
||||
display: bool,
|
||||
pt: f32,
|
||||
aspect: [u16; 2],
|
||||
ink: Color32,
|
||||
/// Shrink `pt` until the ink clears the picture's edges (symbols of any width, in any font).
|
||||
fit: bool,
|
||||
}
|
||||
|
||||
impl MathSource {
|
||||
/// An equation of `nodes` (`display` style, font size `pt`) for a picture `aspect[0]` wide to `aspect[1]` high,
|
||||
/// inked `ink`. The picture is an ink mask baked in `ink`, so the theme's text colour is part of its revision.
|
||||
pub(crate) fn new(nodes: wordcraft_doc::math::Arg, display: bool, pt: f32, aspect: [u16; 2], ink: Color32) -> Self {
|
||||
MathSource { nodes: Arc::new(nodes), display, pt, aspect, ink }
|
||||
MathSource { nodes: Arc::new(nodes), display, pt, aspect, ink, fit: false }
|
||||
}
|
||||
|
||||
/// This source, its size cut down where its ink would reach the picture's edge.
|
||||
pub(crate) fn fitted(mut self) -> Self {
|
||||
self.fit = true;
|
||||
self
|
||||
}
|
||||
|
||||
/// The picture for a `w`×`h` pt box at `ppp`, fitted when asked.
|
||||
pub(crate) fn image(&self, w: f32, h: f32, ppp: f32) -> Option<ColorImage> {
|
||||
if self.fit {
|
||||
math_image_fitted(&self.nodes, self.display, self.pt, w, h, ppp)
|
||||
} else {
|
||||
math_image(&self.nodes, self.display, self.pt, w, h, ppp)
|
||||
}
|
||||
}
|
||||
|
||||
/// The shape the tile or button shows the picture in.
|
||||
@@ -199,10 +220,9 @@ impl ThumbSource<u64> for MathSource {
|
||||
}
|
||||
|
||||
fn render(&self, _key: &u64, request: &ThumbRequest) -> ThumbRender {
|
||||
let (nodes, display, pt, size, ink, ppp) =
|
||||
(Arc::clone(&self.nodes), self.display, self.pt, self.size_for(request), self.ink, request.pixels_per_point);
|
||||
let (source, size, ink, ppp) = (self.clone(), self.size_for(request), self.ink, request.pixels_per_point);
|
||||
ThumbRender::Later(Box::new(move |_| {
|
||||
Ok(match math_image(&nodes, display, pt, size.x, size.y, ppp) {
|
||||
Ok(match source.image(size.x, size.y, ppp) {
|
||||
Some(mut img) => {
|
||||
for p in &mut img.pixels {
|
||||
*p = Color32::from_rgba_unmultiplied(ink.r(), ink.g(), ink.b(), p.a());
|
||||
@@ -225,9 +245,47 @@ pub(crate) fn math_thumbnails(ctx: &egui::Context) -> Thumbnails<u64> {
|
||||
Thumbnails::in_context(ctx, "wordcraft.math", ThumbnailOptions::new())
|
||||
}
|
||||
|
||||
/// The picture request for a tile `rect`: sized by its short side. The picture is fitted into the rect, so a
|
||||
/// request from the long side of a tall tile (24 x 52 pt in the ribbon) shrinks the symbol to a speck.
|
||||
pub(crate) fn cell_request(rect: egui::Rect, pixels_per_point: f32) -> ThumbRequest {
|
||||
ThumbRequest::for_cell(rect.width().min(rect.height()), pixels_per_point)
|
||||
}
|
||||
|
||||
/// Paints the equation picture `key` in a rect, asked for at the size it is painted, for a `GalleryFace::Paint`. The
|
||||
/// picture is an ink mask, so it is drawn without the transparency grid; the store's placeholder shows until the render
|
||||
/// lands. lean: only `GalleryFace::rendered` lacks `Picture`'s `checker(false)`; drop this once it has one.
|
||||
pub(crate) fn math_painter<'a>(key: u64, thumbnails: &'a Thumbnails<u64>, source: &'a MathSource) -> impl Fn(&ContentPainterCx, egui::Rect) + 'a {
|
||||
move |cx, rect| {
|
||||
let request = cell_request(rect, cx.pixels_per_point());
|
||||
let state = thumbnails.state(cx.painter.ctx(), source, &key, &request, Priority::VISIBLE);
|
||||
thumbnails.paint(cx, rect, &state, &ThumbPaint::default().checker(false));
|
||||
}
|
||||
}
|
||||
|
||||
/// An equation picture that shows the framework's placeholder until the render lands.
|
||||
pub(crate) fn math_picture<'a>(label: impl Into<Label>, key: u64, thumbnails: &'a Thumbnails<u64>, source: &'a MathSource) -> Picture<'a> {
|
||||
Picture::rendered(label, key, thumbnails, source)
|
||||
Picture::rendered(label, key, thumbnails, source).checker(false)
|
||||
}
|
||||
|
||||
/// [`math_image`], redrawn smaller while the ink reaches within a margin of the picture's edge, so a glyph
|
||||
/// wider than the tile in this platform's font is shrunk to fit and narrow ones keep `pt`. Measured, not assumed.
|
||||
fn math_image_fitted(nodes: &wordcraft_doc::math::Arg, display: bool, pt: f32, w: f32, h: f32, ppp: f32) -> Option<ColorImage> {
|
||||
let mut pt = pt;
|
||||
let mut img = math_image(nodes, display, pt, w, h, ppp)?;
|
||||
for _ in 0..4 {
|
||||
let [iw, ih] = img.size;
|
||||
let margin = (iw / 16).max(2);
|
||||
let cols: Vec<usize> = (0..iw).filter(|x| (0..ih).any(|y| img.pixels[y * iw + x].a() > 64)).collect();
|
||||
let (Some(lo), Some(hi)) = (cols.first().copied(), cols.last().copied()) else { break };
|
||||
if lo >= margin && hi + margin < iw {
|
||||
break;
|
||||
}
|
||||
// Clipped ink under-measures, so always step down by at least a tenth.
|
||||
let room = iw.saturating_sub(2 * margin) as f32 / (hi - lo + 1) as f32;
|
||||
pt *= room.min(0.9);
|
||||
img = math_image(nodes, display, pt, w, h, ppp)?;
|
||||
}
|
||||
Some(img)
|
||||
}
|
||||
|
||||
/// An equation rasterised for a tile of `w`×`h` points, as an ink mask.
|
||||
|
||||
@@ -53,3 +53,23 @@ fn font_sample_shows_small_caps_and_the_script_mark() {
|
||||
assert_ne!(draw(&plain, None, false), draw(&plain, sup, false), "the mark is drawn");
|
||||
assert_ne!(draw(&plain, None, false), draw(&plain, None, true), "Switch Modes transforms the preview");
|
||||
}
|
||||
|
||||
/// #7975: a symbol in the Equation tab's strip reads in its tile, not as a speck. The real tile is 24 x 52 pt and the
|
||||
/// picture is fitted into it, so the ink as shown spans a third of the tile's width; wide arrows and operators keep
|
||||
/// their whole ink inside the picture (no clipping).
|
||||
#[test]
|
||||
fn symbol_thumbnails_read_in_the_strips_real_tiles() {
|
||||
let tile = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(24.0, 52.0));
|
||||
for c in ['=', '+', '\u{221E}', '\u{00B1}', '\u{27F9}', '\u{27FA}', '\u{27F7}', '\u{2230}'] {
|
||||
let source = crate::equation_tab::symbol_source(c, Color32::WHITE);
|
||||
let size = source.size_for(&cell_request(tile, 1.0));
|
||||
let img = source.image(size.x, size.y, 1.0).expect("renders");
|
||||
let [w, h] = img.size;
|
||||
let inked: Vec<(usize, usize)> = (0..w * h).filter(|i| img.pixels[*i].a() > 64).map(|i| (i % w, i / w)).collect();
|
||||
let (lo, hi) = (inked.iter().map(|p| p.0).min().unwrap_or(0), inked.iter().map(|p| p.0).max().unwrap_or(0));
|
||||
let fit = (tile.width() / w as f32).min(tile.height() / h as f32);
|
||||
let shown = (hi - lo + 1) as f32 * fit;
|
||||
assert!(shown * 3.0 >= tile.width(), "{c} is a speck: {shown} pt wide in a {} pt tile", tile.width());
|
||||
assert!(lo > 0 && hi + 1 < w, "{c} touches the picture's edge ({lo}..{hi} of {w})");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
use craft::behavior::IconId;
|
||||
use craft::keymap::CommandRef;
|
||||
use craft::menu::ribbon::{RibbonGroup, RibbonRow};
|
||||
use craft::menu::ribbon::{Gallery, GalleryFace, GalleryItem, RibbonGroup, RibbonRow};
|
||||
use craft::ui::buttons::{Arrangement, Button, ToggleButton};
|
||||
use craft::ui::contract::{Gap, Props as _, Show as _, ShowContainer as _};
|
||||
use craft::ui::layout_components::Stack;
|
||||
use craft::ui::list::ThumbAspect;
|
||||
use craft::ui::menu::MenuItem;
|
||||
use craft::ui::primitives::FacePaint;
|
||||
use craft::ui::tile_grid::{CaptionPlace, Tile};
|
||||
use craft::ui::primitives::{ContentPainterCx, FacePaint};
|
||||
|
||||
use super::common::{menu_button, size_field};
|
||||
use super::{WordApp, json};
|
||||
use crate::equation_tab::pick_tile;
|
||||
|
||||
/// Chart Design and SmartArt Design › Size: the selected graphic's height and width in points. A
|
||||
/// size outside the range is shown as it is and writes nothing.
|
||||
@@ -62,13 +60,23 @@ pub(super) fn smart_art_design(row: &mut RibbonRow<'_>, app: &mut WordApp) {
|
||||
let colors = g.colors;
|
||||
let theme = &theme;
|
||||
let line = craft::ui::style::rgba_color(craft::ui::runtime::env::Env::of(ui).tokens.color.text.muted);
|
||||
let picked = pick_tile(ui, tl!("Layouts"), 4, CaptionPlace::None, on, layouts.len(), |at| match layouts.get(at).copied() {
|
||||
Some(layout) => Tile::new(tl!(layout.label()).to_string())
|
||||
.thumb(ThumbAspect::new(46, 31), move |cx, r| crate::dialogs_smart_art::preview(cx, r, layout, colors, theme, line)),
|
||||
None => Tile::new(String::new()),
|
||||
});
|
||||
// One strip of small previews, as the old ribbon: the strip steps and its More button lists them all.
|
||||
let painters: Vec<Box<dyn Fn(&ContentPainterCx, egui::Rect) + '_>> = layouts
|
||||
.iter()
|
||||
.map(|&layout| {
|
||||
Box::new(move |cx: &ContentPainterCx, r: egui::Rect| crate::dialogs_smart_art::preview(cx, r, layout, colors, theme, line))
|
||||
as Box<dyn Fn(&ContentPainterCx, egui::Rect) + '_>
|
||||
})
|
||||
.collect();
|
||||
let items: Vec<GalleryItem<'_, usize>> = layouts
|
||||
.iter()
|
||||
.zip(&painters)
|
||||
.enumerate()
|
||||
.map(|(at, (layout, paint))| GalleryItem { key: at, label: tl!(layout.label()).into(), face: GalleryFace::Paint(&**paint) })
|
||||
.collect();
|
||||
let out = Gallery::new(tl!("Layouts").to_string(), &items, on.as_ref()).tiles(6, 3).aspect(ThumbAspect::new(46, 31)).show(ui);
|
||||
// A pick of the current layout does nothing.
|
||||
if let Some(layout) = picked.and_then(|i| layouts.get(i)).copied().filter(|l| *l != g.layout) {
|
||||
if let Some(layout) = out.picked.and_then(|i| layouts.get(i)).copied().filter(|l| *l != g.layout) {
|
||||
let _ = app.run("smartArt.layout", json!({"layout": layout.id()}));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3,9 +3,10 @@ use std::ops::RangeInclusive;
|
||||
use craft::keymap::CommandRef;
|
||||
use craft::menu::ribbon::{RibbonGroup, RibbonRow};
|
||||
use craft::ui::buttons::{Arrangement, Button};
|
||||
use craft::ui::contract::{Bind, BodyCx, Gap, Props as _, Show as _, ShowContainer as _, TooltipSpec, Trigger};
|
||||
use craft::ui::contract::{Bind, BodyCx, Gap, Props as _, Show as _, ShowContainer as _, Sizing, TooltipSpec, Trigger};
|
||||
use craft::ui::controls::disclosure::DisclosureGlyph;
|
||||
use craft::ui::display::Divider;
|
||||
use craft::ui::form::Field;
|
||||
use craft::ui::layout_components::{Row, Stack};
|
||||
use craft::ui::list::ThumbAspect;
|
||||
use craft::ui::menu::{Menu, MenuItem, MenuOutput};
|
||||
@@ -89,11 +90,17 @@ pub(super) fn custom_groups(row: &mut RibbonRow<'_>, app: &mut WordApp, groups:
|
||||
/// Esc cancels. A value outside `range` (points) is shown and writes nothing. `lock_aspect` false
|
||||
/// resizes the one side only.
|
||||
pub(super) fn size_field(ui: &mut Ui, app: &mut WordApp, label: &str, key: &str, pt: f32, lock_aspect: bool, range: RangeInclusive<f32>) {
|
||||
let field = NumberField::length(tl!(label).to_string(), Bind::given(Some(f64::from(pt))), crate::options::lengths(app.session.units()))
|
||||
.range(f64::from(*range.start())..=f64::from(*range.end()))
|
||||
.id_salt(("size_field", key));
|
||||
let events = field.show(ui).edit.events;
|
||||
let lengths = crate::options::lengths(app.session.units());
|
||||
let mut events = None;
|
||||
// The label shows beside the field, as the old ribbon drew `H: 252 pt`; the Field makes it the control's one accessible name.
|
||||
Field::new(tl!(label).to_string()).id_salt(("size_field_label", key)).sizing(Sizing::Content).show(ui, |ui, _| {
|
||||
let field = NumberField::length(tl!(label).to_string(), Bind::given(Some(f64::from(pt))), lengths)
|
||||
.range(f64::from(*range.start())..=f64::from(*range.end()))
|
||||
.id_salt(("size_field", key));
|
||||
events = Some(field.show(ui).edit.events);
|
||||
});
|
||||
let key = key.to_string();
|
||||
let Some(events) = events else { return };
|
||||
apply_edits(app, events, move |app, v: Option<f64>| {
|
||||
let Some(v) = v.map(|v| v as f32).filter(|v| range.contains(v)) else { return };
|
||||
let params = if lock_aspect { json!({ key.as_str(): v }) } else { json!({ key.as_str(): v, "lockAspect": false }) };
|
||||
|
||||
@@ -392,6 +392,22 @@ fn contextual_tabs_follow_the_selection() {
|
||||
}
|
||||
}
|
||||
|
||||
/// #7974: SmartArt Design keeps its Layouts gallery to one strip, as tall as the other groups, and the Size
|
||||
/// fields show their H: and W: labels.
|
||||
#[test]
|
||||
fn smart_art_design_layouts_are_one_strip_and_size_is_labelled() {
|
||||
use egui::accesskit::Role;
|
||||
let mut a = WordApp::new(Session::new(wordcraft_doc::Document::new()), crate::Services::default());
|
||||
a.run("insert.smartArt", json!({"layout": "cycle"})).unwrap();
|
||||
let h = tab_harness(a, "SmartArt Design");
|
||||
let height = |name: &str| h.get_by_role_and_label(Role::Group, name).rect().height();
|
||||
assert!(height("Layouts") <= height("Create Graphic") * 1.2, "Layouts: {} vs {}", height("Layouts"), height("Create Graphic"));
|
||||
for side in ["H:", "W:"] {
|
||||
let roles: Vec<Role> = h.query_all(By::new().label(side)).map(|n| n.accesskit_node().role()).collect();
|
||||
assert_eq!(roles, [Role::SpinButton], "{side} names its field once");
|
||||
}
|
||||
}
|
||||
|
||||
/// No group's content runs into its label: View › Show stacked four check boxes in a column
|
||||
/// made for three, so "Hide White Space" was drawn under "Show". Every tab, every language: each
|
||||
/// control lies inside its group's access node.
|
||||
|
||||
@@ -922,13 +922,10 @@ fn check_doctypes(pkg: &Package, acc: &mut Acc) {
|
||||
|
||||
/// The adverse non-relationships roles in the isolated, closure, and forms probe series.
|
||||
fn is_measured_adverse_doctype(form: scan::DoctypeForm, content_type: Option<&str>) -> bool {
|
||||
// Windows Word refuses a settings part with a DOCTYPE however its content type is cased (#7736 K3/K4).
|
||||
if content_type.is_some_and(|ct| ct.eq_ignore_ascii_case(package::SETTINGS_CONTENT_TYPE)) {
|
||||
return true;
|
||||
}
|
||||
match content_type {
|
||||
Some(
|
||||
package::STYLES_CONTENT_TYPE
|
||||
| package::SETTINGS_CONTENT_TYPE
|
||||
| package::FONT_TABLE_CONTENT_TYPE
|
||||
| package::THEME_CONTENT_TYPE
|
||||
| package::NUMBERING_CONTENT_TYPE
|
||||
|
||||
@@ -503,29 +503,6 @@ fn xml_doctype_internal_entity_in_diagram_definitions_warns() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn xml_doctype_in_settings_grades_the_same_whatever_the_content_type_casing() {
|
||||
// #7736 K3/K4: Windows Word refuses both packages; the grade must not depend on the Override's casing.
|
||||
let exact = "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml";
|
||||
let varied = "application/vnd.openxmlformats-officedocument.Wordprocessingml.Settings+XML";
|
||||
let grade = |content_type: &str| {
|
||||
let mut doc = Doc::minimal();
|
||||
doc.set_doc_rels(
|
||||
r#"<Relationship Id="rSet" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings" Target="settings.xml"/>"#,
|
||||
);
|
||||
doc.add_with_override(
|
||||
"word/settings.xml",
|
||||
content_type,
|
||||
r#"<!DOCTYPE w:settings [<!ENTITY greeting "hello">]><w:settings xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"/>"#,
|
||||
);
|
||||
let report = validate(&doc);
|
||||
let finding = assert_finding(&report, "XML-DOCTYPE", Some("word/settings.xml"));
|
||||
(finding.severity, finding.evidence)
|
||||
};
|
||||
assert_eq!(grade(exact), (Severity::Error, Evidence::Observed));
|
||||
assert_eq!(grade(varied), grade(exact));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn xml_doctype_attlist_in_diagram_layout_warns() {
|
||||
let mut doc = Doc::minimal();
|
||||
|
||||
@@ -189,7 +189,7 @@ def reviewed_manual_actors(caller_source, policy):
|
||||
|
||||
|
||||
def caller_pin(name):
|
||||
return re.findall(r"(?m)^ tooling-revision: (\S+)$", (ROOT / ".github/workflows" / name).read_text())[0]
|
||||
return re.findall(r"(?m)^ tooling-revision: ([0-9a-f]{40})$", (ROOT / ".github/workflows" / name).read_text())[0]
|
||||
|
||||
|
||||
class TrustedSourcePreparation(unittest.TestCase):
|
||||
@@ -354,7 +354,7 @@ class NightlyTrustAnchors(unittest.TestCase):
|
||||
self.assertEqual(tooling, uses, "the defining workflow SHA and tooling input must match")
|
||||
pins.update(uses)
|
||||
self.assertEqual(len(pins), 1, "producer and signer must pin the same shared commit")
|
||||
self.assertEqual(pins.pop(), "main", "pin storytold/craft-common-actions to @main")
|
||||
self.assertRegex(pins.pop(), r"^[0-9a-f]{40}$", "pin a full immutable commit, never a branch or placeholder")
|
||||
|
||||
|
||||
class NightlyEnabledCallers(unittest.TestCase):
|
||||
@@ -737,7 +737,7 @@ def trust_closure_problems(workflows):
|
||||
if workflow.lower() in ("nightly-release.yml", "nightly-release.yaml"):
|
||||
if name == "nightly-sign.yml":
|
||||
signer_calls += 1
|
||||
if name != "nightly-sign.yml" or ref != "main":
|
||||
if name != "nightly-sign.yml" or not re.fullmatch(r"[0-9a-f]{40}", ref):
|
||||
problems.append(name + " calls nightly-release.yml@" + ref)
|
||||
if workflow.lower() in ("release.yml", "release.yaml"):
|
||||
stable_callers.add(name)
|
||||
@@ -784,7 +784,7 @@ class NightlySignerBranchTrustClosure(unittest.TestCase):
|
||||
"environment in any flow mapping": {**tree, "extra.yml": "jobs:\n x:\n runs-on: ubuntu-latest\n with: {environment: release}\n"},
|
||||
"uses in any flow mapping": {**tree, "extra.yml": "jobs:\n x:\n steps:\n - {uses: actions/checkout@v4}\n"},
|
||||
"another caller of the signer": {**tree, "extra.yml": "jobs:\n x:\n uses: " + SHARED + "nightly-release.yml@" + "a" * 40 + "\n"},
|
||||
"a signer caller on a non-main branch or tag ref": {**tree, "nightly-sign.yml": tree["nightly-sign.yml"].replace("nightly-release.yml@main", "nightly-release.yml@v1")},
|
||||
"a mutable signer pin": {**tree, "nightly-sign.yml": re.sub(r"nightly-release\.yml@[0-9a-f]{40}", "nightly-release.yml@main", tree["nightly-sign.yml"])},
|
||||
"a new stable release caller": {**tree, "extra.yml": "jobs:\n x:\n uses: " + SHARED + "release.yml@main\n"},
|
||||
"a stable caller on a branch or tag ref": {**tree, "release.yml": tree["release.yml"].replace(SHARED + "release.yml@main", SHARED + "release.yml@v1")},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user