Skip to content

Commit

Permalink
Add docs to element mod
Browse files Browse the repository at this point in the history
  • Loading branch information
matthunz committed Sep 24, 2023
1 parent 4a27ade commit 537a224
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/element/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,74 @@ use taffy::{
#[derive(Clone, Copy, PartialEq, Eq)]
/// Element attribute kind.
pub enum AttributeKind {
/// Size attribute.
Size,

/// Flex direction attribute.
FlexDirection,

/// Item alignment attribute..
AlignItems,

/// Content justification attribute.
JustifyContent,

/// Click handler attribute.
OnClick,

/// Mouse in handler attribute.
OnMouseIn,

/// Mouse out handler attribute.
OnMouseOut,

/// Background color attribute.
BackgroundColor,
}

/// Element attribute value.
pub enum AttributeValue {
/// Size attribute value.
Size(Size<Dimension>),

/// Flex direction attribute value.
FlexDirection(FlexDirection),

/// Item alignment attribute value.
AlignItems(AlignItems),

/// Content justification attribute value.
JustifyContent(JustifyContent),

/// Click handler attribute value.
OnClick(Box<dyn FnMut(&mut Context, event::Click)>),

/// Mouse in handler attribute value.
OnMouseIn(Box<dyn FnMut(&mut Context, event::MouseIn)>),

// Mouse out handler attribute value.
OnMouseOut(Box<dyn FnMut(&mut Context, event::MouseOut)>),

/// Color attribute value.
Color(Color4f),
}

/// Element attribute.
pub struct Attribute {
/// Attribute kind.
pub(super) kind: AttributeKind,

/// Attribute value.
pub(super) value: AttributeValue,
}

impl Attribute {
/// Get the kind of this attribute.
pub fn kind(&self) -> AttributeKind {
self.kind
}

/// Get the value of this attribute.
pub fn value(&self) -> &AttributeValue {
&self.value
}
Expand Down
3 changes: 3 additions & 0 deletions src/element/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,17 @@ pub struct ElementData {
}

impl ElementData {
/// Get a reference to the attribute of this kind if present.
pub fn attr(&self, kind: AttributeKind) -> Option<&Attribute> {
self.attributes.iter().find(|attr| attr.kind() == kind)
}

/// Get a mutable reference to the attribute of this kind if present.
pub fn attr_mut(&mut self, kind: AttributeKind) -> Option<&mut Attribute> {
self.attributes.iter_mut().find(|attr| attr.kind() == kind)
}

/// Remove an attribute by kind from this element.
pub fn remove(&mut self, kind: AttributeKind) -> Option<Attribute> {
self.attributes
.iter()
Expand Down

0 comments on commit 537a224

Please sign in to comment.