Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

center window on create and set_window_size() #348

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions src/native/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,11 @@ impl crate::native::NativeDisplay for Display {
self.user_cursor = cursor_icon != CursorIcon::Default;
}
fn set_window_size(&mut self, new_width: u32, new_height: u32) {
let mut x = 0;
let mut y = 0;
let mut final_new_width = new_width;
let mut final_new_height = new_height;

let mut rect: RECT = unsafe { std::mem::zeroed() };
if unsafe { GetClientRect(self.wnd, &mut rect as *mut _ as _) } != 0 {
x = rect.left;
y = rect.bottom;
}
unsafe { GetClientRect(self.wnd, &mut rect as *mut _ as _) };

rect.right = (rect.left + new_width as i32) as _;
rect.top = (rect.bottom - new_height as i32) as _;
Expand All @@ -143,12 +138,12 @@ impl crate::native::NativeDisplay for Display {
SetWindowPos(
self.wnd,
HWND_TOP,
x,
y,
(GetSystemMetrics(SM_CXSCREEN) - final_new_width as i32) / 2,
(GetSystemMetrics(SM_CYSCREEN) - final_new_height as i32) / 2,
final_new_width as i32,
final_new_height as i32,
SWP_NOMOVE,
)
0,
);
};
}

Expand Down Expand Up @@ -644,6 +639,9 @@ unsafe fn create_window(
AdjustWindowRectEx(&rect as *const _ as _, win_style, false as _, win_ex_style);
let win_width = rect.right - rect.left;
let win_height = rect.bottom - rect.top;
let win_x = (GetSystemMetrics(SM_CXSCREEN) - win_width) / 2;
let win_y = (GetSystemMetrics(SM_CYSCREEN) - win_height) / 2;

let class_name = "MINIQUADAPP\0".encode_utf16().collect::<Vec<u16>>();
let mut window_name = window_title.encode_utf16().collect::<Vec<u16>>();
window_name.push(0);
Expand All @@ -652,8 +650,8 @@ unsafe fn create_window(
class_name.as_ptr(), // lpClassName
window_name.as_ptr(), // lpWindowName
win_style, // dwStyle
CW_USEDEFAULT, // X
CW_USEDEFAULT, // Y
win_x, // X
win_y, // Y
win_width, // nWidth
win_height, // nHeight
NULL as _, // hWndParent
Expand Down