use crate::view::any_element::AnyElement;
use crate::view::div::Div;
use crate::view::drag::{DragSource, DropTarget};
use crate::view::interactivity::EventContext;
use crate::view::style::Style;
use crate::core::CursorStyle;
use std::any::{Any, TypeId};
use std::rc::Rc;
impl Div {
pub fn cursor(mut self, cursor: CursorStyle) -> Self {
self.interactivity.cursor = Some(cursor);
self
}
pub fn cursor_pointer(self) -> Self {
self.cursor(CursorStyle::PointingHand)
}
pub fn cursor_text(self) -> Self {
self.cursor(CursorStyle::IBeam)
}
pub fn cursor_col_resize(self) -> Self {
self.cursor(CursorStyle::ResizeColumn)
}
pub fn cursor_row_resize(self) -> Self {
self.cursor(CursorStyle::ResizeRow)
}
pub fn group(mut self, name: &str) -> Self {
self.interactivity.group = Some(Rc::from(name));
self
}
pub fn group_hover(mut self, name: &str, refine: impl FnOnce(Style) -> Style) -> Self {
self.interactivity.group_hover = Some((Rc::from(name), refine(Style::default())));
self
}
pub fn draggable<T: Any>(mut self, value: T, preview: impl Fn(&T) -> AnyElement + 'static) -> Self {
self.interactivity.drag = Some(DragSource::new(value, preview));
self
}
pub fn on_drop<T: Any>(mut self, handler: impl Fn(&T, &mut EventContext) + 'static) -> Self {
self.interactivity.drops.push(DropTarget::new(handler));
self
}
pub fn drag_over<T: Any>(mut self, refine: impl FnOnce(Style) -> Style) -> Self {
self.interactivity.drag_over.push((TypeId::of::<T>(), refine(Style::default())));
self
}
pub fn role(mut self, role: accesskit::Role) -> Self {
self.interactivity.role = Some(role);
self
}
pub fn label(mut self, label: impl Into<String>) -> Self {
let label: String = label.into();
self.interactivity.label = Some(Rc::from(label));
self
}
}