Commit hovered font rows and avoid native clock calls in web character controls

This commit is contained in:
Codex committed 2026-11-30 13:21:47 +01:00
1 parent 891909a9d5
commit 98e5003ec3
2 files changed
+17 -12

No files matched your search

+16 -12
View File
@@ -6,7 +6,6 @@ use std::cell::RefCell;
use std::collections::HashSet;
use std::rc::Rc;
use std::sync::{Arc, Mutex, Weak};
use std::time::SystemTime;
// PLAN: assumed the framework paths below (craft::text::ui re-exports, craft_ui widgets and runtime, craft::font_manager).
use craft::behavior::EditEvent;
@@ -47,12 +46,15 @@ use crate::font_menu;
/// attributes of the paragraph the selection starts in (else of the first paragraph).
/// Font/paragraph controls and named-style capture use this; dimensional fields use `shared_effective`.
pub(crate) fn text_style(app: &VectorcraftApp) -> Option<(CharStyle, vectorcraft_doc::ParaStyle)> {
let state = app.session.active()?;
// Hover changes the canvas, but the picker compares its next row click against the committed font.
let doc = state.interaction.as_ref().filter(|_| app.font_preview_owner.is_some()).map_or(&state.doc, |preview| &preview.doc);
if let Some((id, a, b)) = text_editing(app)
&& let Some(NodeKind::Text(t)) = app.session.active().and_then(|d| d.doc.node(id)).map(|n| &n.kind)
&& let Some(NodeKind::Text(t)) = doc.node(id).map(|n| &n.kind)
{
return Some((vectorcraft_text::edit::insertion_style(&t.runs, a, b), t.para_at(t.paragraphs_in(a, a).start).clone()));
}
let t = first_selected_text(app)?;
let NodeKind::Text(t) = &first_selected_text_node_in(state, doc)?.kind else { return None };
Some((t.first_style(), t.para_at(0).clone()))
}
@@ -68,7 +70,11 @@ pub(crate) fn first_selected_text(app: &VectorcraftApp) -> Option<&vectorcraft_d
/// their descendants, in selection order, then paint order within each selected object.
pub(crate) fn first_selected_text_node(app: &VectorcraftApp) -> Option<&vectorcraft_doc::Node> {
let st = app.session.active()?;
for node in st.selection.objects.iter().filter_map(|id| st.doc.node(*id)) {
first_selected_text_node_in(st, &st.doc)
}
fn first_selected_text_node_in<'a>(state: &DocState, doc: &'a vectorcraft_doc::Document) -> Option<&'a vectorcraft_doc::Node> {
for node in state.selection.objects.iter().filter_map(|id| doc.node(*id)) {
let mut text = None;
node.walk(&mut |n| {
if text.is_none() && matches!(n.kind, NodeKind::Text(_)) {
@@ -1219,16 +1225,14 @@ pub(crate) fn controls(app: &mut VectorcraftApp, ui: &mut Ui, rows: CharacterRow
let languages: Option<Vec<(String, String)>> =
rows.contains(CharacterRows::STYLE_TOGGLES).then(|| LANGUAGES.iter().map(|(name, _, _)| (name.to_string(), name.to_string())).collect());
let catalog = vectorcraft_text::FontDb::global().catalog();
let before = font_menu::picker_settings(app);
let mut settings = before.clone();
let document = font_menu::document_family_set(app);
let recent = font_menu::recently_added_set(app, SystemTime::now());
let sets = font_menu::family_sets(Some(&document[..]), &recent[..]);
let mut hold = font_menu::hold(app);
let before = hold.settings.clone();
let sets = font_menu::family_sets(hold.document.as_deref(), &hold.recently_added);
let sample = font_menu::sample_text(app);
let unit = type_unit(app);
let mut source = FontPickerSource::new(catalog)
.settings(Bind::bound(&mut settings))
.filters(Bind::bound(&mut app.ui.font_filters))
.settings(Bind::bound(&mut hold.settings))
.filters(Bind::bound(&mut hold.filters))
.sets(&sets)
.scripts(&FontScript::ALL)
.filter_layout(FilterLayout::Toolbar);
@@ -1248,7 +1252,7 @@ pub(crate) fn controls(app: &mut VectorcraftApp, ui: &mut Ui, rows: CharacterRow
controls = controls.axes(FaceAxes::new(axes, instances).italic(face_of(&current.font_style).2));
}
let out = controls.show(ui);
font_menu::store_picker_settings(app, &before, settings);
hold.store(app, &before);
let CharacterControlsOutput { picker, preview_family, edits, .. } = out;
if let Some(owner) = picker {
font_menu::apply_preview(app, owner, preview_family);
+1
View File
@@ -86,6 +86,7 @@ fn preview_changes_the_text_live_and_only_a_choice_is_a_step() {
let before = steps(&app);
apply_preview(&mut app, owner(), Preview::Shows("Source Serif 4".into()));
assert_eq!(font_of(&app, id), "Source Serif 4", "previewed on the text");
assert_eq!(crate::panels::character::values(&mut app).family.as_deref(), Some("Inter"), "the picker must still be able to commit the previewed row");
apply_preview(&mut app, owner(), Preview::Shows("Source Sans 3".into()));
assert_eq!(font_of(&app, id), "Source Sans 3");
apply_preview(&mut app, owner(), Preview::Ended);