GPUI change proposals
This commit is contained in:
parent
4d88088ca4
commit
b2fa511acd
5 changed files with 24 additions and 9 deletions
|
@ -90,7 +90,7 @@ impl Element for EventHandler {
|
||||||
click: Some(Rc::new(|_, _, _| {})),
|
click: Some(Rc::new(|_, _, _| {})),
|
||||||
right_mouse_down: Some(Rc::new(|_, _| {})),
|
right_mouse_down: Some(Rc::new(|_, _| {})),
|
||||||
right_click: Some(Rc::new(|_, _, _| {})),
|
right_click: Some(Rc::new(|_, _, _| {})),
|
||||||
drag: Some(Rc::new(|_, _| {})),
|
drag: Some(Rc::new(|_, _, _| {})),
|
||||||
mouse_down_out: Some(Rc::new(|_, _| {})),
|
mouse_down_out: Some(Rc::new(|_, _| {})),
|
||||||
right_mouse_down_out: Some(Rc::new(|_, _| {})),
|
right_mouse_down_out: Some(Rc::new(|_, _| {})),
|
||||||
});
|
});
|
||||||
|
|
|
@ -24,7 +24,7 @@ pub struct MouseEventHandler {
|
||||||
right_click: Option<Rc<dyn Fn(Vector2F, usize, &mut EventContext)>>,
|
right_click: Option<Rc<dyn Fn(Vector2F, usize, &mut EventContext)>>,
|
||||||
mouse_down_out: Option<Rc<dyn Fn(Vector2F, &mut EventContext)>>,
|
mouse_down_out: Option<Rc<dyn Fn(Vector2F, &mut EventContext)>>,
|
||||||
right_mouse_down_out: Option<Rc<dyn Fn(Vector2F, &mut EventContext)>>,
|
right_mouse_down_out: Option<Rc<dyn Fn(Vector2F, &mut EventContext)>>,
|
||||||
drag: Option<Rc<dyn Fn(Vector2F, &mut EventContext)>>,
|
drag: Option<Rc<dyn Fn(Vector2F, Vector2F, &mut EventContext)>>,
|
||||||
hover: Option<Rc<dyn Fn(Vector2F, bool, &mut EventContext)>>,
|
hover: Option<Rc<dyn Fn(Vector2F, bool, &mut EventContext)>>,
|
||||||
padding: Padding,
|
padding: Padding,
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,10 @@ impl MouseEventHandler {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_drag(mut self, handler: impl Fn(Vector2F, &mut EventContext) + 'static) -> Self {
|
pub fn on_drag(
|
||||||
|
mut self,
|
||||||
|
handler: impl Fn(Vector2F, Vector2F, &mut EventContext) + 'static,
|
||||||
|
) -> Self {
|
||||||
self.drag = Some(Rc::new(handler));
|
self.drag = Some(Rc::new(handler));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
@ -306,8 +306,11 @@ impl Presenter {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.zip(self.prev_drag_position.as_mut())
|
.zip(self.prev_drag_position.as_mut())
|
||||||
{
|
{
|
||||||
dragged_region =
|
dragged_region = Some((
|
||||||
Some((clicked_region.clone(), position - *prev_drag_position));
|
clicked_region.clone(),
|
||||||
|
position - *prev_drag_position,
|
||||||
|
position,
|
||||||
|
));
|
||||||
*prev_drag_position = position;
|
*prev_drag_position = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,11 +369,11 @@ impl Presenter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some((dragged_region, delta)) = dragged_region {
|
if let Some((dragged_region, delta, position)) = dragged_region {
|
||||||
handled = true;
|
handled = true;
|
||||||
if let Some(drag_callback) = dragged_region.drag {
|
if let Some(drag_callback) = dragged_region.drag {
|
||||||
event_cx.with_current_view(dragged_region.view_id, |event_cx| {
|
event_cx.with_current_view(dragged_region.view_id, |event_cx| {
|
||||||
drag_callback(delta, event_cx);
|
drag_callback(delta, position, event_cx);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -648,6 +651,15 @@ impl<'a> PaintContext<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn paint_layer<F>(&mut self, clip_bounds: Option<RectF>, f: F)
|
||||||
|
where
|
||||||
|
F: FnOnce(&mut Self) -> (),
|
||||||
|
{
|
||||||
|
self.scene.push_layer(clip_bounds);
|
||||||
|
f(self);
|
||||||
|
self.scene.pop_layer();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn current_view_id(&self) -> usize {
|
pub fn current_view_id(&self) -> usize {
|
||||||
*self.view_stack.last().unwrap()
|
*self.view_stack.last().unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ pub struct MouseRegion {
|
||||||
pub click: Option<Rc<dyn Fn(Vector2F, usize, &mut EventContext)>>,
|
pub click: Option<Rc<dyn Fn(Vector2F, usize, &mut EventContext)>>,
|
||||||
pub right_mouse_down: Option<Rc<dyn Fn(Vector2F, &mut EventContext)>>,
|
pub right_mouse_down: Option<Rc<dyn Fn(Vector2F, &mut EventContext)>>,
|
||||||
pub right_click: Option<Rc<dyn Fn(Vector2F, usize, &mut EventContext)>>,
|
pub right_click: Option<Rc<dyn Fn(Vector2F, usize, &mut EventContext)>>,
|
||||||
pub drag: Option<Rc<dyn Fn(Vector2F, &mut EventContext)>>,
|
pub drag: Option<Rc<dyn Fn(Vector2F, Vector2F, &mut EventContext)>>,
|
||||||
pub mouse_down_out: Option<Rc<dyn Fn(Vector2F, &mut EventContext)>>,
|
pub mouse_down_out: Option<Rc<dyn Fn(Vector2F, &mut EventContext)>>,
|
||||||
pub right_mouse_down_out: Option<Rc<dyn Fn(Vector2F, &mut EventContext)>>,
|
pub right_mouse_down_out: Option<Rc<dyn Fn(Vector2F, &mut EventContext)>>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,7 +188,7 @@ impl Sidebar {
|
||||||
})
|
})
|
||||||
.with_cursor_style(CursorStyle::ResizeLeftRight)
|
.with_cursor_style(CursorStyle::ResizeLeftRight)
|
||||||
.on_mouse_down(|_, _| {}) // This prevents the mouse down event from being propagated elsewhere
|
.on_mouse_down(|_, _| {}) // This prevents the mouse down event from being propagated elsewhere
|
||||||
.on_drag(move |delta, cx| {
|
.on_drag(move |delta, _, cx| {
|
||||||
let prev_width = *actual_width.borrow();
|
let prev_width = *actual_width.borrow();
|
||||||
*custom_width.borrow_mut() = 0f32
|
*custom_width.borrow_mut() = 0f32
|
||||||
.max(match side {
|
.max(match side {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue