Skip to content

Commit 32dd49f

Browse files
committed
fix(cocoa): CATextLayer contents scale
1 parent 85559b5 commit 32dd49f

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ objc2-foundation = { version = "0.3", features = [
8888
] }
8989
objc2-app-kit = { version = "0.3", features = [
9090
"block2",
91+
"objc2-core-foundation",
9192
"objc2-quartz-core",
9293
"objc2-uniform-type-identifiers",
9394
"NSAlert",

src/ui/mac/canvas.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{marker::PhantomData, ops::Deref, ptr::null};
1+
use std::{ops::Deref, ptr::null};
22

33
use image::DynamicImage;
44
use objc2::{
@@ -99,7 +99,7 @@ impl Canvas {
9999
DrawingContext {
100100
size,
101101
layer,
102-
_p: PhantomData,
102+
canvas: self,
103103
}
104104
}
105105
}
@@ -196,7 +196,7 @@ unsafe fn mouse_button(event: &NSEvent) -> MouseButton {
196196
pub struct DrawingContext<'a> {
197197
size: Size,
198198
layer: Retained<CALayer>,
199-
_p: PhantomData<&'a mut Canvas>,
199+
canvas: &'a mut Canvas,
200200
}
201201

202202
impl DrawingContext<'_> {
@@ -286,6 +286,11 @@ impl DrawingContext<'_> {
286286
layer.setFrame(transform_rect(self.size, rect));
287287
layer.setString(Some(&astr));
288288
layer.setWrapped(true);
289+
if let Some(window) = self.canvas.view.window() {
290+
if let Some(screen) = window.screen() {
291+
layer.setContentsScale(screen.backingScaleFactor());
292+
}
293+
}
289294
let brush_layer = brush.create_layer();
290295
brush_layer.setFrame(self.layer.bounds());
291296
brush_layer.setMask(Some(&layer));

0 commit comments

Comments
 (0)