mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-21 01:18:43 +00:00
Make font-family names directly editable with keyboard and preview regressions
This commit is contained in:
1 parent
b0622d20ca
commit
7996987dfd
8 files changed
+480
-189
No files matched your search
@@ -200,12 +200,12 @@ fn every_theme_shows_the_type_options() {
|
||||
);
|
||||
PhotocraftApp::setup_context(&h.ctx, theme);
|
||||
h.run_steps(4);
|
||||
let combos: Vec<String> = h
|
||||
.query_all_by_role(egui::accesskit::Role::ComboBox)
|
||||
let fields: Vec<String> = h
|
||||
.query_all_by_role(egui::accesskit::Role::TextInput)
|
||||
.map(|n| format!("{:?} {:?}", n.accesskit_node().label(), n.accesskit_node().value()))
|
||||
.collect();
|
||||
let font = h.state().ui.tool_options.type_font.clone();
|
||||
assert!(combos.iter().any(|c| c.contains(&font)), "{theme:?}: the font picker shows {font:?}; combo boxes: {combos:?}");
|
||||
assert!(fields.iter().any(|c| c.contains(&font)), "{theme:?}: the font picker shows {font:?}; font fields: {fields:?}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -98,12 +98,17 @@ pub fn above_parent_ui(parent: egui::LayerId, popup_ui: &egui::Ui) {
|
||||
/// Shows `button`'s menu (an `egui::Popup::menu`) with press-drag-release; `content` chooses its
|
||||
/// items with [`PressMenu::item`].
|
||||
pub fn show<R>(button: &Response, content: impl FnOnce(&mut Ui, &PressMenu) -> R) -> Option<R> {
|
||||
show_with_close_behavior(button, PopupCloseBehavior::CloseOnClick, content)
|
||||
}
|
||||
|
||||
/// A press menu whose content owns its close behavior (e.g. a scrollable font list).
|
||||
pub fn show_with_close_behavior<R>(button: &Response, close_behavior: PopupCloseBehavior, content: impl FnOnce(&mut Ui, &PressMenu) -> R) -> Option<R> {
|
||||
let ctx = button.ctx.clone();
|
||||
let menu = PressMenu { popup: Popup::default_response_id(button) };
|
||||
let open = open_command(button, menu.popup);
|
||||
// The release ending the press that opened the menu is a click outside the popup: it must not
|
||||
// close it again.
|
||||
let close = if button.clicked() && menu.owns_gesture(&ctx) { PopupCloseBehavior::IgnoreClicks } else { PopupCloseBehavior::CloseOnClick };
|
||||
let close = if button.clicked() && menu.owns_gesture(&ctx) { PopupCloseBehavior::IgnoreClicks } else { close_behavior };
|
||||
let shown = Popup::menu(button).open_memory(open).close_behavior(close).show(|ui| content(ui, &menu)).map(|r| r.inner);
|
||||
if shown.is_some() || Popup::is_id_open(&ctx, menu.popup) {
|
||||
above_parent(&ctx, button.layer_id, egui::LayerId::new(egui::Order::Foreground, menu.popup));
|
||||
|
||||
@@ -147,14 +147,22 @@ fn type_controls_fill_the_panel_at_every_width_and_scale() {
|
||||
let hs = headers(&h);
|
||||
let header = hs.iter().find(|(n, _)| n == "Character").unwrap().1;
|
||||
let what = format!("{ppp}x @ {dw}");
|
||||
// Font family and style dropdowns span the section.
|
||||
// The editable family field and the style dropdown span the section.
|
||||
let name = h
|
||||
.query_all_by_role(egui::accesskit::Role::TextInput)
|
||||
.map(|n| n.rect())
|
||||
.find(|r| r.top() >= header.bottom() && r.left() >= header.left() - 1.0)
|
||||
.expect("editable family field");
|
||||
let mut family = name.expand2(egui::vec2(6.0, 2.0));
|
||||
family.max.x += crate::widgets::POPUP_ARROW_W;
|
||||
assert!((family.left() - header.left()).abs() <= 2.0 && (family.right() - header.right()).abs() <= 2.0, "{what}: {family:?} vs {header:?}");
|
||||
let combos: Vec<Rect> = h
|
||||
.query_all_by_role(egui::accesskit::Role::ComboBox)
|
||||
.map(|n| n.rect())
|
||||
.filter(|r| r.top() >= header.bottom() && r.left() >= header.left() - 1.0)
|
||||
.collect();
|
||||
assert!(combos.len() >= 2, "{what}: {combos:?}");
|
||||
for r in &combos[..2] {
|
||||
assert!(!combos.is_empty(), "{what}: {combos:?}");
|
||||
for r in &combos[..1] {
|
||||
assert!((r.left() - header.left()).abs() <= 2.0 && (r.right() - header.right()).abs() <= 2.0, "{what}: {r:?} vs {header:?}");
|
||||
}
|
||||
// Number fields end at the section's right edge (the second column), never past it.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! The Type tool's searchable font menu (#1369): it keeps its height and focuses its search field.
|
||||
//! The Type tool's editable family field and searchable menu (#9338, #1369).
|
||||
|
||||
use super::font_picker_in;
|
||||
use egui::accesskit::Role;
|
||||
@@ -50,10 +50,202 @@ fn popup_rect(h: &Harness<'static, State>) -> Option<Rect> {
|
||||
}
|
||||
|
||||
fn open(h: &mut Harness<'static, State>) {
|
||||
h.query_all_by_role(Role::ComboBox).next().unwrap().click();
|
||||
h.query_all_by_role(Role::TextInput).next().unwrap().click();
|
||||
h.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clicking_the_name_selects_all_and_the_first_letter_replaces_it() {
|
||||
let mut h = harness();
|
||||
assert_eq!(h.get_by_role(Role::TextInput).value().as_deref(), Some("Family 00"));
|
||||
open(&mut h);
|
||||
let range = egui::TextEdit::load_state(&h.ctx, h.state().button).unwrap().cursor.char_range().unwrap();
|
||||
assert_eq!(range.sorted_cursors().map(|c| c.index.0), [0, "Family 00".chars().count()]);
|
||||
h.event(egui::Event::Text("z".into()));
|
||||
h.run();
|
||||
assert_eq!(h.get_by_role(Role::TextInput).value().as_deref(), Some("z"));
|
||||
assert_eq!(h.state().current, "Family 00", "typing only filters");
|
||||
assert!(h.query_by_label("Family 01").is_none());
|
||||
assert!(h.query_by_label("Zeta Sans").is_some());
|
||||
assert_eq!(h.query_all_by_role(Role::TextInput).count(), 1, "there is no second search box");
|
||||
h.key_press(Key::Enter);
|
||||
h.run();
|
||||
assert_eq!(h.state().current, "Zeta Sans");
|
||||
assert!(popup_rect(&h).is_none());
|
||||
assert!(h.get_by_role(Role::TextInput).is_focused());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enter_prefers_a_full_name_over_an_earlier_substring_match() {
|
||||
let mut h = harness();
|
||||
h.state_mut().families = vec!["Zeta Sans Display".into(), "Zeta Sans".into()];
|
||||
open(&mut h);
|
||||
h.get_by_role(Role::TextInput).type_text("zEtA sAnS");
|
||||
h.run();
|
||||
assert_eq!(h.state().current, "Family 00");
|
||||
h.key_press(Key::Enter);
|
||||
h.run();
|
||||
assert_eq!(h.state().current, "Zeta Sans");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_or_unmatched_input_applies_nothing_and_escape_restores_the_name() {
|
||||
for query in ["", "no such font"] {
|
||||
let mut h = harness();
|
||||
open(&mut h);
|
||||
h.key_press(Key::Backspace);
|
||||
h.run();
|
||||
h.event(egui::Event::Text(query.into()));
|
||||
h.run();
|
||||
h.key_press(Key::Enter);
|
||||
h.run();
|
||||
assert_eq!(h.state().current, "Family 00");
|
||||
assert!(popup_rect(&h).is_some());
|
||||
h.key_press(Key::Escape);
|
||||
h.run();
|
||||
assert_eq!(h.get_by_role(Role::TextInput).value().as_deref(), Some("Family 00"));
|
||||
assert!(!h.get_by_role(Role::TextInput).is_focused());
|
||||
assert!(popup_rect(&h).is_none());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clicking_elsewhere_discards_unaccepted_input() {
|
||||
let mut h = harness();
|
||||
open(&mut h);
|
||||
h.get_by_role(Role::TextInput).type_text("Zeta");
|
||||
h.run();
|
||||
let outside = egui::pos2(550.0, 850.0);
|
||||
h.hover_at(outside);
|
||||
h.event(egui::Event::PointerButton { pos: outside, button: egui::PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
|
||||
h.event(egui::Event::PointerButton { pos: outside, button: egui::PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
|
||||
h.run();
|
||||
assert_eq!(h.state().current, "Family 00");
|
||||
assert_eq!(h.get_by_role(Role::TextInput).value().as_deref(), Some("Family 00"));
|
||||
assert!(popup_rect(&h).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tab_leaves_the_field_and_discards_its_pending_query() {
|
||||
let mut h = harness();
|
||||
open(&mut h);
|
||||
h.get_by_role(Role::TextInput).type_text("Zeta");
|
||||
h.run();
|
||||
h.key_press(Key::Tab);
|
||||
h.run();
|
||||
assert_eq!(h.state().current, "Family 00");
|
||||
assert_eq!(h.get_by_role(Role::TextInput).value().as_deref(), Some("Family 00"));
|
||||
assert!(popup_rect(&h).is_none());
|
||||
assert!(!h.get_by_role(Role::TextInput).is_focused());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_arrow_keeps_press_drag_release_selection() {
|
||||
let mut h = harness();
|
||||
let arrow = h.get_by_role(Role::Button).rect().center();
|
||||
h.hover_at(arrow);
|
||||
h.run();
|
||||
h.event(egui::Event::PointerButton { pos: arrow, button: egui::PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
|
||||
h.run_steps(4);
|
||||
assert!(popup_rect(&h).is_some());
|
||||
let row = h.get_by_label("Family 03").rect().center();
|
||||
h.hover_at(row);
|
||||
h.run();
|
||||
h.event(egui::Event::PointerButton { pos: row, button: egui::PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
|
||||
h.run();
|
||||
assert_eq!(h.state().current, "Family 03");
|
||||
assert!(popup_rect(&h).is_none());
|
||||
assert!(h.get_by_role(Role::TextInput).is_focused());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn two_fields_keep_their_names_and_queries_independent() {
|
||||
let mut h = Harness::builder().with_size(vec2(600.0, 900.0)).build_ui_state(
|
||||
|ui, names: &mut [String; 2]| {
|
||||
let families = vec!["Family 00".to_string(), "Zeta Sans".to_string()];
|
||||
for (i, name) in names.iter_mut().enumerate() {
|
||||
super::family_picker_in(ui, &format!("font-{i}"), name, 170.0, &families, FontPreview::Off, &[]);
|
||||
}
|
||||
},
|
||||
["Family 00".to_string(), "Family 00".to_string()],
|
||||
);
|
||||
h.run();
|
||||
h.query_all_by_role(Role::TextInput).next().unwrap().click();
|
||||
h.run();
|
||||
h.query_all_by_role(Role::TextInput).find(|n| n.is_focused()).unwrap().type_text("Zeta");
|
||||
h.run();
|
||||
let values: Vec<_> = h.query_all_by_role(Role::TextInput).map(|n| n.value().unwrap()).collect();
|
||||
assert_eq!(values, ["Zeta", "Family 00"]);
|
||||
h.key_press(Key::Enter);
|
||||
h.run();
|
||||
assert_eq!(h.state(), &["Zeta Sans", "Family 00"]);
|
||||
h.query_all_by_role(Role::TextInput).nth(1).unwrap().click();
|
||||
h.run();
|
||||
assert!(h.query_by_label("Family 00").is_some(), "the peer opens with its own full list");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tab_focus_selects_the_name_and_pasted_unicode_can_be_accepted() {
|
||||
let mut h = harness();
|
||||
h.state_mut().families = vec!["Family 00".into(), "日本語 Sans".into()];
|
||||
h.key_press(Key::Tab);
|
||||
h.run();
|
||||
assert!(h.get_by_role(Role::TextInput).is_focused());
|
||||
h.event(egui::Event::Paste("日本語 Sans".into()));
|
||||
h.run();
|
||||
assert_eq!(h.get_by_role(Role::TextInput).value().as_deref(), Some("日本語 Sans"));
|
||||
h.key_press(Key::Enter);
|
||||
h.run();
|
||||
assert_eq!(h.state().current, "日本語 Sans");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ime_confirmation_does_not_accept_a_font_until_a_separate_enter() {
|
||||
let mut h = harness();
|
||||
h.state_mut().families = vec!["Family 00".into(), "日本語 Sans".into()];
|
||||
open(&mut h);
|
||||
h.event(egui::Event::Ime(egui::ImeEvent::Preedit { text: "日本語 Sans".into(), active_range_chars: None }));
|
||||
h.run();
|
||||
h.key_press(Key::ArrowDown);
|
||||
h.run();
|
||||
h.key_press(Key::ArrowUp);
|
||||
h.run();
|
||||
assert_eq!(h.state().current, "Family 00", "IME arrows do not select a font");
|
||||
assert!(h.get_by_role(Role::TextInput).is_focused());
|
||||
h.key_press(Key::Enter);
|
||||
h.run();
|
||||
assert_eq!(h.state().current, "Family 00", "IME Enter only confirms composition");
|
||||
assert!(popup_rect(&h).is_some());
|
||||
assert!(h.get_by_role(Role::TextInput).is_focused());
|
||||
h.event(egui::Event::Ime(egui::ImeEvent::Commit("日本語 Sans".into())));
|
||||
h.run();
|
||||
h.key_press(Key::Enter);
|
||||
h.run();
|
||||
assert_eq!(h.state().current, "日本語 Sans");
|
||||
assert!(popup_rect(&h).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dragging_inside_the_name_selects_text_without_picking_a_font() {
|
||||
let mut h = harness();
|
||||
open(&mut h);
|
||||
let field = h.get_by_role(Role::TextInput).rect();
|
||||
let from = egui::pos2(field.left() + 5.0, field.center().y);
|
||||
let to = egui::pos2(field.left() + 30.0, field.center().y);
|
||||
h.hover_at(from);
|
||||
h.event(egui::Event::PointerButton { pos: from, button: egui::PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
|
||||
h.run();
|
||||
h.hover_at(to);
|
||||
h.run();
|
||||
h.event(egui::Event::PointerButton { pos: to, button: egui::PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
|
||||
h.run();
|
||||
let range = egui::TextEdit::load_state(&h.ctx, h.state().button).unwrap().cursor.char_range().unwrap();
|
||||
assert!(!range.is_empty());
|
||||
assert!(range.as_sorted_char_range().end.0 - range.as_sorted_char_range().start.0 < "Family 00".chars().count());
|
||||
assert_eq!(h.state().current, "Family 00");
|
||||
assert!(popup_rect(&h).is_some());
|
||||
}
|
||||
|
||||
/// A native click can leave the opening button held across several rendered frames.
|
||||
fn hold_open<S>(h: &mut Harness<'_, S>, button: egui::Pos2) {
|
||||
h.hover_at(button);
|
||||
@@ -142,10 +334,10 @@ fn the_search_field_stays_put_while_the_list_scrolls() {
|
||||
let scrolled = h.get_by_label("Family 00").rect();
|
||||
assert!(scrolled.top() < first_row.top() - 1.0, "the list did not scroll: {first_row:?} -> {scrolled:?}");
|
||||
|
||||
// The field did not move with the rows: it is still where it was, inside the menu.
|
||||
// The name stays in the original control while the list scrolls underneath.
|
||||
let after = h.get_by_role(Role::TextInput).rect();
|
||||
assert_eq!(search, after, "the search field scrolled away with the list");
|
||||
assert!(popup.contains(after.center()), "the search field left the menu");
|
||||
assert!(!popup.contains(after.center()), "the editable name stays above the menu");
|
||||
}
|
||||
|
||||
/// #7792: the arrow keys scroll the list to the selected family without moving the search
|
||||
@@ -186,42 +378,37 @@ fn clearing_the_query_restores_the_menu_height() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reopening_focuses_the_search_field_and_clicking_it_keeps_the_menu_open() {
|
||||
fn reopening_selects_the_applied_name_and_clicking_it_keeps_the_menu_open() {
|
||||
let mut h = harness();
|
||||
let button = h.query_all_by_role(Role::ComboBox).next().unwrap().rect().center();
|
||||
hold_open(&mut h, button);
|
||||
assert!(h.get_by_role(Role::TextInput).is_focused(), "search is focused on first open");
|
||||
let field = h.get_by_role(Role::TextInput).rect().center();
|
||||
hold_open(&mut h, field);
|
||||
assert!(h.get_by_role(Role::TextInput).is_focused());
|
||||
h.event(egui::Event::Text("zeta".into()));
|
||||
h.run();
|
||||
assert_eq!(h.get_by_role(Role::TextInput).value().as_deref(), Some("zeta"), "typing goes straight to the search field");
|
||||
// Close and reopen on consecutive passes: the query stays and the field is focused again.
|
||||
h.input_mut().events.push(egui::Event::Key { key: Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE });
|
||||
h.step();
|
||||
assert!(popup_rect(&h).is_none(), "Escape closes the menu");
|
||||
h.query_all_by_role(Role::ComboBox).next().unwrap().click_accesskit();
|
||||
assert_eq!(h.get_by_role(Role::TextInput).value().as_deref(), Some("zeta"));
|
||||
h.key_press(Key::Escape);
|
||||
h.run();
|
||||
let search = h.get_by_role(Role::TextInput);
|
||||
assert_eq!(search.value().as_deref(), Some("zeta"));
|
||||
assert!(search.is_focused(), "search is focused on reopen with a query");
|
||||
// Clicking the search field (to edit the query) must not close the menu.
|
||||
assert!(popup_rect(&h).is_none());
|
||||
assert_eq!(h.get_by_role(Role::TextInput).value().as_deref(), Some("Family 00"));
|
||||
open(&mut h);
|
||||
assert!(h.get_by_role(Role::TextInput).is_focused());
|
||||
assert!(h.query_by_label("Family 01").is_some(), "reopening starts with the full list");
|
||||
h.get_by_role(Role::TextInput).click();
|
||||
h.run();
|
||||
assert!(popup_rect(&h).is_some(), "clicking the search field keeps the menu open");
|
||||
assert!(popup_rect(&h).is_some(), "editing the name keeps the list open");
|
||||
h.key_press_modifiers(Modifiers::COMMAND, Key::A);
|
||||
h.get_by_role(Role::TextInput).type_text("Zeta S");
|
||||
h.run();
|
||||
assert!(popup_rect(&h).is_some());
|
||||
// Picking a font still closes the menu.
|
||||
h.get_by_label("Zeta Sans").click();
|
||||
h.run();
|
||||
assert_eq!(h.state().current, "Zeta Sans");
|
||||
assert!(popup_rect(&h).is_none(), "choosing a font closes the menu");
|
||||
assert!(popup_rect(&h).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opening_click_release_returns_focus_to_search_before_typing() {
|
||||
fn opening_arrow_release_returns_focus_to_the_name_before_typing() {
|
||||
let mut h = harness();
|
||||
let button = h.query_all_by_role(Role::ComboBox).next().unwrap().rect().center();
|
||||
let button = h.get_by_role(Role::Button).rect().center();
|
||||
h.hover_at(button);
|
||||
h.run();
|
||||
h.event(egui::Event::PointerButton { pos: button, button: egui::PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
|
||||
@@ -229,7 +416,7 @@ fn opening_click_release_returns_focus_to_search_before_typing() {
|
||||
assert!(h.get_by_role(Role::TextInput).is_focused());
|
||||
// A native opening click can hand focus back to its button when it ends, after the
|
||||
// search has already been focused for several passes. Model that platform handoff.
|
||||
let id = h.state().button;
|
||||
let id = h.state().button.with("arrow");
|
||||
h.ctx.memory_mut(|m| m.request_focus(id));
|
||||
h.event(egui::Event::PointerButton { pos: button, button: egui::PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
|
||||
h.run();
|
||||
@@ -260,7 +447,7 @@ fn first_options_bar_open_searches_without_changing_the_tool_or_edited_text() {
|
||||
app
|
||||
});
|
||||
h.run_steps(8);
|
||||
let button = h.query_all_by_role(Role::ComboBox).find(|n| n.value().as_deref() == Some("Inter")).unwrap().rect().center();
|
||||
let button = h.query_all_by_role(Role::TextInput).find(|n| n.value().as_deref() == Some("Inter")).unwrap().rect().center();
|
||||
hold_open(&mut h, button);
|
||||
// Native typing carries key events as well as text; an unfocused search would let
|
||||
// the first key switch tools, or replace the selected inline text instead.
|
||||
@@ -445,10 +632,9 @@ fn font_cycle_in_options_bar_edits_the_layer_and_can_be_undone() {
|
||||
);
|
||||
crate::PhotocraftApp::setup_context(&h.ctx, Default::default());
|
||||
h.run_steps(4);
|
||||
h.query_all_by_role(Role::ComboBox).next().unwrap().click();
|
||||
h.query_all_by_role(Role::TextInput).next().unwrap().click();
|
||||
h.run();
|
||||
h.get_by_role(Role::TextInput).type_text("JetBrains");
|
||||
h.key_press(Key::ArrowDown);
|
||||
h.run();
|
||||
let font = |app: &PhotocraftApp| {
|
||||
let doc = &app.session.active().unwrap().doc;
|
||||
@@ -457,9 +643,10 @@ fn font_cycle_in_options_bar_edits_the_layer_and_can_be_undone() {
|
||||
_ => panic!("type layer"),
|
||||
}
|
||||
};
|
||||
assert_eq!(font(h.state()), "JetBrains Mono");
|
||||
assert_eq!(font(h.state()), "Inter", "typing creates no document edit");
|
||||
h.key_press(Key::Enter);
|
||||
h.run();
|
||||
assert_eq!(font(h.state()), "JetBrains Mono");
|
||||
h.state_mut().run("edit.undo", json!({})).unwrap();
|
||||
assert_eq!(font(h.state()), "Inter");
|
||||
h.state_mut().run("edit.redo", json!({})).unwrap();
|
||||
@@ -538,7 +725,7 @@ fn options_bar_hover_previews_on_canvas_without_committing() {
|
||||
let layer = h.state().app.session.active().unwrap().active_layer.unwrap();
|
||||
h.state_mut().app.ui.tool = crate::state::Tool::Type;
|
||||
h.run_steps(3);
|
||||
h.query_all_by_role(Role::ComboBox).next().unwrap().click();
|
||||
h.query_all_by_role(Role::TextInput).next().unwrap().click();
|
||||
h.run();
|
||||
h.get_by_role(Role::TextInput).type_text("JetBrains Mono");
|
||||
h.run();
|
||||
@@ -809,7 +996,7 @@ fn options_bar_menu_arrows_walk_on_while_recording_recent_fonts() {
|
||||
);
|
||||
crate::PhotocraftApp::setup_context(&h.ctx, Default::default());
|
||||
h.run_steps(4);
|
||||
h.query_all_by_role(Role::ComboBox).next().unwrap().click();
|
||||
h.query_all_by_role(Role::TextInput).next().unwrap().click();
|
||||
h.run();
|
||||
let mut seen = vec![h.state().ui.tool_options.type_font.clone()];
|
||||
for _ in 0..4 {
|
||||
@@ -827,7 +1014,7 @@ fn options_bar_menu_arrows_walk_on_while_recording_recent_fonts() {
|
||||
#[test]
|
||||
fn wheel_over_the_closed_font_button_steps_through_the_families() {
|
||||
let mut h = harness();
|
||||
let button = h.query_all_by_role(Role::ComboBox).next().unwrap().rect().center();
|
||||
let button = h.query_all_by_role(Role::TextInput).next().unwrap().rect().center();
|
||||
h.hover_at(button);
|
||||
h.run();
|
||||
let wheel = |h: &mut Harness<'static, State>, y: f32| {
|
||||
@@ -846,7 +1033,7 @@ fn wheel_over_the_closed_font_button_steps_through_the_families() {
|
||||
#[test]
|
||||
fn wheel_over_the_closed_button_keeps_a_stable_order_with_recents() {
|
||||
let mut h = harness_with_recents(FontPreview::Medium, vec![]);
|
||||
let button = h.query_all_by_role(Role::ComboBox).next().unwrap().rect().center();
|
||||
let button = h.query_all_by_role(Role::TextInput).next().unwrap().rect().center();
|
||||
h.hover_at(button);
|
||||
h.run();
|
||||
let wheel = |h: &mut Harness<'static, State>, y: f32| {
|
||||
@@ -901,7 +1088,7 @@ fn options_bar_hover_previews_with_the_character_picker_also_shown() {
|
||||
let LayerContent::Text(t) = &shown.layer(layer).unwrap().content else { panic!("type layer") };
|
||||
t.char_runs()[0].style.font_family.clone()
|
||||
};
|
||||
let pickers: Vec<_> = h.query_all_by_role(Role::ComboBox).filter(|n| n.value().as_deref() == Some("Inter")).collect();
|
||||
let pickers: Vec<_> = h.query_all_by_role(Role::TextInput).filter(|n| n.value().as_deref() == Some("Inter")).collect();
|
||||
assert_eq!(pickers.len(), 2, "options bar and Character section both show the font picker");
|
||||
let button = pickers[0].rect().center();
|
||||
hold_open(&mut h, button);
|
||||
@@ -914,3 +1101,36 @@ fn options_bar_hover_previews_with_the_character_picker_also_shown() {
|
||||
h.run();
|
||||
assert_eq!(font(&mut h), "Inter", "leaving the row restores the committed font");
|
||||
}
|
||||
|
||||
// FONT_FIELD_VISUAL_FIXTURE_START: kept compatible with the base revision for before/after capture.
|
||||
#[test]
|
||||
fn capture_font_field_gpu_visual_fixtures() {
|
||||
let Some(directory) = std::env::var_os("CRAFT_FONT_FIELD_FIXTURES").map(std::path::PathBuf::from) else { return };
|
||||
let _gpu = photocraft_testkit::gpu_lock();
|
||||
std::fs::create_dir_all(&directory).unwrap();
|
||||
let phase = std::env::var("FONT_FIELD_FIXTURE_PHASE").unwrap_or_else(|_| "after".into());
|
||||
for theme in crate::theme::ThemeKind::ALL {
|
||||
for scale in [1.0, 2.0] {
|
||||
for width in [140.0, 170.0] {
|
||||
let mut h = Harness::builder().with_size(vec2(420.0, 560.0)).with_pixels_per_point(scale).wgpu().build_ui_state(
|
||||
move |ui, current: &mut String| {
|
||||
let families = ["Arial", "Consolas", "Inter", "JetBrains Mono"].map(str::to_string);
|
||||
font_picker_in(ui, current, width, &families, FontPreview::Medium, &[]);
|
||||
},
|
||||
"Inter".to_string(),
|
||||
);
|
||||
crate::PhotocraftApp::setup_context(&h.ctx, theme);
|
||||
h.run_steps(4);
|
||||
let stem = format!("{phase}-{}-{width}-{scale}x", theme.id());
|
||||
h.render().unwrap().save(directory.join(format!("{stem}-closed.png"))).unwrap();
|
||||
// The base revision has a ComboBox and a separate TextInput inside its popup.
|
||||
h.query_by_role(Role::TextInput).or_else(|| h.query_by_role(Role::ComboBox)).unwrap().click();
|
||||
h.run();
|
||||
h.render().unwrap().save(directory.join(format!("{stem}-selected.png"))).unwrap();
|
||||
h.event(egui::Event::Text("C".into()));
|
||||
h.run();
|
||||
h.render().unwrap().save(directory.join(format!("{stem}-filtered.png"))).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+179
-142
@@ -1770,6 +1770,20 @@ fn font_picker_in(
|
||||
family_picker_in(ui, "type-font", current, width, families, preview, recents)
|
||||
}
|
||||
|
||||
/// Transient input belongs to one field, independently of the applied family and its peers.
|
||||
#[derive(Clone)]
|
||||
struct FontFieldEdit {
|
||||
text: String,
|
||||
query: String,
|
||||
current: String,
|
||||
recents: Vec<String>,
|
||||
row: Option<usize>,
|
||||
opening: bool,
|
||||
accepted: bool,
|
||||
composing: bool,
|
||||
menu_height: Option<f32>,
|
||||
}
|
||||
|
||||
/// Shared by the Type options, Character, style and Glyphs panels. Selection changes still
|
||||
/// flow through each caller's existing engine command.
|
||||
pub(crate) fn family_picker_in(
|
||||
@@ -1781,60 +1795,99 @@ pub(crate) fn family_picker_in(
|
||||
preview: photocraft_engine::prefs::FontPreview,
|
||||
recents: &[String],
|
||||
) -> bool {
|
||||
let mut changed = false;
|
||||
// A font picked from the open menu (click or Enter): the field keeps the focus afterwards.
|
||||
let mut picked = false;
|
||||
let search_id = ui.id().with(("font-search", salt));
|
||||
let focus_id = search_id.with("focus");
|
||||
let recents_id = search_id.with("recents");
|
||||
let row_id = search_id.with("row");
|
||||
// The list opens on the press, so a press-drag-release picks a font too (#2735).
|
||||
let (press, close) = crate::press_menu::PressCombo::before(ui, salt);
|
||||
let field = ui.make_persistent_id(egui::IdSalt::new(salt));
|
||||
let popup = field.with("popup");
|
||||
let edit_id = field.with("edit");
|
||||
let was_open = egui::Popup::is_id_open(ui.ctx(), popup);
|
||||
let had_focus = ui.memory(|m| m.has_focus(field));
|
||||
let labels: Option<Arc<HashMap<String, String>>> = ui.ctx().data(|d| d.get_temp(font_labels_id()));
|
||||
let labels = labels.as_deref();
|
||||
let shown = labels.and_then(|l| l.get(current.as_str())).unwrap_or(current).clone();
|
||||
let combo = egui::ComboBox::from_id_salt(salt)
|
||||
.selected_text(shown)
|
||||
.width(width)
|
||||
.height(FONT_MENU_HEIGHT)
|
||||
.icon(crate::widgets::chevron_icon)
|
||||
// Clicks inside the menu (the search field, the scroll bar) must not close it (#1369);
|
||||
// picking a font closes it explicitly below.
|
||||
.close_behavior(if matches!(close, egui::PopupCloseBehavior::IgnoreClicks) { close } else { egui::PopupCloseBehavior::CloseOnClickOutside });
|
||||
|
||||
let response = combo.show_ui(ui, |ui| {
|
||||
let height_id = search_id.with("height");
|
||||
// Each opening focuses the search, including a reopen on the very next pass. Keep
|
||||
// asking through the invisible sizing pass, until the field receives focus.
|
||||
let mut focus = ui.data(|d| d.get_temp(focus_id)).unwrap_or(true);
|
||||
let mut q: String = ui.data(|d| d.get_temp(search_id)).unwrap_or_default();
|
||||
// Consume these before TextEdit and the canvas can interpret them as caret movement.
|
||||
let down = ui.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::ArrowDown));
|
||||
let up = ui.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::ArrowUp));
|
||||
let enter = ui.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Enter));
|
||||
if focus {
|
||||
ui.memory_mut(|m| m.request_focus(search_id.with("input")));
|
||||
}
|
||||
let r = ui.add(egui::TextEdit::singleline(&mut q).id(search_id.with("input")).hint_text(tl!("Search fonts")).desired_width(200.0));
|
||||
if focus {
|
||||
// The opening click can release after several focused frames. Keep the request
|
||||
// pending through that release, which can hand focus back to the combo button.
|
||||
focus = !r.has_focus() || ui.input(|i| i.pointer.primary_down() || i.pointer.primary_released());
|
||||
}
|
||||
ui.data_mut(|d| {
|
||||
d.insert_temp(focus_id, focus);
|
||||
d.insert_temp(search_id, q.clone());
|
||||
let label = |f: &str| labels.and_then(|l| l.get(f)).cloned().unwrap_or_else(|| f.to_string());
|
||||
let mut edit =
|
||||
ui.data(|d| d.get_temp::<FontFieldEdit>(edit_id)).filter(|e| e.current == *current && (was_open || had_focus)).unwrap_or_else(|| FontFieldEdit {
|
||||
text: label(current),
|
||||
query: String::new(),
|
||||
current: current.clone(),
|
||||
recents: recents.to_vec(),
|
||||
row: None,
|
||||
opening: false,
|
||||
accepted: false,
|
||||
composing: false,
|
||||
menu_height: None,
|
||||
});
|
||||
let ql = q.to_lowercase();
|
||||
// The recent group stays as it was when the menu opened: each arrow step applies (and so
|
||||
// records) a family, and moving it to the top would send the next step back up.
|
||||
let open_recents: Vec<String> = ui.data_mut(|d| d.get_temp_mut_or_insert_with(recents_id, || recents.to_vec()).clone());
|
||||
let (rows, n_recent) = font_menu_rows(families, labels, &ql, &open_recents);
|
||||
// A recent family is listed twice. The current family's row is the one the last arrow
|
||||
// selected while it still shows that family, else its alphabetical copy, so the arrows
|
||||
// step through the alphabet as on the closed field.
|
||||
let mut selected = ui
|
||||
.data(|d| d.get_temp::<usize>(row_id))
|
||||
// Take navigation before TextEdit interprets it, and before the canvas can see it.
|
||||
let owns_keys = ui.is_enabled() && (had_focus || was_open);
|
||||
if had_focus {
|
||||
ui.memory_mut(|m| m.set_focus_lock_filter(field, egui::EventFilter { vertical_arrows: true, ..Default::default() }));
|
||||
}
|
||||
// IME confirmation/navigation belongs to composition, even when its current spelling
|
||||
// happens to be an exact font name. A separate Enter accepts the completed name.
|
||||
let composing = edit.composing || ui.input(|i| i.events.iter().any(|e| matches!(e, egui::Event::Ime(_))));
|
||||
if owns_keys {
|
||||
ui.input(|i| {
|
||||
for event in &i.events {
|
||||
match event {
|
||||
egui::Event::Ime(egui::ImeEvent::Preedit { text, .. }) => edit.composing = !text.is_empty(),
|
||||
egui::Event::Ime(egui::ImeEvent::Commit(_)) => edit.composing = false,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
let key = |k| owns_keys && ui.input_mut(|i| i.consume_key(egui::Modifiers::NONE, k));
|
||||
let navigation_down = key(egui::Key::ArrowDown);
|
||||
let navigation_up = key(egui::Key::ArrowUp);
|
||||
let down = navigation_down && !composing;
|
||||
let up = navigation_up && !composing;
|
||||
let enter = key(egui::Key::Enter) && !composing;
|
||||
let escape = key(egui::Key::Escape) && !composing;
|
||||
let tab = owns_keys && ui.input(|i| i.key_pressed(egui::Key::Tab));
|
||||
if navigation_down || navigation_up {
|
||||
ui.memory_mut(|m| m.move_focus(egui::FocusDirection::None));
|
||||
}
|
||||
if edit.opening {
|
||||
ui.memory_mut(|m| m.request_focus(field));
|
||||
}
|
||||
let (input, rect) = crate::widgets::text_field_with_trailing(ui, field, &mut edit.text, tl!("Font"), width, crate::widgets::POPUP_ARROW_W);
|
||||
let arrow_rect =
|
||||
egui::Rect::from_min_max(egui::pos2(rect.right() - crate::widgets::POPUP_ARROW_W - 2.0, rect.top() + 2.0), rect.max - egui::vec2(2.0, 2.0));
|
||||
let arrow = ui.interact(arrow_rect, field.with("arrow"), egui::Sense::click());
|
||||
arrow.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, ui.is_enabled(), tl!("Font")));
|
||||
crate::widgets::chevron_icon(ui, arrow_rect, ui.style().interact(&arrow), was_open);
|
||||
// The arrow owns press-drag-release; dragging in the name remains normal text selection.
|
||||
// Its menu is anchored to the full control and keeps the existing stable popup id.
|
||||
let mut anchor = arrow.clone();
|
||||
anchor.id = field;
|
||||
anchor.rect = rect;
|
||||
anchor.interact_rect = rect;
|
||||
if arrow.clicked() && !ui.input(|i| i.pointer.any_click()) {
|
||||
egui::Popup::toggle_id(ui.ctx(), popup);
|
||||
}
|
||||
let mut select_all = input.gained_focus() || (!was_open && input.clicked());
|
||||
if (input.gained_focus() && !edit.accepted) || (!was_open && input.clicked()) || input.changed() {
|
||||
egui::Popup::open_id(ui.ctx(), popup);
|
||||
}
|
||||
if input.changed() {
|
||||
edit.query = edit.text.to_lowercase();
|
||||
edit.row = None;
|
||||
edit.accepted = false;
|
||||
select_all = false;
|
||||
}
|
||||
if escape || tab {
|
||||
egui::Popup::close_id(ui.ctx(), popup);
|
||||
if escape {
|
||||
ui.memory_mut(|m| m.surrender_focus(field));
|
||||
}
|
||||
edit.opening = false;
|
||||
}
|
||||
let mut changed = false;
|
||||
let mut picked = false;
|
||||
// The name is outside the popup: clicking it to move the caret keeps the list open.
|
||||
let close = if input.contains_pointer() { egui::PopupCloseBehavior::IgnoreClicks } else { egui::PopupCloseBehavior::CloseOnClickOutside };
|
||||
let response = crate::press_menu::show_with_close_behavior(&anchor, close, |ui, press| {
|
||||
let (rows, n_recent) = font_menu_rows(families, labels, &edit.query, &edit.recents);
|
||||
let mut selected = edit
|
||||
.row
|
||||
.filter(|&i| rows.get(i).is_some_and(|(f, _)| *f == current))
|
||||
.or_else(|| rows.iter().skip(n_recent).position(|(f, _)| *f == current).map(|i| i + n_recent))
|
||||
.or_else(|| rows.iter().position(|(f, _)| *f == current));
|
||||
@@ -1846,39 +1899,47 @@ pub(crate) fn family_picker_in(
|
||||
None if down => 0,
|
||||
None => rows.len().saturating_sub(1),
|
||||
};
|
||||
if let Some((f, _)) = rows.get(next) {
|
||||
if let Some((f, shown)) = rows.get(next) {
|
||||
changed = **f != *current;
|
||||
current.clone_from(f);
|
||||
// A served family not fetched yet: start now, as a click does.
|
||||
photocraft_text::served::request(f);
|
||||
stepped = Some(next);
|
||||
edit.text = (*shown).to_string();
|
||||
edit.row = Some(next);
|
||||
selected = Some(next);
|
||||
ui.data_mut(|d| d.insert_temp(row_id, next));
|
||||
stepped = Some(next);
|
||||
select_all = true;
|
||||
}
|
||||
}
|
||||
let accept = enter && rows.iter().any(|(f, _)| *f == current);
|
||||
picked |= accept;
|
||||
if accept {
|
||||
ui.data_mut(|d| d.remove::<String>(search_id));
|
||||
ui.close();
|
||||
if enter && !edit.text.trim().is_empty() {
|
||||
// A full name wins over a substring match (including localized family names).
|
||||
let exact = edit.text.to_lowercase();
|
||||
let accept = rows
|
||||
.iter()
|
||||
.position(|(f, shown)| f.to_lowercase() == exact || shown.to_lowercase() == exact)
|
||||
.or(selected)
|
||||
.or_else(|| (!rows.is_empty()).then_some(0));
|
||||
if let Some((f, _)) = accept.and_then(|i| rows.get(i)) {
|
||||
changed |= **f != *current;
|
||||
current.clone_from(f);
|
||||
photocraft_text::served::request(f);
|
||||
picked = true;
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
let preview = crate::font_preview::sample(preview);
|
||||
let row_h = preview.map_or(28.0, |(_, [_, h])| (h + 4.0).max(28.0));
|
||||
|
||||
// Wrap the font rows in a ScrollArea so only the list scrolls: the search field above
|
||||
// stays fixed at the top of the popup.
|
||||
let mut hovered: Option<String> = None;
|
||||
egui::ScrollArea::vertical().show(ui, |ui| {
|
||||
for (i, (f, label)) in rows.into_iter().enumerate() {
|
||||
let mut scroll = egui::ScrollArea::vertical().max_height(FONT_MENU_HEIGHT);
|
||||
if let Some(height) = edit.menu_height {
|
||||
scroll = scroll.max_height(height).min_scrolled_height(height).auto_shrink([true, false]);
|
||||
}
|
||||
let list = scroll.show(ui, |ui| {
|
||||
for (i, (f, shown)) in rows.into_iter().enumerate() {
|
||||
if i == n_recent && n_recent > 0 {
|
||||
ui.separator();
|
||||
}
|
||||
// Highlighted by its fill alone, as Photoshop's font menu is. A selectable button lays
|
||||
// out its frame's stroke only once hovered or selected, so with the theme's stroke the
|
||||
// row under the pointer (and the selected one) grew and pushed the rows below down:
|
||||
// the list jumped as the pointer moved (#7406). One row only, though a recent
|
||||
// family is listed twice.
|
||||
let mut button = egui::Button::selectable(selected == Some(i), label).truncate().stroke(egui::Stroke::NONE);
|
||||
// No hover stroke: growing rows would make the list jump (#7406).
|
||||
let mut button = egui::Button::selectable(selected == Some(i), shown).truncate().stroke(egui::Stroke::NONE);
|
||||
if let Some((size, [_, h])) = preview {
|
||||
button = button
|
||||
.right_text(egui::Atom::custom(ui.id().with(("font-sample", f)), egui::vec2(crate::font_preview::slot_width(ui.ctx(), f, size), h)));
|
||||
@@ -1896,83 +1957,40 @@ pub(crate) fn family_picker_in(
|
||||
hovered = Some(f.clone());
|
||||
}
|
||||
if press.chosen(ui, &response) {
|
||||
*current = f.clone();
|
||||
// A served family not fetched yet: start now, before any text needs it.
|
||||
photocraft_text::served::request(f);
|
||||
changed = true;
|
||||
current.clone_from(f);
|
||||
photocraft_text::served::request(f);
|
||||
picked = true;
|
||||
ui.data_mut(|d| d.remove::<String>(search_id));
|
||||
hovered = None;
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
// egui measures a popup only when it opens and never lets it grow back, so a filtered
|
||||
// list would leave the menu short after the query is cleared (#1369). Keep the unfiltered
|
||||
// height while searching. Measured after the rows: before them `min_rect` only holds the
|
||||
// search field, and the cache would shrink the menu to it.
|
||||
if ql.is_empty() {
|
||||
let h = ui.min_rect().height();
|
||||
ui.data_mut(|d| d.insert_temp(height_id, h));
|
||||
} else if let Some(h) = ui.data(|d| d.get_temp::<f32>(height_id)) {
|
||||
ui.set_min_height(h.min(FONT_MENU_HEIGHT));
|
||||
}
|
||||
if accept { None } else { hovered }
|
||||
// Freeze the measured viewport, rather than the popup's padded minimum height:
|
||||
// feeding the latter back into the scroll area makes clearing a query grow it (#1369).
|
||||
edit.menu_height.get_or_insert(list.inner_rect.height());
|
||||
if picked { None } else { hovered }
|
||||
});
|
||||
press.after(&response.response);
|
||||
if !egui::ComboBox::is_open(ui.ctx(), response.response.id) {
|
||||
ui.data_mut(|d| {
|
||||
d.remove::<bool>(focus_id);
|
||||
d.remove::<Vec<String>>(recents_id);
|
||||
d.remove::<usize>(row_id);
|
||||
});
|
||||
}
|
||||
let hovered_font = response.inner.unwrap_or_default();
|
||||
|
||||
// As in Photoshop, the field keeps the keyboard focus once a font is picked, and ↑ / ↓ on the
|
||||
// focused, closed field step to the previous / next family, applying each (#7407). The lock
|
||||
// filter keeps egui from using those arrows to move the focus to another widget.
|
||||
let field = response.response.id;
|
||||
if picked {
|
||||
let open = egui::Popup::is_id_open(ui.ctx(), popup);
|
||||
if !was_open && open {
|
||||
edit.recents = recents.to_vec();
|
||||
edit.opening = arrow.is_pointer_button_down_on() && ui.input(|i| i.pointer.primary_down());
|
||||
ui.memory_mut(|m| m.request_focus(field));
|
||||
select_all = !input.changed();
|
||||
}
|
||||
let open = egui::ComboBox::is_open(ui.ctx(), field);
|
||||
if !open && ui.is_enabled() && ui.memory(|m| m.has_focus(field)) {
|
||||
ui.memory_mut(|m| m.set_focus_lock_filter(field, egui::EventFilter { vertical_arrows: true, ..Default::default() }));
|
||||
let down = ui.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::ArrowDown));
|
||||
let up = ui.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::ArrowUp));
|
||||
if down || up {
|
||||
// The lock filter only holds from the frame after the field got the focus: an arrow
|
||||
// right after a pick was already read by egui as a focus move, applied at the end of
|
||||
// the frame. Cancel it, so the arrow only steps the font.
|
||||
ui.memory_mut(|m| m.move_focus(egui::FocusDirection::None));
|
||||
}
|
||||
// The wheel's step: a negative notch is the next family. Steps use a stable order (no
|
||||
// recent group), so recording the picked family cannot make the next step jump back.
|
||||
let notches = f32::from(u8::from(up)) - f32::from(u8::from(down));
|
||||
let (rows, _) = font_menu_rows(families, labels, "", &[]);
|
||||
if let Some(i) = rows.iter().position(|(f, _)| *f == current)
|
||||
&& let Some(n) = wheel_family_index(i, rows.len(), notches)
|
||||
&& let Some((f, _)) = rows.get(n)
|
||||
&& **f != *current
|
||||
{
|
||||
current.clone_from(f);
|
||||
photocraft_text::served::request(f);
|
||||
changed = true;
|
||||
}
|
||||
// A held opening arrow can regain focus on release; keep the name selected through it.
|
||||
if edit.opening {
|
||||
ui.memory_mut(|m| m.request_focus(field));
|
||||
select_all |= !input.changed();
|
||||
edit.opening = ui.input(|i| i.pointer.primary_down());
|
||||
}
|
||||
|
||||
// The wheel over the closed button steps through the families, a notch each, like Photoshop's
|
||||
// options-bar font menu: no need to open the list (#3350).
|
||||
if !egui::ComboBox::is_open(ui.ctx(), response.response.id) && ui.is_enabled() {
|
||||
let hovered = response.response.hovered();
|
||||
if !open && !escape && ui.is_enabled() {
|
||||
let notches = if had_focus { f32::from(u8::from(up)) - f32::from(u8::from(down)) } else { 0.0 };
|
||||
let hovered = input.hovered() || arrow.hovered();
|
||||
if hovered {
|
||||
ui.input_mut(|i| i.smooth_scroll_delta = egui::Vec2::ZERO);
|
||||
}
|
||||
let notches = crate::widgets::wheel_notches_of(ui, response.response.id.with("family-wheel"), hovered, 1.0);
|
||||
// The wheel steps in a stable order: a recent group holding the family it just picked
|
||||
// would change the order between notches and can jump back to the previous family.
|
||||
// The open menu still shows the recent families first.
|
||||
let notches = notches + crate::widgets::wheel_notches_of(ui, field.with("family-wheel"), hovered, 1.0);
|
||||
// Closed-field navigation stays alphabetical, independent of recent picks (#3350, #7407).
|
||||
let (rows, _) = font_menu_rows(families, labels, "", &[]);
|
||||
if let Some(i) = rows.iter().position(|(f, _)| *f == current)
|
||||
&& let Some(n) = wheel_family_index(i, rows.len(), notches)
|
||||
@@ -1982,20 +2000,39 @@ pub(crate) fn family_picker_in(
|
||||
current.clone_from(f);
|
||||
photocraft_text::served::request(f);
|
||||
changed = true;
|
||||
select_all |= had_focus;
|
||||
}
|
||||
}
|
||||
|
||||
if salt == "type-font" {
|
||||
if picked || (!open && (was_open || changed || escape)) {
|
||||
edit.text = label(current);
|
||||
edit.query.clear();
|
||||
edit.row = None;
|
||||
edit.accepted = true;
|
||||
edit.opening = false;
|
||||
edit.composing = false;
|
||||
}
|
||||
if picked {
|
||||
ui.memory_mut(|m| m.request_focus(field));
|
||||
select_all = true;
|
||||
}
|
||||
if select_all && !escape {
|
||||
crate::field_tab::select_all(ui.ctx(), field, &edit.text);
|
||||
}
|
||||
edit.current.clone_from(current);
|
||||
if open || ui.memory(|m| m.has_focus(field)) {
|
||||
ui.data_mut(|d| d.insert_temp(edit_id, edit));
|
||||
} else {
|
||||
ui.data_mut(|d| d.remove::<FontFieldEdit>(edit_id));
|
||||
}
|
||||
if salt == "type-font" && (was_open || open || response.is_some()) {
|
||||
// Only this popup's owner clears its preview; a closed peer must leave it alone (#5152).
|
||||
let hover_id = egui::Id::new("type-font-hover");
|
||||
if let Some(f) = hovered_font {
|
||||
if let Some(f) = response.flatten().filter(|_| open) {
|
||||
ui.ctx().data_mut(|d| d.insert_temp(hover_id, f));
|
||||
} else if egui::ComboBox::is_open(ui.ctx(), response.response.id) {
|
||||
// Only the open menu clears it: the options bar and the Character section both draw
|
||||
// this picker, and the closed one must not wipe the other's hover (#5152).
|
||||
} else {
|
||||
ui.ctx().data_mut(|d| d.remove::<String>(hover_id));
|
||||
}
|
||||
}
|
||||
|
||||
changed
|
||||
}
|
||||
|
||||
|
||||
@@ -2019,7 +2019,7 @@ mod multi_layer_formatting {
|
||||
let (app, ids) = fixture();
|
||||
let before = ids.map(|id| style(&app, id, 0));
|
||||
let mut h = controls(app, false);
|
||||
h.get_all_by_role(Role::ComboBox).next().unwrap().click();
|
||||
h.get_all_by_role(Role::TextInput).next().unwrap().click();
|
||||
h.run();
|
||||
h.get_by_role(Role::TextInput).type_text("JetBrains");
|
||||
h.key_press(egui::Key::ArrowDown);
|
||||
@@ -2042,7 +2042,7 @@ mod multi_layer_formatting {
|
||||
assert_eq!(style(h.state(), ids[i], 0), expected, "family changes preserve each peer's face and metrics");
|
||||
}
|
||||
assert_eq!(style(h.state(), ids[2], 0), before[2]);
|
||||
h.get_all_by_role(Role::ComboBox).nth(2).unwrap().click();
|
||||
h.get_all_by_role(Role::ComboBox).find(|n| n.value().as_deref() == Some("Smooth")).unwrap().click();
|
||||
h.run();
|
||||
h.get_by_label("Sharp").click();
|
||||
h.run();
|
||||
@@ -2079,7 +2079,7 @@ mod multi_layer_formatting {
|
||||
);
|
||||
PhotocraftApp::setup_context(&h.ctx, Default::default());
|
||||
h.run_steps(4);
|
||||
h.get_all_by_role(Role::ComboBox).next().unwrap().click();
|
||||
h.get_all_by_role(Role::TextInput).next().unwrap().click();
|
||||
h.run();
|
||||
h.run();
|
||||
}
|
||||
|
||||
@@ -869,6 +869,24 @@ pub fn text_field(ui: &mut Ui, id: egui::Id, text: &mut String, hint: &str, widt
|
||||
/// [`text_field`] limited to `char_limit` characters (a hex field's six digits, say), or to
|
||||
/// [`TEXT_FIELD_LIMIT`] without one.
|
||||
pub fn text_field_ex(ui: &mut Ui, id: egui::Id, text: &mut String, hint: &str, width: f32, mono: bool, char_limit: Option<usize>) -> Response {
|
||||
text_field_in(ui, id, text, hint, [width, 0.0], mono, char_limit).0
|
||||
}
|
||||
|
||||
/// A plain text field reserving space at its right for an embedded popup arrow.
|
||||
/// Returns the editor and the full field rectangle; the arrow gets its own interaction id.
|
||||
pub fn text_field_with_trailing(ui: &mut Ui, id: egui::Id, text: &mut String, hint: &str, width: f32, trailing: f32) -> (Response, Rect) {
|
||||
text_field_in(ui, id, text, hint, [width, trailing], false, None)
|
||||
}
|
||||
|
||||
fn text_field_in(
|
||||
ui: &mut Ui,
|
||||
id: egui::Id,
|
||||
text: &mut String,
|
||||
hint: &str,
|
||||
[width, trailing]: [f32; 2],
|
||||
mono: bool,
|
||||
char_limit: Option<usize>,
|
||||
) -> (Response, Rect) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let (rect, _) = ui.allocate_exact_size(vec2(width.max(16.0), TEXT_FIELD_H), Sense::hover());
|
||||
surface(ui, rect, t.field, false);
|
||||
@@ -876,7 +894,8 @@ pub fn text_field_ex(ui: &mut Ui, id: egui::Id, text: &mut String, hint: &str, w
|
||||
ui.painter().rect_stroke(rect, t.radius_sm, Stroke::new(1.0, t.field_border), StrokeKind::Inside);
|
||||
}
|
||||
let font = if mono { theme::mono(12.0) } else { egui::FontId::proportional(12.5) };
|
||||
let inner = rect.shrink2(TEXT_FIELD_PAD);
|
||||
let mut inner = rect.shrink2(TEXT_FIELD_PAD);
|
||||
inner.max.x = (inner.max.x - trailing).max(inner.min.x + 1.0);
|
||||
let limit = char_limit.unwrap_or(TEXT_FIELD_LIMIT);
|
||||
// A value already past the limit (restored from a state file, set by automation) is shown and
|
||||
// edited as its first `limit` characters, so it is never laid out whole; the caller's string
|
||||
@@ -909,7 +928,7 @@ pub fn text_field_ex(ui: &mut Ui, id: egui::Id, text: &mut String, hint: &str, w
|
||||
{
|
||||
*text = b;
|
||||
}
|
||||
response
|
||||
(response, rect)
|
||||
}
|
||||
|
||||
fn first_field_id() -> egui::Id {
|
||||
|
||||
+3
-1
@@ -1,6 +1,6 @@
|
||||
# UI parity: tools, handles, modifiers and feel
|
||||
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-23 · **Change:** minor (⌥ + an adjustment's shortcut reopens it at its last settings, ⌥⌘L / ⌥⌘M, #8900; Crop default mode: moving the image under the box snaps the frame's edges and centre, #8580; View › Extras hides the Move transform controls, #6699; adjustment clipping stays visible in compact Properties, #5231; Color panel modes from its panel menu, the same in every theme, UI-217-17, #6000; a picked colour recolours the selected type and shapes; Hand tool ⌘ / ⌥ are Zoom In / Zoom Out while held, #6434; the wheel steps value fields, #5473; a dragged guide shows its X or Y beside the pointer, #7680; Type options bar "T" icon scrubs the font size, #6437; Move tool: dragged selected pixels take their own outline as the selection, #7538; artboard backgrounds remain below child Free Transform previews; ⌫/Delete removes the selected smart filter, #4751; Object Finder foreground/background discrimination (#6548); rounded triangle, polygon and star corners; shape Fill/Stroke popovers accept hex RGB values, #6176; a guide let go over either ruler is removed, #6286; Crop rows corrected: saved crop presets and Delete Cropped Pixels off are done, #6562; marching ants in device pixels, #7489; Animated Zoom: holding the Zoom tool zooms continuously, #6210; shape Density and Feather, TOOL-214-12, #5846; Pen Auto Add/Delete on the path being drawn, #6140; Show Transform Controls frames every selected layer; guide keys and clicks; menu bar from the keyboard, #4988; Crop tool Content-Aware Fill; on-canvas corner radius widgets, TOOL-214-12; Curvature Pen edits the active path; Clip Thumbnails to Layer Bounds; Pen ⇧ 45°; last selected tool restored at launch; Layers panel filter-type dropdown with Kind, Name and Mode, #5048; Free Transform box and marching ants follow the selection, #5297; History: the trash deletes the selected snapshot, rows drag onto the trash, #5324; smart filter reordering by drag; smart object perspective row corrected to done, #426; Free Transform H/V skew fields; toolbar tool shortcuts can be reassigned; ⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys; spring-loaded tool letters; type formatting keys; Pen Auto Add/Delete, #4144; smart filter rows; stale missing-tool rows corrected: Color Replacement, Red Eye and the Add/Delete Anchor Point pair are live toolbar tools, Frame landed; no percentage changed; selection-modifier and ⌥-wheel rows match their tests) · **Target:** Adobe Photoshop 2026
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-25 · **Change:** minor (direct font-name editing in shared Type controls, #9338; ⌥ + an adjustment's shortcut reopens it at its last settings, ⌥⌘L / ⌥⌘M, #8900; Crop default mode: moving the image under the box snaps the frame's edges and centre, #8580; View › Extras hides the Move transform controls, #6699; adjustment clipping stays visible in compact Properties, #5231; Color panel modes from its panel menu, the same in every theme, UI-217-17, #6000; a picked colour recolours the selected type and shapes; Hand tool ⌘ / ⌥ are Zoom In / Zoom Out while held, #6434; the wheel steps value fields, #5473; a dragged guide shows its X or Y beside the pointer, #7680; Type options bar "T" icon scrubs the font size, #6437; Move tool: dragged selected pixels take their own outline as the selection, #7538; artboard backgrounds remain below child Free Transform previews; ⌫/Delete removes the selected smart filter, #4751; Object Finder foreground/background discrimination (#6548); rounded triangle, polygon and star corners; shape Fill/Stroke popovers accept hex RGB values, #6176; a guide let go over either ruler is removed, #6286; Crop rows corrected: saved crop presets and Delete Cropped Pixels off are done, #6562; marching ants in device pixels, #7489; Animated Zoom: holding the Zoom tool zooms continuously, #6210; shape Density and Feather, TOOL-214-12, #5846; Pen Auto Add/Delete on the path being drawn, #6140; Show Transform Controls frames every selected layer; guide keys and clicks; menu bar from the keyboard, #4988; Crop tool Content-Aware Fill; on-canvas corner radius widgets, TOOL-214-12; Curvature Pen edits the active path; Clip Thumbnails to Layer Bounds; Pen ⇧ 45°; last selected tool restored at launch; Layers panel filter-type dropdown with Kind, Name and Mode, #5048; Free Transform box and marching ants follow the selection, #5297; History: the trash deletes the selected snapshot, rows drag onto the trash, #5324; smart filter reordering by drag; smart object perspective row corrected to done, #426; Free Transform H/V skew fields; toolbar tool shortcuts can be reassigned; ⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys; spring-loaded tool letters; type formatting keys; Pen Auto Add/Delete, #4144; smart filter rows; stale missing-tool rows corrected: Color Replacement, Red Eye and the Add/Delete Anchor Point pair are live toolbar tools, Frame landed; no percentage changed; selection-modifier and ⌥-wheel rows match their tests) · **Target:** Adobe Photoshop 2026
|
||||
|
||||
How PhotoCraft's direct manipulation compares with Photoshop 2026 (27.11.0): the toolbox, the
|
||||
handles and modifier keys of each gesture, nudging, snapping, numeric precision, navigation,
|
||||
@@ -171,6 +171,7 @@ Triangle and Curvature Pen (minus legacy Rounded Rectangle and Targeted Adjustme
|
||||
| Geometry precision | partial | `geom::Point` f64, paths f64; paint internals mostly f32 |
|
||||
| Numeric fields: arithmetic, scrubby labels | partial | units in expressions and double-click reset missing (UI-217-13) |
|
||||
| Wheel steps a value field, ⇧ ×10: clicked into, wherever the pointer is; not clicked, a gesture that starts over it | partial | `field_wheel.rs` (#5473, #4061). Photoshop: a field takes the wheel once clicked into (shortcut guides, user reports); whether the pointer must stay over it is unconfirmed. Stepping on hover alone is Photopea's, kept deliberately |
|
||||
| Font-name field: click selects the full name; typing searches in place | done | `type_tool.rs` `family_picker_in`, `type_font_picker_tests.rs` (#9338): one editable name above the list; Enter or a row accepts; Escape/outside click discards pending text; existing navigation and previews retained |
|
||||
| Type options bar: drag the "T" icon to change the font size | done | `type_tool.rs` `options_bar`: the icon scrubs the size field like the Character panel's icons (Shift x10, Alt fine), at layer or selection scope, one history step per drag, within 1–1296 pt (#6437) |
|
||||
|
||||
## Navigation
|
||||
@@ -300,3 +301,4 @@ Paragraph; the rest open as in-app floating windows.
|
||||
| 2026-10-14 | minor | A colour picked in the Color or Swatches panel or the Color Picker recolours the selected type layers (Type tool) or shape fills (shape, Pen and path selection tools) |
|
||||
| 2026-10-15 | minor | Color panel: Photoshop's panel-menu modes, colour ramp and copy commands; the theme no longer picks the panel's layout (UI-217-17 done, #2569, #6000) |
|
||||
| 2026-10-23 | minor | ⌥ + an adjustment's shortcut (⌥⌘L Levels, ⌥⌘M Curves) opens its dialog at the settings of its last OK, as in Photoshop (#8900); no percentage changed |
|
||||
| 2026-10-25 | minor | Shared font-family fields support direct name editing and search, with full-name selection on entry, explicit acceptance and cancellation (#9338); no percentage changed |
|
||||
Reference in new issue
Block a user