Browse Source

Return InnerResponse from Frame, Grid and ui.group()

pull/249/head
Emil Ernerfeldt 4 years ago
parent
commit
25c5e9d94e
  1. 11
      egui/src/containers/frame.rs
  2. 40
      egui/src/containers/panel.rs
  3. 2
      egui/src/containers/popup.rs
  4. 2
      egui/src/containers/window.rs
  5. 3
      egui/src/grid.rs
  6. 2
      egui/src/menu.rs
  7. 2
      egui/src/ui.rs
  8. 2
      egui/src/widgets/color_picker.rs

11
egui/src/containers/frame.rs

@ -134,11 +134,11 @@ impl Frame {
}
}
pub fn show<R>(self, ui: &mut Ui, add_contents: impl FnOnce(&mut Ui) -> R) -> R {
pub fn show<R>(self, ui: &mut Ui, add_contents: impl FnOnce(&mut Ui) -> R) -> InnerResponse<R> {
let mut prepared = self.begin(ui);
let ret = add_contents(&mut prepared.content_ui);
prepared.end(ui);
ret
let response = prepared.end(ui);
InnerResponse::new(ret, response)
}
pub fn paint(&self, outer_rect: Rect) -> Shape {
@ -175,7 +175,7 @@ impl Prepared {
)
}
pub fn end(self, ui: &mut Ui) -> Rect {
pub fn end(self, ui: &mut Ui) -> Response {
let outer_rect = self.outer_rect();
let Prepared {
@ -186,7 +186,6 @@ impl Prepared {
let shape = frame.paint(outer_rect);
ui.painter().set(where_to_put_background, shape);
ui.advance_cursor_after_rect(outer_rect);
outer_rect
ui.allocate_rect(outer_rect, Sense::hover())
}
}

40
egui/src/containers/panel.rs

@ -51,21 +51,16 @@ impl SidePanel {
let mut panel_ui = Ui::new(ctx.clone(), layer_id, id, panel_rect, clip_rect);
let frame = Frame::side_top_panel(&ctx.style());
let (r, used_space) = frame.show(&mut panel_ui, |ui| {
let r = add_contents(ui);
let used_space = ui.min_rect();
let inner_response = frame.show(&mut panel_ui, |ui| {
ui.set_min_height(ui.max_rect_finite().height()); // Make sure the frame fills the full height
(r, used_space)
add_contents(ui)
});
let panel_rect = panel_ui.min_rect();
let response = panel_ui.interact(panel_rect, id, Sense::hover());
// Only inform ctx about what we actually used, so we can shrink the native window to fit.
ctx.frame_state()
.allocate_left_panel(used_space.expand2(frame.margin));
.allocate_left_panel(inner_response.response.rect);
InnerResponse::new(r, response)
inner_response
}
}
@ -118,21 +113,16 @@ impl TopPanel {
let mut panel_ui = Ui::new(ctx.clone(), layer_id, id, panel_rect, clip_rect);
let frame = Frame::side_top_panel(&ctx.style());
let (r, used_space) = frame.show(&mut panel_ui, |ui| {
let r = add_contents(ui);
let used_space = ui.min_rect();
let inner_response = frame.show(&mut panel_ui, |ui| {
ui.set_min_width(ui.max_rect_finite().width()); // Make the frame fill full width
(r, used_space)
add_contents(ui)
});
let panel_rect = panel_ui.min_rect();
let response = panel_ui.interact(panel_rect, id, Sense::hover());
// Only inform ctx about what we actually used, so we can shrink the native window to fit.
ctx.frame_state()
.allocate_top_panel(used_space.expand2(frame.margin));
.allocate_top_panel(inner_response.response.rect);
InnerResponse::new(r, response)
inner_response
}
}
@ -182,21 +172,15 @@ impl CentralPanel {
let mut panel_ui = Ui::new(ctx.clone(), layer_id, id, panel_rect, clip_rect);
let frame = frame.unwrap_or_else(|| Frame::central_panel(&ctx.style()));
let (r, used_space) = frame.show(&mut panel_ui, |ui| {
let r = add_contents(ui);
let used_space = ui.min_rect();
let inner_response = frame.show(&mut panel_ui, |ui| {
ui.expand_to_include_rect(ui.max_rect()); // Expand frame to include it all
(r, used_space)
add_contents(ui)
});
let panel_rect = panel_ui.min_rect();
let id = Id::new("central_panel");
let response = panel_ui.interact(panel_rect, id, Sense::hover());
// Only inform ctx about what we actually used, so we can shrink the native window to fit.
ctx.frame_state()
.allocate_central_panel(used_space.expand2(frame.margin));
.allocate_central_panel(inner_response.response.rect);
InnerResponse::new(r, response)
inner_response
}
}

2
egui/src/containers/popup.rs

@ -139,7 +139,7 @@ fn show_tooltip_area(
Frame::popup(&ctx.style()).show(ui, |ui| {
ui.set_max_width(ui.spacing().tooltip_width);
add_contents(ui);
})
});
})
}

2
egui/src/containers/window.rs

@ -343,7 +343,7 @@ impl<'open> Window<'open> {
})
.map(|ir| ir.response);
let outer_rect = frame.end(&mut area_content_ui);
let outer_rect = frame.end(&mut area_content_ui).rect;
if possible.resizable {
paint_resize_corner(&mut area_content_ui, outer_rect, frame_stroke);

3
egui/src/grid.rs

@ -305,7 +305,7 @@ impl Grid {
}
impl Grid {
pub fn show<R>(self, ui: &mut Ui, add_contents: impl FnOnce(&mut Ui) -> R) -> R {
pub fn show<R>(self, ui: &mut Ui, add_contents: impl FnOnce(&mut Ui) -> R) -> InnerResponse<R> {
let Self {
id_source,
striped,
@ -337,6 +337,5 @@ impl Grid {
ui.save_grid();
r
})
.inner
}
}

2
egui/src/menu.rs

@ -113,7 +113,7 @@ fn menu_impl<'c>(
style.visuals.widgets.inactive.bg_stroke = Stroke::none();
ui.set_style(style);
ui.with_layout(Layout::top_down_justified(Align::LEFT), add_contents);
})
});
});
// TODO: this prevents sub-menus in menus. We should fix that.

2
egui/src/ui.rs

@ -1121,7 +1121,7 @@ impl Ui {
/// ui.label("Within a frame");
/// });
/// ```
pub fn group<R>(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> R {
pub fn group<R>(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> InnerResponse<R> {
crate::Frame::group(self.style()).show(self, add_contents)
}

2
egui/src/widgets/color_picker.rs

@ -347,7 +347,7 @@ pub fn color_edit_button_hsva(ui: &mut Ui, hsva: &mut Hsva, alpha: Alpha) -> Res
if color_picker_hsva_2d(ui, hsva, alpha) {
button_response.mark_changed();
}
})
});
});
if !button_response.clicked()

Loading…
Cancel
Save