StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.
| 1 | use super::window_attribute::get_window_attribute; |
| 2 | use super::WindowAttributeErr; |
| 3 | use windows::Win32::Foundation::RECT; |
| 4 | use windows::Win32::Graphics::Dwm; |
| 5 | use winit::window::Window as WinitWindow; |
| 6 | |
| 7 | #[derive(Debug)] |
| 8 | pub struct SystemCaptionButtonData { |
| 9 | bounds: RECT, |
| 10 | } |
| 11 | |
| 12 | #[derive(Debug)] |
| 13 | pub enum SystemCaptionButtonSide { |
| 14 | Left, |
| 15 | Right, |
| 16 | } |
| 17 | |
| 18 | impl 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. |
| 34 | pub 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 |