Skip to content

Commit 25afc6e

Browse files
authored
Merge pull request #6 from slint-ui/simon/macos-scale-fix
Fix scaling of the buffer on macOS
2 parents dbd4e79 + b74047a commit 25afc6e

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

examples/fruit.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ fn main() {
1616
}).collect::<Vec<_>>();
1717

1818
let event_loop = EventLoop::new();
19-
let window = WindowBuilder::new().build(&event_loop).unwrap();
19+
let window = WindowBuilder::new()
20+
.with_inner_size(winit::dpi::PhysicalSize::new(fruit.width(), fruit.height()))
21+
.build(&event_loop)
22+
.unwrap();
2023

2124
#[cfg(target_arch = "wasm32")]
2225
{

src/cg.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use core_graphics::data_provider::CGDataProvider;
66
use core_graphics::image::CGImage;
77

88
use cocoa::base::{id, nil};
9-
use cocoa::appkit::{NSView, NSViewWidthSizable, NSViewHeightSizable};
9+
use cocoa::appkit::{NSView, NSViewWidthSizable, NSViewHeightSizable, NSWindow};
1010
use cocoa::quartzcore::{CALayer, ContentsGravity};
1111
use foreign_types::ForeignType;
1212

@@ -18,11 +18,13 @@ pub struct CGImpl {
1818

1919
impl CGImpl {
2020
pub unsafe fn new(handle: AppKitWindowHandle) -> Result<Self, SwBufError> {
21+
let window = handle.ns_window as id;
2122
let view = handle.ns_view as id;
2223
let layer = CALayer::new();
23-
let subview: id = NSView::alloc(nil).initWithFrame_(view.frame());
24+
let subview: id = NSView::alloc(nil).initWithFrame_(NSView::frame(view));
2425
layer.set_contents_gravity(ContentsGravity::TopLeft);
2526
layer.set_needs_display_on_bounds_change(false);
27+
layer.set_contents_scale(window.backingScaleFactor());
2628
subview.setLayer(layer.id());
2729
subview.setAutoresizingMask_(NSViewWidthSizable | NSViewHeightSizable);
2830

0 commit comments

Comments
 (0)