Changed: ui.allocate_painter returns a Response
This commit is contained in:
parent
48dfcde65f
commit
58fcf0f2a1
3 changed files with 15 additions and 15 deletions
|
@ -20,7 +20,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
* You can now control the minimum and maixumum number of decimals to show in a `Slider` or `DragValue`.
|
* You can now control the minimum and maixumum number of decimals to show in a `Slider` or `DragValue`.
|
||||||
* Add `egui::math::Rot2`: rotation helper.
|
* Add `egui::math::Rot2`: rotation helper.
|
||||||
* `Response` now contains the `Id` of the widget it pertains to.
|
* `Response` now contains the `Id` of the widget it pertains to.
|
||||||
* `ui.allocate_response` that allocated space and checks for interactions.
|
* `ui.allocate_response` that allocates space and checks for interactions.
|
||||||
|
|
||||||
### Changed 🔧
|
### Changed 🔧
|
||||||
|
|
||||||
|
|
|
@ -28,9 +28,9 @@ impl Painting {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ui_content(&mut self, ui: &mut Ui) {
|
pub fn ui_content(&mut self, ui: &mut Ui) {
|
||||||
let (id, painter) = ui.allocate_painter(ui.available_size_before_wrap_finite());
|
let (response, painter) =
|
||||||
let rect = painter.clip_rect();
|
ui.allocate_painter(ui.available_size_before_wrap_finite(), Sense::drag());
|
||||||
let response = ui.interact(rect, id, Sense::drag());
|
let rect = response.rect;
|
||||||
|
|
||||||
if self.lines.is_empty() {
|
if self.lines.is_empty() {
|
||||||
self.lines.push(vec![]);
|
self.lines.push(vec![]);
|
||||||
|
|
|
@ -568,11 +568,11 @@ impl Ui {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience function to get a region to paint on
|
/// Convenience function to get a region to paint on
|
||||||
pub fn allocate_painter(&mut self, desired_size: Vec2) -> (Id, Painter) {
|
pub fn allocate_painter(&mut self, desired_size: Vec2, sense: Sense) -> (Response, Painter) {
|
||||||
let (id, rect) = self.allocate_space(desired_size);
|
let response = self.allocate_response(desired_size, sense);
|
||||||
let clip_rect = self.clip_rect().intersect(rect); // Make sure we don't paint out of bounds
|
let clip_rect = self.clip_rect().intersect(response.rect); // Make sure we don't paint out of bounds
|
||||||
let painter = Painter::new(self.ctx().clone(), self.layer_id(), clip_rect);
|
let painter = Painter::new(self.ctx().clone(), self.layer_id(), clip_rect);
|
||||||
(id, painter)
|
(response, painter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -808,8 +808,8 @@ impl Ui {
|
||||||
let mut child_ui = self.child_ui(child_rect, self.layout);
|
let mut child_ui = self.child_ui(child_rect, self.layout);
|
||||||
let ret = add_contents(&mut child_ui);
|
let ret = add_contents(&mut child_ui);
|
||||||
let size = child_ui.min_size();
|
let size = child_ui.min_size();
|
||||||
let (id, rect) = self.allocate_space(size);
|
let response = self.allocate_response(size, Sense::hover());
|
||||||
(ret, self.interact(rect, id, Sense::hover()))
|
(ret, response)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Redirect paint commands to another paint layer.
|
/// Redirect paint commands to another paint layer.
|
||||||
|
@ -872,8 +872,8 @@ impl Ui {
|
||||||
self.style().visuals.widgets.noninteractive.bg_stroke,
|
self.style().visuals.widgets.noninteractive.bg_stroke,
|
||||||
);
|
);
|
||||||
|
|
||||||
let (id, rect) = self.allocate_space(indent + size);
|
let response = self.allocate_response(indent + size, Sense::hover());
|
||||||
(ret, self.interact(rect, id, Sense::hover()))
|
(ret, response)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deprecated]
|
#[deprecated]
|
||||||
|
@ -1071,11 +1071,11 @@ impl Ui {
|
||||||
let spacing = self.style().spacing.item_spacing.x;
|
let spacing = self.style().spacing.item_spacing.x;
|
||||||
let total_spacing = spacing * (num_columns as f32 - 1.0);
|
let total_spacing = spacing * (num_columns as f32 - 1.0);
|
||||||
let column_width = (self.available_width() - total_spacing) / (num_columns as f32);
|
let column_width = (self.available_width() - total_spacing) / (num_columns as f32);
|
||||||
|
let top_left = self.region.cursor;
|
||||||
|
|
||||||
let mut columns: Vec<Self> = (0..num_columns)
|
let mut columns: Vec<Self> = (0..num_columns)
|
||||||
.map(|col_idx| {
|
.map(|col_idx| {
|
||||||
let pos =
|
let pos = top_left + vec2((col_idx as f32) * (column_width + spacing), 0.0);
|
||||||
self.region.cursor + vec2((col_idx as f32) * (column_width + spacing), 0.0);
|
|
||||||
let child_rect = Rect::from_min_max(
|
let child_rect = Rect::from_min_max(
|
||||||
pos,
|
pos,
|
||||||
pos2(pos.x + column_width, self.max_rect().right_bottom().y),
|
pos2(pos.x + column_width, self.max_rect().right_bottom().y),
|
||||||
|
@ -1100,7 +1100,7 @@ impl Ui {
|
||||||
let total_required_width = total_spacing + max_column_width * (num_columns as f32);
|
let total_required_width = total_spacing + max_column_width * (num_columns as f32);
|
||||||
|
|
||||||
let size = vec2(self.available_width().max(total_required_width), max_height);
|
let size = vec2(self.available_width().max(total_required_width), max_height);
|
||||||
self.allocate_space(size);
|
self.advance_cursor_after_rect(Rect::from_min_size(top_left, size));
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue