mirror of
https://github.com/storytold/designcraft.git
synced 2026-11-15 23:02:32 +00:00
This commit is contained in:
1 parent
963baa1bba
commit
8ad537632e
2 files changed
+48
-9
No files matched your search
@@ -8354,6 +8354,9 @@ const PREVIEW_FAILED: &str = "previewFailed";
|
||||
/// edited.
|
||||
fn justification(lang: &str, ui: &mut egui::Ui, d: &mut Dialog, prefix: &str, current: &Value) {
|
||||
let cur = |d: &Dialog, k: &str| d.fields.get(&format!("{prefix}{k}")).cloned().unwrap_or_else(|| current[k].clone());
|
||||
// The spacing table keeps its own grid: its columns are only as wide as the percent fields.
|
||||
// The rows below (a wide menu, composer buttons, long checkboxes) sit outside it, so they
|
||||
// cannot stretch its columns and push Desired and Maximum off-screen.
|
||||
egui::Grid::new("psj").num_columns(4).spacing([8.0, 6.0]).show(ui, |ui| {
|
||||
ui.label("");
|
||||
crate::rtl::label(ui, crate::i18n::tr(lang, "Minimum"));
|
||||
@@ -8377,6 +8380,8 @@ fn justification(lang: &str, ui: &mut egui::Ui, d: &mut Dialog, prefix: &str, cu
|
||||
d.fields.insert(format!("{prefix}autoLeading"), json!(auto_leading_typed(n)));
|
||||
}
|
||||
ui.end_row();
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
let single_label = crate::rtl::label(ui, crate::i18n::tr(lang, "Single Word Justification:"));
|
||||
let single = cur(d, "singleWordJustify");
|
||||
// Mixed (null) shows blank until a choice is made.
|
||||
@@ -8399,7 +8404,8 @@ fn justification(lang: &str, ui: &mut egui::Ui, d: &mut Dialog, prefix: &str, cu
|
||||
})
|
||||
.response
|
||||
.labelled_by(single_label.id);
|
||||
ui.end_row();
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
crate::rtl::label(ui, crate::i18n::tr(lang, "Composer:"));
|
||||
let composer = cur(d, "composer");
|
||||
// Mixed (null) selects neither; a Japanese composer keeps its kind.
|
||||
@@ -8411,20 +8417,20 @@ fn justification(lang: &str, ui: &mut egui::Ui, d: &mut Dialog, prefix: &str, cu
|
||||
if ui.selectable_label(known && single, crate::rtl::widget(ui, crate::i18n::tr(lang, "Single-line Composer"))).clicked() {
|
||||
d.fields.insert(format!("{prefix}composer"), json!(single_line));
|
||||
}
|
||||
ui.end_row();
|
||||
for (label, key, text, default) in [
|
||||
("Insert Kashidas:", "kashidas", "In justified Arabic text", true),
|
||||
("Korean Line Breaks:", "koreanCharBreaks", "Between syllables (not only at spaces)", false),
|
||||
] {
|
||||
});
|
||||
for (label, key, text, default) in [
|
||||
("Insert Kashidas:", "kashidas", "In justified Arabic text", true),
|
||||
("Korean Line Breaks:", "koreanCharBreaks", "Between syllables (not only at spaces)", false),
|
||||
] {
|
||||
ui.horizontal(|ui| {
|
||||
crate::rtl::label(ui, crate::i18n::tr(lang, label));
|
||||
let v = cur(d, key);
|
||||
let mut on = v.as_bool().unwrap_or(default);
|
||||
if ui.add(egui::Checkbox::new(&mut on, crate::rtl::widget(ui, crate::i18n::tr(lang, text))).indeterminate(v.is_null())).changed() {
|
||||
d.fields.insert(format!("{prefix}{key}"), json!(on));
|
||||
}
|
||||
ui.end_row();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
if let Some(e) = d.fields.get("justifyError").and_then(Value::as_str) {
|
||||
ui.add_space(6.0);
|
||||
crate::rtl::label(ui, egui::RichText::new(e).color(ui.visuals().error_fg_color));
|
||||
|
||||
@@ -1253,6 +1253,39 @@ fn paragraph_style_options_justification_sets_auto_leading_and_single_word_justi
|
||||
assert_eq!((para.auto_leading, para.single_word_justify), (Some(1.0), Some(designcraft_doc::Align::Right)));
|
||||
}
|
||||
|
||||
/// Paragraph Style Options › Justification fits at the normal dialog width: the spacing table
|
||||
/// keeps its own narrow columns (the wide Single Word Justification menu must not stretch
|
||||
/// them), so Minimum/Desired sit close together and Maximum stays in view with no horizontal
|
||||
/// scrolling.
|
||||
#[test]
|
||||
fn paragraph_style_options_justification_fits_without_horizontal_scrolling() {
|
||||
let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("file.new", json!({})).unwrap();
|
||||
app.run("style.paragraph.create", json!({"name": "Headline"})).unwrap();
|
||||
app.ui.dialog = Some(Dialog::new("paragraphStyleOptions", json!({"name": "Headline", "section": "justify"})));
|
||||
let ctx = dialog_context("en");
|
||||
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1200.0, 800.0));
|
||||
for _ in 0..3 {
|
||||
dialog_frame(&mut app, &ctx, screen, vec![]);
|
||||
}
|
||||
let labels = dialog_frame(&mut app, &ctx, screen, vec![]);
|
||||
let rect_of =
|
||||
|text: &str| labels.iter().find(|(t, _, _)| t.trim() == text).map(|(_, r, _)| *r).unwrap_or_else(|| panic!("{text} is painted: {labels:?}"));
|
||||
let (minimum, desired) = (rect_of("Minimum"), rect_of("Desired"));
|
||||
// Left edge to left edge of the two header labels. With the 130 pt Single Word menu sharing
|
||||
// the grid's column, column 1 stretches and this distance measures ~130+; with the spacing
|
||||
// table in its own grid it is ~70. The bound sits comfortably between the two.
|
||||
let gap = desired.min.x - minimum.min.x;
|
||||
assert!(gap < 100.0, "Minimum/Desired headers {gap:.1} pt apart: {minimum:?} {desired:?}");
|
||||
// The whole section stays inside the dialog: Maximum and every control label are painted
|
||||
// unclipped on screen (no horizontal scrolling needed to reach them).
|
||||
visible_label(&labels, screen, "Maximum");
|
||||
visible_label(&labels, screen, "Single Word Justification:");
|
||||
visible_label(&labels, screen, "Composer:");
|
||||
visible_label(&labels, screen, "Insert Kashidas:");
|
||||
visible_label(&labels, screen, "Korean Line Breaks:");
|
||||
}
|
||||
|
||||
fn command_app(id: &str, fields: Value) -> DesignApp {
|
||||
let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
|
||||
app.ui.dialog = Some(Dialog::new(&format!("cmd:{id}"), fields));
|
||||
|
||||
Reference in new issue
Block a user