Merge branch 'main' into ime-support-2
This commit is contained in:
commit
7b009c8bbe
209 changed files with 1859 additions and 9740 deletions
|
@ -1,5 +1,3 @@
|
|||
use std::{any::TypeId, ops::Range, rc::Rc};
|
||||
|
||||
use super::Padding;
|
||||
use crate::{
|
||||
geometry::{
|
||||
|
@ -7,25 +5,19 @@ use crate::{
|
|||
vector::{vec2f, Vector2F},
|
||||
},
|
||||
platform::CursorStyle,
|
||||
scene::CursorRegion,
|
||||
DebugContext, Element, ElementBox, Event, EventContext, LayoutContext, MouseRegion,
|
||||
MouseState, PaintContext, RenderContext, SizeConstraint, View, presenter::MeasurementContext,
|
||||
scene::{CursorRegion, HandlerSet},
|
||||
DebugContext, Element, ElementBox, Event, EventContext, LayoutContext, MeasurementContext,
|
||||
MouseButton, MouseButtonEvent, MouseMovedEvent, MouseRegion, MouseState, PaintContext,
|
||||
RenderContext, SizeConstraint, View,
|
||||
};
|
||||
use serde_json::json;
|
||||
use std::{any::TypeId, ops::Range};
|
||||
|
||||
pub struct MouseEventHandler {
|
||||
child: ElementBox,
|
||||
tag: TypeId,
|
||||
id: usize,
|
||||
discriminant: (TypeId, usize),
|
||||
cursor_style: Option<CursorStyle>,
|
||||
mouse_down: Option<Rc<dyn Fn(Vector2F, &mut EventContext)>>,
|
||||
click: Option<Rc<dyn Fn(Vector2F, usize, &mut EventContext)>>,
|
||||
right_mouse_down: Option<Rc<dyn Fn(Vector2F, &mut EventContext)>>,
|
||||
right_click: Option<Rc<dyn Fn(Vector2F, usize, &mut EventContext)>>,
|
||||
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, Vector2F, &mut EventContext)>>,
|
||||
hover: Option<Rc<dyn Fn(Vector2F, bool, &mut EventContext)>>,
|
||||
handlers: HandlerSet,
|
||||
padding: Padding,
|
||||
}
|
||||
|
||||
|
@ -37,18 +29,10 @@ impl MouseEventHandler {
|
|||
F: FnOnce(MouseState, &mut RenderContext<V>) -> ElementBox,
|
||||
{
|
||||
Self {
|
||||
id,
|
||||
tag: TypeId::of::<Tag>(),
|
||||
child: render_child(cx.mouse_state::<Tag>(id), cx),
|
||||
cursor_style: None,
|
||||
mouse_down: None,
|
||||
click: None,
|
||||
right_mouse_down: None,
|
||||
right_click: None,
|
||||
mouse_down_out: None,
|
||||
right_mouse_down_out: None,
|
||||
drag: None,
|
||||
hover: None,
|
||||
discriminant: (TypeId::of::<Tag>(), id),
|
||||
handlers: Default::default(),
|
||||
padding: Default::default(),
|
||||
}
|
||||
}
|
||||
|
@ -58,67 +42,47 @@ impl MouseEventHandler {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn on_mouse_down(
|
||||
pub fn on_down(
|
||||
mut self,
|
||||
handler: impl Fn(Vector2F, &mut EventContext) + 'static,
|
||||
button: MouseButton,
|
||||
handler: impl Fn(MouseButtonEvent, &mut EventContext) + 'static,
|
||||
) -> Self {
|
||||
self.mouse_down = Some(Rc::new(handler));
|
||||
self.handlers = self.handlers.on_down(button, handler);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn on_click(
|
||||
mut self,
|
||||
handler: impl Fn(Vector2F, usize, &mut EventContext) + 'static,
|
||||
button: MouseButton,
|
||||
handler: impl Fn(MouseButtonEvent, &mut EventContext) + 'static,
|
||||
) -> Self {
|
||||
self.click = Some(Rc::new(handler));
|
||||
self.handlers = self.handlers.on_click(button, handler);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn on_right_mouse_down(
|
||||
pub fn on_down_out(
|
||||
mut self,
|
||||
handler: impl Fn(Vector2F, &mut EventContext) + 'static,
|
||||
button: MouseButton,
|
||||
handler: impl Fn(MouseButtonEvent, &mut EventContext) + 'static,
|
||||
) -> Self {
|
||||
self.right_mouse_down = Some(Rc::new(handler));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn on_right_click(
|
||||
mut self,
|
||||
handler: impl Fn(Vector2F, usize, &mut EventContext) + 'static,
|
||||
) -> Self {
|
||||
self.right_click = Some(Rc::new(handler));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn on_mouse_down_out(
|
||||
mut self,
|
||||
handler: impl Fn(Vector2F, &mut EventContext) + 'static,
|
||||
) -> Self {
|
||||
self.mouse_down_out = Some(Rc::new(handler));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn on_right_mouse_down_out(
|
||||
mut self,
|
||||
handler: impl Fn(Vector2F, &mut EventContext) + 'static,
|
||||
) -> Self {
|
||||
self.right_mouse_down_out = Some(Rc::new(handler));
|
||||
self.handlers = self.handlers.on_down_out(button, handler);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn on_drag(
|
||||
mut self,
|
||||
handler: impl Fn(Vector2F, Vector2F, &mut EventContext) + 'static,
|
||||
button: MouseButton,
|
||||
handler: impl Fn(Vector2F, MouseMovedEvent, &mut EventContext) + 'static,
|
||||
) -> Self {
|
||||
self.drag = Some(Rc::new(handler));
|
||||
self.handlers = self.handlers.on_drag(button, handler);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn on_hover(
|
||||
mut self,
|
||||
handler: impl Fn(Vector2F, bool, &mut EventContext) + 'static,
|
||||
handler: impl Fn(bool, MouseMovedEvent, &mut EventContext) + 'static,
|
||||
) -> Self {
|
||||
self.hover = Some(Rc::new(handler));
|
||||
self.handlers = self.handlers.on_hover(handler);
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -163,19 +127,12 @@ impl Element for MouseEventHandler {
|
|||
});
|
||||
}
|
||||
|
||||
cx.scene.push_mouse_region(MouseRegion {
|
||||
view_id: cx.current_view_id(),
|
||||
discriminant: Some((self.tag, self.id)),
|
||||
bounds: hit_bounds,
|
||||
hover: self.hover.clone(),
|
||||
click: self.click.clone(),
|
||||
mouse_down: self.mouse_down.clone(),
|
||||
right_click: self.right_click.clone(),
|
||||
right_mouse_down: self.right_mouse_down.clone(),
|
||||
mouse_down_out: self.mouse_down_out.clone(),
|
||||
right_mouse_down_out: self.right_mouse_down_out.clone(),
|
||||
drag: self.drag.clone(),
|
||||
});
|
||||
cx.scene.push_mouse_region(MouseRegion::from_handlers(
|
||||
cx.current_view_id(),
|
||||
Some(self.discriminant.clone()),
|
||||
hit_bounds,
|
||||
self.handlers.clone(),
|
||||
));
|
||||
|
||||
self.child.paint(bounds.origin(), visible_bounds, cx);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue