mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 06:10:06 -04:00
advance_after_rect
This commit is contained in:
@@ -303,25 +303,6 @@ impl Layout {
|
|||||||
rect
|
rect
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Advance the cursor by this many points.
|
|
||||||
pub fn advance_cursor(self, region: &mut Region, 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,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Advance the cursor by this spacing
|
|
||||||
pub fn advance_cursor2(self, region: &mut Region, amount: Vec2) {
|
|
||||||
if self.main_dir.is_horizontal() {
|
|
||||||
self.advance_cursor(region, amount.x)
|
|
||||||
} else {
|
|
||||||
self.advance_cursor(region, amount.y)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Reserve this much space and move the cursor.
|
/// Reserve this much space and move the cursor.
|
||||||
/// Returns where to put the widget.
|
/// Returns where to put the widget.
|
||||||
///
|
///
|
||||||
@@ -375,6 +356,36 @@ impl Layout {
|
|||||||
|
|
||||||
Rect::from_min_size(child_pos, child_size)
|
Rect::from_min_size(child_pos, child_size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Advance the cursor by this many points.
|
||||||
|
pub fn advance_cursor(self, region: &mut Region, 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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Advance the cursor by this spacing
|
||||||
|
pub fn advance_cursor2(self, region: &mut Region, amount: Vec2) {
|
||||||
|
if self.main_dir.is_horizontal() {
|
||||||
|
self.advance_cursor(region, amount.x)
|
||||||
|
} else {
|
||||||
|
self.advance_cursor(region, amount.y)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Advance cursor after a widget was added to a specific rectangle.
|
||||||
|
pub fn advance_after_rect(self, region: &mut Region, rect: Rect, item_spacing: Vec2) {
|
||||||
|
match self.main_dir {
|
||||||
|
Direction::LeftToRight => region.cursor.x = rect.right() + item_spacing.x,
|
||||||
|
Direction::RightToLeft => region.cursor.x = rect.left() - item_spacing.x,
|
||||||
|
Direction::TopDown => region.cursor.y = rect.bottom() + item_spacing.y,
|
||||||
|
Direction::BottomUp => region.cursor.y = rect.top() - item_spacing.y,
|
||||||
|
}
|
||||||
|
region.expand_to_include_rect(rect);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -439,11 +439,10 @@ impl Ui {
|
|||||||
/// Returns where to put the widget.
|
/// Returns where to put the widget.
|
||||||
fn allocate_space_impl(&mut self, desired_size: Vec2) -> Rect {
|
fn allocate_space_impl(&mut self, desired_size: Vec2) -> Rect {
|
||||||
let child_rect = self.layout.next_space(&self.region, desired_size);
|
let child_rect = self.layout.next_space(&self.region, desired_size);
|
||||||
self.layout
|
|
||||||
.advance_cursor2(&mut self.region, child_rect.size());
|
|
||||||
let item_spacing = self.style().spacing.item_spacing;
|
let item_spacing = self.style().spacing.item_spacing;
|
||||||
self.layout.advance_cursor2(&mut self.region, item_spacing);
|
self.layout
|
||||||
self.region.expand_to_include_rect(child_rect);
|
.advance_after_rect(&mut self.region, child_rect, item_spacing);
|
||||||
|
|
||||||
self.next_auto_id = self.next_auto_id.wrapping_add(1);
|
self.next_auto_id = self.next_auto_id.wrapping_add(1);
|
||||||
child_rect
|
child_rect
|
||||||
@@ -463,11 +462,9 @@ impl Ui {
|
|||||||
let ret = add_contents(&mut child_ui);
|
let ret = add_contents(&mut child_ui);
|
||||||
let child_rect = child_ui.region.max_rect;
|
let child_rect = child_ui.region.max_rect;
|
||||||
|
|
||||||
self.layout
|
|
||||||
.advance_cursor2(&mut self.region, child_rect.size());
|
|
||||||
let item_spacing = self.style().spacing.item_spacing;
|
let item_spacing = self.style().spacing.item_spacing;
|
||||||
self.layout.advance_cursor2(&mut self.region, item_spacing);
|
self.layout
|
||||||
self.region.expand_to_include_rect(child_rect);
|
.advance_after_rect(&mut self.region, child_rect, item_spacing);
|
||||||
|
|
||||||
let response = self.interact_hover(child_rect);
|
let response = self.interact_hover(child_rect);
|
||||||
(ret, response)
|
(ret, response)
|
||||||
@@ -477,7 +474,7 @@ impl Ui {
|
|||||||
/// If the contents overflow, more space will be allocated.
|
/// If the contents overflow, more space will be allocated.
|
||||||
/// When finished, the amount of space actually used (`min_rect`) will be allocated.
|
/// When finished, the amount of space actually used (`min_rect`) will be allocated.
|
||||||
/// So you can request a lot of space and then use less.
|
/// So you can request a lot of space and then use less.
|
||||||
fn allocate_ui_min<R>(
|
pub fn allocate_ui_min<R>(
|
||||||
&mut self,
|
&mut self,
|
||||||
initial_size: Vec2,
|
initial_size: Vec2,
|
||||||
add_contents: impl FnOnce(&mut Self) -> R,
|
add_contents: impl FnOnce(&mut Self) -> R,
|
||||||
@@ -487,11 +484,9 @@ impl Ui {
|
|||||||
let ret = add_contents(&mut child_ui);
|
let ret = add_contents(&mut child_ui);
|
||||||
let child_rect = child_ui.region.min_rect;
|
let child_rect = child_ui.region.min_rect;
|
||||||
|
|
||||||
self.layout
|
|
||||||
.advance_cursor2(&mut self.region, child_rect.size());
|
|
||||||
let item_spacing = self.style().spacing.item_spacing;
|
let item_spacing = self.style().spacing.item_spacing;
|
||||||
self.layout.advance_cursor2(&mut self.region, item_spacing);
|
self.layout
|
||||||
self.region.expand_to_include_rect(child_rect);
|
.advance_after_rect(&mut self.region, child_rect, item_spacing);
|
||||||
|
|
||||||
let response = self.interact_hover(child_rect);
|
let response = self.interact_hover(child_rect);
|
||||||
(ret, response)
|
(ret, response)
|
||||||
|
|||||||
Reference in New Issue
Block a user