Adding in SVG support

This commit is contained in:
Pauan 2018-05-24 00:22:47 -10:00
parent 47a6641495
commit 3082edde66
3 changed files with 42 additions and 25 deletions

View File

@ -461,13 +461,6 @@ impl Percentage {
} }
} }
impl Into<f64> for Percentage {
#[inline]
fn into(self) -> f64 {
self.0
}
}
#[inline] #[inline]
fn range_inclusive(percentage: f64, low: f64, high: f64) -> f64 { fn range_inclusive(percentage: f64, low: f64, high: f64) -> f64 {
low + (percentage * (high - low)) low + (percentage * (high - low))
@ -540,8 +533,8 @@ impl MutableAnimation {
fn start_animating(&self, lock: &mut MutableAnimationState) { fn start_animating(&self, lock: &mut MutableAnimationState) {
if lock.playing { if lock.playing {
// TODO use Copy constraint to make value.get() faster ? // TODO use Copy constraint to make value.get() faster ?
let start: f64 = self.inner.value.get().into(); let start: f64 = self.inner.value.get().into_f64();
let end: f64 = lock.end.into(); let end: f64 = lock.end.into_f64();
if start != end { if start != end {
if lock.duration > 0.0 { if lock.duration > 0.0 {
@ -660,7 +653,6 @@ impl MutableAnimation {
pub mod easing { pub mod easing {
use super::Percentage; use super::Percentage;
// TODO should this use map rather than map_unchecked ? // TODO should this use map rather than map_unchecked ?
#[inline] #[inline]
pub fn powi(p: Percentage, n: i32) -> Percentage { pub fn powi(p: Percentage, n: i32) -> Percentage {

View File

@ -1,6 +1,6 @@
use stdweb::{Reference, Value, JsSerialize}; use stdweb::{Reference, Value, JsSerialize};
use stdweb::unstable::{TryFrom, TryInto}; use stdweb::unstable::{TryFrom, TryInto};
use stdweb::web::{IEventTarget, INode, IElement, IHtmlElement, HtmlElement, Node, window, TextNode}; use stdweb::web::{IEventTarget, INode, IElement, IHtmlElement, HtmlElement, Node, window, TextNode, EventTarget, Element};
use stdweb::web::event::ConcreteEvent; use stdweb::web::event::ConcreteEvent;
use callbacks::Callbacks; use callbacks::Callbacks;
use traits::*; use traits::*;
@ -21,6 +21,15 @@ use discard::{Discard, DiscardOnDrop};
pub struct CssStyleRule(Reference); pub struct CssStyleRule(Reference);
/// A reference to an SVG Element.
///
/// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/API/SVGElement)
#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
#[reference(instance_of = "SVGElement")]
#[reference(subclass_of(EventTarget, Node, Element))]
pub struct SvgElement(Reference);
// https://developer.mozilla.org/en-US/docs/Web/API/Document/createElementNS#Valid%20Namespace%20URIs // https://developer.mozilla.org/en-US/docs/Web/API/Document/createElementNS#Valid%20Namespace%20URIs
pub const HTML_NAMESPACE: &str = "http://www.w3.org/1999/xhtml"; pub const HTML_NAMESPACE: &str = "http://www.w3.org/1999/xhtml";
pub const SVG_NAMESPACE: &str = "http://www.w3.org/2000/svg"; pub const SVG_NAMESPACE: &str = "http://www.w3.org/2000/svg";

View File

@ -1,20 +1,36 @@
#[macro_export] #[macro_export]
macro_rules! html { macro_rules! builder {
($kind:expr => $t:ty) => { ($namespace:expr, $default:ty, $kind:expr => $t:ty) => {
html!($kind => $t, {}) builder!($namespace, $default, $kind => $t, {})
}; };
($kind:expr => $t:ty, { $( $name:ident( $( $args:expr ),* ); )* }) => {{ ($namespace:expr, $default:ty, $kind:expr => $t:ty, { $( $name:ident( $( $args:expr ),* ); )* }) => {{
let a: $crate::DomBuilder<$t> = $crate::DomBuilder::new($crate::create_element_ns($kind, $crate::HTML_NAMESPACE))$(.$name($($args),*))*; let a: $crate::DomBuilder<$t> = $crate::DomBuilder::new($crate::create_element_ns($kind, $namespace))$(.$name($($args),*))*;
let b: $crate::Dom = $crate::DomBuilder::into_dom(a); let b: $crate::Dom = $crate::DomBuilder::into_dom(a);
b b
}}; }};
($kind:expr) => { ($namespace:expr, $default:ty, $kind:expr) => {
html!($kind => $crate::HtmlElement) builder!($namespace, $default, $kind => $default)
};
($namespace:expr, $default:ty, $kind:expr, { $( $name:ident( $( $args:expr ),* ); )* }) => {
builder!($namespace, $default, $kind => $default, { $( $name( $( $args ),* ); )* })
};
}
#[macro_export]
macro_rules! html {
($($args:tt)+) => {
builder!($crate::HTML_NAMESPACE, $crate::HtmlElement, $($args)+)
};
}
#[macro_export]
macro_rules! svg {
($($args:tt)+) => {
builder!($crate::SVG_NAMESPACE, $crate::SvgElement, $($args)+)
}; };
($kind:expr, { $( $name:ident( $( $args:expr ),* ); )* }) => {{
html!($kind => $crate::HtmlElement, { $( $name( $( $args ),* ); )* })
}};
} }
@ -23,17 +39,17 @@ macro_rules! stylesheet {
($rule:expr) => { ($rule:expr) => {
stylesheet!($rule, {}) stylesheet!($rule, {})
}; };
($rule:expr, { $( $name:ident( $( $args:expr ),* ); )* }) => {{ ($rule:expr, { $( $name:ident( $( $args:expr ),* ); )* }) => {
$crate::StylesheetBuilder::new($rule)$(.$name($($args),*))*.done() $crate::StylesheetBuilder::new($rule)$(.$name($($args),*))*.done()
}}; };
} }
#[macro_export] #[macro_export]
macro_rules! class { macro_rules! class {
($( $name:ident( $( $args:expr ),* ); )*) => {{ ($( $name:ident( $( $args:expr ),* ); )*) => {
$crate::ClassBuilder::new()$(.$name($($args),*))*.done() $crate::ClassBuilder::new()$(.$name($($args),*))*.done()
}}; };
} }