Skip to content

Commit 7b9a4df

Browse files
gweisertemilk
andauthored
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 <emil.ernerfeldt@gmail.com>
1 parent 64acd9d commit 7b9a4df

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

egui_plot/src/lib.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ pub struct Plot<'a> {
180180
x_axes: Vec<AxisHints<'a>>, // default x axes
181181
y_axes: Vec<AxisHints<'a>>, // default y axes
182182
legend_config: Option<Legend>,
183+
cursor_color: Option<Color32>,
183184
show_background: bool,
184185
show_axes: Vec2b,
185186

@@ -227,6 +228,7 @@ impl<'a> Plot<'a> {
227228
x_axes: vec![AxisHints::new(Axis::X)],
228229
y_axes: vec![AxisHints::new(Axis::Y)],
229230
legend_config: None,
231+
cursor_color: None,
230232
show_background: true,
231233
show_axes: true.into(),
232234

@@ -713,6 +715,15 @@ impl<'a> Plot<'a> {
713715
self
714716
}
715717

718+
/// Set custom cursor color.
719+
///
720+
/// You may set the color to [`Color32::TRANSPARENT`] to hide the cursors.
721+
#[inline]
722+
pub fn cursor_color(mut self, color: Color32) -> Self {
723+
self.cursor_color = Some(color);
724+
self
725+
}
726+
716727
/// Interact with and add items to the plot and finally draw it.
717728
pub fn show<R>(
718729
self,
@@ -754,6 +765,7 @@ impl<'a> Plot<'a> {
754765
x_axes,
755766
y_axes,
756767
legend_config,
768+
cursor_color,
757769
reset,
758770
show_background,
759771
show_axes,
@@ -1182,6 +1194,7 @@ impl<'a> Plot<'a> {
11821194
draw_cursor_x: linked_cursors.as_ref().map_or(false, |group| group.1.x),
11831195
draw_cursor_y: linked_cursors.as_ref().map_or(false, |group| group.1.y),
11841196
draw_cursors,
1197+
cursor_color,
11851198
grid_spacers,
11861199
sharp_grid_lines,
11871200
clamp_grid,
@@ -1472,6 +1485,7 @@ struct PreparedPlot<'a> {
14721485
draw_cursor_x: bool,
14731486
draw_cursor_y: bool,
14741487
draw_cursors: Vec<Cursor>,
1488+
cursor_color: Option<Color32>,
14751489

14761490
sharp_grid_lines: bool,
14771491
clamp_grid: bool,
@@ -1513,7 +1527,7 @@ impl<'a> PreparedPlot<'a> {
15131527
};
15141528

15151529
// Draw cursors
1516-
let line_color = rulers_color(ui);
1530+
let line_color = self.cursor_color.unwrap_or_else(|| rulers_color(ui));
15171531

15181532
let mut draw_cursor = |cursors: &Vec<Cursor>, always| {
15191533
for &cursor in cursors {

0 commit comments

Comments
 (0)