Resize component: better handling of resize=false
This commit is contained in:
parent
dba494e306
commit
ad0f6f6117
1 changed files with 27 additions and 24 deletions
|
@ -133,10 +133,6 @@ impl Resize {
|
|||
// TODO: a common trait for Things that follow this pattern
|
||||
impl Resize {
|
||||
pub fn show(mut self, ui: &mut Ui, add_contents: impl FnOnce(&mut Ui)) {
|
||||
if !self.resizable {
|
||||
return add_contents(ui);
|
||||
}
|
||||
|
||||
let id = ui.make_child_id("scroll");
|
||||
self.min_size = self.min_size.min(ui.available_space());
|
||||
self.max_size = self.max_size.min(ui.available_space());
|
||||
|
@ -155,6 +151,7 @@ impl Resize {
|
|||
|
||||
let position = ui.cursor();
|
||||
|
||||
let corner_interact = if self.resizable {
|
||||
// Resize-corner:
|
||||
let corner_size = Vec2::splat(16.0); // TODO: style
|
||||
let corner_rect = Rect::from_min_size(
|
||||
|
@ -167,14 +164,18 @@ impl Resize {
|
|||
if let Some(mouse_pos) = ui.input().mouse_pos {
|
||||
// This is the desired size. We may not be able to achieve it.
|
||||
|
||||
state.size =
|
||||
mouse_pos - position + 0.5 * corner_interact.rect.size() - self.handle_offset;
|
||||
state.size = mouse_pos - position + 0.5 * corner_interact.rect.size()
|
||||
- self.handle_offset;
|
||||
// We don't clamp to max size, because we want to be able to push against outer bounds.
|
||||
// For instance, if we are inside a bigger Resize region, we want to expand that.
|
||||
// state.size = state.size.clamp(self.min_size..=self.max_size);
|
||||
state.size = state.size.max(self.min_size);
|
||||
}
|
||||
}
|
||||
Some(corner_interact)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
// ------------------------------
|
||||
|
||||
|
@ -224,11 +225,13 @@ impl Resize {
|
|||
|
||||
// ------------------------------
|
||||
|
||||
if let Some(corner_interact) = corner_interact {
|
||||
paint_resize_corner(ui, &corner_interact);
|
||||
|
||||
if corner_interact.hovered || corner_interact.active {
|
||||
ui.ctx().output().cursor_icon = CursorIcon::ResizeNwSe;
|
||||
}
|
||||
}
|
||||
|
||||
ui.memory().resize.insert(id, state);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue