freya_components/
native_router.rs1use freya_core::prelude::*;
2use freya_router::prelude::Navigator;
3
4#[derive(PartialEq)]
5pub struct NativeRouter {
6 children: Vec<Element>,
7}
8
9impl ChildrenExt for NativeRouter {
10 fn get_children(&mut self) -> &mut Vec<Element> {
11 &mut self.children
12 }
13}
14
15impl Default for NativeRouter {
16 fn default() -> Self {
17 Self::new()
18 }
19}
20
21impl NativeRouter {
22 pub fn new() -> Self {
23 Self { children: vec![] }
24 }
25}
26
27impl Render for NativeRouter {
28 fn render(&self) -> impl IntoElement {
29 rect()
30 .on_global_mouse_up(|e: Event<MouseEventData>| match e.button {
31 Some(MouseButton::Back) => Navigator::get().go_back(),
32 Some(MouseButton::Forward) => Navigator::get().go_forward(),
33 _ => {}
34 })
35 .children(self.children.clone())
36 }
37}