Trigger PaneGrid
resize on click
This commit is contained in:
parent
f08cb4ad56
commit
eb5e2251bd
@ -111,6 +111,47 @@ impl<'a, Message, Renderer> PaneGrid<'a, Message, Renderer> {
|
|||||||
self.on_resize = Some(Box::new(f));
|
self.on_resize = Some(Box::new(f));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn trigger_resize(
|
||||||
|
&mut self,
|
||||||
|
layout: Layout<'_>,
|
||||||
|
cursor_position: Point,
|
||||||
|
messages: &mut Vec<Message>,
|
||||||
|
) {
|
||||||
|
if let Some(on_resize) = &self.on_resize {
|
||||||
|
if let Some((split, _)) = self.state.picked_split() {
|
||||||
|
let bounds = layout.bounds();
|
||||||
|
|
||||||
|
let splits = self.state.splits(
|
||||||
|
f32::from(self.spacing),
|
||||||
|
Size::new(bounds.width, bounds.height),
|
||||||
|
);
|
||||||
|
|
||||||
|
if let Some((axis, rectangle, _)) = splits.get(&split) {
|
||||||
|
let ratio = match axis {
|
||||||
|
Axis::Horizontal => {
|
||||||
|
let position =
|
||||||
|
cursor_position.x - bounds.x + rectangle.x;
|
||||||
|
|
||||||
|
(position / (rectangle.x + rectangle.width))
|
||||||
|
.max(0.1)
|
||||||
|
.min(0.9)
|
||||||
|
}
|
||||||
|
Axis::Vertical => {
|
||||||
|
let position =
|
||||||
|
cursor_position.y - bounds.y + rectangle.y;
|
||||||
|
|
||||||
|
(position / (rectangle.y + rectangle.height))
|
||||||
|
.max(0.1)
|
||||||
|
.min(0.9)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
messages.push(on_resize(ResizeEvent { split, ratio }));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
@ -280,6 +321,11 @@ where
|
|||||||
sorted_splits.first()
|
sorted_splits.first()
|
||||||
{
|
{
|
||||||
self.state.pick_split(split, *axis);
|
self.state.pick_split(split, *axis);
|
||||||
|
self.trigger_resize(
|
||||||
|
layout,
|
||||||
|
cursor_position,
|
||||||
|
messages,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ButtonState::Released => {
|
ButtonState::Released => {
|
||||||
@ -288,41 +334,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Mouse(mouse::Event::CursorMoved { .. }) => {
|
Event::Mouse(mouse::Event::CursorMoved { .. }) => {
|
||||||
if let Some(on_resize) = &self.on_resize {
|
self.trigger_resize(layout, cursor_position, messages);
|
||||||
if let Some((split, _)) = self.state.picked_split() {
|
|
||||||
let bounds = layout.bounds();
|
|
||||||
|
|
||||||
let splits = self.state.splits(
|
|
||||||
f32::from(self.spacing),
|
|
||||||
Size::new(bounds.width, bounds.height),
|
|
||||||
);
|
|
||||||
|
|
||||||
if let Some((axis, rectangle, _)) = splits.get(&split) {
|
|
||||||
let ratio = match axis {
|
|
||||||
Axis::Horizontal => {
|
|
||||||
let position = cursor_position.x - bounds.x
|
|
||||||
+ rectangle.x;
|
|
||||||
|
|
||||||
(position / (rectangle.x + rectangle.width))
|
|
||||||
.max(0.1)
|
|
||||||
.min(0.9)
|
|
||||||
}
|
|
||||||
Axis::Vertical => {
|
|
||||||
let position = cursor_position.y - bounds.y
|
|
||||||
+ rectangle.y;
|
|
||||||
|
|
||||||
(position
|
|
||||||
/ (rectangle.y + rectangle.height))
|
|
||||||
.max(0.1)
|
|
||||||
.min(0.9)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
messages
|
|
||||||
.push(on_resize(ResizeEvent { split, ratio }));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Event::Keyboard(keyboard::Event::Input { modifiers, .. }) => {
|
Event::Keyboard(keyboard::Event::Input { modifiers, .. }) => {
|
||||||
*self.modifiers = modifiers;
|
*self.modifiers = modifiers;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user