Process legend items, create legend widget, and determine show flags. Returns `(legend_widget, show_x, show_y)`.
(
&self,
plot_ui: &mut PlotUi<'a>,
mem: &PlotMemory,
plot_rect: Rect,
)
| 938 | /// Process legend items, create legend widget, and determine show flags. |
| 939 | /// Returns `(legend_widget, show_x, show_y)`. |
| 940 | fn prepare_legend( |
| 941 | &self, |
| 942 | plot_ui: &mut PlotUi<'a>, |
| 943 | mem: &PlotMemory, |
| 944 | plot_rect: Rect, |
| 945 | ) -> (Option<LegendWidget>, Vec2b) { |
| 946 | // Create legend widget if configured (needs all items, including hidden ones) |
| 947 | let legend = self |
| 948 | .legend_config |
| 949 | .as_ref() |
| 950 | .and_then(|config| LegendWidget::try_new(plot_rect, config.clone(), &plot_ui.items, &mem.hidden_items)); |
| 951 | |
| 952 | // Process legend items: filter hidden items, highlight hovered items |
| 953 | // Remove the deselected items. |
| 954 | plot_ui.items.retain(|item| !mem.hidden_items.contains(&item.id())); |
| 955 | // Highlight the hovered items. |
| 956 | if let Some(item_id) = &mem.hovered_legend_item { |
| 957 | plot_ui |
| 958 | .items |
| 959 | .iter_mut() |
| 960 | .filter(|entry| &entry.id() == item_id) |
| 961 | .for_each(|entry| entry.highlight()); |
| 962 | } |
| 963 | // Move highlighted items to front. |
| 964 | plot_ui.items.sort_by_key(|item| item.highlighted()); |
| 965 | |
| 966 | // Determine show_x/show_y based on legend hover state (from previous frame) |
| 967 | let show_xy = Vec2b { |
| 968 | x: mem.hovered_legend_item.is_none() && self.show_x, |
| 969 | y: mem.hovered_legend_item.is_none() && self.show_y, |
| 970 | }; |
| 971 | |
| 972 | (legend, show_xy) |
| 973 | } |
| 974 | |
| 975 | /// Show legend widget and update memory with legend state. |
| 976 | fn show_legend_and_update_memory( |
no test coverage detected