From a5622af68d792899e4de6c79c848d15161fbc511 Mon Sep 17 00:00:00 2001 From: Jonathan Marler Date: Tue, 14 Jan 2025 09:19:12 -0700 Subject: [PATCH] win32 gui: keep window aspect ratio during resizing Now instead of snapping to a size after releasing the mouse from resizing the window, the window will incrementally snap to a good size while the window is being resized. --- src/win32/gui.zig | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/win32/gui.zig b/src/win32/gui.zig index bc9091a..e880972 100644 --- a/src/win32/gui.zig +++ b/src/win32/gui.zig @@ -198,7 +198,6 @@ const State = struct { pid: thespian.pid, render_state: render.WindowState, scroll_delta: isize = 0, - last_sizing_edge: ?win32.WPARAM = null, bounds: ?WindowBounds = null, }; fn stateFromHwnd(hwnd: win32.HWND) *State { @@ -1036,15 +1035,17 @@ fn WndProc( return 0; }, win32.WM_SIZING => { + const rect: *win32.RECT = @ptrFromInt(@as(usize, @bitCast(lparam))); + const dpi = win32.dpiFromHwnd(hwnd); + const font = getFont(dpi, getFontSize(), getFontFace()); + const cell_size = font.getCellSize(i32); + const new_rect = calcWindowRect(dpi, rect.*, wparam, cell_size); const state = stateFromHwnd(hwnd); - state.last_sizing_edge = wparam; - return 0; - }, - win32.WM_EXITSIZEMOVE => { - const state = stateFromHwnd(hwnd); - state.bounds = null; - updateWindowSize(hwnd, state.last_sizing_edge, &state.bounds); - state.last_sizing_edge = null; + state.bounds = .{ + .token = new_rect, + .rect = rect.*, + }; + rect.* = new_rect; return 0; }, win32.WM_DISPLAYCHANGE => {