Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions crates/ui-egui/src/headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,56 @@ mod tests {
assert_eq!(diff, 0, "{diff} pixels differ between two runs");
}

#[test]
fn survey_thumbnail_clicks_add_and_activate_without_losing_the_group() {
let mut h = demo([1200.0, 760.0]);
let t = Duration::from_secs(10);
let ids: Vec<u64> = h.app.session.visible_cloned().iter().map(|id| id.0).collect();
h.request("engine.execute", json!({"command": "library.select", "params": {"ids": [ids[0]]}}), t);
let reply = h.request("ui.clickWidget", json!({"id": "icon:survey"}), t);
assert_eq!(reply["ok"], true, "{reply}");
for id in &ids[1..4] {
h.request("ui.clickWidget", json!({"id": format!("film:{id}")}), t);
}
let state = h.request("ui.inspect", json!({}), t)["result"].clone();
assert_eq!(state["selection"], json!(ids[..4]));
let tiles = h.request("ui.widgets", json!({"filter": "cull:"}), t)["result"].clone();
let displayed: Vec<_> = tiles.as_array().unwrap().iter().map(|tile| tile["id"].as_str().unwrap().to_owned()).collect();
assert_eq!(displayed, ids[..4].iter().map(|id| format!("cull:{id}")).collect::<Vec<_>>());
// Revisiting a selected thumbnail activates it without collapsing the survey.
h.request("ui.clickWidget", json!({"id": format!("film:{}", ids[1])}), t);
let state = h.request("ui.inspect", json!({}), t)["result"].clone();
assert_eq!(state["selection"], json!(ids[..4]));
assert_eq!(state["active"], ids[1]);
h.request("ui.clickWidget", json!({"id":format!("film:{}",ids[3]),"cmd":true}), t);
assert_eq!(h.request("ui.inspect", json!({}), t)["result"]["selection"], json!(ids[..3]));
h.request("ui.clickWidget", json!({"id":format!("film:{}",ids[4]),"shift":true}), t);
assert_eq!(h.request("ui.inspect", json!({}), t)["result"]["selection"], json!(ids[..5]));
h.settle(SETTLE);
}

#[test]
fn survey_remove_click_keeps_the_other_photos() {
let mut h = demo([1200.0, 760.0]);
let t = Duration::from_secs(10);
let ids: Vec<u64> = h.app.session.visible_cloned().iter().map(|id| id.0).collect();
h.request("engine.execute", json!({"command":"library.select", "params":{"ids":ids[..3]}}), t);
h.request("ui.set", json!({"view":"survey"}), t);
h.settle(SETTLE);
let widget = format!("cull:{}", ids[1]);
h.request("ui.hoverWidget", json!({"id":widget}), t);
let widgets = h.request("ui.widgets", json!({"filter":widget}), t)["result"].clone();
let rect = &widgets[0]["rect"];
// The close control sits at the displayed photo's top-right corner.
let x = rect[0].as_f64().unwrap() + rect[2].as_f64().unwrap() - 16.0;
let y = rect[1].as_f64().unwrap() + 16.0;
let reply = h.request("ui.click", json!({"x":x,"y":y}), t);
assert_eq!(reply["ok"], true, "{reply}");
let state = h.request("ui.inspect", json!({}), t)["result"].clone();
assert_eq!(state["selection"], json!([ids[0], ids[2]]));
h.settle(SETTLE);
}

/// Keyboard culling: Compare (rating keys hit the candidate, arrows move it, auto-advance),
/// Survey (keys hit the active photo only), and auto-advance in Detail.
#[test]
Expand Down
4 changes: 3 additions & 1 deletion crates/ui-egui/src/panels/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,11 @@ pub fn show_survey(app: &mut LightcraftApp, ui: &mut egui::Ui) {
app.ui.view = ViewMode::Detail;
}
// remove from the survey (deselect) on hover
if resp.hovered() && photos.len() > 1 {
if ui.input(|input| input.pointer.hover_pos().is_some_and(|pos| cell.contains(pos))) && photos.len() > 1 {
let xr = Rect::from_min_size(pos2(img.right() - 26.0, img.top() + 6.0), vec2(20.0, 20.0));
let xresp = ui.interact(xr, egui::Id::new(("survey-x", id.0)), Sense::click()).on_hover_text(crate::i18n::tr("Remove from survey"));
xresp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, crate::i18n::tr("Remove from survey")));
register(ui.ctx(), format!("icon:surveyRemove:{}", id.0), xr);
ui.painter().circle_filled(xr.center(), 10.0, Color32::from_black_alpha(if xresp.hovered() { 230 } else { 160 }));
paint(ui.painter(), xr.shrink(4.0), Icon::Close, t.text);
if xresp.clicked() {
Expand Down
3 changes: 3 additions & 0 deletions crates/ui-egui/src/panels/detail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2344,6 +2344,9 @@ pub(crate) fn filmstrip(app: &mut LightcraftApp, ui: &mut egui::Ui, r: Rect) {
"toggle"
} else if m.shift {
"range"
} else if app.ui.view == crate::state::ViewMode::Survey {
// Keep the surveyed group; an existing thumbnail only becomes active.
"add"
} else {
"replace"
};
Expand Down