wip
This commit is contained in:
parent
6c60853842
commit
ba50b35de6
9 changed files with 634 additions and 525 deletions
|
@ -3816,6 +3816,12 @@ impl<T> PartialEq for ViewHandle<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> PartialEq<AnyViewHandle> for ViewHandle<T> {
|
||||
fn eq(&self, other: &AnyViewHandle) -> bool {
|
||||
self.window_id == other.window_id && self.view_id == other.view_id
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> PartialEq<WeakViewHandle<T>> for ViewHandle<T> {
|
||||
fn eq(&self, other: &WeakViewHandle<T>) -> bool {
|
||||
self.window_id == other.window_id && self.view_id == other.view_id
|
||||
|
|
|
@ -33,8 +33,11 @@ use crate::{
|
|||
rect::RectF,
|
||||
vector::{vec2f, Vector2F},
|
||||
},
|
||||
json, Action, LayoutContext, SceneBuilder, SizeConstraint, View, ViewContext, WeakViewHandle,
|
||||
WindowContext,
|
||||
json,
|
||||
platform::MouseButton,
|
||||
scene::MouseDown,
|
||||
Action, EventContext, LayoutContext, SceneBuilder, SizeConstraint, View, ViewContext,
|
||||
WeakViewHandle, WindowContext,
|
||||
};
|
||||
use anyhow::{anyhow, Result};
|
||||
use collections::HashMap;
|
||||
|
@ -198,6 +201,13 @@ pub trait Element<V: View>: 'static {
|
|||
{
|
||||
Resizable::new(self.into_any(), side, size, on_resize)
|
||||
}
|
||||
|
||||
fn mouse<Tag>(self, region_id: usize) -> MouseEventHandler<Tag, V>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
MouseEventHandler::for_child(self.into_any(), region_id)
|
||||
}
|
||||
}
|
||||
|
||||
trait AnyElementState<V: View> {
|
||||
|
|
|
@ -32,10 +32,25 @@ pub struct MouseEventHandler<Tag: 'static, V: View> {
|
|||
/// Element which provides a render_child callback with a MouseState and paints a mouse
|
||||
/// region under (or above) it for easy mouse event handling.
|
||||
impl<Tag, V: View> MouseEventHandler<Tag, V> {
|
||||
pub fn new<D, F>(region_id: usize, cx: &mut ViewContext<V>, render_child: F) -> Self
|
||||
pub fn for_child(child: impl Element<V>, region_id: usize) -> Self {
|
||||
Self {
|
||||
child: child.into_any(),
|
||||
region_id,
|
||||
cursor_style: None,
|
||||
handlers: Default::default(),
|
||||
notify_on_hover: false,
|
||||
notify_on_click: false,
|
||||
hoverable: false,
|
||||
above: false,
|
||||
padding: Default::default(),
|
||||
_tag: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new<E, F>(region_id: usize, cx: &mut ViewContext<V>, render_child: F) -> Self
|
||||
where
|
||||
D: Element<V>,
|
||||
F: FnOnce(&mut MouseState, &mut ViewContext<V>) -> D,
|
||||
E: Element<V>,
|
||||
F: FnOnce(&mut MouseState, &mut ViewContext<V>) -> E,
|
||||
{
|
||||
let mut mouse_state = cx.mouse_state::<Tag>(region_id);
|
||||
let child = render_child(&mut mouse_state, cx).into_any();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue