1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
use dioxus::prelude::*;
use freya_elements::{
elements as dioxus_elements,
events::MouseEvent,
};
use freya_hooks::use_platform;
use winit::event::MouseButton;
/// Allow dragging the window when the cursor drag this component with a left mouse click.
///
/// # Example
///
/// ```no_run
/// # use freya::prelude::*;
/// fn app() -> Element {
/// rsx!(
/// WindowDragArea {
/// label {
/// height: "100%",
/// width: "100%",
/// "Drag Me"
/// }
/// }
/// )
/// }
/// ```
#[allow(non_snake_case)]
#[component]
pub fn WindowDragArea(
/// The inner children for the WindowDragArea
children: Element,
) -> Element {
let platform = use_platform();
let onmousedown = move |e: MouseEvent| {
if let Some(MouseButton::Left) = e.trigger_button {
e.stop_propagation();
platform.drag_window();
}
};
rsx!(
rect {
onmousedown,
{children}
}
)
}