@@ -729,6 +729,19 @@ impl Flag {
729729 }
730730}
731731
732+ /// A color represented in 8-bit sRGB plus alpha.
733+ #[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
734+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
735+ #[ cfg_attr( feature = "schemars" , derive( JsonSchema ) ) ]
736+ #[ cfg_attr( feature = "serde" , serde( deny_unknown_fields) ) ]
737+ #[ repr( C ) ]
738+ pub struct Color {
739+ pub r : u8 ,
740+ pub g : u8 ,
741+ pub b : u8 ,
742+ pub a : u8 ,
743+ }
744+
732745// The following is based on the technique described here:
733746// https://viruta.org/reducing-memory-consumption-in-librsvg-2.html
734747
@@ -740,7 +753,7 @@ enum PropertyValue {
740753 String ( Box < str > ) ,
741754 F64 ( f64 ) ,
742755 Usize ( usize ) ,
743- Color ( u32 ) ,
756+ Color ( Color ) ,
744757 TextDecoration ( TextDecoration ) ,
745758 LengthSlice ( Box < [ u8 ] > ) ,
746759 CoordSlice ( Box < [ f32 ] > ) ,
@@ -1337,14 +1350,14 @@ macro_rules! color_property_methods {
13371350 ( $( $( #[ $doc: meta] ) * ( $id: ident, $getter: ident, $setter: ident, $clearer: ident) ) ,+) => {
13381351 $( property_methods! {
13391352 $( #[ $doc] ) *
1340- ( $id, $getter, get_color_property, Option <u32 >, $setter, set_color_property, u32 , $clearer)
1353+ ( $id, $getter, get_color_property, Option <Color >, $setter, set_color_property, Color , $clearer)
13411354 } ) *
13421355 impl Node {
13431356 option_properties_debug_method! { debug_color_properties, [ $( $getter, ) * ] }
13441357 }
13451358 $( #[ cfg( test) ]
13461359 mod $getter {
1347- use super :: { Node , Role } ;
1360+ use super :: { Color , Node , Role } ;
13481361
13491362 #[ test]
13501363 fn getter_should_return_default_value( ) {
@@ -1354,13 +1367,13 @@ macro_rules! color_property_methods {
13541367 #[ test]
13551368 fn setter_should_update_the_property( ) {
13561369 let mut node = Node :: new( Role :: Unknown ) ;
1357- node. $setter( 1 ) ;
1358- assert_eq!( node. $getter( ) , Some ( 1 ) ) ;
1370+ node. $setter( Color { r : 255 , g : 255 , b : 255 , a : 255 } ) ;
1371+ assert_eq!( node. $getter( ) , Some ( Color { r : 255 , g : 255 , b : 255 , a : 255 } ) ) ;
13591372 }
13601373 #[ test]
13611374 fn clearer_should_reset_the_property( ) {
13621375 let mut node = Node :: new( Role :: Unknown ) ;
1363- node. $setter( 1 ) ;
1376+ node. $setter( Color { r : 255 , g : 255 , b : 255 , a : 255 } ) ;
13641377 node. $clearer( ) ;
13651378 assert!( node. $getter( ) . is_none( ) ) ;
13661379 }
@@ -1676,7 +1689,7 @@ copy_type_getters! {
16761689 ( get_node_id_property, NodeId , NodeId ) ,
16771690 ( get_f64_property, f64 , F64 ) ,
16781691 ( get_usize_property, usize , Usize ) ,
1679- ( get_color_property, u32 , Color ) ,
1692+ ( get_color_property, Color , Color ) ,
16801693 ( get_text_decoration_property, TextDecoration , TextDecoration ) ,
16811694 ( get_bool_property, bool , Bool )
16821695}
@@ -1694,7 +1707,7 @@ copy_type_setters! {
16941707 ( set_node_id_property, NodeId , NodeId ) ,
16951708 ( set_f64_property, f64 , F64 ) ,
16961709 ( set_usize_property, usize , Usize ) ,
1697- ( set_color_property, u32 , Color ) ,
1710+ ( set_color_property, Color , Color ) ,
16981711 ( set_text_decoration_property, TextDecoration , TextDecoration ) ,
16991712 ( set_bool_property, bool , Bool )
17001713}
@@ -1828,11 +1841,11 @@ usize_property_methods! {
18281841}
18291842
18301843color_property_methods ! {
1831- /// For [`Role::ColorWell`], specifies the selected color in RGBA .
1844+ /// For [`Role::ColorWell`], specifies the selected color.
18321845 ( ColorValue , color_value, set_color_value, clear_color_value) ,
1833- /// Background color in RGBA .
1846+ /// Background color.
18341847 ( BackgroundColor , background_color, set_background_color, clear_background_color) ,
1835- /// Foreground color in RGBA .
1848+ /// Foreground color.
18361849 ( ForegroundColor , foreground_color, set_foreground_color, clear_foreground_color)
18371850}
18381851
@@ -2516,7 +2529,7 @@ impl JsonSchema for Properties {
25162529 SizeOfSet ,
25172530 PositionInSet
25182531 } ,
2519- u32 {
2532+ Color {
25202533 ColorValue ,
25212534 BackgroundColor ,
25222535 ForegroundColor
0 commit comments