freya_devtools_app/tabs/
misc.rs1use freya::prelude::*;
2use freya_devtools::IncomingMessageAction;
3use freya_radio::hooks::use_radio;
4
5use crate::state::DevtoolsChannel;
6
7#[derive(PartialEq)]
8pub struct Misc;
9impl Component for Misc {
10 fn render(&self) -> impl IntoElement {
11 let mut radio = use_radio(DevtoolsChannel::Misc);
12
13 use_side_effect(move || {
14 let radio = radio.read();
15 let animation_speed = AnimationClock::MAX_SPEED / 100. * radio.animation_speed;
16 radio.send_action(IncomingMessageAction::SetSpeedTo {
17 speed: animation_speed,
18 });
19 });
20 let speed = radio.read().animation_speed;
21 let normalized_speed = AnimationClock::MAX_SPEED / 100. * speed;
22
23 rect()
24 .width(Size::fill())
25 .height(Size::fill())
26 .padding(8.)
27 .spacing(6.)
28 .child("Animation Speed")
29 .child(
30 rect()
31 .horizontal()
32 .child(
33 Slider::new(move |p| {
34 radio.write().animation_speed = p as f32;
35 })
36 .size(Size::px(200.))
37 .value(speed as f64),
38 )
39 .child(format!("{normalized_speed:.2}x")),
40 )
41 .child(
42 Button::new()
43 .on_press(move |_| {
44 radio.write().animation_speed = 1. / AnimationClock::MAX_SPEED * 100.
45 })
46 .child("Reset"),
47 )
48 }
49}