Skip to content

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

Merged
emilk merged 9 commits into
emilk:masterfrom
FarProbe:separate-x-y-zoom-drag
Apr 18, 2023
Merged

emilk merged 9 commits into
emilk:masterfrom
FarProbe:separate-x-y-zoom-drag

Conversation

@OmegaJak

Copy link
Copy Markdown
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

}

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

@OmegaJak OmegaJak Apr 14, 2023

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

@emilk emilk left a comment

Copy link
Copy Markdown
Owner

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

Comment thread crates/egui/src/widgets/plot/mod.rs Outdated
Comment thread crates/egui/src/widgets/plot/mod.rs Outdated
}

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

Copy link
Copy Markdown
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.

2 participants