uzor_framework/widgets/
host.rs1use uzor::render::RenderContext;
4use uzor::tokens::Tokens;
5
6use crate::handle::{FrameTime, OverlayCx, PanelCx, VisualView, Widgets};
7use crate::types::spec::Spec;
8
9pub trait ContentCx<'a> {
16 type Spec: Spec;
18
19 fn with_paint<R>(
21 &mut self,
22 f: impl FnOnce(&mut dyn RenderContext, &mut Widgets<'a>, &VisualView<Self::Spec>, &Tokens) -> R,
23 ) -> R;
24
25 fn ime_area(&mut self, _rect: uzor::Rect) {}
27
28 fn time_ms(&self) -> u64;
31}
32
33impl<'a, S: Spec> ContentCx<'a> for PanelCx<'a, S> {
34 type Spec = S;
35
36 fn ime_area(&mut self, rect: uzor::Rect) {
37 self.out.ime_area(rect);
38 }
39
40 fn time_ms(&self) -> u64 {
41 frame_ms(self.time)
42 }
43
44 fn with_paint<R>(
45 &mut self,
46 f: impl FnOnce(&mut dyn RenderContext, &mut Widgets<'a>, &VisualView<S>, &Tokens) -> R,
47 ) -> R {
48 f(self.render, &mut self.widgets, self.view, self.tokens)
49 }
50}
51
52impl<'a, S: Spec> ContentCx<'a> for OverlayCx<'a, S> {
53 type Spec = S;
54
55 fn ime_area(&mut self, rect: uzor::Rect) {
56 self.out.ime_area(rect);
57 }
58
59 fn time_ms(&self) -> u64 {
60 frame_ms(self.time)
61 }
62
63 fn with_paint<R>(
64 &mut self,
65 f: impl FnOnce(&mut dyn RenderContext, &mut Widgets<'a>, &VisualView<S>, &Tokens) -> R,
66 ) -> R {
67 f(self.render, &mut self.widgets, self.view, self.tokens)
68 }
69}
70
71fn frame_ms(time: FrameTime) -> u64 {
72 (time.now.get() * 1000.0).round().max(0.0) as u64
73}