mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-17 08:26:28 +00:00
Properties: the Character section shows the Type tool selection's font style
While the Type tool edits text, the Properties panel's Character section showed the font family and style of the text object's first run. It now reads character::text_style, as the Character panel, the Control bar and the Contextual Task Bar do: the first selected character's style, or the style of the character before the caret. With the Selection tool it still shows the first run's. Fixes #8189.
This commit is contained in:
@@ -1015,11 +1015,13 @@ pub fn type_sections(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
dim_label(ui, tl!("Select a text object"));
|
||||
return;
|
||||
};
|
||||
let NodeKind::Text(tx) = &n.kind else {
|
||||
let NodeKind::Text(_) = &n.kind else {
|
||||
dim_label(ui, tl!("Select a text object"));
|
||||
return;
|
||||
};
|
||||
let s = tx.first_style();
|
||||
// The style of the Type tool's selection (or caret) when it edits text, else of the selected
|
||||
// text's first run, as the Character panel shows it (#8189).
|
||||
let Some((s, para)) = super::character::text_style(app) else { return };
|
||||
section_header(ui, tl!("Character"));
|
||||
// The font, Font Size, Leading, Kerning and Tracking as in the Character panel.
|
||||
let w = ui.available_width();
|
||||
@@ -1029,25 +1031,23 @@ pub fn type_sections(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
section_header(ui, tl!("Paragraph"));
|
||||
// As in the Paragraph panel: the seven alignments and Hyphenate (#775), and area type's
|
||||
// vertical alignment (#3759); the rest is there.
|
||||
if let Some((_, para)) = super::character::text_style(app) {
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = 3.0;
|
||||
super::paragraph::alignment_buttons(app, ui, ¶, 24.0);
|
||||
if widgets::icon_button(ui, "ellipsis", tl!("More Paragraph options"), false, 24.0).clicked() {
|
||||
app.ui.open_panel = Some("paragraph".into());
|
||||
}
|
||||
});
|
||||
// Area type: its vertical alignment in the frame (#3759).
|
||||
if vertical_align::shown(app).is_some() {
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = 3.0;
|
||||
super::paragraph::alignment_buttons(app, ui, ¶, 24.0);
|
||||
if widgets::icon_button(ui, "ellipsis", tl!("More Paragraph options"), false, 24.0).clicked() {
|
||||
app.ui.open_panel = Some("paragraph".into());
|
||||
}
|
||||
vertical_align::buttons(app, ui, 24.0);
|
||||
});
|
||||
// Area type: its vertical alignment in the frame (#3759).
|
||||
if vertical_align::shown(app).is_some() {
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = 3.0;
|
||||
vertical_align::buttons(app, ui, 24.0);
|
||||
});
|
||||
}
|
||||
super::paragraph::hyphenate_check(app, ui, ¶);
|
||||
// Area type: Dynamic Text's Block and its gaps.
|
||||
dynamic_text::rows(app, ui);
|
||||
}
|
||||
super::paragraph::hyphenate_check(app, ui, ¶);
|
||||
// Area type: Dynamic Text's Block and its gaps.
|
||||
dynamic_text::rows(app, ui);
|
||||
}
|
||||
|
||||
pub(crate) mod dynamic_text;
|
||||
|
||||
@@ -2165,3 +2165,34 @@ fn the_graph_section_needs_one_graph_selected() {
|
||||
app.run("select.set", json!({"ids": [groups[0], series_groups(&app, b)[0]]})).unwrap();
|
||||
assert_eq!(graph::shown(&app), None, "series of two graphs");
|
||||
}
|
||||
|
||||
/// With the Type tool, the Character section's font style shows the style of the first selected
|
||||
/// character (or of the character before the caret), not the text object's first run; with the
|
||||
/// Selection tool, the first run's (#8189).
|
||||
#[test]
|
||||
fn character_section_shows_the_type_tool_selections_style() {
|
||||
use vectorcraft_text::test_fonts::{TWO_AXIS_FAMILY, two_axis_font};
|
||||
vectorcraft_text::FontDb::global().add_font(two_axis_font().unwrap());
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 300, "height": 200})).unwrap();
|
||||
app.session.select_tool("type", Default::default()).unwrap();
|
||||
// Regular 0..8, Bold 8..13, Condensed 13..22.
|
||||
let id = app.run("text.create", json!({"x": 20, "y": 50, "text": "Regular Bold Condensed", "font": TWO_AXIS_FAMILY})).unwrap()["id"].clone();
|
||||
app.session.apply_actions(vec![vectorcraft_tools::Action::Notify("text.editNew".into())]).unwrap();
|
||||
app.run("text.setRangeStyle", json!({"id": id, "start": 8, "end": 13, "style": "Bold"})).unwrap();
|
||||
app.run("text.setRangeStyle", json!({"id": id, "start": 13, "end": 22, "style": "Condensed"})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let shown = |app: &mut VectorcraftApp| {
|
||||
let texts = panel_frame(app, &ctx, vec![], type_sections);
|
||||
texts.into_iter().map(|(t, _)| t).filter(|t| ["Regular", "Bold", "Condensed"].contains(&t.as_str())).collect::<Vec<_>>()
|
||||
};
|
||||
for (start, end, want) in [(8, 12, "Bold"), (13, 22, "Condensed"), (0, 7, "Regular"), (15, 15, "Condensed"), (13, 13, "Bold")] {
|
||||
app.session.set_tool_option("select", &json!({"start": start, "end": end}));
|
||||
assert_eq!(crate::panels::character::text_editing(&app).map(|(_, a, b)| (a, b)), Some((start, end)));
|
||||
assert_eq!(shown(&mut app), [want], "{start}..{end}");
|
||||
}
|
||||
app.session.select_tool("selection", Default::default()).unwrap();
|
||||
app.run("select.set", json!({"ids": [id]})).unwrap();
|
||||
assert_eq!(crate::panels::character::text_editing(&app), None);
|
||||
assert_eq!(shown(&mut app), ["Regular"], "the Selection tool shows the first run's style");
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user