Skip to main content

xrack_layout/
window_chrome.rs

1use crate::{Point, Rect};
2
3#[derive(Clone, Copy, Debug, PartialEq, Eq)]
4pub enum WindowResizeEdge {
5    North,
6    South,
7    East,
8    West,
9    NorthEast,
10    NorthWest,
11    SouthEast,
12    SouthWest,
13}
14
15impl WindowResizeEdge {
16    pub(crate) fn at(bounds: Rect, point: Point, border: f32) -> Option<Self> {
17        if !border.is_finite() || border <= 0.0 || !bounds.contains(point) {
18            return None;
19        }
20        let horizontal = border.min(bounds.width * 0.5);
21        let vertical = border.min(bounds.height * 0.5);
22        let left = point.x - bounds.x < horizontal;
23        let right = bounds.x + bounds.width - point.x <= horizontal;
24        let top = point.y - bounds.y < vertical;
25        let bottom = bounds.y + bounds.height - point.y <= vertical;
26        Some(match (left, right, top, bottom) {
27            (true, _, true, _) => Self::NorthWest,
28            (_, true, true, _) => Self::NorthEast,
29            (true, _, _, true) => Self::SouthWest,
30            (_, true, _, true) => Self::SouthEast,
31            (_, _, true, _) => Self::North,
32            (_, _, _, true) => Self::South,
33            (true, _, _, _) => Self::West,
34            (_, true, _, _) => Self::East,
35            _ => return None,
36        })
37    }
38}