[][src]Macro rsvg_internals::make_property

macro_rules! make_property {
    ($computed_values_type: ty,
     $name: ident,
     default: $default: ident,
     inherits_automatically: $inherits_automatically: expr,
     identifiers:
     $($str_prop: expr => $variant: ident,)+
    ) => { ... };
    ($computed_values_type: ty,
     $name: ident,
     default: $default: expr,
     inherits_automatically: $inherits_automatically: expr,
     newtype_parse: $type: ty,
    ) => { ... };
    ($computed_values_type: ty,
     $name: ident,
     default: $default: expr,
     property_impl: { $prop: item }
    ) => { ... };
    ($computed_values_type: ty,
     $name: ident,
     default: $default: expr,
     inherits_automatically: $inherits_automatically: expr,
    ) => { ... };
    ($computed_values_type: ty,
     $name: ident,
     default: $default: expr,
     inherits_automatically: $inherits_automatically: expr,
     parse_impl: { $parse: item }
    ) => { ... };
    ($computed_values_type: ty,
     $name: ident,
     default: $default: expr,
     newtype: $type: ty,
     property_impl: { $prop: item },
     parse_impl: { $parse: item }
    ) => { ... };
    ($computed_values_type: ty,
     $name: ident,
     default: $default: expr,
     inherits_automatically: $inherits_automatically: expr,
     newtype: $type: ty,
     parse_impl: { $parse: item },
    ) => { ... };
    ($computed_values_type: ty,
     $name: ident,
     inherits_automatically: $inherits_automatically: expr,
     fields: {
       $($field_name: ident : $field_type: ty, default: $field_default : expr,)+
     }
     parse_impl: { $parse: item }
    ) => { ... };
}

Generates a type for a CSS property.

Writing a property by hand takes a bit of boilerplate:

When going from SpecifiedValues to ComputedValues, properties which inherit automatically from the parent element will just have their values cloned. Properties which do not inherit will be reset back to their initial value (i.e. their Default).

The default implementation of Property::compute() is to just clone the property's value. Properties which need more sophisticated computation can override this.

This macro allows defining properties of different kinds; see the following sections for examples.

Simple identifiers

Many properties are just sets of identifiers and can be represented by simple enums. In this case, you can use the following:

This example is not tested
make_property!(
  ComputedValues,
  StrokeLinejoin,
  default: Miter,
  inherits_automatically: true,

  identifiers:
    "miter" => Miter,
    "round" => Round,
    "bevel" => Bevel,
);

This generates a simple enum like the following, with implementations of Parse, Default, and Property.

This example is not tested
pub enum StrokeLinejoin { Miter, Round, Bevel }

Properties from an existing, general-purpose type

For example, both the lightingColor and floodColor properties can be represented with a cssparser::Color, but their intial values are different. In this case, the macro can generate a newtype around cssparser::Color for each case:

This example is not tested
make_property!(
    ComputedValues,
    FloodColor,
    default: cssparser::Color::RGBA(cssparser::RGBA::new(0, 0, 0, 0)),
    inherits_automatically: false,
    newtype_parse: cssparser::Color,
);

Properties from custom specific types

For example, font-related properties have custom, complex types that require an implentation of Property::compute that is more than a simple clone. In this case, define the custom type separately, and use the macro to specify the default value and the Property implementation.