use super::{LeafId, TabHit, FloatingWindowId};
#[derive(Clone, Debug)]
pub enum HitResult {
Panel(LeafId),
Separator(usize),
Corner(usize),
TabBar(LeafId, TabHit),
FloatingHeader(FloatingWindowId),
FloatingBody(FloatingWindowId),
FloatingClose(FloatingWindowId),
None,
}
impl HitResult {
pub fn is_panel(&self) -> bool {
matches!(self, HitResult::Panel(_))
}
pub fn is_separator(&self) -> bool {
matches!(self, HitResult::Separator(_))
}
pub fn is_corner(&self) -> bool {
matches!(self, HitResult::Corner(_))
}
pub fn is_tab_bar(&self) -> bool {
matches!(self, HitResult::TabBar(_, _))
}
pub fn is_floating(&self) -> bool {
matches!(
self,
HitResult::FloatingHeader(_) | HitResult::FloatingBody(_) | HitResult::FloatingClose(_)
)
}
pub fn panel_id(&self) -> Option<LeafId> {
match self {
HitResult::Panel(id) => Some(*id),
_ => None,
}
}
pub fn floating_id(&self) -> Option<FloatingWindowId> {
match self {
HitResult::FloatingHeader(id) | HitResult::FloatingBody(id) | HitResult::FloatingClose(id) => Some(*id),
_ => None,
}
}
}
#[derive(Clone, Debug)]
pub struct CornerHandle {
pub v_separator_idx: usize,
pub h_separator_idx: usize,
pub x: f32,
pub y: f32,
}
impl CornerHandle {
pub fn new(v_separator_idx: usize, h_separator_idx: usize, x: f32, y: f32) -> Self {
Self {
v_separator_idx,
h_separator_idx,
x,
y,
}
}
pub fn hit_test(&self, px: f32, py: f32, radius: f32) -> bool {
let dx = px - self.x;
let dy = py - self.y;
(dx * dx + dy * dy).sqrt() <= radius
}
pub fn rect(&self, size: f32) -> super::PanelRect {
let half = size / 2.0;
super::PanelRect::new(self.x - half, self.y - half, size, size)
}
}