@@ -20,10 +20,30 @@ impl core::fmt::Display for WidgetId {
2020 }
2121}
2222
23- #[ cfg_attr( feature = "wasm" , derive( tsify:: Tsify ) ) ]
24- #[ derive( PartialEq , Clone , Debug , Hash , Eq , Copy , serde:: Serialize , serde:: Deserialize ) ]
25- #[ repr( u8 ) ]
26- pub enum LayoutTarget {
23+ macro_rules! define_layout_target {
24+ ( $( $( #[ $attr: meta] ) * $variant: ident) ,* $( , ) ?) => {
25+ #[ cfg_attr( feature = "wasm" , derive( tsify:: Tsify ) ) ]
26+ #[ derive( PartialEq , Clone , Debug , Hash , Eq , Copy , serde:: Serialize , serde:: Deserialize ) ]
27+ #[ repr( u8 ) ]
28+ pub enum LayoutTarget {
29+ $( $( #[ $attr] ) * $variant, ) *
30+ // KEEP THIS ENUM LAST
31+ // This is a marker that is used to define an array that is used to hold widgets
32+ #[ serde( skip) ]
33+ _LayoutTargetLength,
34+ }
35+
36+ impl From <u8 > for LayoutTarget {
37+ fn from( value: u8 ) -> Self {
38+ match value {
39+ $( x if x == Self :: $variant as u8 => Self :: $variant, ) *
40+ _ => panic!( "Invalid LayoutTarget discriminant: {value}" ) ,
41+ }
42+ }
43+ }
44+ } ;
45+ }
46+ define_layout_target ! (
2747 /// The spreadsheet panel allows for the visualisation of data in the graph.
2848 DataPanel ,
2949 /// Contains the action buttons at the bottom of the dialog. Must be shown with the `FrontendMessage::DisplayDialog` message.
@@ -58,12 +78,7 @@ pub enum LayoutTarget {
5878 WelcomeScreenButtons ,
5979 /// The color swatch for the working colors and a flip and reset button found at the bottom of the tool shelf.
6080 WorkingColors ,
61-
62- // KEEP THIS ENUM LAST
63- // This is a marker that is used to define an array that is used to hold widgets
64- #[ serde( skip) ]
65- _LayoutTargetLength,
66- }
81+ ) ;
6782
6883/// For use by structs that define a UI widget layout by implementing the layout() function belonging to this trait.
6984/// The send_layout() function can then be called by other code which is a part of the same struct so as to send the layout to the frontend.
0 commit comments