use crate::{
app::ctx::{CollisionStrategy, OpenState, OutsidePress, Overlay, Placement},
core::{ElementRef, Signal},
node::{Element, HitTestBehavior},
};
pub struct Popup {
overlay: Overlay,
}
impl Popup {
pub fn new(anchor: impl Into<ElementRef>, content: impl Into<Element>) -> Self {
Self {
overlay: Overlay::new(content)
.anchor(anchor)
.hit_test(HitTestBehavior::ContentOnly)
.dismiss_on_outside_click(true)
.dismiss_on_escape(true),
}
}
pub fn anchor(mut self, anchor: impl Into<ElementRef>) -> Self {
self.overlay = self.overlay.anchor(anchor);
self
}
pub fn open(mut self, open: impl Into<OpenState>) -> Self {
self.overlay = self.overlay.open(open);
self
}
pub fn open_signal(self, open: Signal<bool>) -> Self {
self.open(open)
}
pub fn open_when(mut self, open: bool) -> Self {
self.overlay = self.overlay.open_when(open);
self
}
pub fn placement(mut self, placement: Placement) -> Self {
self.overlay = self.overlay.placement(placement);
self
}
pub fn offset(mut self, x: f32, y: f32) -> Self {
self.overlay = self.overlay.offset(x, y);
self
}
pub fn match_anchor_width(mut self, match_anchor_width: bool) -> Self {
self.overlay = self.overlay.match_anchor_width(match_anchor_width);
self
}
pub fn within(mut self, element: impl Into<ElementRef>) -> Self {
self.overlay = self.overlay.within(element);
self
}
pub fn within_inset(mut self, element: impl Into<ElementRef>, top: f32, right: f32, bottom: f32, left: f32) -> Self {
self.overlay = self.overlay.within_inset(element, top, right, bottom, left);
self
}
pub fn placed_by(mut self, element: impl Into<ElementRef>) -> Self {
self.overlay = self.overlay.placed_by(element);
self
}
pub fn clear_of(mut self, element: impl Into<ElementRef>) -> Self {
self.overlay = self.overlay.clear_of(element);
self
}
pub fn collision(mut self, collision: CollisionStrategy) -> Self {
self.overlay = self.overlay.collision(collision);
self
}
pub fn hit_test(mut self, behavior: HitTestBehavior) -> Self {
self.overlay = self.overlay.hit_test(behavior);
self
}
pub fn dismiss_on_outside_click(mut self, dismiss: bool) -> Self {
self.overlay = self.overlay.dismiss_on_outside_click(dismiss);
self
}
pub fn outside_press(mut self, outside_press: OutsidePress) -> Self {
self.overlay = self.overlay.outside_press(outside_press);
self
}
pub fn takes_focus(mut self, takes: bool) -> Self {
self.overlay = self.overlay.takes_focus(takes);
self
}
pub fn tab_after_anchor(mut self, tab: bool) -> Self {
self.overlay = self.overlay.tab_after_anchor(tab);
self
}
pub fn traps_tab(mut self, traps: bool) -> Self {
self.overlay = self.overlay.traps_tab(traps);
self
}
pub fn dismiss_on_escape(mut self, dismiss: bool) -> Self {
self.overlay = self.overlay.dismiss_on_escape(dismiss);
self
}
pub fn on_dismiss(mut self, handler: impl Fn() + Send + Sync + 'static) -> Self {
self.overlay = self.overlay.on_dismiss(handler);
self
}
pub fn at(mut self, point: Option<(f32, f32)>) -> Self {
self.overlay = self.overlay.at(point);
self
}
pub(crate) fn at_placed(mut self, placement: Placement) -> Self {
self.overlay = self.overlay.at_placed(placement);
self
}
pub(crate) fn keep_clear(mut self, top: f32, right: f32, bottom: f32, left: f32) -> Self {
self.overlay = self.overlay.keep_clear(top, right, bottom, left);
self
}
pub fn switch_on_anchor_press(mut self, switch: bool) -> Self {
self.overlay = self.overlay.switch_on_anchor_press(switch);
self
}
}
impl From<Popup> for Element {
fn from(popup: Popup) -> Self {
popup.overlay.into()
}
}
pub type Popover = Popup;