use crate::widget::WidgetNode;
use crate::{element::OverlayHandle, Point};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum AnchorPlacement {
TopLeft,
#[default]
Top,
TopRight,
Left,
Right,
BottomLeft,
Bottom,
BottomRight,
InsideTopRight,
}
#[derive(Debug, Clone)]
pub enum OverlayIntent {
Show {
anchor: OverlayAnchor,
node: WidgetNode,
focus: OverlayFocus,
},
Hide(OverlayRef),
}
#[derive(Debug, Clone, Copy)]
pub enum OverlayAnchor {
Point {
position: Point,
offset: Point,
},
Element {
placement: AnchorPlacement,
gap: f32,
offset: Point,
},
}
impl OverlayAnchor {
pub fn point(position: Point) -> Self {
Self::Point { position, offset: Point::ZERO }
}
pub fn point_with_offset(position: Point, offset: Point) -> Self {
Self::Point { position, offset }
}
pub fn element(placement: AnchorPlacement, gap: f32) -> Self {
Self::Element { placement, gap, offset: Point::ZERO }
}
pub fn element_with_offset(placement: AnchorPlacement, gap: f32, offset: Point) -> Self {
Self::Element { placement, gap, offset }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OverlayFocus {
Passive,
Modal {
restore_on_close: bool,
},
}
impl OverlayFocus {
pub fn modal() -> Self {
OverlayFocus::Modal { restore_on_close: true }
}
pub fn is_modal(self) -> bool {
matches!(self, OverlayFocus::Modal { .. })
}
}
#[derive(Debug, Clone, Copy)]
pub enum OverlayRef {
Handle(OverlayHandle),
Own,
}
#[derive(Debug, Clone, Copy)]
pub enum OverlayEvent {
Shown(OverlayHandle),
Hidden(OverlayHandle),
ClickOutside,
}
pub trait OverlayAware {
fn take_overlay_intents(&mut self, now_ms: u64) -> Vec<OverlayIntent>;
fn on_overlay_event(&mut self, event: OverlayEvent);
fn on_overlay_force_closed(&mut self, _handle: OverlayHandle) {}
}