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:
parent
e09df735a5
commit
a5622af68d
1 changed files with 10 additions and 9 deletions
|
@ -198,7 +198,6 @@ const State = struct {
|
||||||
pid: thespian.pid,
|
pid: thespian.pid,
|
||||||
render_state: render.WindowState,
|
render_state: render.WindowState,
|
||||||
scroll_delta: isize = 0,
|
scroll_delta: isize = 0,
|
||||||
last_sizing_edge: ?win32.WPARAM = null,
|
|
||||||
bounds: ?WindowBounds = null,
|
bounds: ?WindowBounds = null,
|
||||||
};
|
};
|
||||||
fn stateFromHwnd(hwnd: win32.HWND) *State {
|
fn stateFromHwnd(hwnd: win32.HWND) *State {
|
||||||
|
@ -1036,15 +1035,17 @@ fn WndProc(
|
||||||
return 0;
|
return 0;
|
||||||
},
|
},
|
||||||
win32.WM_SIZING => {
|
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);
|
const state = stateFromHwnd(hwnd);
|
||||||
state.last_sizing_edge = wparam;
|
state.bounds = .{
|
||||||
return 0;
|
.token = new_rect,
|
||||||
},
|
.rect = rect.*,
|
||||||
win32.WM_EXITSIZEMOVE => {
|
};
|
||||||
const state = stateFromHwnd(hwnd);
|
rect.* = new_rect;
|
||||||
state.bounds = null;
|
|
||||||
updateWindowSize(hwnd, state.last_sizing_edge, &state.bounds);
|
|
||||||
state.last_sizing_edge = null;
|
|
||||||
return 0;
|
return 0;
|
||||||
},
|
},
|
||||||
win32.WM_DISPLAYCHANGE => {
|
win32.WM_DISPLAYCHANGE => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue