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

Improved plot interaction methods #892

Merged
merged 6 commits into from
Nov 27, 2021

Conversation

EmbersArc
Copy link
Contributor

@EmbersArc EmbersArc commented Nov 14, 2021

Closes #891

Changes:

  • Added access to the context with plot_ui.ctx() inside the plot show closure.
  • More PlotUi methods: ctx, plot_bounds, plot_hovered and screen_from_plot.
  • Simplified the way plot bounds and the screen transform are initialized.
  • Fixed the plot_from_screen function.
  • Plot::show now returns an InnerResponse to be consistent with similar functions.
  • Improved demo

@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?

self.ctx
}

/// The plot bounds as they were in the last frame.
Copy link
Owner

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?

Copy link
Owner

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?

Copy link
Contributor Author

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?

Copy link
Owner

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?

Copy link
Contributor Author

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.

egui_demo_lib/src/apps/demo/plot_demo.rs Show resolved Hide resolved
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.

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!

response: Response,
ctx: &'ctx CtxRef,
Copy link
Owner

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

Copy link
Contributor Author

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.

self.ctx
}

/// The plot bounds as they were in the last frame.
Copy link
Owner

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?

@EmbersArc EmbersArc requested a review from emilk November 27, 2021 14:29
@emilk emilk merged commit 9d56bce into emilk:master Nov 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improved plot interaction methods
2 participants