[refactor] Simplify how ui calls placer after adding a widget
This commit is contained in:
parent
641a302e0a
commit
8e1c7625f1
3 changed files with 17 additions and 15 deletions
|
@ -446,12 +446,12 @@ impl Layout {
|
|||
}
|
||||
|
||||
/// Advance the cursor by this many points.
|
||||
pub(crate) fn advance_cursor(&self, region: &mut Region, amount: f32) {
|
||||
pub(crate) fn advance_cursor(&self, cursor: &mut Pos2, amount: f32) {
|
||||
match self.main_dir {
|
||||
Direction::LeftToRight => region.cursor.x += amount,
|
||||
Direction::RightToLeft => region.cursor.x -= amount,
|
||||
Direction::TopDown => region.cursor.y += amount,
|
||||
Direction::BottomUp => region.cursor.y -= amount,
|
||||
Direction::LeftToRight => cursor.x += amount,
|
||||
Direction::RightToLeft => cursor.x -= amount,
|
||||
Direction::TopDown => cursor.y += amount,
|
||||
Direction::BottomUp => cursor.y -= amount,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -461,12 +461,12 @@ impl Layout {
|
|||
/// * `widget_rect`: the actual rect used by the widget
|
||||
pub(crate) fn advance_after_rects(
|
||||
&self,
|
||||
region: &mut Region,
|
||||
cursor: &mut Pos2,
|
||||
frame_rect: Rect,
|
||||
widget_rect: Rect,
|
||||
item_spacing: Vec2,
|
||||
) {
|
||||
region.cursor = match self.main_dir {
|
||||
*cursor = match self.main_dir {
|
||||
Direction::LeftToRight => pos2(widget_rect.right() + item_spacing.x, frame_rect.top()),
|
||||
Direction::RightToLeft => pos2(widget_rect.left() - item_spacing.x, frame_rect.top()),
|
||||
Direction::TopDown => pos2(frame_rect.left(), widget_rect.bottom() + item_spacing.y),
|
||||
|
|
|
@ -111,10 +111,11 @@ impl Placer {
|
|||
self.grid.is_none(),
|
||||
"You cannot advance the cursor when in a grid layout"
|
||||
);
|
||||
self.layout.advance_cursor(&mut self.region, amount)
|
||||
self.layout.advance_cursor(&mut self.region.cursor, amount)
|
||||
}
|
||||
|
||||
/// Advance cursor after a widget was added to a specific rectangle.
|
||||
/// Advance cursor after a widget was added to a specific rectangle
|
||||
/// and expand the region min_rect.
|
||||
///
|
||||
/// * `frame_rect`: the frame inside which a widget was e.g. centered
|
||||
/// * `widget_rect`: the actual rect used by the widget
|
||||
|
@ -127,9 +128,14 @@ impl Placer {
|
|||
if let Some(grid) = &mut self.grid {
|
||||
grid.advance(&mut self.region.cursor, frame_rect, widget_rect)
|
||||
} else {
|
||||
self.layout
|
||||
.advance_after_rects(&mut self.region, frame_rect, widget_rect, item_spacing)
|
||||
self.layout.advance_after_rects(
|
||||
&mut self.region.cursor,
|
||||
frame_rect,
|
||||
widget_rect,
|
||||
item_spacing,
|
||||
)
|
||||
}
|
||||
self.region.expand_to_include_rect(widget_rect);
|
||||
}
|
||||
|
||||
/// Move to the next row in a grid layout or wrapping layout.
|
||||
|
|
|
@ -512,7 +512,6 @@ impl Ui {
|
|||
|
||||
self.placer
|
||||
.advance_after_rects(frame_rect, widget_rect, item_spacing);
|
||||
self.expand_to_include_rect(widget_rect);
|
||||
|
||||
widget_rect
|
||||
}
|
||||
|
@ -520,7 +519,6 @@ impl Ui {
|
|||
pub(crate) fn advance_cursor_after_rect(&mut self, rect: Rect) -> Id {
|
||||
let item_spacing = self.style().spacing.item_spacing;
|
||||
self.placer.advance_after_rects(rect, rect, item_spacing);
|
||||
self.expand_to_include_rect(rect);
|
||||
|
||||
self.next_auto_id = self.next_auto_id.wrapping_add(1);
|
||||
Id::new(self.next_auto_id)
|
||||
|
@ -552,7 +550,6 @@ impl Ui {
|
|||
final_child_rect,
|
||||
item_spacing,
|
||||
);
|
||||
self.expand_to_include_rect(final_child_rect);
|
||||
|
||||
let response = self.interact(final_child_rect, child_ui.id, Sense::hover());
|
||||
(ret, response)
|
||||
|
@ -1104,7 +1101,6 @@ impl Ui {
|
|||
let rect = child_ui.min_rect();
|
||||
let item_spacing = self.style().spacing.item_spacing;
|
||||
self.placer.advance_after_rects(rect, rect, item_spacing);
|
||||
self.expand_to_include_rect(rect);
|
||||
(ret, self.interact(rect, child_ui.id, Sense::hover()))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue