Skip to content

Commit d14484c

Browse files
authored
fix: Handle views with flipped coordinates (#174)
1 parent 14dd2da commit d14484c

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

platforms/macos/src/adapter.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,15 @@ impl Adapter {
112112
let window = view.window().unwrap();
113113
let point = window.convert_point_from_screen(point);
114114
let point = view.convert_point_from_view(point, None);
115-
let view_bounds = view.bounds();
116-
let point = Point::new(point.x, view_bounds.size.height - point.y);
115+
let point = Point::new(
116+
point.x,
117+
if view.is_flipped() {
118+
point.y
119+
} else {
120+
let view_bounds = view.bounds();
121+
view_bounds.size.height - point.y
122+
},
123+
);
117124

118125
let state = context.tree.read();
119126
let root = state.root();

platforms/macos/src/appkit/view.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,8 @@ extern_methods!(
4141
point: NSPoint,
4242
view: Option<&NSView>,
4343
) -> NSPoint;
44+
45+
#[sel(isFlipped)]
46+
pub(crate) fn is_flipped(&self) -> bool;
4447
}
4548
);

platforms/macos/src/node.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,15 @@ declare_class!(
351351
};
352352

353353
node.bounding_box().map_or(NSRect::ZERO, |rect| {
354-
let view_bounds = view.bounds();
355354
let rect = NSRect {
356355
origin: NSPoint {
357356
x: rect.x0,
358-
y: view_bounds.size.height - rect.y1,
357+
y: if view.is_flipped() {
358+
rect.y0
359+
} else {
360+
let view_bounds = view.bounds();
361+
view_bounds.size.height - rect.y1
362+
},
359363
},
360364
size: NSSize {
361365
width: rect.width(),

0 commit comments

Comments
 (0)