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

Add fn add_boxed(&mut self, Box<dyn PlotItem>) method to PlotUi. #53

Closed
freeformstu opened this issue Oct 6, 2024 · 1 comment · Fixed by #51
Closed

Add fn add_boxed(&mut self, Box<dyn PlotItem>) method to PlotUi. #53

freeformstu opened this issue Oct 6, 2024 · 1 comment · Fixed by #51

Comments

@freeformstu
Copy link
Contributor

Is your feature request related to a problem? Please describe.

We have a somewhat unique setup in which we use dioxus for state management and egui for all of the underlying component rendering. When passing attributes through dioxus we have to cast the incoming type which requires that the trait objects be "object safe". PlotItem is not object safe, so we can't pass it through directly. But we also cannot pass in our own trait which has a method such as fn as_egui_plot_item(&self) -> impl PlotItem because that is also not object safe so instead we have a trait which has a method fn as_egui_plot_item(&self) -> Box<dyn PlotItem>. This cannot be passed to the existing fn add(&self, impl PlotItem) method because Box<dyn PlotItem> does not satisfy the impl PlotItem argument.

Describe the solution you'd like

Add an fn add_boxed(&mut self, Box<dyn PlotItem>) method to allow insertion directly into the underlying plot_items Vec.

Describe alternatives you've considered

  1. Make PlotItem object safe (likely a pretty large effort and I'm not sure anyone else cares about this).
  2. impl<T: PlotItem> PlotItem for Rc<T> so we can pass an Rc directly to the .add( function. (This could also be done for Arc and others for convenience).
  3. Possibly some more options?

Additional context

@madser123
Copy link

Please add this 🙏 This is missed

emilk added a commit that referenced this issue Dec 17, 2024
<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui_plot/blob/master/CONTRIBUTING.md)
before opening a Pull Request!

* Keep your PR:s small and focused.
* The PR title is what ends up in the changelog, so make it descriptive!
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for a new
example.
* Do NOT open PR:s from your `master` or `main` branch, as that makes it
hard for maintainers to test and add commits to your PR.
* Remember to run `cargo fmt` and `cargo clippy`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.

Please be patient! We will review your PR, but our time is limited!
-->

* Closes <#53>
* [x] I have followed the instructions in the PR template

We have a somewhat unique setup in which we use dioxus for state
management and egui for all of the underlying component rendering. When
passing attributes through dioxus we have to cast the incoming type
which requires that the trait objects be "object safe". `PlotItem` is
not object safe, so we can't pass it through directly. But we also
cannot pass in our own trait which has a method such as `fn
as_egui_plot_item(&self) -> impl PlotItem` because that is also not
object safe so instead we have a trait which has a method `fn
as_egui_plot_item(&self) -> Box<dyn PlotItem>`. This cannot be passed to
the existing `fn add(&self, impl PlotItem)` method because `Box<dyn
PlotItem>` does not satisfy the `impl PlotItem` argument but since the
`plot_items` are stored as `Vec<Box<dyn PlotItem>>` I've added this
method to give access to insert directly.

---------

Co-authored-by: Emil Ernerfeldt <[email protected]>
@emilk emilk closed this as completed in #51 Dec 17, 2024
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 a pull request may close this issue.

2 participants