1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
use crate::{bind, Result};
use super::Window;
/// A border widths for the window.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct BorderWidths {
/// A border width on the top.
pub top: u32,
/// A border width on the right.
pub right: u32,
/// A border width on the bottom.
pub bottom: u32,
/// A border width on the left.
pub left: u32,
}
/// An extension for [`Window`] to query border widths.
pub trait BorderExt {
/// Returns the border widths of the window.
///
/// # Errors
///
/// Returns `Err` if querying them is unsupported.
fn border_widths(&self) -> Result<BorderWidths>;
}
impl BorderExt for Window<'_> {
fn border_widths(&self) -> Result<BorderWidths> {
let (mut top, mut left, mut bottom, mut right) = (0, 0, 0, 0);
let ret = unsafe {
bind::SDL_GetWindowBordersSize(
self.as_ptr(),
&mut top,
&mut left,
&mut bottom,
&mut right,
)
};
if ret != 0 {
return Err(crate::SdlError::UnsupportedFeature);
}
Ok(BorderWidths {
top: top as u32,
right: right as u32,
bottom: bottom as u32,
left: left as u32,
})
}
}