Skip to content

Commit

Permalink
Add content_insets on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
HoNile committed Feb 16, 2021
1 parent d846cc2 commit 57960f4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
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
46 changes: 45 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,51 @@ 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 {
cbSize: mem::size_of::<WINDOWINFO>() as u32,
rcWindow: RECT {
left: 0,
top: 0,
right: 0,
bottom: 0,
},
rcClient: RECT {
left: 0,
top: 0,
right: 0,
bottom: 0,
},
dwStyle: 0,
dwExStyle: 0,
dwWindowStatus: 0,
cxWindowBorders: 0,
cyWindowBorders: 0,
atomWindowType: 0,
wCreatorVersion: 0,
};
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

0 comments on commit 57960f4

Please sign in to comment.