use crate::{
action::{drag_window, toggle_window_maximized},
event::{Event, EventListener},
id::ViewId,
pointer::PointerButton,
view::{IntoView, View},
};
use super::Decorators;
pub struct DragWindowArea {
id: ViewId,
}
pub fn drag_window_area<V: IntoView + 'static>(child: V) -> DragWindowArea {
let id = ViewId::new();
id.set_children(vec![child]);
DragWindowArea { id }
.on_event_stop(EventListener::PointerDown, |e| {
if let Event::PointerDown(input_event) = e {
if input_event.button == PointerButton::Primary {
drag_window();
}
}
})
.on_double_click_stop(|_| toggle_window_maximized())
}
impl View for DragWindowArea {
fn id(&self) -> ViewId {
self.id
}
fn debug_name(&self) -> std::borrow::Cow<'static, str> {
"Drag Window Area".into()
}
}