Checkpoint

This commit is contained in:
Antonio Scandurra
2023-10-18 13:36:26 +02:00
parent 296a2b8e5d
commit ad1b96720a
7 changed files with 340 additions and 142 deletions
+32 -5
View File
@@ -1,4 +1,4 @@
use crate::{BorrowWindow, Bounds, ElementId, LayoutId, Pixels, Point, ViewContext};
use crate::{BorrowWindow, Bounds, ElementId, FocusHandle, LayoutId, Pixels, Point, ViewContext};
use derive_more::{Deref, DerefMut};
pub(crate) use smallvec::SmallVec;
@@ -31,21 +31,48 @@ pub trait ElementIdentity: 'static + Send + Sync {
fn id(&self) -> Option<ElementId>;
}
pub struct IdentifiedElement(pub(crate) ElementId);
pub struct AnonymousElement;
pub struct Identified(pub(crate) ElementId);
impl ElementIdentity for IdentifiedElement {
impl ElementIdentity for Identified {
fn id(&self) -> Option<ElementId> {
Some(self.0.clone())
}
}
impl ElementIdentity for AnonymousElement {
pub struct Anonymous;
impl ElementIdentity for Anonymous {
fn id(&self) -> Option<ElementId> {
None
}
}
pub trait ElementFocusability: 'static + Send + Sync {
fn focus_handle(&self) -> Option<&FocusHandle>;
}
pub struct Focusable(FocusHandle);
impl ElementFocusability for Focusable {
fn focus_handle(&self) -> Option<&FocusHandle> {
Some(&self.0)
}
}
impl From<FocusHandle> for Focusable {
fn from(value: FocusHandle) -> Self {
Self(value)
}
}
pub struct NonFocusable;
impl ElementFocusability for NonFocusable {
fn focus_handle(&self) -> Option<&FocusHandle> {
None
}
}
pub trait ParentElement: Element {
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement<Self::ViewState>; 2]>;