From 0d094f244e4ae3ea96ce39da9b4f6d1c76e277f1 Mon Sep 17 00:00:00 2001 From: Mat Date: Sat, 2 Sep 2023 13:00:04 -0400 Subject: [PATCH 1/2] Update font DPI when the content scale is updated --- src/Surface.zig | 9 +++++++++ src/apprt/embedded.zig | 2 ++ 2 files changed, 11 insertions(+) diff --git a/src/Surface.zig b/src/Surface.zig index 9299aa111..d15e56cf1 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -1192,6 +1192,15 @@ pub fn scrollCallback( try self.queueRender(); } +pub fn contentScaleCallback(self: *Surface, content_scale: apprt.ContentScale) void { + var size = self.font_size; + const x_dpi = content_scale.x * font.face.default_dpi; + const y_dpi = content_scale.y * font.face.default_dpi; + size.xdpi = @intFromFloat(x_dpi); + size.ydpi = @intFromFloat(y_dpi); + self.setFontSize(size); +} + /// The type of action to report for a mouse event. const MouseReportAction = enum { press, release, motion }; diff --git a/src/apprt/embedded.zig b/src/apprt/embedded.zig index 03b6409cf..5bf1ec485 100644 --- a/src/apprt/embedded.zig +++ b/src/apprt/embedded.zig @@ -348,6 +348,8 @@ pub const Surface = struct { .x = @floatCast(x), .y = @floatCast(y), }; + + self.core_surface.contentScaleCallback(self.content_scale); } pub fn updateSize(self: *Surface, width: u32, height: u32) void { From 9e5ced26001f879d3d45d1c7abdaa403780c4dc7 Mon Sep 17 00:00:00 2001 From: Mat Date: Sat, 2 Sep 2023 13:39:29 -0400 Subject: [PATCH 2/2] use a const scoped block for font size --- src/Surface.zig | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index d15e56cf1..449a506a9 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -1193,11 +1193,14 @@ pub fn scrollCallback( } pub fn contentScaleCallback(self: *Surface, content_scale: apprt.ContentScale) void { - var size = self.font_size; const x_dpi = content_scale.x * font.face.default_dpi; const y_dpi = content_scale.y * font.face.default_dpi; - size.xdpi = @intFromFloat(x_dpi); - size.ydpi = @intFromFloat(y_dpi); + const size = size: { + var size = self.font_size; + size.xdpi = @intFromFloat(x_dpi); + size.ydpi = @intFromFloat(y_dpi); + break :size size; + }; self.setFontSize(size); }