mirror of
https://github.com/storytold/materialcraft.git
synced 2026-11-21 06:50:53 +01:00
Merge pull request #68 from Belligerently/fix/search-result-row-width
Make node-search result rows clickable across their width
This commit is contained in:
2 files changed
+44
No files matched your search
@@ -1157,6 +1157,7 @@ fn search_popup(app: &mut MaterialCraftApp, ui: &mut Ui, cam: &Cam) {
|
||||
for (i, d) in list.iter().enumerate() {
|
||||
let r = ui.add(
|
||||
egui::Button::selectable(i == s.sel, format!("{} ", d.label))
|
||||
.min_size(vec2(ui.available_width(), 0.0))
|
||||
.right_text(egui::RichText::new(d.group()).size(10.0).color(tk.text_dim)),
|
||||
);
|
||||
if i == s.sel && (up || down || reveal_selection) {
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
//! Clicking anywhere across a search result's row should insert that result.
|
||||
#[path = "common/search.rs"]
|
||||
mod search;
|
||||
use egui::{Event, Modifiers, PointerButton, Pos2, pos2, vec2};
|
||||
use egui_kittest::Harness;
|
||||
use materialcraft_ui_egui::MaterialCraftApp;
|
||||
|
||||
fn right_side(h: &Harness<'static, MaterialCraftApp>) -> Pos2 {
|
||||
let y = search::label_position(h, "Bitmap").unwrap().y;
|
||||
let popup = h.ctx.memory(|m| m.area_rect(egui::Id::unique("node-search"))).unwrap();
|
||||
pos2(popup.right() - 24.0, y)
|
||||
}
|
||||
fn click(h: &mut Harness<'static, MaterialCraftApp>, pos: Pos2) {
|
||||
h.event(Event::PointerMoved(pos));
|
||||
h.step();
|
||||
for pressed in [true, false] {
|
||||
h.event(Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE });
|
||||
h.step();
|
||||
}
|
||||
h.run_steps(3);
|
||||
}
|
||||
#[test]
|
||||
fn clicking_label_or_right_side_inserts_the_same_result() {
|
||||
for right in [false, true] {
|
||||
let mut h = search::harness(false);
|
||||
let pos = if right { right_side(&h) } else { search::label_position(&h, "Bitmap").unwrap() + vec2(8.0, 0.0) };
|
||||
click(&mut h, pos);
|
||||
let graph = h.state().session.graph().unwrap();
|
||||
assert_eq!(graph.nodes.len(), 1, "row click did not insert a node (right_side={right})");
|
||||
assert_eq!(graph.nodes[0].def, "bitmap");
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
#[ignore = "requires an offscreen GPU"]
|
||||
fn full_width_result_screenshot() {
|
||||
let mut h = search::harness(true);
|
||||
let pos = right_side(&h);
|
||||
h.event(Event::PointerMoved(pos));
|
||||
h.run_steps(3);
|
||||
let dir = std::path::PathBuf::from(std::env::var_os("MC_SNAPSHOT_DIR").expect("set MC_SNAPSHOT_DIR"));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
h.render().unwrap().save(dir.join("full-width-search-result.png")).unwrap();
|
||||
}
|
||||
Reference in new issue
Block a user