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

Plot widget - allow disabling zoom and drag for x and y separately #2901

Merged
merged 9 commits into from
Apr 18, 2023

Conversation

OmegaJak
Copy link
Contributor

Currently, allow_zoom and allow_drag apply to both axes at the same time. This PR makes it possible to specify whether zooming and dragging is allowed per axis. This helps in a scenario where the range of one axis is fixed for the whole range-- like a sinusoid. In that case, it's nice if zooming and dragging is only possible on the X axis.

This partially addresses #1164, but isn't exactly what was asked for there.

Egui.Plot.zoom.drag.demo.webm

@@ -402,9 +402,19 @@ impl Plot {
self
}

/// Whether to allow zooming in the plot. Default: `true`.
pub fn allow_zoom(mut self, on: bool) -> Self {
Copy link
Contributor Author

@OmegaJak OmegaJak Apr 14, 2023

Choose a reason for hiding this comment

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

It would be very easy to maintain backwards compatibility here by keeping these methods and having them set both x and y at the same time.

Question to the reviewers: what's the preference - keep backwards compatibility here or go with a more minimal API?

I'll update the changelog once this is decided.

Copy link
Owner

Choose a reason for hiding this comment

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

I vote keeping the old one. Not just for backwards compatibility, but also ergonomics: in most cases, you want to control both the same

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, good point. It occurs to me now that having it be generic in T where T : Into<AxisBools> would produce the best of both worlds. That way there's only the one method needed, and it maintains the current ergonomics for setting both at once, while allowing the new flexibility.

The main cost I see there is that it requires exposing AxisBools, which has been private until now. I guess it will also be a little more verbose to disable just one of the axes, as you'll have to do something like .allow_zoom(AxisBools::new(false, true)) (unless we keep the allow_zoom_x/y methods, which doesn't seem worth it). I'll go ahead and update with the new signature, and probably drop the x/y-specific methods.

@OmegaJak OmegaJak changed the title Plot - Allow disabling zoom and drag for x and y separately Plot widget - allow disabling zoom and drag for x and y separately Apr 14, 2023
@OmegaJak
Copy link
Contributor Author

The referenced issue #1164 wasn't exactly asking for this - should I open a separate issue asking for this exactly?

@OmegaJak OmegaJak marked this pull request as ready for review April 14, 2023 01:39
Copy link
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

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

Looks good, but please reintroduce the old functions as a simplified interface

crates/egui/src/widgets/plot/mod.rs Outdated Show resolved Hide resolved
crates/egui/src/widgets/plot/mod.rs Outdated Show resolved Hide resolved
@@ -402,9 +402,19 @@ impl Plot {
self
}

/// Whether to allow zooming in the plot. Default: `true`.
pub fn allow_zoom(mut self, on: bool) -> Self {
Copy link
Owner

Choose a reason for hiding this comment

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

I vote keeping the old one. Not just for backwards compatibility, but also ergonomics: in most cases, you want to control both the same

@OmegaJak OmegaJak requested a review from emilk April 18, 2023 17:52
@emilk emilk added egui_plot Related to egui_plot egui labels Apr 18, 2023
@emilk emilk merged commit 438f6ea into emilk:master Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
egui_plot Related to egui_plot egui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants