LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Merge PR #1755
Brandon Thomasa0b55e66bb71
diff --cc crates/ui-egui/src/panels/right.rsindex 6a363278a,49f1949d0..685f4bc33--- a/crates/ui-egui/src/panels/right.rs+++ b/crates/ui-egui/src/panels/right.rs@@@ -876,15 -852,8 +910,17 @@@ fn keywords(app: &mut LightcraftApp, uiif app.session.catalog.photo(id).is_none() {return;}+ let top = ui.cursor().top();- header(ui, "Keywords");+ if fold_header(app, ui, "keywording", "Keywords") {+ keywording(app, ui);+ }++ hold_list_in_place(ui, top);+ super::keyword_list::show(app, ui);+}++/// The Keywording box: the field that adds keywords, the selection's keywords, the keyword set,+/// the painter and the suggestions.+fn keywording(app: &mut LightcraftApp, ui: &mut egui::Ui) {let t = Tokens::get(ui.ctx());padded(ui, |ui| {let kid = egui::Id::new("kw-input");@@@ -1061,8 -932,39 +1097,37 @@@});}});- hold_list_in_place(ui, top);- super::keyword_list::show(app, ui);}+ /// Keeps the Keyword List where it is on screen when the Keywords box above it (starting at+ /// `top`) grows or shrinks: a keyword ticked or unticked in the list, another selection. Without it+ /// a long tree slides away from under the pointer by a row of chips each time. It holds only while+ /// the box's top is scrolled out of sight (at the top of the panel the box is watched growing) and+ /// while the change does not come from the box itself (the pointer on it, or typing in its field).+ fn hold_list_in_place(ui: &mut egui::Ui, top: f32) {+ let height = ui.cursor().top() - top;+ let key = egui::Id::new("kw-box-height");+ let pass = ui.ctx().cumulative_pass_nr();+ // (the height drawn on the pass before: one from an earlier visit to the panel says nothing)+ let before = ui.data(|d| d.get_temp::<(f32, u64)>(key)).filter(|&(_, drawn)| drawn.checked_add(1) == Some(pass)).map(|(h, _)| h);+ ui.data_mut(|d| d.insert_temp(key, (height, pass)));+ let Some(before) = before else { return };+ let grew = height - before;+ if !grew.is_finite() || grew.abs() < 0.5 || top >= ui.clip_rect().top() - 0.5 {+ return;+ }+ // (only the part of it in sight: the pointer on the top bar above a half-hidden box isn't on it)+ let old_box = Rect::from_x_y_ranges(ui.max_rect().x_range(), top..=top + before).intersect(ui.clip_rect());+ let on_box = ui.input(|i| i.pointer.latest_pos()).is_some_and(|p| old_box.contains(p));+ let typing = ui.memory(|m| m.has_focus(crate::text_field::id("field:keyword")));+ if on_box || typing {+ return;+ }+ ui.data_mut(|d| d.insert_temp(egui::Id::new(HOLD), (grew, pass)));+ // (drawn again at once at the new offset, so the list never shows a frame out of place)+ ui.ctx().request_discard("the Keyword List holds its place");+ }+/// The keyword set: pick a set, then nine buttons (⌥1–⌥9) that toggle its keywords on the/// selected photos; "Save as Set…" keeps the current nine under a name.fn keyword_set(app: &mut LightcraftApp, ui: &mut egui::Ui) {