freya_devtools_app/tabs/
misc.rs1use freya::prelude::*;
2use freya_devtools::{
3 IncomingMessage,
4 IncomingMessageAction,
5};
6use freya_radio::hooks::use_radio;
7use tungstenite::Message;
8
9use crate::state::DevtoolsChannel;
10
11#[derive(PartialEq)]
12pub struct Misc;
13impl Render for Misc {
14 fn render(&self) -> impl IntoElement {
15 let mut radio = use_radio(DevtoolsChannel::Misc);
16
17 use_side_effect(move || {
18 let radio = radio.read();
19
20 let client = radio.client.clone();
21 let animation_speed = AnimationClock::MAX_SPEED / 100. * radio.animation_speed;
22 let message = Message::Text(
23 serde_json::to_string(&IncomingMessage {
24 action: IncomingMessageAction::SetSpeedTo {
25 speed: animation_speed,
26 },
27 })
28 .unwrap()
29 .into(),
30 );
31 spawn(async move {
32 if let Some(client) = client.lock().await.as_mut() {
33 client.send(message).await.ok();
34 }
35 });
36 });
37 let speed = radio.read().animation_speed;
38 let normalized_speed = AnimationClock::MAX_SPEED / 100. * speed;
39
40 rect()
41 .width(Size::fill())
42 .height(Size::fill())
43 .padding(8.)
44 .spacing(6.)
45 .child("Animation Speed")
46 .child(
47 rect()
48 .horizontal()
49 .child(
50 Slider::new(move |p| {
51 radio.write().animation_speed = p as f32;
52 })
53 .size(Size::px(200.))
54 .value(speed as f64),
55 )
56 .child(format!("{normalized_speed:.2}x")),
57 )
58 .child(
59 Button::new()
60 .on_press(move |_| {
61 radio.write().animation_speed = 1. / AnimationClock::MAX_SPEED * 100.
62 })
63 .child("Reset"),
64 )
65 }
66}