From 7b9a4df1fd14b9c005c8973a59ddf548ca699657 Mon Sep 17 00:00:00 2001 From: Georg Weisert Date: Tue, 17 Dec 2024 09:13:41 +0100 Subject: [PATCH] Implement custom ruler color for Plot (#47) Implement custom ruler color for Plot which is exposed through the new `custom_ruler_color` method. The entire thing is only a few lines. --------- Co-authored-by: Emil Ernerfeldt --- egui_plot/src/lib.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/egui_plot/src/lib.rs b/egui_plot/src/lib.rs index 8f22bbc..df74ffa 100644 --- a/egui_plot/src/lib.rs +++ b/egui_plot/src/lib.rs @@ -180,6 +180,7 @@ pub struct Plot<'a> { x_axes: Vec>, // default x axes y_axes: Vec>, // default y axes legend_config: Option, + cursor_color: Option, show_background: bool, show_axes: Vec2b, @@ -227,6 +228,7 @@ impl<'a> Plot<'a> { x_axes: vec![AxisHints::new(Axis::X)], y_axes: vec![AxisHints::new(Axis::Y)], legend_config: None, + cursor_color: None, show_background: true, show_axes: true.into(), @@ -713,6 +715,15 @@ impl<'a> Plot<'a> { self } + /// Set custom cursor color. + /// + /// You may set the color to [`Color32::TRANSPARENT`] to hide the cursors. + #[inline] + pub fn cursor_color(mut self, color: Color32) -> Self { + self.cursor_color = Some(color); + self + } + /// Interact with and add items to the plot and finally draw it. pub fn show( self, @@ -754,6 +765,7 @@ impl<'a> Plot<'a> { x_axes, y_axes, legend_config, + cursor_color, reset, show_background, show_axes, @@ -1182,6 +1194,7 @@ impl<'a> Plot<'a> { draw_cursor_x: linked_cursors.as_ref().map_or(false, |group| group.1.x), draw_cursor_y: linked_cursors.as_ref().map_or(false, |group| group.1.y), draw_cursors, + cursor_color, grid_spacers, sharp_grid_lines, clamp_grid, @@ -1472,6 +1485,7 @@ struct PreparedPlot<'a> { draw_cursor_x: bool, draw_cursor_y: bool, draw_cursors: Vec, + cursor_color: Option, sharp_grid_lines: bool, clamp_grid: bool, @@ -1513,7 +1527,7 @@ impl<'a> PreparedPlot<'a> { }; // Draw cursors - let line_color = rulers_color(ui); + let line_color = self.cursor_color.unwrap_or_else(|| rulers_color(ui)); let mut draw_cursor = |cursors: &Vec, always| { for &cursor in cursors {