Implement fix suggestions (interact area on resize)

This commit is contained in:
Okko Hakola 2023-04-23 19:44:32 +03:00
parent 790d9ef5f9
commit 4cfe393412
2 changed files with 28 additions and 10 deletions

View File

@ -455,6 +455,9 @@ fn draw_connection(painter: &Painter, src_pos: Pos2, dst_pos: Pos2, color: Color
painter.add(bezier);
}
#[derive(Clone, Copy, Debug)]
struct OuterRectMemory(Rect);
impl<'a, NodeData, DataType, ValueType, UserResponse, UserState>
GraphNodeWidget<'a, NodeData, DataType, ValueType>
where
@ -513,15 +516,6 @@ where
let outer_rect_bounds = ui.available_rect_before_wrap();
// Hack?: Call this before the content of the node
// to ensure interaction works after egui 0.19. Otherwise the layers block
// hover interaction
let window_response = ui.interact(
outer_rect_bounds,
Id::new((self.node_id, "window")),
Sense::click_and_drag(),
);
let mut inner_rect = outer_rect_bounds.shrink2(margin);
// Make sure we don't shrink to the negative:
@ -529,6 +523,24 @@ where
inner_rect.max.y = inner_rect.max.y.max(inner_rect.min.y);
let mut child_ui = ui.child_ui(inner_rect, *ui.layout());
// Get interaction rect from memory, it may expand after the window response on resize.
let interaction_rect = ui
.ctx()
.memory_mut(|mem| {
mem.data
.get_temp::<OuterRectMemory>(child_ui.id())
.map(|stored| stored.0)
})
.unwrap_or(outer_rect_bounds);
// After 0.20, layers added over others can block hover interaction. Call this first
// before creating the node content.
let window_response = ui.interact(
interaction_rect,
Id::new((self.node_id, "window")),
Sense::click_and_drag(),
);
let mut title_height = 0.0;
let mut input_port_heights = vec![];
@ -600,6 +612,12 @@ where
let port_left = outer_rect.left();
let port_right = outer_rect.right();
// Save expanded rect to memory.
ui.ctx().memory_mut(|mem| {
mem.data
.insert_temp(child_ui.id(), OuterRectMemory(outer_rect))
});
#[allow(clippy::too_many_arguments)]
fn draw_port<NodeData, DataType, ValueType, UserResponse, UserState>(
ui: &mut Ui,

View File

@ -65,7 +65,7 @@ where
let mut query_submit = resp.lost_focus() && ui.input(|i| i.key_pressed(Key::Enter));
let max_height = ui.input(|i| i.screen_rect.height());
let max_height = ui.input(|i| i.screen_rect.height() * 0.5);
let scroll_area_width = resp.rect.width() - 30.0;
Frame::default()