mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 05:10:03 -04:00
Add ui.allocate_painter helper
This commit is contained in:
@@ -243,7 +243,7 @@ impl Default for Painting {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
lines: Default::default(),
|
||||
stroke: Stroke::new(1.0, LIGHT_GRAY),
|
||||
stroke: Stroke::new(1.0, LIGHT_BLUE),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -265,11 +265,10 @@ impl Painting {
|
||||
}
|
||||
|
||||
fn content(&mut self, ui: &mut Ui) {
|
||||
let rect = ui.allocate_space(ui.available_size_before_wrap_finite());
|
||||
let response = ui.interact(rect, ui.id(), Sense::drag());
|
||||
let rect = response.rect;
|
||||
let clip_rect = ui.clip_rect().intersect(rect); // Make sure we don't paint out of bounds
|
||||
let painter = Painter::new(ui.ctx().clone(), ui.layer_id(), clip_rect);
|
||||
let painter = ui.allocate_painter(ui.available_size_before_wrap_finite());
|
||||
let rect = painter.clip_rect();
|
||||
let id = ui.make_position_id();
|
||||
let response = ui.interact(rect, id, Sense::drag());
|
||||
|
||||
if self.lines.is_empty() {
|
||||
self.lines.push(vec![]);
|
||||
|
||||
@@ -525,6 +525,13 @@ impl Ui {
|
||||
let response = self.interact_hover(final_child_rect);
|
||||
(ret, response)
|
||||
}
|
||||
|
||||
/// Convenience function to get a region to paint on
|
||||
pub fn allocate_painter(&mut self, desired_size: Vec2) -> Painter {
|
||||
let rect = self.allocate_space(desired_size);
|
||||
let clip_rect = self.clip_rect().intersect(rect); // Make sure we don't paint out of bounds
|
||||
Painter::new(self.ctx().clone(), self.layer_id(), clip_rect)
|
||||
}
|
||||
}
|
||||
|
||||
/// # Adding widgets
|
||||
|
||||
Reference in New Issue
Block a user