mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-21 20:39:29 +00:00
Merge pull request #2480 from storytold/feat/text-position-2338
M4: Type settings ▸ Details ▸ Position sets superscript or subscript (#2338)
This commit is contained in:
@@ -1552,9 +1552,11 @@ name = "English"
|
||||
"Stylistic set 3" = "Stylistic set 3"
|
||||
"Stylistic set 4" = "Stylistic set 4"
|
||||
"Stylistic set 5" = "Stylistic set 5"
|
||||
"Subscript" = "Subscript"
|
||||
"Subtract" = "Subtract"
|
||||
"Subtracts" = "Subtracts"
|
||||
"Suffix" = "Suffix"
|
||||
"Superscript" = "Superscript"
|
||||
"Suspend snapping while dragging" = "Suspend snapping while dragging"
|
||||
"Swap instance" = "Swap instance"
|
||||
"Swap library: use another library's assets of the same names" = "Swap library: use another library's assets of the same names"
|
||||
|
||||
@@ -429,4 +429,32 @@ mod variable_tests {
|
||||
let t = p.app.session.doc().unwrap().node(p.text).unwrap().kind.text().unwrap().clone();
|
||||
assert_eq!((t.para_wrap_style(0), t.para_wrap_style(1)), (WrapStyle::Balance, WrapStyle::Balance));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn details_position_sets_superscript_subscript_or_neither() {
|
||||
// #2338: Type settings ▸ Details ▸ Position, for the selected layer.
|
||||
let mut p = settings_panel();
|
||||
// The tab is a clickable label: its text is the node's value.
|
||||
let tab = p.nodes.iter().find(|n| n.value() == Some("Details") || n.label() == Some("Details")).expect("the Details tab");
|
||||
let r = tab.bounds().expect("bounds");
|
||||
p.click(Pos2::new(((r.x0 + r.x1) / 2.0) as f32, ((r.y0 + r.y1) / 2.0) as f32));
|
||||
p.frame(vec![]);
|
||||
let on = |p: &Panel| {
|
||||
let toggled = |l: &str| p.nodes.iter().find(|n| n.label() == Some(l)).and_then(|n| n.toggled());
|
||||
["None", "Superscript", "Subscript"].into_iter().filter(|l| toggled(l) == Some(egui::accesskit::Toggled::True)).collect::<Vec<_>>()
|
||||
};
|
||||
let feats = |p: &Panel| {
|
||||
let t = p.app.session.doc().unwrap().node(p.text).unwrap().kind.text().unwrap().features.clone();
|
||||
(t.get("sups").copied(), t.get("subs").copied())
|
||||
};
|
||||
assert_eq!(on(&p), ["None"]);
|
||||
for (label, want) in [("Superscript", (Some(true), None)), ("Subscript", (None, Some(true))), ("None", (None, None))] {
|
||||
let at = node_center(&p, label);
|
||||
p.click(at);
|
||||
p.frame(vec![]);
|
||||
assert_eq!(feats(&p), want, "{label}");
|
||||
assert_eq!(on(&p), [label]);
|
||||
}
|
||||
assert!(p.app.ui.last_error.is_none(), "{:?}", p.app.ui.last_error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -469,6 +469,7 @@ fn type_settings(
|
||||
let face = uniform(styles, |s| (s.font_family.clone(), s.font_style.clone())).and_then(|(f, s)| figcraft_text::find_face(&f, &s));
|
||||
let face_name = face.as_ref().map(|f| format!("{} {}", f.family, f.style)).unwrap_or_else(|| tr("Mixed fonts").into());
|
||||
widgets::label(ui, &face_name, t.text_secondary);
|
||||
position_row(app, ui, doc, ids, w);
|
||||
egui::ScrollArea::vertical().max_height(320.0).show(ui, |ui| {
|
||||
for (tag, label, default_on) in FEATURES {
|
||||
let state = common(doc, ids, |n| n.kind.text().map(|t| t.features.get(tag).copied())).flatten();
|
||||
@@ -485,6 +486,21 @@ fn type_settings(
|
||||
}
|
||||
}
|
||||
|
||||
/// Position: the layers' text as superscript or subscript (`sups`, `subs`; drawn smaller and
|
||||
/// raised or lowered where the font has no glyphs for them), or neither. `sups` wins when a layer
|
||||
/// has both, as when it is drawn (#2338).
|
||||
fn position_row(app: &mut FigApp, ui: &mut Ui, doc: &Document, ids: &[NodeId], w: f32) {
|
||||
caption(ui, tr("Position"));
|
||||
let on = |t: &figcraft_doc::TextData, tag: &str| t.features.get(tag).copied().unwrap_or(false);
|
||||
let active = common(doc, ids, |n| n.kind.text().map(|t| if on(t, "sups") { 1 } else { usize::from(on(t, "subs")) * 2 })).flatten();
|
||||
let items = [("—", tr_noop("None")), ("X²", tr_noop("Superscript")), ("X₂", tr_noop("Subscript"))];
|
||||
if let Some(i) = text_seg(ui, "position", &items, active, w) {
|
||||
let want = |k: usize| if i == k { json!(true) } else { Value::Null };
|
||||
app.run("text.setFeatures", json!({"ids": ids, "features": {"sups": want(1), "subs": want(2)}}));
|
||||
}
|
||||
ui.add_space(4.0);
|
||||
}
|
||||
|
||||
/// How the decoration looks: style, thickness, (underlines) offset and skip ink, and colour.
|
||||
fn decoration_details(app: &mut FigApp, ui: &mut Ui, styles: &[TextStyle], apply_style: &dyn Fn(&mut FigApp, &str, Value), underline: bool, w: f32) {
|
||||
caption(ui, tr("Decoration style"));
|
||||
|
||||
+3
-2
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user