[refactor] remove Ui::canvas (use Ui::allocate_space instead)

This commit is contained in:
Emil Ernerfeldt 2020-10-10 12:24:45 +02:00
parent b01690c7b8
commit 343648b94c
3 changed files with 4 additions and 22 deletions

10
TODO.md
View file

@ -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

View file

@ -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);

View file

@ -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))