diff --git a/src/dom.rs b/src/dom.rs index 6e6d9f1..eba5afa 100644 --- a/src/dom.rs +++ b/src/dom.rs @@ -368,6 +368,33 @@ fn set_style_signal(style: CssStyleDeclaration, callbacks: &mut Call }); } +// TODO should this inline ? +fn set_style_unchecked_signal(style: CssStyleDeclaration, callbacks: &mut Callbacks, name: A, value: D, important: bool) + where A: AsStr + 'static, + B: AsStr, + C: OptionStr, + D: Signal + '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 ? // TODO should this inline ? @@ -906,6 +933,18 @@ impl DomBuilder where A: AsRef { set_style(&self.element.as_ref().style(), &name, value, true); self } + + #[inline] + pub fn style_unchecked(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 DomBuilder where A: AsRef { @@ -931,6 +970,17 @@ impl DomBuilder where A: AsRef { self } + #[inline] + pub fn style_unchecked_signal(mut self, name: B, value: E) -> Self + where B: AsStr + 'static, + C: AsStr, + D: OptionStr, + E: Signal + '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(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(mut self, name: B, value: E) -> Self where B: MultiStr + 'static, @@ -1073,6 +1135,17 @@ impl StylesheetBuilder { self } + #[inline] + pub fn style_unchecked_signal(mut self, name: B, value: E) -> Self + where B: AsStr + 'static, + C: AsStr, + D: OptionStr, + E: Signal + '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(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(mut self, name: B, value: E) -> Self where B: MultiStr + 'static, @@ -1149,6 +1230,17 @@ impl ClassBuilder { self } + #[inline] + pub fn style_unchecked_signal(mut self, name: B, value: E) -> Self + where B: AsStr + 'static, + C: AsStr, + D: OptionStr, + E: Signal + 'static { + + self.stylesheet = self.stylesheet.style_unchecked_signal(name, value); + self + } + // TODO return a Handle ? #[doc(hidden)] #[inline]