Seregon/StratoSDK

StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.

Rust/27.3 KB/No license
crates/strato-ui-renderer/src/windowing/winit/windows/system_caption_buttons.rs
StratoSDK / crates / strato-ui-renderer / src / windowing / winit / windows / system_caption_buttons.rs
1use super::window_attribute::get_window_attribute;
2use super::WindowAttributeErr;
3use windows::Win32::Foundation::RECT;
4use windows::Win32::Graphics::Dwm;
5use winit::window::Window as WinitWindow;
6 
7#[derive(Debug)]
8pub struct SystemCaptionButtonData {
9 bounds: RECT,
10}
11 
12#[derive(Debug)]
13pub enum SystemCaptionButtonSide {
14 Left,
15 Right,
16}
17 
18impl SystemCaptionButtonData {
19 pub fn total_width(&self) -> i32 {
20 self.bounds.right - self.bounds.left
21 }
22 
23 pub fn side(&self) -> SystemCaptionButtonSide {
24 if self.bounds.left == 0 {
25 SystemCaptionButtonSide::Left
26 } else {
27 SystemCaptionButtonSide::Right
28 }
29 }
30}
31 
32/// Retrieves the system caption button's bounds using the window's
33/// CAPTION_BUTTON_BOUNDS attribute.
34pub fn get_system_caption_button_bounds(
35 window: &WinitWindow,
36) -> Result<SystemCaptionButtonData, WindowAttributeErr> {
37 let caption_button_bounds = get_window_attribute(window, Dwm::DWMWA_CAPTION_BUTTON_BOUNDS)?;
38 
39 Ok(SystemCaptionButtonData {
40 bounds: caption_button_bounds,
41 })
42}
43