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

egui_plot: Add sense option to Plot #4052

Merged
merged 2 commits into from
Feb 16, 2024
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 crates/egui_plot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ pub struct Plot {
grid_spacers: [GridSpacer; 2],
sharp_grid_lines: bool,
clamp_grid: bool,

sense: Sense,
}

impl Plot {
Expand Down Expand Up @@ -226,6 +228,8 @@ impl Plot {
grid_spacers: [log_grid_spacer(10), log_grid_spacer(10)],
sharp_grid_lines: true,
clamp_grid: false,

sense: egui::Sense::click_and_drag(),
}
}

Expand Down Expand Up @@ -477,6 +481,15 @@ impl Plot {
self
}

/// Set the sense for the plot rect.
///
/// Default: `Sense::click_and_drag()`.
#[inline]
pub fn sense(mut self, sense: Sense) -> Self {
self.sense = sense;
self
}

/// Expand bounds to include the given x value.
/// For instance, to always show the y axis, call `plot.include_x(0.0)`.
#[inline]
Expand Down Expand Up @@ -745,6 +758,7 @@ impl Plot {
clamp_grid,
grid_spacers,
sharp_grid_lines,
sense,
} = self;

// Determine position of widget.
Expand Down Expand Up @@ -789,7 +803,7 @@ impl Plot {
);

// Allocate the plot window.
let response = ui.allocate_rect(plot_rect, Sense::click_and_drag());
let response = ui.allocate_rect(plot_rect, sense);

// Load or initialize the memory.
ui.ctx().check_for_id_clash(plot_id, plot_rect, "Plot");
Expand Down
Loading