-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Plot interaction methods #766
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
Conversation
|
Sorry for the slow review - I'll get to it after the next egui release! 😓 |
|
I'm a bit worried about I wrote yet another alternative in #734 (comment) This just seems like a very big change for something as simple as "read point position so I can show it the next frame" (what this PR demos). Is there actually something more complex you want to accomplish? |
|
Btw, I've just created a egui discord server where I was hoping we could more easily have design discussions like these - perhaps you care to join it? https://discord.gg/qzvmcrUe |
Finally! I was secretly hoping for a egui discord for a long time. I would recommend that you put this as a badge in readme where it shows how many people are online in discord |
emilk
left a comment
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.
Overall this looks great!
What do you think about using Value instead of Pos2 for the values in plot-coordinates?
We could add helpers to Value (to_pos2 and to_vec2) instead.
Value could also do with a better name, but that's another problem :)
CHANGELOG.md
Outdated
| * MSRV (Minimum Supported Rust Version) is now `1.54.0`. | ||
| * By default, `DragValue`:s no longer show a tooltip when hovered. Change with `Style::explanation_tooltips`. | ||
| * Smaller and nicer color picker. | ||
| * Plots now provide a `build` method that has to be used to add items to and show the plot. |
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.
Thanks to my slow review, these lines now need to be moved to new ## Unreleased header! Please also add a PR link (it's something new I'm trying to do).
CHANGELOG.md
Outdated
| * Add `ui.add_enabled_ui(bool, |ui| …)` to create a possibly disabled UI section. | ||
| * Add feature `"serialize"` separatedly from `"persistence"`. | ||
| * Add `egui::widgets::global_dark_light_mode_buttons` to easily add buttons for switching the egui theme. | ||
| * Add interaction methods to the plot. |
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.
Can we improve this wording a bit? Maybe "You can now read the Plot coordinates of the mouse when building a Plot." ? 🤷
egui/src/widgets/plot/mod.rs
Outdated
| impl Widget for Plot { | ||
| fn ui(self, ui: &mut Ui) -> Response { | ||
| /// Interact with and add items to the plot and finally draw it. | ||
| pub fn build(self, ui: &mut Ui, build_fn: impl FnOnce(&mut PlotUi)) -> Response { |
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.
For better or for worse, the name show is used for the similar thing in CollapsingHeader, Window etc. I think we should be consistent with that.
egui/src/widgets/plot/mod.rs
Outdated
| } | ||
|
|
||
| /// Transform the screen coordinates to plot coordinates. | ||
| pub fn screen_to_plot_coordinates(&self, position: Pos2) -> Pos2 { |
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 prefer x_from_y to y_to_x for a few reasons:
For one, it is more consistent with stlib (let string = String::from_utf8(utf8); etc)
But more importantly, it puts the spaces in sequence:
V-------------V
let pos_in_plot = plot_ui.plot_from_screen(pos_in_screen);
^--------------^vs
V-----------------------V
let pos_in_plot = plot_ui.screen_to_plot(pos_in_screen);
^---------------------^
egui/src/widgets/plot/mod.rs
Outdated
| } | ||
|
|
||
| /// The pointer position in plot coordinates, if the pointer is inside the plot area. | ||
| pub fn pointer_coordinate(&self) -> Option<Pos2> { |
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 wonder if we should not use Value here instead of Pos2. f32 is not enough accuracy in many situations. For instance, if I am plotting things as a function of time I may be using seconds since unix epoch as the X coordinate, and that won't round very well to f32.
The added type-safety may also be nice (we can see from the type in what space it is in).
Co-authored-by: Emil Ernerfeldt <[email protected]>
…into plot-get-mouse-pos
|
I had completely missed your review and only just saw it. Sorry about the delay. I agree with all of your suggestions and have made the changes. |
|
I tested this today and am pretty happy with how it works. I'd like to add the following features as well though:
|
emilk
left a comment
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.
Excellent!
Closes #734.
I went with option 2 described in #734. This is a small breaking change and updating shouldn't be difficult. In the long run we can use this to add even more methods for interacting with the plot.
Might be a bit rough around the edges so feel free to suggest improvements.