mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-06-28 05:06:17 +02:00
5ee827ecaf
The layout should leave the space configured for the border, so that the border always stays within the workspace bounds. Border offset is cleaned up, as it is no longer a rect, but instead just a fixed value. The rect function for adjusting padding now takes a concrete value, as the optional has no local meaning to the operation, being equivalent to the default value. A margin function is added to centralize the notion of increasing the size of a rect by the given margin, the opposite of the padding operation.
64 lines
1.7 KiB
Rust
64 lines
1.7 KiB
Rust
use schemars::JsonSchema;
|
|
use serde::Deserialize;
|
|
use serde::Serialize;
|
|
use windows::Win32::Foundation::RECT;
|
|
|
|
#[derive(Debug, Default, Clone, Copy, Serialize, Deserialize, Eq, PartialEq, JsonSchema)]
|
|
pub struct Rect {
|
|
/// The left point in a Win32 Rect
|
|
pub left: i32,
|
|
/// The top point in a Win32 Rect
|
|
pub top: i32,
|
|
/// The right point in a Win32 Rect
|
|
pub right: i32,
|
|
/// The bottom point in a Win32 Rect
|
|
pub bottom: i32,
|
|
}
|
|
|
|
impl From<RECT> for Rect {
|
|
fn from(rect: RECT) -> Self {
|
|
Self {
|
|
left: rect.left,
|
|
top: rect.top,
|
|
right: rect.right - rect.left,
|
|
bottom: rect.bottom - rect.top,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Rect {
|
|
/// decrease the size of self by the padding amount.
|
|
pub fn add_padding(&mut self, padding: i32) {
|
|
self.left += padding;
|
|
self.top += padding;
|
|
self.right -= padding * 2;
|
|
self.bottom -= padding * 2;
|
|
}
|
|
|
|
/// increase the size of self by the margin amount.
|
|
pub fn add_margin(&mut self, margin: i32) {
|
|
self.left -= margin;
|
|
self.top -= margin;
|
|
self.right += margin * 2;
|
|
self.bottom += margin * 2;
|
|
}
|
|
|
|
#[must_use]
|
|
pub const fn contains_point(&self, point: (i32, i32)) -> bool {
|
|
point.0 >= self.left
|
|
&& point.0 <= self.left + self.right
|
|
&& point.1 >= self.top
|
|
&& point.1 <= self.top + self.bottom
|
|
}
|
|
|
|
#[must_use]
|
|
pub const fn scale(&self, system_dpi: i32, rect_dpi: i32) -> Rect {
|
|
Rect {
|
|
left: (self.left * rect_dpi) / system_dpi,
|
|
top: (self.top * rect_dpi) / system_dpi,
|
|
right: (self.right * rect_dpi) / system_dpi,
|
|
bottom: (self.bottom * rect_dpi) / system_dpi,
|
|
}
|
|
}
|
|
}
|