Skip to content

Commit

Permalink
implement custom ruler color for plot
Browse files Browse the repository at this point in the history
  • Loading branch information
gweisert committed Sep 19, 2024
1 parent 0fe0ea6 commit 0f11ff2
Showing 1 changed file with 15 additions and 1 deletion.
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>,
ruler_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,
ruler_color: None,
show_background: true,
show_axes: true.into(),

Expand Down Expand Up @@ -727,6 +729,15 @@ impl<'a> Plot<'a> {
self
}

/// Set color of the rulers.
///
/// You may set the color to Color32::TRANSPARENT to hide the rulers.

Check failure on line 734 in egui_plot/src/lib.rs

View workflow job for this annotation

GitHub Actions / Rust

item in documentation is missing backticks

Check failure on line 734 in egui_plot/src/lib.rs

View workflow job for this annotation

GitHub Actions / Check wasm32

item in documentation is missing backticks
#[inline]
pub fn custom_ruler_color(mut self, color: Color32) -> Self {
self.ruler_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,
ruler_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,
ruler_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>,
ruler_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.ruler_color.unwrap_or_else(|| rulers_color(ui));

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

0 comments on commit 0f11ff2

Please sign in to comment.