Skip to content

Commit

Permalink
egui_plot: Add sense option to Plot (#4052)
Browse files Browse the repository at this point in the history
This PR adds a `sense` option to `Plot`.
  • Loading branch information
AmesingFlank authored Feb 16, 2024
1 parent 61b53ae commit 62e80c7
Showing 1 changed file with 15 additions and 1 deletion.
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

0 comments on commit 62e80c7

Please sign in to comment.