From 9e5b553fe0d285c75d76e83042b3290380ef221d Mon Sep 17 00:00:00 2001 From: Sven Niederberger Date: Fri, 21 Feb 2025 09:17:45 +0100 Subject: [PATCH 1/3] add the toggle --- egui_plot/src/items/mod.rs | 9 +++++++++ egui_plot/src/legend.rs | 1 + 2 files changed, 10 insertions(+) diff --git a/egui_plot/src/items/mod.rs b/egui_plot/src/items/mod.rs index ce7533c..07fb9e8 100644 --- a/egui_plot/src/items/mod.rs +++ b/egui_plot/src/items/mod.rs @@ -34,6 +34,7 @@ pub struct PlotItemBase { id: Id, highlight: bool, allow_hover: bool, + pub(crate) show_in_legend: bool, } impl PlotItemBase { @@ -44,6 +45,7 @@ impl PlotItemBase { id, highlight: false, allow_hover: true, + show_in_legend: true, } } } @@ -84,6 +86,13 @@ macro_rules! builder_methods_for_base { self.base_mut().id = id.into(); self } + + /// Whether to show the item in the legend. Default: `true`. + #[inline] + pub fn show_in_legend(mut self, show: bool) -> Self { + self.base_mut().show_in_legend = show; + self + } }; } diff --git a/egui_plot/src/legend.rs b/egui_plot/src/legend.rs index db97661..7bfb2e8 100644 --- a/egui_plot/src/legend.rs +++ b/egui_plot/src/legend.rs @@ -242,6 +242,7 @@ impl LegendWidget { items .iter() .filter(|item| !item.name().is_empty()) + .filter(|item| item.base().show_in_legend) .for_each(|item| { let next_entry = entries.len(); let key = if config.follow_insertion_order { From 454e66d5e9875b9c5837daefbcdd4913eb09860c Mon Sep 17 00:00:00 2001 From: Sven Niederberger Date: Mon, 3 Mar 2025 13:39:34 +0100 Subject: [PATCH 2/3] document the name --- egui_plot/src/items/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/egui_plot/src/items/mod.rs b/egui_plot/src/items/mod.rs index 07fb9e8..4e1a43f 100644 --- a/egui_plot/src/items/mod.rs +++ b/egui_plot/src/items/mod.rs @@ -38,6 +38,8 @@ pub struct PlotItemBase { } impl PlotItemBase { + /// The given name will show up in the legend and serves to track the visibility of items. + /// Multiple items may share the same name, in which case they also share a legend entry. pub fn new(name: String) -> Self { let id = Id::new(&name); Self { From 87920be7b8ed5af77a48f0a264948256320a445d Mon Sep 17 00:00:00 2001 From: Sven Niederberger Date: Mon, 3 Mar 2025 13:40:58 +0100 Subject: [PATCH 3/3] small PR template fix --- .github/pull_request_template.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 71ed0cf..7ce5a8f 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -4,7 +4,7 @@ Please read the "Making a PR" section of [`CONTRIBUTING.md`](https://github.com/ * 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 f or a new example. +* 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`.