-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Add window drag area * stop propagating event in window drag area * clean up window drag area example
- Loading branch information
Showing
6 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use dioxus::prelude::*; | ||
use freya_hooks::use_platform; | ||
use freya_elements::{elements as dioxus_elements, events::MouseEvent}; | ||
|
||
/// 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| { | ||
e.stop_propagation(); | ||
platform.drag_window(); | ||
}; | ||
|
||
rsx!( | ||
rect { | ||
onmousedown, | ||
{children} | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#![cfg_attr( | ||
all(not(debug_assertions), target_os = "windows"), | ||
windows_subsystem = "windows" | ||
)] | ||
|
||
use freya::prelude::*; | ||
|
||
fn main() { | ||
launch(app); | ||
} | ||
|
||
fn app() -> Element { | ||
rsx!( | ||
rect { | ||
width: "100%", | ||
height: "100%", | ||
WindowDragArea { | ||
rect { | ||
width: "100%", | ||
height: "50%", | ||
background: "rgb(28, 28, 28)", | ||
color: "white", | ||
main_align: "center", | ||
label { | ||
width: "100%", | ||
text_align: "center", | ||
"Drag Me!" | ||
} | ||
} | ||
} | ||
rect { | ||
width: "100%", | ||
height: "50%", | ||
main_align: "center", | ||
label { | ||
text_align: "center", | ||
"Use the top half to drag the window" | ||
} | ||
} | ||
} | ||
) | ||
} |