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 21, 2023
1 parent 89d893b commit 39e7a3f
Show file tree
Hide file tree
Showing 9 changed files with 869 additions and 1,110 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
25 changes: 25 additions & 0 deletions crates/xilem_html/src/element/attribute_value.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
use std::collections::BTreeSet;

type CowStr = std::borrow::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 {
True, // for the boolean true, this serializes to an empty string (e.g. for <input checked>)
Expand All @@ -8,6 +19,7 @@ pub enum AttributeValue {
F32(f32),
F64(f64),
String(CowStr),
Classes(BTreeSet<CowStr>),
}

impl AttributeValue {
Expand All @@ -19,6 +31,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(),
}
}
}
Expand Down
Loading

0 comments on commit 39e7a3f

Please sign in to comment.