Getting the selected value from a Plot #1778
Replies: 4 comments
-
I have the same problem. |
Beta Was this translation helpful? Give feedback.
-
I'm working on something right now and would like this feature as well. |
Beta Was this translation helpful? Give feedback.
-
I propose a pull request #2572 that covers this aspect, it not directly retrieve the pointer coordinate selected by the radius but give if is_in_radius, hovered indexes and item name hovered after that you can retrieve information about the selected value from a item Plot. |
Beta Was this translation helpful? Give feedback.
-
You can use The obvious implementation of this workaround - cloning the My solution looks like this: let (tx, rx) = mpsc::channel::<PlotPoint>();
let plot_response = Plot::new("known implants plot")
.label_formatter(move |_name, value| {
let _response = tx.send(value.clone());
format!("x={value.x}\ny={value.y}")
})
.show(ui, |ui| { ui.points(points) } );
let crosshair: PlotPoint = if let Ok(value) = rx.recv() {
Some(value)
} else {
// nothing was sent, e.g. because the user doesn't hover the plot
None
}; Additionally, you can check if the crosshair is snapped to a plot item or not by doing: let mouse_position = plot_response.response.hover_pos();
if let Some(crosshair) = crosshair {
// check if the position of the mouse and the position of the crosshair
// are identical (in screenspace here, but plotspace should work too)
let crosshair_is_snapped = mouse_position != plot_response.transform.position_from_point(&crosshair);
} |
Beta Was this translation helpful? Give feedback.
-
Hey,
I would like to know if there is a way to get the value that has been auto-snap-selected by egui when the cursor moves nearby.
I know that we can get the exact position of the cursor by using
PlotUi::pointer_coordinate
but it is not exactly what I would like.For example on this screenshot, my cursor is at something like 30px from the auto-snap-selected value.
Beta Was this translation helpful? Give feedback.
All reactions