gardesk/ers / 72496e3

Browse files

OverlayWindow API takes primitive coords to avoid CGRect type clash

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
72496e323ba8a65952fa81eb63228ff758876aaf
Parents
e3cd26b
Tree
f66d9fe

1 changed file

StatusFile+-
M src/nswindow_overlay.rs 27 20
src/nswindow_overlay.rsmodified
@@ -50,32 +50,39 @@ pub fn init_application() -> MainThreadMarker {
5050
 }
5151
 
5252
 /// One NSWindow + CAShapeLayer pair drawing a rounded-rect border.
53
+///
54
+/// `bounds_cg_*` fields are the TARGET window's CG bounds (origin
55
+/// top-left, Y-down) — same coordinate system the rest of ers uses.
5356
 pub struct OverlayWindow {
5457
     window: Retained<NSWindow>,
5558
     border_layer: Retained<CAShapeLayer>,
56
-    pub bounds_cg: CGRect,
59
+    pub bounds_cg_x: f64,
60
+    pub bounds_cg_y: f64,
61
+    pub bounds_cg_w: f64,
62
+    pub bounds_cg_h: f64,
5763
     pub border_width: f64,
5864
     pub radius: f64,
5965
     mtm: MainThreadMarker,
6066
 }
6167
 
6268
 impl OverlayWindow {
63
-    /// Create an NSWindow border overlay covering `target_bounds_cg + border_width`.
69
+    /// Create an NSWindow border overlay around the given target bounds.
70
+    /// Coords are in CG space (origin top-left, Y-down).
6471
     pub fn new(
65
-        target_bounds_cg: CGRect,
72
+        bounds_cg_x: f64,
73
+        bounds_cg_y: f64,
74
+        bounds_cg_w: f64,
75
+        bounds_cg_h: f64,
6676
         border_width: f64,
6777
         radius: f64,
6878
         color: (f64, f64, f64, f64),
6979
         mtm: MainThreadMarker,
7080
     ) -> Option<Self> {
7181
         let outer_cg = CGRect::new(
72
-            CGPoint::new(
73
-                target_bounds_cg.origin.x - border_width,
74
-                target_bounds_cg.origin.y - border_width,
75
-            ),
82
+            CGPoint::new(bounds_cg_x - border_width, bounds_cg_y - border_width),
7683
             CGSize::new(
77
-                target_bounds_cg.size.width + 2.0 * border_width,
78
-                target_bounds_cg.size.height + 2.0 * border_width,
84
+                bounds_cg_w + 2.0 * border_width,
85
+                bounds_cg_h + 2.0 * border_width,
7986
             ),
8087
         );
8188
         let cocoa_frame = cg_to_cocoa_frame(outer_cg, mtm);
@@ -141,7 +148,10 @@ impl OverlayWindow {
141148
         Some(OverlayWindow {
142149
             window,
143150
             border_layer,
144
-            bounds_cg: target_bounds_cg,
151
+            bounds_cg_x,
152
+            bounds_cg_y,
153
+            bounds_cg_w,
154
+            bounds_cg_h,
145155
             border_width,
146156
             radius,
147157
             mtm,
@@ -153,16 +163,10 @@ impl OverlayWindow {
153163
         self.window.windowNumber() as u32
154164
     }
155165
 
156
-    pub fn set_bounds(&mut self, target_bounds_cg: CGRect) {
166
+    pub fn set_bounds(&mut self, x: f64, y: f64, w: f64, h: f64) {
157167
         let outer_cg = CGRect::new(
158
-            CGPoint::new(
159
-                target_bounds_cg.origin.x - self.border_width,
160
-                target_bounds_cg.origin.y - self.border_width,
161
-            ),
162
-            CGSize::new(
163
-                target_bounds_cg.size.width + 2.0 * self.border_width,
164
-                target_bounds_cg.size.height + 2.0 * self.border_width,
165
-            ),
168
+            CGPoint::new(x - self.border_width, y - self.border_width),
169
+            CGSize::new(w + 2.0 * self.border_width, h + 2.0 * self.border_width),
166170
         );
167171
         let cocoa_frame = cg_to_cocoa_frame(outer_cg, self.mtm);
168172
         self.window.setFrame_display(cocoa_frame, true);
@@ -182,7 +186,10 @@ impl OverlayWindow {
182186
                 CGSize::new(outer_cg.size.width, outer_cg.size.height),
183187
             ));
184188
         }
185
-        self.bounds_cg = target_bounds_cg;
189
+        self.bounds_cg_x = x;
190
+        self.bounds_cg_y = y;
191
+        self.bounds_cg_w = w;
192
+        self.bounds_cg_h = h;
186193
     }
187194
 
188195
     pub fn set_color(&self, color: (f64, f64, f64, f64)) {