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 PlotUi::add_item(Box<dyn PlotItem>) #51

Merged
merged 2 commits into from
Dec 17, 2024

Conversation

freeformstu
Copy link
Contributor

@freeformstu freeformstu commented Oct 4, 2024

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.

@freeformstu freeformstu marked this pull request as draft October 4, 2024 23:41
@freeformstu freeformstu changed the title Add add_boxed to PlotUi. Allow adding Box<dyn PlotItem> directly to a plot. Oct 4, 2024
@freeformstu freeformstu marked this pull request as ready for review October 6, 2024 20:03
@@ -126,6 +126,11 @@ impl PlotUi {
self.items.push(Box::new(item));
}

/// Add an arbitrary item.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test for that or an example would be nice

@emilk emilk added enhancement New feature or request include in changelog This change will be included in the changelog labels Dec 17, 2024
egui_plot/src/plot_ui.rs Outdated Show resolved Hide resolved
@emilk emilk changed the title Allow adding Box<dyn PlotItem> directly to a plot. Add PlotUi::add_item(Box<dyn PlotItem>) Dec 17, 2024
@emilk emilk merged commit 64acd9d into emilk:main Dec 17, 2024
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request include in changelog This change will be included in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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