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

Shell: windows implementation from content_insets #1592

Merged
merged 1 commit into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ You can find its changes [documented below](#070---2021-01-01).
- Contexts: to_window and to_screen (useful for relatively positioning sub windows) ([#1532] by [@rjwittams])
- WindowSizePolicy: allow windows to be sized by their content ([#1532] by [@rjwittams])
- Implemented `Data` for more datatypes from `std` ([#1534] by [@derekdreery])
- Shell: windows implementation from content_insets ([#1592] by [@HoNile])

### Changed

Expand Down Expand Up @@ -415,6 +416,7 @@ Last release without a changelog :(
[@MaximilianKoestler]: https://github.com/MaximilianKoestler
[@lassipulkkinen]: https://github.com/lassipulkkinen
[@Poignardazur]: https://github.com/PoignardAzur
[@HoNile]: https://github.com/HoNile

[#599]: https://github.com/linebender/druid/pull/599
[#611]: https://github.com/linebender/druid/pull/611
Expand Down Expand Up @@ -614,6 +616,7 @@ Last release without a changelog :(
[#1254]: https://github.com/linebender/druid/pull/1254
[#1559]: https://github.com/linebender/druid/pull/1559
[#1562]: https://github.com/linebender/druid/pull/1562
[#1592]: https://github.com/linebender/druid/pull/1592

[Unreleased]: https://github.com/linebender/druid/compare/v0.6.0...master
[0.6.0]: https://github.com/linebender/druid/compare/v0.5.0...v0.6.0
Expand Down
27 changes: 26 additions & 1 deletion druid-shell/src/platform/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,32 @@ impl WindowHandle {
}

pub fn content_insets(&self) -> Insets {
warn!("WindowHandle::content_insets unimplemented for windows.");
if let Some(w) = self.state.upgrade() {
let hwnd = w.hwnd.get();
unsafe {
let mut info: WINDOWINFO = mem::zeroed();
info.cbSize = mem::size_of::<WINDOWINFO>() as u32;

if GetWindowInfo(hwnd, &mut info) == 0 {
warn!(
"failed to get window info: {}",
Error::Hr(HRESULT_FROM_WIN32(GetLastError()))
);
};

let window_frame = Rect::from_points(
(info.rcWindow.left as f64, info.rcWindow.top as f64),
(info.rcWindow.right as f64, info.rcWindow.bottom as f64),
);
let content_frame = Rect::from_points(
(info.rcClient.left as f64, info.rcClient.top as f64),
(info.rcClient.right as f64, info.rcClient.bottom as f64),
);

return window_frame - content_frame;
}
}

Insets::ZERO
}

Expand Down