Files
komorebi/komorebi-core/src/rect.rs
LGUG2Z 2db0d888c1 feat(subscriptions): add cmd to gen json schema
This commit introduces the 'notification-schema' command to generate a
JSON schema of the Notification struct which gets sent when notifying
subscribers of updates.
2022-02-01 12:38:11 -08:00

43 lines
1.0 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 {
pub left: i32,
pub top: i32,
pub right: i32,
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 {
pub fn add_padding(&mut self, padding: Option<i32>) {
if let Some(padding) = padding {
self.left += padding;
self.top += padding;
self.right -= padding * 2;
self.bottom -= padding * 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
}
}