Skip to content

Commit

Permalink
Implemented all HTML DOM interface traits (most without explicit attr…
Browse files Browse the repository at this point in the history
…ibute methods yet)

* Macro refactor
* Disabled/Deleted previous generated elements
* Disabled/Commented out event views, (implemented some of them on the Element DOM interface trait
* Lots of smaller fixes
  • Loading branch information
Philipp-M committed Aug 9, 2023
1 parent f08d942 commit c4d978b
Show file tree
Hide file tree
Showing 9 changed files with 859 additions and 1,108 deletions.
2 changes: 1 addition & 1 deletion crates/xilem_html/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ typed = [
"web-sys/HtmlTableSectionElement", "web-sys/HtmlTemplateElement", "web-sys/HtmlTextAreaElement",
"web-sys/HtmlTimeElement", "web-sys/HtmlTrackElement", "web-sys/HtmlUListElement",
"web-sys/HtmlVideoElement", "web-sys/InputEvent", "web-sys/KeyboardEvent", "web-sys/MouseEvent",
"web-sys/PointerEvent", "web-sys/WheelEvent",
"web-sys/PointerEvent", "web-sys/WheelEvent", "web-sys/TouchEvent",
]

[dependencies]
Expand Down
29 changes: 28 additions & 1 deletion crates/xilem_html/src/element/attributes.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
use std::borrow::Cow;
use std::{borrow::Cow, collections::BTreeSet};

use crate::{diff::Diff, vecmap::VecMap};

type CowStr = Cow<'static, str>;

// TODO not sure how useful an extra enum for attribute keys is (comparison is probably a little bit faster...)
// #[derive(PartialEq, Eq)]
// enum AttrKey {
// Width,
// Height,
// Class,
// Untyped(Box<Cow<'static, str>>),
// }

#[derive(PartialEq, Debug)]
pub enum AttributeValue {
Null,
Expand All @@ -13,6 +22,7 @@ pub enum AttributeValue {
F32(f32),
F64(f64),
String(CowStr),
Classes(BTreeSet<CowStr>),
}

impl AttributeValue {
Expand All @@ -24,6 +34,19 @@ impl AttributeValue {
AttributeValue::F32(n) => n.to_string().into(),
AttributeValue::F64(n) => n.to_string().into(),
AttributeValue::String(s) => s.clone(),
// TODO maybe use Vec as backend (should probably be more performant for few classes, which seems to be the average case)
AttributeValue::Classes(set) => set
.iter()
.fold(String::new(), |mut acc, s| {
if !acc.is_empty() {
acc += " ";
}
if !s.is_empty() {
acc += s;
}
acc
})
.into(),
// AttributeValue::Null shouldn't be serialized within attribute serialization/diffing
// as null values should never show up in the attributes map, but for completeness it's serialized to an empty string
AttributeValue::Null => "".into(),
Expand Down Expand Up @@ -114,6 +137,10 @@ impl Attributes {
self.0.iter()
}

pub fn get_mut(&mut self, key: &str) -> Option<&mut AttributeValue> {
self.0.get_mut(key)
}

/// Computes the diff between two attribute maps
/// `other` is the "newer" map,
/// i.e. when `other` contains an element that this map doesn't, the diff iterator outputs Diff::Add
Expand Down
Loading

0 comments on commit c4d978b

Please sign in to comment.