|
@ -133,10 +133,6 @@ impl Resize { |
|
|
// TODO: a common trait for Things that follow this pattern
|
|
|
// TODO: a common trait for Things that follow this pattern
|
|
|
impl Resize { |
|
|
impl Resize { |
|
|
pub fn show(mut self, ui: &mut Ui, add_contents: impl FnOnce(&mut Ui)) { |
|
|
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"); |
|
|
let id = ui.make_child_id("scroll"); |
|
|
self.min_size = self.min_size.min(ui.available_space()); |
|
|
self.min_size = self.min_size.min(ui.available_space()); |
|
|
self.max_size = self.max_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 position = ui.cursor(); |
|
|
|
|
|
|
|
|
|
|
|
let corner_interact = if self.resizable { |
|
|
// Resize-corner:
|
|
|
// Resize-corner:
|
|
|
let corner_size = Vec2::splat(16.0); // TODO: style
|
|
|
let corner_size = Vec2::splat(16.0); // TODO: style
|
|
|
let corner_rect = Rect::from_min_size( |
|
|
let corner_rect = Rect::from_min_size( |
|
@ -167,14 +164,18 @@ impl Resize { |
|
|
if let Some(mouse_pos) = ui.input().mouse_pos { |
|
|
if let Some(mouse_pos) = ui.input().mouse_pos { |
|
|
// This is the desired size. We may not be able to achieve it.
|
|
|
// This is the desired size. We may not be able to achieve it.
|
|
|
|
|
|
|
|
|
state.size = |
|
|
state.size = mouse_pos - position + 0.5 * corner_interact.rect.size() |
|
|
mouse_pos - position + 0.5 * corner_interact.rect.size() - self.handle_offset; |
|
|
- self.handle_offset; |
|
|
// We don't clamp to max size, because we want to be able to push against outer bounds.
|
|
|
// 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.
|
|
|
// 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.clamp(self.min_size..=self.max_size);
|
|
|
state.size = state.size.max(self.min_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); |
|
|
paint_resize_corner(ui, &corner_interact); |
|
|
|
|
|
|
|
|
if corner_interact.hovered || corner_interact.active { |
|
|
if corner_interact.hovered || corner_interact.active { |
|
|
ui.ctx().output().cursor_icon = CursorIcon::ResizeNwSe; |
|
|
ui.ctx().output().cursor_icon = CursorIcon::ResizeNwSe; |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
ui.memory().resize.insert(id, state); |
|
|
ui.memory().resize.insert(id, state); |
|
|
} |
|
|
} |
|
|