From 0490cde55ab8d44f3ae2e9e7e134933a902cb1d1 Mon Sep 17 00:00:00 2001 From: Ygor Souza Date: Mon, 27 May 2024 17:18:00 +0200 Subject: [PATCH] Use the interact_radius from the UI style on the plot --- crates/egui_demo_lib/src/demo/plot_demo.rs | 12 ++++++------ crates/egui_plot/src/lib.rs | 18 +----------------- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/crates/egui_demo_lib/src/demo/plot_demo.rs b/crates/egui_demo_lib/src/demo/plot_demo.rs index 326fd18edce..e8644ef3ab0 100644 --- a/crates/egui_demo_lib/src/demo/plot_demo.rs +++ b/crates/egui_demo_lib/src/demo/plot_demo.rs @@ -133,7 +133,7 @@ struct LineDemo { show_axes: bool, show_grid: bool, line_style: LineStyle, - interact_distance: f32, + interact_radius: f32, } impl Default for LineDemo { @@ -149,7 +149,7 @@ impl Default for LineDemo { show_axes: true, show_grid: true, line_style: LineStyle::Solid, - interact_distance: 16.0, + interact_radius: egui::style::Interaction::default().interact_radius, } } } @@ -167,7 +167,7 @@ impl LineDemo { show_axes, show_grid, line_style, - interact_distance, + interact_radius, } = self; ui.horizontal(|ui| { @@ -201,8 +201,8 @@ impl LineDemo { ui.checkbox(coordinates, "Show coordinates on hover") .on_hover_text("Can take a custom formatting function."); ui.horizontal(|ui| { - ui.add(egui::DragValue::new(interact_distance).clamp_range(0.0..=100.0)); - ui.label("Interact distance"); + ui.add(egui::DragValue::new(interact_radius).clamp_range(0.0..=100.0)); + ui.label("Interact radius"); }); }); @@ -285,7 +285,6 @@ impl LineDemo { let mut plot = Plot::new("lines_demo") .legend(Legend::default()) .y_axis_width(4) - .interact_distance(self.interact_distance) .show_axes(self.show_axes) .show_grid(self.show_grid); if self.square { @@ -297,6 +296,7 @@ impl LineDemo { if self.coordinates { plot = plot.coordinates_formatter(Corner::LeftBottom, CoordinatesFormatter::default()); } + ui.style_mut().interaction.interact_radius = self.interact_radius; plot.show(ui, |plot_ui| { plot_ui.line(self.circle()); plot_ui.line(self.sin()); diff --git a/crates/egui_plot/src/lib.rs b/crates/egui_plot/src/lib.rs index 75fdc7a2d4e..6dec9d7276d 100644 --- a/crates/egui_plot/src/lib.rs +++ b/crates/egui_plot/src/lib.rs @@ -170,7 +170,6 @@ pub struct Plot<'a> { show_x: bool, show_y: bool, - interact_distance: f32, label_formatter: LabelFormatter<'a>, coordinates_formatter: Option<(Corner, CoordinatesFormatter<'a>)>, x_axes: Vec>, // default x axes @@ -218,7 +217,6 @@ impl<'a> Plot<'a> { show_x: true, show_y: true, - interact_distance: 16.0, label_formatter: None, coordinates_formatter: None, x_axes: vec![AxisHints::new(Axis::X)], @@ -384,17 +382,6 @@ impl<'a> Plot<'a> { self } - /// The snapping distance for hovering an item or plot point - /// - /// The cursor will snap to the closest item to the pointer if it is closer than this value. - /// - /// Default: `16.0` - #[inline] - pub fn interact_distance(mut self, distance: f32) -> Self { - self.interact_distance = distance; - self - } - /// Provide a function to customize the on-hover label for the x and y axis /// /// ``` @@ -764,7 +751,6 @@ impl<'a> Plot<'a> { view_aspect, mut show_x, mut show_y, - interact_distance, label_formatter, coordinates_formatter, x_axes, @@ -1187,7 +1173,6 @@ impl<'a> Plot<'a> { items, show_x, show_y, - interact_distance, label_formatter, coordinates_formatter, show_grid, @@ -1470,7 +1455,6 @@ struct PreparedPlot<'a> { items: Vec>, show_x: bool, show_y: bool, - interact_distance: f32, label_formatter: LabelFormatter<'a>, coordinates_formatter: Option<(Corner, CoordinatesFormatter<'a>)>, // axis_formatters: [AxisFormatter; 2], @@ -1682,7 +1666,7 @@ impl<'a> PreparedPlot<'a> { return (Vec::new(), None); } - let interact_radius_sq = self.interact_distance.powi(2); + let interact_radius_sq = ui.style().interaction.interact_radius.powi(2); let candidates = items .iter()