Commit 43531e34 authored by Michael Aaron Murphy's avatar Michael Aaron Murphy

[api update] Simplify PropertySource conversion

parent 95ff0925
......@@ -8,7 +8,7 @@ macro_rules! property {
#[derive(Default, Debug, Clone, PartialEq)]
$(#[$property_doc])*
pub struct $property(pub $type);
impl $property {
/// Returns the value of a property.
pub fn get(entity: Entity, ecm: &EntityComponentManager) -> $type {
......@@ -16,9 +16,9 @@ macro_rules! property {
}
}
impl Into<PropertySource<$property>> for $property {
fn into(self) -> PropertySource<$property> {
PropertySource::Value(self)
impl<T: Into<$property>> From<T> for PropertySource<$property> {
fn from(value: T) -> Self {
PropertySource::Value(value.into())
}
}
......@@ -33,18 +33,6 @@ macro_rules! property {
$property(value)
}
}
impl Into<PropertySource<$property>> for $type {
fn into(self) -> PropertySource<$property> {
PropertySource::Value($property::from(self))
}
}
impl Into<PropertySource<$property>> for Entity {
fn into(self) -> PropertySource<$property> {
PropertySource::Source(self)
}
}
};
}
......@@ -210,11 +198,11 @@ macro_rules! widget {
let state = Rc::new($state::default());
*self.state.borrow_mut() = Some(state.clone());
state
}
)*
$(
$(
$(#[$prop_doc])*
......@@ -302,7 +290,7 @@ macro_rules! widget {
// register helpers
context.register_property(entity, Point::default());
// register attached properties
for (_, property) in this.attached_properties {
context.register_property_box(entity, property);
......@@ -331,11 +319,11 @@ macro_rules! widget {
// register event handlers
for handler in this.event_handlers {
context.register_handler(entity, handler);
}
}
// register name
if let Some(name) = this.name {
context.register_property(entity, name);
context.register_property(entity, name);
}
for child in this.children {
......
......@@ -102,9 +102,3 @@ impl From<(f64, f64, f64, f64)> for Bounds {
Bounds::from(Rect::new(t.0, t.1, t.2, t.3))
}
}
impl Into<PropertySource<Bounds>> for (f64, f64, f64, f64) {
fn into(self) -> PropertySource<Bounds> {
PropertySource::Value(Bounds::from(self))
}
}
......@@ -38,9 +38,3 @@ impl From<&str> for HorizontalAlignment {
HorizontalAlignment(s.into())
}
}
impl Into<PropertySource<HorizontalAlignment>> for &str {
fn into(self) -> PropertySource<HorizontalAlignment> {
PropertySource::Value(HorizontalAlignment::from(self))
}
}
......@@ -57,32 +57,14 @@ impl From<(f64, f64, f64, f64)> for Margin {
}
}
impl Into<PropertySource<Margin>> for (f64, f64, f64, f64) {
fn into(self) -> PropertySource<Margin> {
PropertySource::Value(Margin::from(self))
}
}
impl From<(f64, f64)> for Margin {
fn from(t: (f64, f64)) -> Self {
Margin::from(Thickness::new(t.0, t.1, t.0, t.1))
}
}
impl Into<PropertySource<Margin>> for (f64, f64) {
fn into(self) -> PropertySource<Margin> {
PropertySource::Value(Margin::from(self))
}
}
impl From<f64> for Margin {
fn from(t: f64) -> Self {
Margin::from(Thickness::new(t, t, t, t))
}
}
impl Into<PropertySource<Margin>> for f64 {
fn into(self) -> PropertySource<Margin> {
PropertySource::Value(Margin::from(self))
}
}
......@@ -8,9 +8,3 @@ impl From<f64> for Offset {
Offset((t, t))
}
}
impl Into<PropertySource<Offset>> for f64 {
fn into(self) -> PropertySource<Offset> {
PropertySource::Value(Offset::from(self))
}
}
\ No newline at end of file
......@@ -29,9 +29,3 @@ impl From<&str> for Orientation {
}
}
}
impl Into<PropertySource<Orientation>> for &str {
fn into(self) -> PropertySource<Orientation> {
PropertySource::Value(Orientation::from(self))
}
}
......@@ -57,32 +57,14 @@ impl From<(f64, f64, f64, f64)> for Padding {
}
}
impl Into<PropertySource<Padding>> for (f64, f64, f64, f64) {
fn into(self) -> PropertySource<Padding> {
PropertySource::Value(Padding::from(self))
}
}
impl From<(f64, f64)> for Padding {
fn from(t: (f64, f64)) -> Self {
Padding::from(Thickness::new(t.0, t.1, t.0, t.1))
}
}
impl Into<PropertySource<Padding>> for (f64, f64) {
fn into(self) -> PropertySource<Padding> {
PropertySource::Value(Padding::from(self))
}
}
impl From<f64> for Padding {
fn from(t: f64) -> Self {
Padding::from(Thickness::new(t, t, t, t))
}
}
impl Into<PropertySource<Padding>> for f64 {
fn into(self) -> PropertySource<Padding> {
PropertySource::Value(Padding::from(self))
}
}
......@@ -34,9 +34,3 @@ impl From<(&str, &str)> for ScrollViewerMode {
})
}
}
impl Into<PropertySource<ScrollViewerMode>> for (&str, &str) {
fn into(self) -> PropertySource<ScrollViewerMode> {
PropertySource::Value(ScrollViewerMode::from(self))
}
}
\ No newline at end of file
......@@ -38,9 +38,3 @@ impl From<&str> for VerticalAlignment {
VerticalAlignment(s.into())
}
}
impl Into<PropertySource<VerticalAlignment>> for &str {
fn into(self) -> PropertySource<VerticalAlignment> {
PropertySource::Value(VerticalAlignment::from(self))
}
}
......@@ -34,12 +34,8 @@ pub enum PropertySource<P: Component + PartialEq + Debug> {
Value(P),
}
// impl<P: Component> PropertySource<P> {
// pub fn is_value(&self) -> bool {
// if let PropertySource::Value(_) = self {
// return true;
// }
// false
// }
// }
\ No newline at end of file
impl<P: Component + PartialEq + Debug> From<Entity> for PropertySource<P> {
fn from(entity: Entity) -> Self {
PropertySource::Source(entity)
}
}
......@@ -33,9 +33,3 @@ impl From<&str> for Visibility {
}
}
}
impl Into<PropertySource<Visibility>> for &str {
fn into(self) -> PropertySource<Visibility> {
PropertySource::Value(Visibility::from(self))
}
}
......@@ -14,12 +14,6 @@ impl From<&str> for Background {
}
}
impl Into<PropertySource<Background>> for &str {
fn into(self) -> PropertySource<Background> {
PropertySource::Value(Background::from(self))
}
}
impl From<Background> for Color {
fn from(b: Background) -> Color {
b.0.into()
......
......@@ -14,12 +14,6 @@ impl From<&str> for BorderBrush {
}
}
impl Into<PropertySource<BorderBrush>> for &str {
fn into(self) -> PropertySource<BorderBrush> {
PropertySource::Value(BorderBrush::from(self))
}
}
impl From<BorderBrush> for Color {
fn from(b: BorderBrush) -> Color {
b.0.into()
......
......@@ -57,32 +57,14 @@ impl From<(f64, f64, f64, f64)> for BorderThickness {
}
}
impl Into<PropertySource<BorderThickness>> for (f64, f64, f64, f64) {
fn into(self) -> PropertySource<BorderThickness> {
PropertySource::Value(BorderThickness::from(self))
}
}
impl From<(f64, f64)> for BorderThickness {
fn from(t: (f64, f64)) -> Self {
BorderThickness::from(Thickness::new(t.0, t.1, t.0, t.1))
}
}
impl Into<PropertySource<BorderThickness>> for (f64, f64) {
fn into(self) -> PropertySource<BorderThickness> {
PropertySource::Value(BorderThickness::from(self))
}
}
impl From<f64> for BorderThickness {
fn from(t: f64) -> Self {
BorderThickness::from(Thickness::new(t, t, t, t))
}
}
impl Into<PropertySource<BorderThickness>> for f64 {
fn into(self) -> PropertySource<BorderThickness> {
PropertySource::Value(BorderThickness::from(self))
}
}
......@@ -51,32 +51,14 @@ impl From<&str> for Font {
}
}
impl Into<PropertySource<Font>> for &str {
fn into(self) -> PropertySource<Font> {
PropertySource::Value(Font::from(self))
}
}
impl From<String> for Font {
fn from(s: String) -> Font {
Font::from(InnerFont::from(OrbFont::from_path(s).unwrap()))
}
}
impl Into<PropertySource<Font>> for String {
fn into(self) -> PropertySource<Font> {
PropertySource::Value(Font::from(self))
}
}
impl From<Box<[u8]>> for Font {
fn from(s: Box<[u8]>) -> Font {
Font::from(InnerFont::from(OrbFont::from_data(s).unwrap()))
}
}
impl Into<PropertySource<Font>> for Box<[u8]> {
fn into(self) -> PropertySource<Font> {
PropertySource::Value(Font::from(self))
}
}
......@@ -14,12 +14,6 @@ impl From<&str> for Foreground {
}
}
impl Into<PropertySource<Foreground>> for &str {
fn into(self) -> PropertySource<Foreground> {
PropertySource::Value(Foreground::from(self))
}
}
impl From<Foreground> for Color {
fn from(b: Foreground) -> Color {
b.0.into()
......
......@@ -13,12 +13,6 @@ impl From<&str> for IconBrush {
}
}
impl Into<PropertySource<IconBrush>> for &str {
fn into(self) -> PropertySource<IconBrush> {
PropertySource::Value(IconBrush::from(self))
}
}
impl From<IconBrush> for Color {
fn from(b: IconBrush) -> Color {
b.0.into()
......
......@@ -15,32 +15,14 @@ impl From<&str> for IconFont {
}
}
impl Into<PropertySource<IconFont>> for &str {
fn into(self) -> PropertySource<IconFont> {
PropertySource::Value(IconFont::from(self))
}
}
impl From<String> for IconFont {
fn from(s: String) -> IconFont {
IconFont::from(InnerFont::from(OrbFont::from_path(s).unwrap()))
}
}
impl Into<PropertySource<IconFont>> for String {
fn into(self) -> PropertySource<IconFont> {
PropertySource::Value(IconFont::from(self))
}
}
impl From<Box<[u8]>> for IconFont {
fn from(s: Box<[u8]>) -> IconFont {
IconFont::from(InnerFont::from(OrbFont::from_data(s).unwrap()))
}
}
impl Into<PropertySource<IconFont>> for Box<[u8]> {
fn into(self) -> PropertySource<IconFont> {
PropertySource::Value(IconFont::from(self))
}
}
......@@ -285,20 +285,8 @@ impl From<String> for Selector {
}
}
impl Into<PropertySource<Selector>> for String {
fn into(self) -> PropertySource<Selector> {
PropertySource::Value(Selector::from(self))
}
}
impl From<&str> for Selector {
fn from(s: &str) -> Selector {
Selector(SelectorValue::new().with(s.to_string()))
}
}
impl Into<PropertySource<Selector>> for &str {
fn into(self) -> PropertySource<Selector> {
PropertySource::Value(Selector::from(self))
}
}
\ No newline at end of file
......@@ -10,9 +10,3 @@ impl From<&str> for FontIcon {
FontIcon(s.into())
}
}
impl Into<PropertySource<FontIcon>> for &str {
fn into(self) -> PropertySource<FontIcon> {
PropertySource::Value(FontIcon::from(self))
}
}
\ No newline at end of file
......@@ -87,20 +87,8 @@ impl From<&str> for Image {
}
}
impl Into<PropertySource<Image>> for &str {
fn into(self) -> PropertySource<Image> {
PropertySource::Value(Image::from(self))
}
}
impl From<String> for Image {
fn from(s: String) -> Image {
Image::from(InnerImage::from(OrbImage::from_path(s).unwrap()))
}
}
impl Into<PropertySource<Image>> for String {
fn into(self) -> PropertySource<Image> {
PropertySource::Value(Image::from(self))
}
}
......@@ -10,9 +10,3 @@ impl From<&str> for Name {
Name(s.into())
}
}
impl Into<PropertySource<Name>> for &str {
fn into(self) -> PropertySource<Name> {
PropertySource::Value(Name::from(self))
}
}
\ No newline at end of file
......@@ -10,9 +10,3 @@ impl From<&str> for Text {
Text(s.into())
}
}
impl Into<PropertySource<Text>> for &str {
fn into(self) -> PropertySource<Text> {
PropertySource::Value(Text::from(self))
}
}
\ No newline at end of file
......@@ -18,9 +18,3 @@ impl From<(usize, usize)> for TextSelection {
})
}
}
impl Into<PropertySource<TextSelection>> for (usize, usize) {
fn into(self) -> PropertySource<TextSelection> {
PropertySource::Value(TextSelection::from(self))
}
}
\ No newline at end of file
......@@ -10,9 +10,3 @@ impl From<&str> for WaterMark {
WaterMark(s.into())
}
}
impl Into<PropertySource<WaterMark>> for &str {
fn into(self) -> PropertySource<WaterMark> {
PropertySource::Value(WaterMark::from(self))
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment