mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-18 16:37:32 +00:00
Merge pull request #8340 from dotCooCoo/feat/font-menu-sample-size
Font menu: Small, Medium and Large set the sample size from inside the menu
This commit is contained in:
@@ -583,6 +583,7 @@ impl VectorcraftApp {
|
||||
self.ime_caret_rect = None;
|
||||
scrub::begin_frame(self, &ctx);
|
||||
font_menu::end_stale_preview(self, &ctx);
|
||||
font_menu::apply_preview_size(self, &ctx);
|
||||
tools_float::track(self, &ctx);
|
||||
// A selection move released over a panel ends before any panel sees the release (#2826).
|
||||
canvas::release_over_panel(self, &ctx);
|
||||
|
||||
@@ -13,9 +13,12 @@
|
||||
//! they look to it ([`vectorcraft_text::FontDb::similar_families`]), that family first and without the Recent
|
||||
//! Fonts section, until the ≈ chip under the filters clears it or the menu closes. The Font
|
||||
//! Technology filter's Variable lists only variable font families. Preferences › Type › Enable
|
||||
//! in-menu font previews and Font Preview Size turn the samples off or size the rows. The menu lays
|
||||
//! out its filters on the same five rows wherever it opens. However narrow its field, it opens at
|
||||
//! least wide enough for those rows and for a family name up to 220 points wide with its sample
|
||||
//! in-menu font previews and Font Preview Size turn the samples off or size the rows. While the
|
||||
//! samples are shown, a row under the filters sets Font Preview Size to Small, Medium or Large
|
||||
//! ([`apply_preview_size`]), which sizes the rows of every font menu, and the list stays on the
|
||||
//! rows it showed. The menu lays out its filters on the same five rows wherever it opens, with the
|
||||
//! size row under them while the samples are shown. However narrow its field, it opens at least
|
||||
//! wide enough for those rows and for a family name up to 220 points wide with its sample
|
||||
//! beside it, up to 60% of the window; each sample fills its row's height. Recently used families
|
||||
//! appear first, in the order they were last applied, within the same search and filters as the
|
||||
//! remaining families. In the Character and Properties panels and the Control bar,
|
||||
@@ -185,11 +188,7 @@ impl Default for MenuLook<'static> {
|
||||
|
||||
impl<'a> MenuLook<'a> {
|
||||
pub fn of(app: &'a VectorcraftApp) -> Self {
|
||||
let row = match app.session.prefs.font_preview_size.as_str() {
|
||||
"small" => 20.0,
|
||||
"large" => 32.0,
|
||||
_ => ROW,
|
||||
};
|
||||
let row = preview_row(&app.session.prefs.font_preview_size);
|
||||
Self {
|
||||
samples: app.session.prefs.font_preview,
|
||||
on_white: app.session.prefs.font_samples_on_white,
|
||||
@@ -211,6 +210,22 @@ impl<'a> MenuLook<'a> {
|
||||
|
||||
/// Height of a row, in points (Font Preview Size: Medium).
|
||||
const ROW: f32 = 24.0;
|
||||
/// Font Preview Size's values (Preferences › Type), each with the row height it gives.
|
||||
const PREVIEW_SIZES: [(&str, f32); 3] = [("small", 20.0), ("medium", ROW), ("large", 32.0)];
|
||||
|
||||
/// The row height of Font Preview Size `size`: Medium's for a value it does not have.
|
||||
fn preview_row(size: &str) -> f32 {
|
||||
PREVIEW_SIZES.iter().find(|(key, _)| *key == size).map_or(ROW, |(_, row)| *row)
|
||||
}
|
||||
|
||||
/// The label of Font Preview Size `size`, as Preferences names it.
|
||||
fn preview_size_label(size: &str) -> &'static str {
|
||||
match size {
|
||||
"small" => tl!("Small"),
|
||||
"large" => tl!("Large"),
|
||||
_ => tl!("Medium"),
|
||||
}
|
||||
}
|
||||
/// Width of the star at the end of a family's row.
|
||||
const STAR: f32 = 18.0;
|
||||
/// Width of the Show Similar Fonts button before the star.
|
||||
@@ -453,6 +468,9 @@ struct MenuState {
|
||||
header: f32,
|
||||
/// The width of the widest row of filters without wrapping, last frame.
|
||||
filters: f32,
|
||||
/// The rows' height last frame, and how far down the list its view began, in rows. At a new
|
||||
/// height (Font Preview Size) the list scrolls back to the same row.
|
||||
scrolled: Option<(f32, f32)>,
|
||||
/// The families the wheel steps through, listed at its first notch over the closed field and
|
||||
/// kept for that text selection while the pointer stays on it: each step makes its family a recent one, which would
|
||||
/// otherwise move it in the order. The Document filter's families are kept the same way: a
|
||||
@@ -1307,7 +1325,7 @@ fn header<'s>(ui: &mut Ui, db: &'s vectorcraft_text::FontDb, state_id: egui::Id,
|
||||
ui.memory_mut(|m| m.request_focus(field.with("edit")));
|
||||
}
|
||||
let query = widgets::search_field(ui, field, tl!("Search")).to_lowercase();
|
||||
let refilter = filters(ui, st, &t, look.document.is_some());
|
||||
let refilter = filters(ui, st, &t, look.document.is_some(), look.samples.then_some(look.row));
|
||||
let added = added_families(db, st, look);
|
||||
// On the system clock, the list is drawn again when a family's 30 days end.
|
||||
if let (Some(at), None) = (added.as_ref().and_then(|a| a.recheck_at), look.clock)
|
||||
@@ -1440,9 +1458,11 @@ fn filter_rows() -> [Vec<Chip>; 5] {
|
||||
}
|
||||
|
||||
/// The filters on their rows ([`filter_rows`]): a row wraps only where the menu is narrower than
|
||||
/// it. The Document filter is unavailable without a `document`. Records in `st` the width of the
|
||||
/// widest row unwrapped; whether a filter changed.
|
||||
fn filters(ui: &mut Ui, st: &mut MenuState, t: &Tokens, document: bool) -> bool {
|
||||
/// it. The Document filter is unavailable without a `document`. With `row` (the rows' height while
|
||||
/// samples are shown), a row under them offers Font Preview Size's values, the one of that height
|
||||
/// selected; a click on one asks for it ([`apply_preview_size`]). Records in `st` the width of the
|
||||
/// widest row unwrapped, the size row included; whether a filter changed.
|
||||
fn filters(ui: &mut Ui, st: &mut MenuState, t: &Tokens, document: bool, row: Option<f32>) -> bool {
|
||||
let mut refilter = false;
|
||||
let mut widest = 0.0_f32;
|
||||
for row in filter_rows() {
|
||||
@@ -1492,6 +1512,31 @@ fn filters(ui: &mut Ui, st: &mut MenuState, t: &Tokens, document: bool) -> bool
|
||||
widest = widest.max(width);
|
||||
});
|
||||
}
|
||||
if let Some(row) = row {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.spacing_mut().item_spacing = vec2(4.0, 2.0);
|
||||
let gap = ui.spacing().item_spacing.x;
|
||||
let text = |s: &str| egui::RichText::new(s).size(FILTER_SIZE);
|
||||
let mut width = ui.label(text(tl!("Font Preview Size")).color(t.text_dim)).rect.width();
|
||||
// Screen readers find the three sizes in a radio group named after the row.
|
||||
let group = egui::UiBuilder::new().accessibility_role(egui::accesskit::Role::RadioGroup).accessibility_label(tl!("Font Preview Size"));
|
||||
ui.scope_builder(group, |ui| {
|
||||
for (size, height) in PREVIEW_SIZES {
|
||||
let on = (height - row).abs() < 0.5;
|
||||
let label = preview_size_label(size);
|
||||
let resp = ui.selectable_label(on, text(label));
|
||||
resp.widget_info(|| egui::WidgetInfo::selected(egui::Role::RadioButton, true, on, label));
|
||||
width += gap + resp.rect.width();
|
||||
if resp.clicked() {
|
||||
ui.data_mut(|d| d.insert_temp(preview_size_id(), size));
|
||||
// A focused button is activated by Enter; the list must not read it as a pick.
|
||||
ui.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Enter));
|
||||
}
|
||||
}
|
||||
});
|
||||
widest = widest.max(width);
|
||||
});
|
||||
}
|
||||
st.filters = widest;
|
||||
// While Show Similar Fonts orders the list: the family it orders by, which clears it. Its
|
||||
// width is left out of the widest row: a long name wraps instead of widening the menu.
|
||||
@@ -1679,8 +1724,16 @@ fn rows(ui: &mut Ui, range: std::ops::Range<usize>, h: Listed<'_>, sample: Optio
|
||||
let place = egui::Rect::from_min_size(egui::pos2(left, top + i as f32 * row_h), vec2(width, row_h));
|
||||
ui.scroll_to_rect_animation(place, align, egui::style::ScrollAnimation::none());
|
||||
};
|
||||
// At a new row height (Font Preview Size, set from the menu), the view stays on the rows it
|
||||
// showed: the scroll offset is in points.
|
||||
let at = (ui.clip_rect().top() - top) / row_h;
|
||||
let kept = st.scrolled.filter(|&(h, _)| !opening && (h - row_h).abs() > 0.5).map(|(_, at)| at);
|
||||
st.scrolled = Some((row_h, kept.unwrap_or(at)));
|
||||
if let Some((i, align)) = scroll_target(st, &rows, opening, keyed) {
|
||||
scroll_to(ui, i, align);
|
||||
} else if let Some(at) = kept {
|
||||
let place = egui::Rect::from_min_size(egui::pos2(left, top + at * row_h), vec2(width, row_h));
|
||||
ui.scroll_to_rect_animation(place, Some(egui::Align::TOP), egui::style::ScrollAnimation::none());
|
||||
}
|
||||
let mut chosen: Option<(String, Option<String>)> = None;
|
||||
let mut hovered: Option<usize> = None;
|
||||
@@ -2027,6 +2080,31 @@ fn open_id() -> egui::Id {
|
||||
egui::Id::unique("font-menu-open")
|
||||
}
|
||||
|
||||
/// The id under which a font menu keeps the Font Preview Size its buttons asked for, until
|
||||
/// [`apply_preview_size`] sets it.
|
||||
fn preview_size_id() -> egui::Id {
|
||||
egui::Id::unique("font-menu-preview-size")
|
||||
}
|
||||
|
||||
/// Set the Font Preview Size (Preferences › Type) that a font menu's Small, Medium or Large button
|
||||
/// asked for in the last pass, which sizes the rows of every font menu, and have the host write the
|
||||
/// preferences file as it does when Preferences is confirmed. Nothing runs when it is already that
|
||||
/// size; a saved value that is none of the sizes is replaced. The shell calls it at the start of
|
||||
/// each frame.
|
||||
pub(crate) fn apply_preview_size(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
||||
let Some(size) = ctx.data_mut(|d| d.remove_temp::<&'static str>(preview_size_id())) else { return };
|
||||
if app.session.prefs.font_preview_size == size {
|
||||
return;
|
||||
}
|
||||
match app.run("prefs.set", json!({"key": "fontPreviewSize", "value": size})) {
|
||||
Ok(_) => {
|
||||
crate::prefs_dialog::snapshot(app);
|
||||
app.prefs_changed = true;
|
||||
}
|
||||
Err(e) => app.ui.status = e,
|
||||
}
|
||||
}
|
||||
|
||||
/// Undo a preview whose menu is gone (its panel wasn't drawn: the text was deselected, the panel
|
||||
/// closed) or is closing (Escape, a press outside the menu), before anything else sees this
|
||||
/// frame's input: the canvas must not act inside the preview's interaction (a drag would be
|
||||
|
||||
@@ -1468,3 +1468,212 @@ fn the_recently_added_filter_lists_a_font_installed_just_now() {
|
||||
assert!(st.rows.is_empty(), "31 days later: {:?}", st.rows);
|
||||
std::fs::remove_dir_all(&dir).unwrap();
|
||||
}
|
||||
|
||||
/// While the samples are shown, a row under the filters offers Font Preview Size's Small, Medium
|
||||
/// and Large at every size of the rows: a click on one asks for that size ([`super::apply_preview_size`]
|
||||
/// leaves the rows' own size as it is). Without samples the row is not drawn.
|
||||
#[test]
|
||||
fn the_preview_size_row_asks_for_the_size_clicked() {
|
||||
// The bundled fonts alone: fonts that tests running alongside add stay out of the rows.
|
||||
let db = vectorcraft_text::FontDb::with_font_dirs(vec![]);
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
let mut st = super::MenuState::default();
|
||||
for size in ["small", "medium", "large"] {
|
||||
let look = super::MenuLook { row: super::preview_row(size), ..Default::default() };
|
||||
let shapes = settle_menu_of(&ctx, &db, &mut st, look, vec![]);
|
||||
assert!(text_at(&shapes, |t| t == "Font Preview Size").is_some(), "the row is drawn at {size}");
|
||||
let mut click = |label: &str| {
|
||||
let shapes = settle_menu_of(&ctx, &db, &mut st, look, vec![]);
|
||||
let at = text_at(&shapes, |t| t == label).unwrap_or_else(|| panic!("{label} is drawn at {size}"));
|
||||
let button =
|
||||
|pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
|
||||
settle_menu_of(&ctx, &db, &mut st, look, vec![egui::Event::PointerMoved(at), button(true)]);
|
||||
settle_menu_of(&ctx, &db, &mut st, look, vec![button(false)]);
|
||||
ctx.data_mut(|d| d.remove_temp::<&'static str>(super::preview_size_id()))
|
||||
};
|
||||
assert_eq!(click("Large"), Some("large"), "at {size}");
|
||||
assert_eq!(click("Small"), Some("small"), "at {size}");
|
||||
assert_eq!(click("Medium"), Some("medium"), "at {size}");
|
||||
}
|
||||
let look = super::MenuLook { row: super::preview_row("medium"), ..Default::default() };
|
||||
let shapes = settle_menu_of(&ctx, &db, &mut st, super::MenuLook { samples: false, ..look }, vec![]);
|
||||
assert!(text_at(&shapes, |t| t == "Font Preview Size").is_none(), "without samples the row is not drawn");
|
||||
super::wait_for_samples(&ctx);
|
||||
}
|
||||
|
||||
/// Enter on a focused size button asks for that size and picks no font: the key is not also read as
|
||||
/// the list's Enter, which would apply the highlighted font and close the menu.
|
||||
#[test]
|
||||
fn enter_on_a_focused_size_button_picks_no_font() {
|
||||
let db = vectorcraft_text::FontDb::with_font_dirs(vec![]);
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
// The Recently Added filter gives the list rows from the bundled fonts alone.
|
||||
let mut st = super::MenuState { added_only: true, added: added_in(&db, &["Source Serif 4", "Inter"], None), ..Default::default() };
|
||||
let id = egui::Id::unique("size-enter");
|
||||
let look = super::MenuLook { row: super::preview_row("small"), clock: Some(clock()), ..Default::default() };
|
||||
let area = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(800.0, 900.0));
|
||||
let frame = |st: &mut super::MenuState, events: Vec<egui::Event>| {
|
||||
let mut pick = None;
|
||||
let mut out = ctx.run_ui(egui::RawInput { events, screen_rect: Some(area), ..Default::default() }, |ui| {
|
||||
pick = super::list_of(ui, &db, id, st, "Inter", None, look).inner;
|
||||
});
|
||||
out.textures_delta.clear();
|
||||
(out.shapes, pick)
|
||||
};
|
||||
frame(&mut st, vec![]);
|
||||
let (shapes, _) = frame(&mut st, vec![]);
|
||||
let at = text_at(&shapes, |t| t == "Large").expect("Large is drawn");
|
||||
let button = |pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
|
||||
frame(&mut st, vec![egui::Event::PointerMoved(at), button(true)]);
|
||||
frame(&mut st, vec![button(false)]);
|
||||
ctx.data_mut(|d| d.remove_temp::<&'static str>(super::preview_size_id()));
|
||||
let enter = |pressed| egui::Event::Key {
|
||||
key: egui::Key::Enter,
|
||||
physical_key: Some(egui::Key::Enter),
|
||||
pressed,
|
||||
repeat: false,
|
||||
modifiers: Default::default(),
|
||||
};
|
||||
let tab =
|
||||
|pressed| egui::Event::Key { key: egui::Key::Tab, physical_key: Some(egui::Key::Tab), pressed, repeat: false, modifiers: Default::default() };
|
||||
assert!(!listed_families(&st).is_empty(), "the list has rows an Enter could pick");
|
||||
// Tab moves the focus along the controls until it is on the Large button, where Enter is pressed.
|
||||
let mut found = None;
|
||||
for _ in 0..60 {
|
||||
frame(&mut st, vec![tab(true)]);
|
||||
frame(&mut st, vec![tab(false)]);
|
||||
let on_large = ctx.memory(|m| m.focused()).and_then(|f| ctx.read_response(f)).is_some_and(|r| r.rect.contains(at));
|
||||
if !on_large {
|
||||
continue;
|
||||
}
|
||||
let (_, pick) = frame(&mut st, vec![enter(true)]);
|
||||
frame(&mut st, vec![enter(false)]);
|
||||
if ctx.data_mut(|d| d.remove_temp::<&'static str>(super::preview_size_id())) == Some("large") {
|
||||
found = Some(pick);
|
||||
break;
|
||||
}
|
||||
}
|
||||
let pick = found.expect("Enter on the focused Large button asks for the size");
|
||||
assert!(pick.is_none(), "Enter on the size button picks no font: {pick:?}");
|
||||
super::wait_for_samples(&ctx);
|
||||
}
|
||||
|
||||
/// The size a font menu's button asked for becomes Font Preview Size, which sizes every font
|
||||
/// menu's rows, and the host is asked to write the preferences file. The document is left as it
|
||||
/// was: a font previewed on the selected type stays previewed, and the change adds no undo step.
|
||||
#[test]
|
||||
fn a_preview_size_asked_for_sets_the_preference_and_keeps_the_preview() {
|
||||
let ctx = egui::Context::default();
|
||||
let mut app = app_with_type(&[]);
|
||||
let id = app.run("text.create", serde_json::json!({"x": 20, "y": 90, "text": "Size", "font": "Inter"})).unwrap()["id"].as_u64().unwrap();
|
||||
app.run("select.set", serde_json::json!({"ids": [id]})).unwrap();
|
||||
let font = |app: &crate::VectorcraftApp| match &app.session.active().unwrap().doc.node(vectorcraft_doc::NodeId(id)).unwrap().kind {
|
||||
vectorcraft_doc::NodeKind::Text(t) => t.first_style().font_family,
|
||||
_ => String::new(),
|
||||
};
|
||||
super::apply(&mut app, &ctx, super::FontPick::Preview("Source Serif 4".into(), None));
|
||||
assert_eq!(font(&app), "Source Serif 4");
|
||||
assert_eq!(super::MenuLook::of(&app).row, super::preview_row("medium"));
|
||||
assert!(!app.take_prefs_changed(), "nothing to write yet");
|
||||
let undo_depth = |app: &crate::VectorcraftApp| app.session.doc().unwrap().history.undo.len();
|
||||
let depth = undo_depth(&app);
|
||||
// The rows' own size: nothing changes.
|
||||
ctx.data_mut(|d| d.insert_temp(super::preview_size_id(), "medium"));
|
||||
super::apply_preview_size(&mut app, &ctx);
|
||||
assert_eq!(app.session.prefs.font_preview_size, "medium");
|
||||
assert!(!app.take_prefs_changed(), "nothing to write for the size the rows have");
|
||||
ctx.data_mut(|d| d.insert_temp(super::preview_size_id(), "large"));
|
||||
super::apply_preview_size(&mut app, &ctx);
|
||||
assert_eq!(app.session.prefs.font_preview_size, "large");
|
||||
assert_eq!(undo_depth(&app), depth, "the size is not an undo step");
|
||||
assert_eq!(super::MenuLook::of(&app).row, super::preview_row("large"));
|
||||
assert!(app.take_prefs_changed(), "the host is asked to write the preferences file");
|
||||
assert_eq!(app.ui.engine_prefs["fontPreviewSize"], "large");
|
||||
assert!(app.session.in_interaction(), "the preview is still open");
|
||||
assert_eq!(font(&app), "Source Serif 4", "the preview stays on the type");
|
||||
// Asked for once, applied once.
|
||||
super::apply_preview_size(&mut app, &ctx);
|
||||
assert_eq!(app.session.prefs.font_preview_size, "large");
|
||||
assert!(!app.take_prefs_changed(), "nothing more to write");
|
||||
// A saved value that is none of the sizes draws Medium's rows, and Medium replaces it.
|
||||
app.session.prefs.font_preview_size = "huge".into();
|
||||
assert_eq!(super::MenuLook::of(&app).row, super::preview_row("medium"));
|
||||
ctx.data_mut(|d| d.insert_temp(super::preview_size_id(), "medium"));
|
||||
super::apply_preview_size(&mut app, &ctx);
|
||||
assert_eq!(app.session.prefs.font_preview_size, "medium");
|
||||
assert!(app.take_prefs_changed(), "the replaced value is written");
|
||||
super::apply(&mut app, &ctx, super::FontPick::EndPreview);
|
||||
assert_eq!(font(&app), "Inter");
|
||||
app.run("edit.undo", serde_json::json!({})).unwrap();
|
||||
assert!(
|
||||
app.session.active().unwrap().doc.node(vectorcraft_doc::NodeId(id)).is_none(),
|
||||
"undo takes the type away: no step was added for the size"
|
||||
);
|
||||
}
|
||||
|
||||
/// Screen readers find Small, Medium and Large as radio buttons in a group named Font Preview
|
||||
/// Size, with the size of the rows chosen.
|
||||
#[test]
|
||||
fn the_preview_size_row_is_a_radio_group_showing_the_size() {
|
||||
use crate::widgets::accessibility_tests::{named, role_and_state, tree};
|
||||
use egui::accesskit::{Role, Toggled};
|
||||
// The bundled fonts alone: fonts that tests running alongside add stay out of the rows.
|
||||
let db = vectorcraft_text::FontDb::with_font_dirs(vec![]);
|
||||
let sizes = ["small", "medium", "large"];
|
||||
for size in sizes {
|
||||
let mut st = super::MenuState::default();
|
||||
let look = super::MenuLook { row: super::preview_row(size), ..Default::default() };
|
||||
let nodes = tree(|ui| {
|
||||
let _ = super::list_of(ui, &db, egui::Id::unique("size-group"), &mut st, "Inter", None, look);
|
||||
});
|
||||
assert_eq!(named(&nodes, "Font Preview Size").role(), Role::RadioGroup, "at {size}");
|
||||
for other in sizes {
|
||||
let chosen = if other == size { Toggled::True } else { Toggled::False };
|
||||
assert_eq!(role_and_state(&nodes, super::preview_size_label(other)), (Role::RadioButton, Some(chosen)), "{other} at {size}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A new Font Preview Size chosen in the open menu keeps the list on the rows it showed: the
|
||||
/// view starts the same number of rows down at the new height, not the same number of points.
|
||||
#[test]
|
||||
fn a_new_preview_size_keeps_the_list_on_its_rows() {
|
||||
// The bundled fonts alone: fonts that tests running alongside add stay out of the rows.
|
||||
let db = vectorcraft_text::FontDb::with_font_dirs(vec![]);
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
let mut st = super::MenuState::default();
|
||||
// One frame `height` points high at `size`: the list's offset, top, view height and content height.
|
||||
let frame = |height: f32, size: &str, st: &mut super::MenuState| {
|
||||
let area = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(800.0, height));
|
||||
let look = super::MenuLook { row: super::preview_row(size), ..Default::default() };
|
||||
let mut shown = None;
|
||||
let mut out = ctx.run_ui(egui::RawInput { screen_rect: Some(area), ..Default::default() }, |ui| {
|
||||
let mut child = ui.new_child(egui::UiBuilder::new().max_rect(area));
|
||||
// Opening on the last family scrolls the list to its end.
|
||||
let list = super::list_of(&mut child, &db, egui::Id::unique("keep-rows"), st, "Source Serif 4", None, look);
|
||||
shown = Some((list.state.clamped_offset().y, list.inner_rect.top(), list.inner_rect.height(), list.content_size.y));
|
||||
});
|
||||
out.textures_delta.clear();
|
||||
shown.unwrap_or_else(|| panic!("the list was not drawn"))
|
||||
};
|
||||
let (_, top, _, _) = frame(900.0, "medium", &mut st);
|
||||
// A fresh opening, with room for fewer rows than the list holds.
|
||||
let mut st = super::MenuState::default();
|
||||
let mut medium = (0.0, 0.0, 0.0, 0.0);
|
||||
for _ in 0..4 {
|
||||
medium = frame(top + 64.0, "medium", &mut st);
|
||||
}
|
||||
let (offset, _, view, content) = medium;
|
||||
assert!(content > view + 0.5 && offset > 0.5, "the list is scrolled: {medium:?}");
|
||||
let rows_down = offset / super::preview_row("medium");
|
||||
let mut large = (0.0, 0.0, 0.0, 0.0);
|
||||
for _ in 0..3 {
|
||||
large = frame(top + 64.0, "large", &mut st);
|
||||
}
|
||||
let expected = rows_down * super::preview_row("large");
|
||||
assert!((large.0 - expected).abs() < 0.5, "the view starts {rows_down} rows down: offset {} for {expected}", large.0);
|
||||
super::wait_for_samples(&ctx);
|
||||
}
|
||||
|
||||
@@ -1944,6 +1944,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
The font menu's Font Technology › Variable (under the kind filter, as [Find, apply, and adjust variable fonts](https://helpx.adobe.com/illustrator/desktop/design-with-text/fonts-and-scripts/find-apply-and-adjust-variable-fonts.html) places Variable in the classification filter's Font Technology section) lists only the families with variation axes, a family with a variable file beside static ones included, and works together with the script, kind, ★ and search filters; it stays set from one opening to the next. Measured by `font_menu::tests::the_variable_filter_lists_only_variable_families`, `font_menu::tests::the_variable_filter_is_named_as_fonts_are`, `tests_axes::a_family_with_variation_axes_is_variable` and `tests_sysfonts::a_family_with_a_variable_file_beside_static_ones_is_variable`.
|
||||
The font menu's Document filter (beside ★) lists only the families that type in the current document is set in, as the quick filter for fonts used in the document does on the [font browser overview](https://helpx.adobe.com/illustrator/desktop/design-with-text/fonts-and-scripts/font-options-overview.html). It works together with the search, script, kind, Variable and ★ filters, Recent Fonts and Show Similar Fonts, steers the closed field's wheel, follows edits and undo while the menu is open, and is shared by every font menu for the session like the other filters. VectorCraft's own rules: hidden, locked, masked, symbol, pattern and graph design type counts, styles no type uses do not, a composite font lists under its own name, a family the document names but this computer lacks is not listed (Find Font reports it), a document without available fonts lists nothing with its own message, and with no document open the filter is unavailable. Measured by `font_menu::tests::the_document_filter_lists_the_families_the_documents_type_uses`, `font_menu::tests::the_document_filter_combines_with_the_others_and_follows_edits`, `font_menu::tests::the_document_filter_counts_type_in_graph_designs` and `font_menu::tests::the_document_filter_on_an_empty_document_or_none`.
|
||||
The font menu's Recently Added filter (on its own row under Font Technology) lists only the installed families added in the last 30 days, the newest at the top, as the [user guide](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=486) and the [font browser overview](https://helpx.adobe.com/illustrator/desktop/design-with-text/fonts-and-scripts/font-options-overview.html) describe it (`vectorcraft_text::FontDb::recently_added`). It works together with the search, script, kind, Variable, ★ and Document filters, lists only the families every active filter matches, steers the closed field's wheel, and is shared by every font menu for the session like the other filters. VectorCraft's own rules: a family is dated by the creation time of its newest font file on this computer (a file the file system keeps no creation time for, or one dated in the future, does not count), the 30th day is included, families added at the same instant are in name order, the recently used families appear in that order without the Recent Fonts section, Show Similar Fonts orders only the families the filter lists, a family leaves the list when its 30 days end while the menu is open, an empty list keeps the filter on and says no fonts match, and fonts bundled with the app or loaded from documents are never listed. Measured by `font_menu::tests::the_recently_added_filter_lists_new_families_newest_first`, `font_menu::tests::the_recently_added_filter_drops_families_as_their_30_days_end`, `font_menu::tests::the_recently_added_filter_lists_a_font_installed_just_now`, `tests::recently_added::families_added_in_the_last_30_days_are_listed_newest_first`, `tests::recently_added::a_family_is_dated_by_its_newest_valid_file` and `tests::sysfonts::installed_fonts_are_recently_added_by_their_files_creation_time`.
|
||||
While the samples are shown, the font menu's row under the filters sets the sample size to Small, Medium or Large from inside the menu, as the [font browser overview](https://helpx.adobe.com/illustrator/desktop/design-with-text/fonts-and-scripts/font-options-overview.html) and the [user guide](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=485) describe the sample size control; with Enable in-menu font previews off, the row is not shown, as the user guide describes. VectorCraft's own rules: the row sits under the filters and sets Preferences › Type › Font Preview Size (`fontPreviewSize`), so every font menu takes the new row height, the Composite Fonts and Dimension dialogs' included, and the open list stays on the rows it showed; the current size is selected and a click on it changes nothing; screen readers find the three sizes as radio buttons in a group named Font Preview Size; a saved value that is none of the three sizes shows Medium and a click replaces it; the change adds no undo step and leaves a font previewed on the selected type in place. Measured by `font_menu::tests::the_preview_size_row_asks_for_the_size_clicked`, `font_menu::tests::a_preview_size_asked_for_sets_the_preference_and_keeps_the_preview`, `font_menu::tests::the_preview_size_row_is_a_radio_group_showing_the_size` and `font_menu::tests::a_new_preview_size_keeps_the_list_on_its_rows`.
|
||||
The font database looks up a name that is neither a loaded nor an installed family among the other names of the loaded and installed fonts once for each style it is asked in, and keeps the answer until fonts are added or rescanned. Laying out a story of 1,000 paragraphs set in a font that is not installed, with 400 more fonts loaded, takes a median of 56 to 71 ms instead of 409 to 507 ms on Windows 11 (`CRAFT_FONTS_DIR=<craft-fonts checkout> cargo test --release -p vectorcraft-text --lib missing_font_story_layout_timing -- --ignored --nocapture`).
|
||||
A font family removed while the app runs leaves the font menus when the app scans the font folders again (when its window comes to the front after a font folder changed, or Refresh Font List), also when type had used it: that type then draws in the fallback font and Find Font lists the font as missing, until the font is installed again and the folders are scanned.
|
||||
- **Files (M4):**
|
||||
|
||||
Reference in New Issue
Block a user