rate_ui/widget/
graphics.rs

1use super::{Msg, OnBridgeEvent, Widget, WidgetContext};
2use crate::agents::graphics::{GraphicsAgent, GraphicsRequest, GraphicsResponse};
3use yew::{Bridge, NodeRef};
4
5pub struct Graphics<'a> {
6    link: &'a mut dyn Bridge<GraphicsAgent>,
7}
8
9impl<'a> Graphics<'a> {
10    pub fn on_frame(&mut self, active: bool) {
11        let msg = GraphicsRequest::OnFrame(active);
12        self.link.send(msg);
13    }
14
15    pub fn track_size(&mut self, node_ref: NodeRef) {
16        let msg = GraphicsRequest::TrackSize(node_ref);
17        self.link.send(msg);
18    }
19}
20
21impl<T: Widget> WidgetContext<T> {
22    pub fn graphics(&mut self) -> Graphics<'_>
23    where
24        T: OnBridgeEvent<GraphicsAgent>,
25    {
26        let link = self.graphics.get_mut_linked(&self.link);
27        Graphics { link }
28    }
29}
30
31impl<T: Widget> From<GraphicsResponse> for Msg<T> {
32    fn from(response: GraphicsResponse) -> Self {
33        Self::GraphicsIncoming(response)
34    }
35}