Commit 06e3f550 authored by Florian Blasius's avatar Florian Blasius 🤘

[refactoring] shared property short hand

parent 85a6d5a0
......@@ -88,49 +88,14 @@ macro_rules! property {
}
impl $type {
pub fn get(entity: Entity, ecm: &EntityComponentManager) -> $type {
get_property::<$type>(entity, ecm)
/// Converts the value into a property object.
pub fn prop(property: impl Into<$type>) -> Property {
Property::new(property.into())
}
}
};
}
macro_rules! widget {
( $(#[$widget_doc:meta])* $widget:ident { $($(#[$prop_doc:meta])* $property:ident: $property_type:tt ),*} ) => {
$(#[$widget_doc])*
pub struct $widget {
$(
$property: $property_type,
)*
}
impl $widget {
/// Creates a new instance of the widget, with all its properties. Used to build the template of the widget.
pub fn create() -> Self {
$widget {
$(
$property: $property_type::default(),
)*
}
}
$(
$(#[$prop_doc])*
pub fn $property(mut self, $property: impl Into<$property_type>) -> Self {
self.$property = $property.into();
self
}
)*
/// Builds the template of the widget.
pub fn build(self) -> Template {
let mut template = self.template();
$(
template.insert_property(TypeId::of::<$property_type>(), self.$property.into());
)*
template
/// Returns the value of a property.
pub fn get(entity: Entity, ecm: &EntityComponentManager) -> $type {
get_property::<$type>(entity, ecm)
}
}
};
......
......@@ -20,8 +20,8 @@ impl Widget for Button {
fn create() -> Self::Template {
// text properties
let text = Property::new(Text::default());
let foreground = Property::new(Foreground::from(colors::LINK_WATER_COLOR));
let text = Text::prop("");
let foreground = Foreground::prop(colors::LINK_WATER_COLOR);
let font =
Property::new(Font::from(fonts::font_into_box(fonts::ROBOTO_REGULAR_FONT)));
let font_size = Property::new(FontSize::from(fonts::FONT_SIZE_12));
......
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