@@ -149,29 +149,33 @@ where
149149 }
150150 }
151151}
152+ macro_rules! make_button {
153+ ( $spin_button: expr, $icon: expr, $operation: expr) => { {
154+ #[ cfg( target_os = "linux" ) ]
155+ let button = icon:: from_name( $icon) ;
156+
157+ #[ cfg( not( target_os = "linux" ) ) ]
158+ let button = icon:: from_svg_bytes(
159+ include_bytes!( concat![ "../../res/icons/" , $icon , ".svg" ] )
160+ ) . symbolic( true ) ;
161+
162+ button. apply( button:: icon)
163+ . on_press( ( $spin_button. on_press) ( $operation(
164+ $spin_button. value,
165+ $spin_button. step,
166+ $spin_button. min,
167+ $spin_button. max,
168+ ) ) )
169+ } } ;
170+ }
152171
153172fn horizontal_variant < T , Message > ( spin_button : SpinButton < ' _ , T , Message > ) -> Element < ' _ , Message >
154173where
155174 Message : Clone + ' static ,
156175 T : Copy + Sub < Output = T > + Add < Output = T > + PartialOrd ,
157176{
158- let decrement_button = icon:: from_name ( "list-remove-symbolic" )
159- . apply ( button:: icon)
160- . on_press ( ( spin_button. on_press ) ( decrement :: < T > (
161- spin_button. value ,
162- spin_button. step ,
163- spin_button. min ,
164- spin_button. max ,
165- ) ) ) ;
166-
167- let increment_button = icon:: from_name ( "list-add-symbolic" )
168- . apply ( button:: icon)
169- . on_press ( ( spin_button. on_press ) ( increment :: < T > (
170- spin_button. value ,
171- spin_button. step ,
172- spin_button. min ,
173- spin_button. max ,
174- ) ) ) ;
177+ let decrement_button = make_button ! ( spin_button, "list-remove-symbolic" , decrement) ;
178+ let increment_button = make_button ! ( spin_button, "list-add-symbolic" , increment) ;
175179
176180 let label = text:: title4 ( spin_button. label )
177181 . apply ( container)
@@ -193,23 +197,8 @@ where
193197 Message : Clone + ' static ,
194198 T : Copy + Sub < Output = T > + Add < Output = T > + PartialOrd ,
195199{
196- let decrement_button = icon:: from_name ( "list-remove-symbolic" )
197- . apply ( button:: icon)
198- . on_press ( ( spin_button. on_press ) ( decrement :: < T > (
199- spin_button. value ,
200- spin_button. step ,
201- spin_button. min ,
202- spin_button. max ,
203- ) ) ) ;
204-
205- let increment_button = icon:: from_name ( "list-add-symbolic" )
206- . apply ( button:: icon)
207- . on_press ( ( spin_button. on_press ) ( increment :: < T > (
208- spin_button. value ,
209- spin_button. step ,
210- spin_button. min ,
211- spin_button. max ,
212- ) ) ) ;
200+ let decrement_button = make_button ! ( spin_button, "list-remove-symbolic" , decrement) ;
201+ let increment_button = make_button ! ( spin_button, "list-add-symbolic" , increment) ;
213202
214203 let label = text:: title4 ( spin_button. label )
215204 . apply ( container)
@@ -263,4 +252,4 @@ mod tests {
263252 fn decrement ( ) {
264253 assert_eq ! ( super :: decrement( 0i32 , 10 , 15 , 35 ) , 15 ) ;
265254 }
266- }
255+ }
0 commit comments