Adding in style_unchecked and style_unchecked_signal methods

This commit is contained in:
Pauan 2021-09-18 21:30:52 +02:00
parent c87c6018bf
commit 29083bf288
1 changed files with 92 additions and 0 deletions

View File

@ -368,6 +368,33 @@ fn set_style_signal<A, B, C, D>(style: CssStyleDeclaration, callbacks: &mut Call
});
}
// TODO should this inline ?
fn set_style_unchecked_signal<A, B, C, D>(style: CssStyleDeclaration, callbacks: &mut Callbacks, name: A, value: D, important: bool)
where A: AsStr + 'static,
B: AsStr,
C: OptionStr<Output = B>,
D: Signal<Item = C> + 'static {
set_option(style, callbacks, value, move |style, value| {
match value {
Some(value) => {
name.with_str(|name| {
let name: &str = intern(name);
value.with_str(|value| {
bindings::set_style(style, name, value, important);
});
});
},
None => {
name.with_str(|name| {
bindings::remove_style(style, intern(name));
});
},
}
});
}
// TODO check that the property *actually* was changed ?
// TODO maybe use AsRef<Object> ?
// TODO should this inline ?
@ -906,6 +933,18 @@ impl<A> DomBuilder<A> where A: AsRef<HtmlElement> {
set_style(&self.element.as_ref().style(), &name, value, true);
self
}
#[inline]
pub fn style_unchecked<B, C>(self, name: B, value: C) -> Self
where B: AsStr,
C: AsStr {
name.with_str(|name| {
value.with_str(|value| {
bindings::set_style(&self.element.as_ref().style(), intern(name), value, false);
});
});
self
}
}
impl<A> DomBuilder<A> where A: AsRef<HtmlElement> {
@ -931,6 +970,17 @@ impl<A> DomBuilder<A> where A: AsRef<HtmlElement> {
self
}
#[inline]
pub fn style_unchecked_signal<B, C, D, E>(mut self, name: B, value: E) -> Self
where B: AsStr + 'static,
C: AsStr,
D: OptionStr<Output = C>,
E: Signal<Item = D> + 'static {
set_style_unchecked_signal(self.element.as_ref().style(), &mut self.callbacks, name, value, false);
self
}
// TODO remove the `value` argument ?
#[inline]
@ -1051,6 +1101,18 @@ impl StylesheetBuilder {
self
}
#[inline]
pub fn style_unchecked<B, C>(self, name: B, value: C) -> Self
where B: AsStr,
C: AsStr {
name.with_str(|name| {
value.with_str(|value| {
bindings::set_style(&self.element, intern(name), value, false);
});
});
self
}
#[inline]
pub fn style_signal<B, C, D, E>(mut self, name: B, value: E) -> Self
where B: MultiStr + 'static,
@ -1073,6 +1135,17 @@ impl StylesheetBuilder {
self
}
#[inline]
pub fn style_unchecked_signal<B, C, D, E>(mut self, name: B, value: E) -> Self
where B: AsStr + 'static,
C: AsStr,
D: OptionStr<Output = C>,
E: Signal<Item = D> + 'static {
set_style_unchecked_signal(self.element.clone(), &mut self.callbacks, name, value, false);
self
}
// TODO return a Handle
#[inline]
#[doc(hidden)]
@ -1127,6 +1200,14 @@ impl ClassBuilder {
self
}
#[inline]
pub fn style_unchecked<B, C>(mut self, name: B, value: C) -> Self
where B: AsStr,
C: AsStr {
self.stylesheet = self.stylesheet.style_unchecked(name, value);
self
}
#[inline]
pub fn style_signal<B, C, D, E>(mut self, name: B, value: E) -> Self
where B: MultiStr + 'static,
@ -1149,6 +1230,17 @@ impl ClassBuilder {
self
}
#[inline]
pub fn style_unchecked_signal<B, C, D, E>(mut self, name: B, value: E) -> Self
where B: AsStr + 'static,
C: AsStr,
D: OptionStr<Output = C>,
E: Signal<Item = D> + 'static {
self.stylesheet = self.stylesheet.style_unchecked_signal(name, value);
self
}
// TODO return a Handle ?
#[doc(hidden)]
#[inline]