desktop_example/app/routes/
portal.rs1use std::time::Duration;
2
3use freya::{
4 animation::*,
5 material_design::Ripple,
6 prelude::*,
7};
8
9#[derive(PartialEq)]
10pub struct PortalDemo;
11
12impl Component for PortalDemo {
13 fn render(&self) -> impl IntoElement {
14 let mut show_popup = use_state::<Option<i32>>(|| None);
15
16 ScrollView::new()
17 .width(Size::fill())
18 .height(Size::fill())
19 .child(
20 rect()
21 .width(Size::fill())
22 .spacing(12.)
23 .padding(12.)
24 .child(portal_popup(show_popup))
25 .children((0..5).map(|i| {
26 rect()
27 .key(i)
28 .spacing(6.)
29 .width(Size::fill())
30 .child(
31 Portal::new(i)
32 .key(show_popup())
33 .show(show_popup() != Some(i))
34 .width(Size::fill())
35 .height(Size::px(120.))
36 .function(Function::Expo)
37 .duration(Duration::from_millis(500))
38 .child(portal_card(i)),
39 )
40 .on_press(move |_| show_popup.set(Some(i)))
41 .into()
42 })),
43 )
44 }
45}
46
47fn portal_card(i: i32) -> impl IntoElement {
48 Ripple::new().color((255, 255, 255)).child(
49 rect()
50 .expanded()
51 .background((103, 80, 164))
52 .corner_radius(16.)
53 .center()
54 .color(Color::WHITE)
55 .child(format!("Card {}", i)),
56 )
57}
58
59fn portal_popup(mut show_popup: State<Option<i32>>) -> impl IntoElement {
60 Popup::new()
61 .on_close_request(move |_| show_popup.set(None))
62 .width(Size::px(350.))
63 .map(show_popup(), |popup, i| {
64 popup
65 .child(PopupTitle::new(format!("Card {i}")))
66 .child(
67 PopupContent::new().child(
68 Portal::new(i)
69 .width(Size::px(250.))
70 .height(Size::px(150.))
71 .function(Function::Expo)
72 .duration(Duration::from_millis(500))
73 .child(portal_card(i)),
74 ),
75 )
76 .child(
77 PopupButtons::new()
78 .child(
79 Button::new()
80 .expanded()
81 .rounded_full()
82 .on_press(move |_| show_popup.set(None))
83 .child("Close"),
84 )
85 .child(
86 Button::new()
87 .filled()
88 .expanded()
89 .rounded_full()
90 .on_press(move |_| show_popup.set(None))
91 .child("Accept"),
92 ),
93 )
94 })
95}