Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to hide rulers of cursor on plots #4555

Closed
wants to merge 2 commits into from
Closed
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
18 changes: 17 additions & 1 deletion crates/egui_plot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ pub struct Plot<'a> {
boxed_zoom_pointer_button: PointerButton,
linked_axes: Option<(Id, Vec2b)>,
linked_cursors: Option<(Id, Vec2b)>,
enable_cursor_drawing: bool,

min_size: Vec2,
width: Option<f32>,
Expand Down Expand Up @@ -206,6 +207,7 @@ impl<'a> Plot<'a> {
boxed_zoom_pointer_button: PointerButton::Secondary,
linked_axes: None,
linked_cursors: None,
enable_cursor_drawing: true,

min_size: Vec2::splat(64.0),
width: None,
Expand Down Expand Up @@ -599,6 +601,15 @@ impl<'a> Plot<'a> {
self
}

/// Show or hide the cursor lines.
///
/// Default: `true`.
#[inline]
pub fn enable_cursor_drawing(mut self, enable: bool) -> Self {
self.enable_cursor_drawing = enable;
Comment on lines +608 to +609
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think show_cursor is a shorter and nicer name

self
}

/// Round grid positions to full pixels to avoid aliasing. Improves plot appearance but might have an
/// undesired effect when shifting the plot bounds. Enabled by default.
#[inline]
Expand Down Expand Up @@ -763,6 +774,7 @@ impl<'a> Plot<'a> {
grid_spacing,
linked_axes,
linked_cursors,
enable_cursor_drawing,

clamp_grid,
grid_spacers,
Expand Down Expand Up @@ -1181,6 +1193,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,
enable_cursor_drawing,
grid_spacers,
sharp_grid_lines,
clamp_grid,
Expand Down Expand Up @@ -1465,6 +1478,7 @@ struct PreparedPlot<'a> {
draw_cursor_x: bool,
draw_cursor_y: bool,
draw_cursors: Vec<Cursor>,
enable_cursor_drawing: bool,

sharp_grid_lines: bool,
clamp_grid: bool,
Expand Down Expand Up @@ -1530,7 +1544,9 @@ impl<'a> PreparedPlot<'a> {
};

draw_cursor(&self.draw_cursors, false);
draw_cursor(&cursors, true);
if self.enable_cursor_drawing {
draw_cursor(&cursors, true);
}

let painter = ui.painter().with_clip_rect(*transform.frame());
painter.extend(shapes);
Expand Down