Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion egui_plot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ pub struct Plot<'a> {
x_axes: Vec<AxisHints<'a>>, // default x axes
y_axes: Vec<AxisHints<'a>>, // default y axes
legend_config: Option<Legend>,
cursor_color: Option<Color32>,
show_background: bool,
show_axes: Vec2b,

Expand Down Expand Up @@ -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(),

Expand Down Expand Up @@ -727,6 +729,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<R>(
self,
Expand Down Expand Up @@ -768,6 +779,7 @@ impl<'a> Plot<'a> {
x_axes,
y_axes,
legend_config,
cursor_color,
reset,
show_background,
show_axes,
Expand Down Expand Up @@ -1196,6 +1208,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,
Expand Down Expand Up @@ -1480,6 +1493,7 @@ struct PreparedPlot<'a> {
draw_cursor_x: bool,
draw_cursor_y: bool,
draw_cursors: Vec<Cursor>,
cursor_color: Option<Color32>,

sharp_grid_lines: bool,
clamp_grid: bool,
Expand Down Expand Up @@ -1517,7 +1531,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<Cursor>, always| {
for &cursor in cursors {
Expand Down
Loading