diff --git a/egui_plot/src/plot.rs b/egui_plot/src/plot.rs index 94ae6ced..f3fa384d 100644 --- a/egui_plot/src/plot.rs +++ b/egui_plot/src/plot.rs @@ -827,10 +827,8 @@ impl<'a> Plot<'a> { self.show_dyn(ui, Box::new(build_fn)) } - /// Calculate the rect inside which everything will be drawn. - fn calculate_widget_complete_rect(&self, ui: &Ui) -> Rect { - // Determine position of widget. - let pos = ui.available_rect_before_wrap().min; + /// Allocate the rect inside which everything will be drawn. + fn allocate_widget_complete_rect(&self, ui: &mut Ui) -> Rect { // Minimum values for screen protection let mut min_size = self.min_size; min_size.x = min_size.x.at_least(1.0); @@ -862,11 +860,8 @@ impl<'a> Plot<'a> { vec2(width, height) }; - // Determine complete rect of widget. - Rect { - min: pos, - max: pos + size, - } + // Let the layout place the widget, so we respect its direction, alignment and wrapping. + ui.allocate_space(size).1 } fn allocate_axis_responses(&self, ui: &mut Ui, axis_widgets: &AxisWidgets<'_>) -> AxisResponses { @@ -1635,7 +1630,7 @@ impl<'a> Plot<'a> { let plot_id = self.id.unwrap_or_else(|| ui.make_persistent_id(self.id_salt)); // Get complete rect for drawing. - let complete_rect = self.calculate_widget_complete_rect(ui); + let complete_rect = self.allocate_widget_complete_rect(ui); let (axis_widgets, plot_rect) = axis_widgets( PlotMemory::load(ui.ctx(), plot_id).as_ref(), // TODO(#164): avoid loading plot memory twice