1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 14:49:06 -04:00

egui_plot: Add sense option to Plot (#4052)

This PR adds a `sense` option to `Plot`.
This commit is contained in:
Dunfan Lu
2024-02-16 03:19:03 -05:00
committed by GitHub
parent 61b53ae937
commit 62e80c7729

View File

@@ -181,6 +181,8 @@ pub struct Plot {
grid_spacers: [GridSpacer; 2],
sharp_grid_lines: bool,
clamp_grid: bool,
sense: Sense,
}
impl Plot {
@@ -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(),
}
}
@@ -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]
@@ -745,6 +758,7 @@ impl Plot {
clamp_grid,
grid_spacers,
sharp_grid_lines,
sense,
} = self;
// Determine position of widget.
@@ -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");