-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Improved plot interaction methods #892
Conversation
egui/src/widgets/plot/mod.rs
Outdated
self.ctx | ||
} | ||
|
||
/// The plot bounds as they were in the last frame. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is its value the first frame? Would it make more sense to return None
the first frame?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the same comment applies to screen_from_plot
and plot_from_screen
- what is apropiate to return the first frame?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We made sure that the bounds never become invalid. So if no items have been added to the plot and the bounds were not specified in the builder, they will at least be in the valid range [-1.0, 1.0]
. The first transform may not be very accurate, but valid and I prefer this to making the user deal with an Option
just because of one frame. But maybe you know an instance where this could go wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense not to have to hassle with Option
. But we should document what it returns the first frame. For instance: does it matter if this is called before or after adding plot items?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I added some documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would love to see the docs on plot_bounds
improved a bit, but you can do so in a later PR if you like.
Great work!
egui/src/widgets/plot/mod.rs
Outdated
response: Response, | ||
ctx: &'ctx CtxRef, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CtxRef
is just a wrapper around an Arc
, so alternatively you can clone it so you don't have to worry about lifetimes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah neat, changed in d1cff07.
egui/src/widgets/plot/mod.rs
Outdated
self.ctx | ||
} | ||
|
||
/// The plot bounds as they were in the last frame. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense not to have to hassle with Option
. But we should document what it returns the first frame. For instance: does it matter if this is called before or after adding plot items?
Closes #891
Changes:
plot_ui.ctx()
inside the plotshow
closure.PlotUi
methods:ctx
,plot_bounds
,plot_hovered
andscreen_from_plot
.plot_from_screen
function.Plot::show
now returns anInnerResponse
to be consistent with similar functions.@emilk I noticed that the plot demo instructions say "Pan by dragging, or scroll (+ shift = horizontal).". This does not work on my system though. Is this a bug or is the note outdated?