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.
This commit is contained in:
Jonathan Marler 2025-01-14 09:19:12 -07:00 committed by CJ van den Berg
parent e09df735a5
commit a5622af68d

View file

@ -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 => {