mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
ui-egui: keep an axis change at the caret over the chosen font's saved axes
rebase put the chosen font's saved variations back after every change, so an axis change at the caret reverted. Axes the change sets now win; the others keep their chosen values.
This commit is contained in:
1 parent
20201d4ed4
commit
c06f404773
3 files changed
+38
-2
No files matched your search
@@ -248,7 +248,7 @@ pub(super) fn apply(app: &mut PhotocraftApp, props: serde_json::Value, coalesce:
|
||||
if app.run("type.setStyle", p).is_ok()
|
||||
&& let Some(kept) = kept
|
||||
{
|
||||
insertion_style::rebase(app, kept);
|
||||
insertion_style::rebase(app, kept, &props);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -408,3 +408,29 @@ fn a_digits_change_at_the_caret_keeps_the_chosen_typing_font() {
|
||||
});
|
||||
assert_eq!(digits, Some(photocraft_doc::text::Digits::Devanagari), "the typed digit takes the picked digit style");
|
||||
}
|
||||
|
||||
/// An axis change at the caret after a font was chosen there wins over the chosen font's saved axes; the axes it does
|
||||
/// not set keep their chosen values.
|
||||
#[test]
|
||||
fn an_axis_change_at_the_caret_keeps_its_value_with_the_chosen_typing_font() {
|
||||
let (mut h, id) = fixture(0, "abcdef");
|
||||
h.state_mut().run("type.setStyle", json!({"layer": id.0, "variations": {"wght": 650, "wdth": 95}})).unwrap();
|
||||
select(&mut h, [3, 3]);
|
||||
h.run();
|
||||
choose(&mut h, FONTS[1], "enter");
|
||||
super::apply(h.state_mut(), json!({"variations": {"wdth": 110}}), None);
|
||||
super::host::type_text(h.state_mut(), "X");
|
||||
h.run();
|
||||
assert_eq!(families(&saved(&h, id))[3], FONTS[1], "the typed letter takes the chosen font");
|
||||
let mut offset = 0;
|
||||
let axes = layer(&h.state().session.active().unwrap().doc, id)
|
||||
.char_runs()
|
||||
.into_iter()
|
||||
.find_map(|r| {
|
||||
offset += r.len;
|
||||
(offset > 3).then_some(r.style.variations)
|
||||
})
|
||||
.unwrap();
|
||||
assert!(axes.iter().any(|v| v.axis == "wdth" && v.value == 110.0), "the changed axis holds: {axes:?}");
|
||||
assert!(axes.iter().any(|v| v.axis == "wght" && v.value == 650.0), "an axis the change left keeps its value: {axes:?}");
|
||||
}
|
||||
@@ -52,7 +52,7 @@ pub(super) fn set_font(app: &mut PhotocraftApp, props: &serde_json::Value) -> bo
|
||||
/// Keeps the caret's pending font `kept` after another character change at the same caret: the style the command
|
||||
/// stored there (in the layer's own units) with the chosen font on it, for the new revision, so the next typed text
|
||||
/// still takes the chosen font and the change.
|
||||
pub(super) fn rebase(app: &mut PhotocraftApp, mut kept: TypeInsertionStyle) {
|
||||
pub(super) fn rebase(app: &mut PhotocraftApp, mut kept: TypeInsertionStyle, props: &serde_json::Value) {
|
||||
let Some((mut style, _)) = styles_at(app) else { return };
|
||||
let Some(st) = app.session.active() else { return };
|
||||
let chosen = &kept.style;
|
||||
@@ -61,6 +61,16 @@ pub(super) fn rebase(app: &mut PhotocraftApp, mut kept: TypeInsertionStyle) {
|
||||
style.italic = chosen.italic;
|
||||
style.postscript_name.clone_from(&chosen.postscript_name);
|
||||
style.variations.clone_from(&chosen.variations);
|
||||
// An axis the change set itself wins over the chosen font's saved value; the others stay as chosen.
|
||||
if let Some(axes) = props.get("variations").and_then(serde_json::Value::as_object) {
|
||||
for (axis, value) in axes {
|
||||
let Some(value) = value.as_f64() else { continue };
|
||||
match style.variations.iter_mut().find(|v| v.axis == *axis) {
|
||||
Some(v) => v.value = value as f32,
|
||||
None => style.variations.push(photocraft_doc::text::FontVariation { axis: axis.clone(), value: value as f32 }),
|
||||
}
|
||||
}
|
||||
}
|
||||
kept.style = style;
|
||||
kept.revision = st.revision;
|
||||
app.ui.type_insertion_style = Some(kept);
|
||||
|
||||
Reference in new issue
Block a user