Checkpoint

This commit is contained in:
Antonio Scandurra
2023-10-20 12:23:22 +02:00
parent c1f7c9bb87
commit 847a1cb068
4 changed files with 47 additions and 8 deletions
+23 -3
View File
@@ -153,12 +153,14 @@ where
}
}
impl<V, I> Div<V, I, FocusDisabled>
impl<V> Div<V, StatefulInteraction<V>, FocusDisabled>
where
I: ElementInteraction<V>,
V: 'static + Send + Sync,
{
pub fn focusable(self, handle: &FocusHandle) -> Div<V, I, FocusEnabled<V>> {
pub fn focusable(
self,
handle: &FocusHandle,
) -> Div<V, StatefulInteraction<V>, FocusEnabled<V>> {
Div {
interaction: self.interaction,
focus: handle.clone().into(),
@@ -169,6 +171,24 @@ where
}
}
impl<V> Div<V, StatelessInteraction<V>, FocusDisabled>
where
V: 'static + Send + Sync,
{
pub fn focusable(
self,
handle: &FocusHandle,
) -> Div<V, StatefulInteraction<V>, FocusEnabled<V>> {
Div {
interaction: self.interaction.into_stateful(handle),
focus: handle.clone().into(),
children: self.children,
group: self.group,
base_style: self.base_style,
}
}
}
impl<V, I> Focusable for Div<V, I, FocusEnabled<V>>
where
I: ElementInteraction<V>,
+15
View File
@@ -544,6 +544,21 @@ pub struct StatelessInteraction<V> {
pub group_hover_style: Option<GroupStyle>,
}
impl<V> StatelessInteraction<V>
where
V: 'static + Send + Sync,
{
pub fn into_stateful(self, id: impl Into<ElementId>) -> StatefulInteraction<V> {
StatefulInteraction {
id: id.into(),
stateless: self,
mouse_click_listeners: SmallVec::new(),
active_style: StyleRefinement::default(),
group_active_style: None,
}
}
}
pub struct GroupStyle {
pub group: SharedString,
pub style: StyleRefinement,
+7
View File
@@ -1573,6 +1573,7 @@ pub enum ElementId {
View(EntityId),
Number(usize),
Name(SharedString),
FocusHandle(FocusId),
}
impl From<EntityId> for ElementId {
@@ -1604,3 +1605,9 @@ impl From<&'static str> for ElementId {
ElementId::Name(name.into())
}
}
impl<'a> From<&'a FocusHandle> for ElementId {
fn from(handle: &'a FocusHandle) -> Self {
ElementId::FocusHandle(handle.id)
}
}
+2 -5
View File
@@ -81,7 +81,6 @@ impl FocusStory {
let child_2 = cx.focus_handle();
view(cx.entity(|cx| ()), move |_, cx| {
div()
.id("parent")
.focusable(&parent)
.context("parent")
.on_action(|_, action: &ActionA, phase, cx| {
@@ -106,12 +105,11 @@ impl FocusStory {
.focus_in(|style| style.bg(color_3))
.child(
div()
.id("child-1")
.focusable(&child_1)
.context("child-1")
.on_action(|_, action: &ActionB, phase, cx| {
println!("Action B dispatched on child 1 during {:?}", phase);
})
.focusable(&child_1)
.w_full()
.h_6()
.bg(color_4)
@@ -131,12 +129,11 @@ impl FocusStory {
)
.child(
div()
.id("child-2")
.focusable(&child_2)
.context("child-2")
.on_action(|_, action: &ActionC, phase, cx| {
println!("Action C dispatched on child 2 during {:?}", phase);
})
.focusable(&child_2)
.w_full()
.h_6()
.bg(color_4)