@@ -2,81 +2,8 @@ pub mod identify_transparency;
22pub mod image;
33pub mod utils;
44
5- use crate :: { ImageOnHeap , Result , WindowId , WindowList } ;
5+ mod margin;
6+ mod platform_api;
67
7- pub trait PlatformApi : Send {
8- /// 1. it does check for the screenshot
9- /// 2. it checks for transparent margins and configures the api
10- /// to cut them away in further screenshots
11- fn calibrate ( & mut self , window_id : WindowId ) -> Result < ( ) > ;
12- fn window_list ( & self ) -> Result < WindowList > ;
13- fn capture_window_screenshot ( & self , window_id : WindowId ) -> Result < ImageOnHeap > ;
14- fn get_active_window ( & self ) -> Result < WindowId > ;
15- }
16-
17- #[ derive( Debug , PartialEq ) ]
18- pub struct Margin {
19- pub top : u16 ,
20- pub right : u16 ,
21- pub bottom : u16 ,
22- pub left : u16 ,
23- }
24-
25- impl Margin {
26- pub fn new ( top : u16 , right : u16 , bottom : u16 , left : u16 ) -> Self {
27- Self {
28- top,
29- right,
30- bottom,
31- left,
32- }
33- }
34-
35- pub fn new_equal ( margin : u16 ) -> Self {
36- Self :: new ( margin, margin, margin, margin)
37- }
38-
39- pub fn zero ( ) -> Self {
40- Self :: new_equal ( 0 )
41- }
42-
43- pub fn is_zero ( & self ) -> bool {
44- self . top == 0
45- && self . right == self . left
46- && self . left == self . bottom
47- && self . bottom == self . top
48- }
49- }
50-
51- #[ cfg( test) ]
52- mod test {
53- use super :: * ;
54-
55- #[ test]
56- fn margin_new ( ) {
57- let m = Margin :: new ( 1 , 2 , 3 , 4 ) ;
58- assert_eq ! ( m. top, 1 ) ;
59- assert_eq ! ( m. right, 2 ) ;
60- assert_eq ! ( m. bottom, 3 ) ;
61- assert_eq ! ( m. left, 4 ) ;
62- }
63-
64- #[ test]
65- fn margin_new_equal ( ) {
66- let m = Margin :: new_equal ( 1 ) ;
67- assert_eq ! ( m. top, 1 ) ;
68- assert_eq ! ( m. right, 1 ) ;
69- assert_eq ! ( m. bottom, 1 ) ;
70- assert_eq ! ( m. left, 1 ) ;
71- }
72-
73- #[ test]
74- fn margin_zero ( ) {
75- let m = Margin :: zero ( ) ;
76- assert_eq ! ( m. top, 0 ) ;
77- assert_eq ! ( m. right, 0 ) ;
78- assert_eq ! ( m. bottom, 0 ) ;
79- assert_eq ! ( m. left, 0 ) ;
80- assert ! ( m. is_zero( ) ) ;
81- }
82- }
8+ pub use margin:: * ;
9+ pub use platform_api:: * ;
0 commit comments