(self, ui: &mut Ui, build_fn: Box<dyn FnOnce(&mut PlotUi<'a>) -> R + 'a>)
| 1611 | } |
| 1612 | |
| 1613 | fn show_dyn<R>(self, ui: &mut Ui, build_fn: Box<dyn FnOnce(&mut PlotUi<'a>) -> R + 'a>) -> PlotResponse<R> { |
| 1614 | let plot_id = self.id.unwrap_or_else(|| ui.make_persistent_id(self.id_source)); |
| 1615 | |
| 1616 | // Get complete rect for drawing. |
| 1617 | let complete_rect = self.calculate_widget_complete_rect(ui); |
| 1618 | |
| 1619 | let (axis_widgets, plot_rect) = axis_widgets( |
| 1620 | PlotMemory::load(ui.ctx(), plot_id).as_ref(), // TODO(#164): avoid loading plot memory twice |
| 1621 | self.show_axes, |
| 1622 | complete_rect, |
| 1623 | [&self.x_axes, &self.y_axes], |
| 1624 | ); |
| 1625 | let response = ui.allocate_rect(plot_rect, self.sense); |
| 1626 | let axis_responses = self.allocate_axis_responses(ui, &axis_widgets); |
| 1627 | |
| 1628 | // Load or initialize memory |
| 1629 | let mut mem = self.load_or_init_memory(ui, plot_id, plot_rect); |
| 1630 | let last_plot_transform = mem.transform; |
| 1631 | |
| 1632 | // Call the plot build function. |
| 1633 | let mut plot_ui = PlotUi { |
| 1634 | ctx: ui.clone(), |
| 1635 | items: Vec::new(), |
| 1636 | next_auto_color_idx: 0, |
| 1637 | last_plot_transform, |
| 1638 | last_auto_bounds: mem.auto_bounds, |
| 1639 | response, |
| 1640 | bounds_modifications: Vec::new(), |
| 1641 | }; |
| 1642 | |
| 1643 | // Populates items and does other modifications to plot_ui. |
| 1644 | let inner = build_fn(&mut plot_ui); |
| 1645 | |
| 1646 | // Background |
| 1647 | self.paint_background(ui, plot_rect); |
| 1648 | |
| 1649 | // Process legend items, create legend widget, and determine show flags. Updates |
| 1650 | // which items are left behind. |
| 1651 | let (legend, show_xy) = self.prepare_legend(&mut plot_ui, &mem, plot_rect); |
| 1652 | |
| 1653 | // Compute bounds |
| 1654 | self.compute_bounds(ui, &mut mem, &plot_ui, plot_rect); |
| 1655 | |
| 1656 | // Handle interactions (modifies plot_ui.response in place) |
| 1657 | self.handle_interactions(ui, &mut mem, &mut plot_ui, plot_rect, &axis_responses); |
| 1658 | |
| 1659 | // Render axis widgets |
| 1660 | self.render_axis_widgets(ui, &mut mem, axis_widgets); |
| 1661 | |
| 1662 | // Initialize values from functions. |
| 1663 | for item in &mut plot_ui.items { |
| 1664 | item.initialize(mem.transform.bounds().range_x()); |
| 1665 | } |
| 1666 | |
| 1667 | let (shapes, plot_cursors, mut hovered_plot_item) = |
| 1668 | self.collect_shapes(ui, &plot_ui, plot_id, &mem.transform, show_xy); |
| 1669 | |
| 1670 | // Get the painter from ui and configure it with the plot's clip rect |
no test coverage detected