diff --git a/TODO.md b/TODO.md index c5095d17..38defad0 100644 --- a/TODO.md +++ b/TODO.md @@ -122,16 +122,6 @@ TODO-list for the Egui project. If you looking for something to do, look here. * e.g. `ui.wrap(Frame::new()).wrap(Resize::new()).wrap(ScrollArea::new()).show(|ui| ...)` * [ ] Attach labels to checkboxes, radio buttons and sliders with a separate wrapper-widget ? -### Refactor space allocation - -When painting a widget, you want to allocate space. On that space you sometimes want to paint, sometimes create a sub-Ui to layout child widgets. So sometimes you want a `Painter` for the region, sometimes a new `Ui`. However, what you are doing is essentially the same thing, and so we should make that clearer somehow, maybe via naming. - -* `ui.allocate(size) -> Rect` -* `ui.canvas(size) -> Paint` -* `ui.child_ui(size) -> Ui` - -This is a good place to support whole-widget culling. If a swidget is not visible, the above functions should maybe return `None` so that the widget code can early-out. - ## Other * [x] Persist UI state in external storage diff --git a/egui/src/demos/demo_window.rs b/egui/src/demos/demo_window.rs index b4980b9e..82338811 100644 --- a/egui/src/demos/demo_window.rs +++ b/egui/src/demos/demo_window.rs @@ -104,9 +104,10 @@ impl DemoWindow { .show(ui, |ui| { ui.horizontal(|ui| { ui.label("You can pretty easily paint your own small icons:"); - let painter = ui.canvas(Vec2::splat(16.0)); - let c = painter.clip_rect().center(); - let r = painter.clip_rect().width() / 2.0 - 1.0; + let rect = ui.allocate_space(Vec2::splat(16.0)); + let painter = ui.painter(); + let c = rect.center(); + let r = rect.width() / 2.0 - 1.0; let color = Srgba::gray(128); let stroke = Stroke::new(1.0, color); painter.circle_stroke(c, r, stroke); diff --git a/egui/src/ui.rs b/egui/src/ui.rs index f901f79b..09cc964c 100644 --- a/egui/src/ui.rs +++ b/egui/src/ui.rs @@ -561,15 +561,6 @@ impl Ui { response } - /// Ask to allocate a certain amount of space and return a Painter for that region. - /// - /// You may get back a `Painter` with a smaller or larger size than what you desired, - /// depending on the available space and the current layout. - pub fn canvas(&mut self, desired_size: Vec2) -> Painter { - let rect = self.allocate_space(desired_size); - self.painter_at(rect) - } - /// Show an image here with the given size pub fn image(&mut self, texture_id: TextureId, desired_size: Vec2) -> Response { self.add(Image::new(texture_id, desired_size))