-
Hello community, I have an issue that I cannot seem to solve: I have a grid with placement slots where vertices can be visually added and removed, something like this: Vertices are placed with absolute positioning within the area, no Layout is involved. In the picture are two vertices, this is the pseudo-code of the impl Widget for Vertex {
fn ui(self, ui: &mut Ui) -> Response {
let response = ui.allocate_rect(cwd.ui_rect(), Sense::click());
let font_id = TextStyle::Body.resolve(ui.style());
if response.hovered() {
ui.painter()
.circle_filled(cwd.ui_pos(), cwd.ui_radius(), Color32::RED);
} else {
ui.painter()
.circle_filled(cwd.ui_pos(), cwd.ui_radius(), Color32::GREEN);
}
ui.painter().text(
cwd.ui_pos(),
Align2::CENTER_CENTER,
self.op.to_string(),
font_id.clone(),
Colors::RED,
);
response
}
} The problem I'm experiencing is that when I proceed to delete the vertex on the right, during the next frame the previous vertex (relative to the rendering order, in this case the left one) will flash RED as if the response to the input state of the old one jumped over to it. I suppose these are Any insight on how the Response system works and what I am doing wrong would be greatly appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Try wrapping your per-vertex ui-code in It would be nice with an API for allocating some space with a specific Id though, but alas we don't have that |
Beta Was this translation helpful? Give feedback.
-
That worked like a charm! Thank you! This will come in handy in the future :) |
Beta Was this translation helpful? Give feedback.
Try wrapping your per-vertex ui-code in
ui.push_id(vertex_uuid, …)
.It would be nice with an API for allocating some space with a specific Id though, but alas we don't have that