Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions egui_plot/src/plot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,8 +812,6 @@ impl<'a> Plot<'a> {

/// 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;
// Minimum values for screen protection
let mut min_size = self.min_size;
min_size.x = min_size.x.at_least(1.0);
Expand Down Expand Up @@ -845,11 +843,27 @@ impl<'a> Plot<'a> {
vec2(width, height)
};

// Determine complete rect of widget.
Rect {
min: pos,
max: pos + size,
}
// Determine position of widget, anchored to whichever corner the
// current layout direction actually grows from. `available_rect_before_wrap`
// only reports the true cursor position on the edge matching `main_dir`
// (e.g. for `BottomUp` layouts that's `.max.y`, not `.min.y`), so blindly
// using `.min` as the origin places the widget in the wrong corner and
// makes successive widgets overlap (#237).
let avail = ui.available_rect_before_wrap();
let main_dir = ui.layout().main_dir();

let (min_x, max_x) = if main_dir == egui::Direction::RightToLeft {
(avail.max.x - size.x, avail.max.x)
} else {
(avail.min.x, avail.min.x + size.x)
};
let (min_y, max_y) = if main_dir == egui::Direction::BottomUp {
(avail.max.y - size.y, avail.max.y)
} else {
(avail.min.y, avail.min.y + size.y)
};

Rect::from_min_max(emath::pos2(min_x, min_y), emath::pos2(max_x, max_y))
}

fn allocate_axis_responses(&self, ui: &mut Ui, axis_widgets: &AxisWidgets<'_>) -> AxisResponses {
Expand Down
Loading