@@ -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 red : u8 ,
740+ pub green : u8 ,
741+ pub blue : u8 ,
742+ pub alpha : 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
@@ -741,7 +754,7 @@ enum PropertyValue {
741754 F64 ( f64 ) ,
742755 F32 ( f32 ) ,
743756 Usize ( usize ) ,
744- Color ( u32 ) ,
757+ Color ( Color ) ,
745758 TextDecoration ( TextDecoration ) ,
746759 LengthSlice ( Box < [ u8 ] > ) ,
747760 CoordSlice ( Box < [ f32 ] > ) ,
@@ -1375,14 +1388,14 @@ macro_rules! color_property_methods {
13751388 ( $( $( #[ $doc: meta] ) * ( $id: ident, $getter: ident, $setter: ident, $clearer: ident) ) ,+) => {
13761389 $( property_methods! {
13771390 $( #[ $doc] ) *
1378- ( $id, $getter, get_color_property, Option <u32 >, $setter, set_color_property, u32 , $clearer)
1391+ ( $id, $getter, get_color_property, Option <Color >, $setter, set_color_property, Color , $clearer)
13791392 } ) *
13801393 impl Node {
13811394 option_properties_debug_method! { debug_color_properties, [ $( $getter, ) * ] }
13821395 }
13831396 $( #[ cfg( test) ]
13841397 mod $getter {
1385- use super :: { Node , Role } ;
1398+ use super :: { Color , Node , Role } ;
13861399
13871400 #[ test]
13881401 fn getter_should_return_default_value( ) {
@@ -1392,13 +1405,13 @@ macro_rules! color_property_methods {
13921405 #[ test]
13931406 fn setter_should_update_the_property( ) {
13941407 let mut node = Node :: new( Role :: Unknown ) ;
1395- node. $setter( 1 ) ;
1396- assert_eq!( node. $getter( ) , Some ( 1 ) ) ;
1408+ node. $setter( Color { red : 255 , green : 255 , blue : 255 , alpha : 255 } ) ;
1409+ assert_eq!( node. $getter( ) , Some ( Color { red : 255 , green : 255 , blue : 255 , alpha : 255 } ) ) ;
13971410 }
13981411 #[ test]
13991412 fn clearer_should_reset_the_property( ) {
14001413 let mut node = Node :: new( Role :: Unknown ) ;
1401- node. $setter( 1 ) ;
1414+ node. $setter( Color { red : 255 , green : 255 , blue : 255 , alpha : 255 } ) ;
14021415 node. $clearer( ) ;
14031416 assert!( node. $getter( ) . is_none( ) ) ;
14041417 }
@@ -1715,7 +1728,7 @@ copy_type_getters! {
17151728 ( get_f64_property, f64 , F64 ) ,
17161729 ( get_f32_property, f32 , F32 ) ,
17171730 ( get_usize_property, usize , Usize ) ,
1718- ( get_color_property, u32 , Color ) ,
1731+ ( get_color_property, Color , Color ) ,
17191732 ( get_text_decoration_property, TextDecoration , TextDecoration ) ,
17201733 ( get_bool_property, bool , Bool )
17211734}
@@ -1734,7 +1747,7 @@ copy_type_setters! {
17341747 ( set_f64_property, f64 , F64 ) ,
17351748 ( set_f32_property, f32 , F32 ) ,
17361749 ( set_usize_property, usize , Usize ) ,
1737- ( set_color_property, u32 , Color ) ,
1750+ ( set_color_property, Color , Color ) ,
17381751 ( set_text_decoration_property, TextDecoration , TextDecoration ) ,
17391752 ( set_bool_property, bool , Bool )
17401753}
@@ -1871,11 +1884,11 @@ usize_property_methods! {
18711884}
18721885
18731886color_property_methods ! {
1874- /// For [`Role::ColorWell`], specifies the selected color in RGBA .
1887+ /// For [`Role::ColorWell`], specifies the selected color.
18751888 ( ColorValue , color_value, set_color_value, clear_color_value) ,
1876- /// Background color in RGBA .
1889+ /// Background color.
18771890 ( BackgroundColor , background_color, set_background_color, clear_background_color) ,
1878- /// Foreground color in RGBA .
1891+ /// Foreground color.
18791892 ( ForegroundColor , foreground_color, set_foreground_color, clear_foreground_color)
18801893}
18811894
@@ -2565,7 +2578,7 @@ impl JsonSchema for Properties {
25652578 SizeOfSet ,
25662579 PositionInSet
25672580 } ,
2568- u32 {
2581+ Color {
25692582 ColorValue ,
25702583 BackgroundColor ,
25712584 ForegroundColor
0 commit comments