3
3
// the LICENSE-APACHE file) or the MIT license (found in
4
4
// the LICENSE-MIT file), at your option.
5
5
6
+ use crate :: { Point , Rect } ;
6
7
use pyo3:: { prelude:: * , types:: PyList } ;
7
8
8
9
#[ pyclass( module = "accesskit" ) ]
@@ -257,7 +258,7 @@ macro_rules! simple_getter {
257
258
} ;
258
259
}
259
260
260
- macro_rules! convertion_getter {
261
+ macro_rules! converting_getter {
261
262
( $struct_name: ident, $getter: ident, $type: ty) => {
262
263
#[ pymethods]
263
264
impl $struct_name {
@@ -292,7 +293,7 @@ macro_rules! simple_setter {
292
293
} ;
293
294
}
294
295
295
- macro_rules! convertion_setter {
296
+ macro_rules! converting_setter {
296
297
( $setter: ident, $setter_param: ty) => {
297
298
#[ pymethods]
298
299
impl NodeBuilder {
@@ -379,7 +380,7 @@ macro_rules! node_id_vec_property_methods {
379
380
macro_rules! node_id_property_methods {
380
381
( $( ( $getter: ident, $setter: ident, $clearer: ident) ) ,+) => {
381
382
$( property_methods! {
382
- ( $getter, option_getter, Option <NodeId >, $setter, convertion_setter , NodeId , $clearer)
383
+ ( $getter, option_getter, Option <NodeId >, $setter, converting_setter , NodeId , $clearer)
383
384
} ) *
384
385
}
385
386
}
@@ -411,15 +412,15 @@ macro_rules! color_property_methods {
411
412
macro_rules! text_decoration_property_methods {
412
413
( $( ( $getter: ident, $setter: ident, $clearer: ident) ) ,+) => {
413
414
$( property_methods! {
414
- ( $getter, option_getter, Option <accesskit:: TextDecoration >, $setter, convertion_setter , accesskit:: TextDecoration , $clearer)
415
+ ( $getter, option_getter, Option <accesskit:: TextDecoration >, $setter, converting_setter , accesskit:: TextDecoration , $clearer)
415
416
} ) *
416
417
}
417
418
}
418
419
419
420
macro_rules! length_slice_property_methods {
420
421
( $( ( $getter: ident, $setter: ident, $clearer: ident) ) ,+) => {
421
422
$( property_methods! {
422
- ( $getter, convertion_getter , Vec <u8 >, $setter, simple_setter, Vec <u8 >, $clearer)
423
+ ( $getter, converting_getter , Vec <u8 >, $setter, simple_setter, Vec <u8 >, $clearer)
423
424
} ) *
424
425
}
425
426
}
@@ -588,7 +589,7 @@ unique_enum_property_methods! {
588
589
589
590
property_methods ! {
590
591
( transform, option_getter, Option <crate :: Affine >, set_transform, simple_setter, crate :: Affine , clear_transform) ,
591
- ( bounds, option_getter, Option <crate :: Rect >, set_bounds, convertion_setter , crate :: Rect , clear_bounds) ,
592
+ ( bounds, option_getter, Option <crate :: Rect >, set_bounds, converting_setter , crate :: Rect , clear_bounds) ,
592
593
( text_selection, option_getter, Option <TextSelection >, set_text_selection, simple_setter, TextSelection , clear_text_selection)
593
594
}
594
595
@@ -602,7 +603,7 @@ pub struct Tree {
602
603
pub root : NodeId ,
603
604
pub app_name : Option < String > ,
604
605
pub toolkit_name : Option < String > ,
605
- toolkit_version : Option < String > ,
606
+ pub toolkit_version : Option < String > ,
606
607
}
607
608
608
609
#[ pymethods]
@@ -674,68 +675,55 @@ impl From<TreeUpdate> for accesskit::TreeUpdate {
674
675
}
675
676
}
676
677
677
- #[ pyclass( module = "accesskit" ) ]
678
- pub struct ActionData ( accesskit:: ActionData ) ;
679
-
680
- #[ pymethods]
681
- impl ActionData {
682
- #[ staticmethod]
683
- pub fn custom_action ( action : i32 ) -> Self {
684
- accesskit:: ActionData :: CustomAction ( action) . into ( )
685
- }
686
-
687
- #[ staticmethod]
688
- pub fn value ( value : & str ) -> Self {
689
- accesskit:: ActionData :: Value ( value. into ( ) ) . into ( )
690
- }
691
-
692
- #[ staticmethod]
693
- pub fn numeric_value ( value : f64 ) -> Self {
694
- accesskit:: ActionData :: NumericValue ( value) . into ( )
695
- }
696
-
697
- #[ staticmethod]
698
- pub fn scroll_target_rect ( rect : crate :: Rect ) -> Self {
699
- accesskit:: ActionData :: ScrollTargetRect ( rect. into ( ) ) . into ( )
700
- }
701
-
702
- #[ staticmethod]
703
- pub fn scroll_to_point ( point : crate :: Point ) -> Self {
704
- accesskit:: ActionData :: ScrollToPoint ( point. into ( ) ) . into ( )
705
- }
706
-
707
- #[ staticmethod]
708
- pub fn set_scroll_offset ( offset : crate :: Point ) -> Self {
709
- accesskit:: ActionData :: SetScrollOffset ( offset. into ( ) ) . into ( )
710
- }
711
-
712
- #[ staticmethod]
713
- pub fn set_text_selection ( selection : TextSelection ) -> Self {
714
- accesskit:: ActionData :: SetTextSelection ( selection. into ( ) ) . into ( )
715
- }
716
- }
717
-
718
- impl From < accesskit:: ActionData > for ActionData {
719
- fn from ( data : accesskit:: ActionData ) -> Self {
720
- Self ( data)
721
- }
722
- }
723
-
724
- #[ pyclass( get_all, set_all, module = "accesskit" ) ]
678
+ #[ derive( Clone ) ]
679
+ #[ pyclass( module = "accesskit" , rename_all = "SCREAMING_SNAKE_CASE" ) ]
680
+ pub enum ActionDataKind {
681
+ CustomAction ,
682
+ Value ,
683
+ NumericValue ,
684
+ ScrollTargetRect ,
685
+ ScrollToPoint ,
686
+ SetScrollOffset ,
687
+ SetTextSelection ,
688
+ }
689
+
690
+ #[ pyclass( get_all, module = "accesskit" ) ]
725
691
pub struct ActionRequest {
726
692
pub action : accesskit:: Action ,
727
693
pub target : NodeId ,
728
- pub data : Option < Py < ActionData > > ,
694
+ pub data : Option < ( ActionDataKind , Py < PyAny > ) > ,
729
695
}
730
696
731
697
impl From < accesskit:: ActionRequest > for ActionRequest {
732
698
fn from ( request : accesskit:: ActionRequest ) -> Self {
733
699
Python :: with_gil ( |py| Self {
734
700
action : request. action ,
735
701
target : request. target . into ( ) ,
736
- data : request
737
- . data
738
- . map ( |data| Py :: new ( py, ActionData :: from ( data) ) . unwrap ( ) ) ,
702
+ data : request. data . map ( |data| match data {
703
+ accesskit:: ActionData :: CustomAction ( action) => {
704
+ ( ActionDataKind :: CustomAction , action. into_py ( py) )
705
+ }
706
+ accesskit:: ActionData :: Value ( value) => ( ActionDataKind :: Value , value. into_py ( py) ) ,
707
+ accesskit:: ActionData :: NumericValue ( value) => {
708
+ ( ActionDataKind :: NumericValue , value. into_py ( py) )
709
+ }
710
+ accesskit:: ActionData :: ScrollTargetRect ( rect) => (
711
+ ActionDataKind :: ScrollTargetRect ,
712
+ Rect :: from ( rect) . into_py ( py) ,
713
+ ) ,
714
+ accesskit:: ActionData :: ScrollToPoint ( point) => (
715
+ ActionDataKind :: ScrollToPoint ,
716
+ Point :: from ( point) . into_py ( py) ,
717
+ ) ,
718
+ accesskit:: ActionData :: SetScrollOffset ( point) => (
719
+ ActionDataKind :: SetScrollOffset ,
720
+ Point :: from ( point) . into_py ( py) ,
721
+ ) ,
722
+ accesskit:: ActionData :: SetTextSelection ( selection) => (
723
+ ActionDataKind :: SetTextSelection ,
724
+ TextSelection :: from ( & selection) . into_py ( py) ,
725
+ ) ,
726
+ } ) ,
739
727
} )
740
728
}
741
729
}
0 commit comments