WIP
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
use crate::{BorrowWindow, Bounds, Element, ElementId, LayoutId, StatefulElement, ViewContext};
|
||||
use refineable::{Refineable, RefinementCascade};
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use crate::{
|
||||
AnyElement, BorrowWindow, Bounds, Element, ElementId, LayoutId, ParentElement, StatefulElement,
|
||||
Styled, ViewContext,
|
||||
};
|
||||
|
||||
pub struct Identified<E> {
|
||||
pub(crate) element: E,
|
||||
@@ -36,3 +42,22 @@ impl<E: Element> Element for Identified<E> {
|
||||
}
|
||||
|
||||
impl<E: Element> StatefulElement for Identified<E> {}
|
||||
|
||||
impl<E: Styled> Styled for Identified<E> {
|
||||
type Style = E::Style;
|
||||
|
||||
fn style_cascade(&mut self) -> &mut RefinementCascade<Self::Style> {
|
||||
self.element.style_cascade()
|
||||
}
|
||||
fn declared_style(&mut self) -> &mut <Self::Style as Refineable>::Refinement {
|
||||
self.element.declared_style()
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: ParentElement> ParentElement for Identified<E> {
|
||||
type State = E::State;
|
||||
|
||||
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement<Self::State>; 2]> {
|
||||
self.element.children_mut()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,25 +92,29 @@ where
|
||||
element_state: &mut Self::ElementState,
|
||||
cx: &mut ViewContext<Self::ViewState>,
|
||||
) {
|
||||
let slot = self.cascade_slot;
|
||||
let style = element_state
|
||||
.pressed
|
||||
.load(SeqCst)
|
||||
.then_some(self.pressed_style.clone());
|
||||
let slot = self.cascade_slot;
|
||||
self.style_cascade().set(slot, style);
|
||||
|
||||
let pressed = element_state.pressed.clone();
|
||||
cx.on_mouse_event(move |_, event: &MouseDownEvent, phase, cx| {
|
||||
if phase == DispatchPhase::Capture {
|
||||
if bounds.contains_point(event.position) != pressed.load(SeqCst) {
|
||||
if bounds.contains_point(event.position) {
|
||||
dbg!("pressed");
|
||||
pressed.store(true, SeqCst);
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
});
|
||||
let hovered = element_state.pressed.clone();
|
||||
cx.on_mouse_event(move |_, event: &MouseUpEvent, phase, cx| {
|
||||
let pressed = element_state.pressed.clone();
|
||||
cx.on_mouse_event(move |_, _: &MouseUpEvent, phase, cx| {
|
||||
if phase == DispatchPhase::Capture {
|
||||
if bounds.contains_point(event.position) != hovered.load(SeqCst) {
|
||||
if pressed.load(SeqCst) {
|
||||
dbg!("released");
|
||||
pressed.store(false, SeqCst);
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user