Skip to main content

uzor_framework/widgets/
host.rs

1//! The paint door shared by [`PanelCx`] and [`OverlayCx`].
2
3use uzor::render::RenderContext;
4use uzor::tokens::Tokens;
5
6use crate::handle::{OverlayCx, PanelCx, VisualView, Widgets};
7use crate::types::spec::Spec;
8
9/// A content hook context a widget convenience function can paint into.
10///
11/// Implemented for [`PanelCx`] and [`OverlayCx`]. The closure receives the
12/// disjoint pieces of one frame (paint target, registration face, this
13/// frame's input truth, tokens) so a widget can register and draw without
14/// reaching an engine.
15pub trait ContentCx<'a> {
16    /// The app vocabulary of the context.
17    type Spec: Spec;
18
19    /// Run `f` against this frame's paint target and registration face.
20    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
26impl<'a, S: Spec> ContentCx<'a> for PanelCx<'a, S> {
27    type Spec = S;
28
29    fn with_paint<R>(
30        &mut self,
31        f: impl FnOnce(&mut dyn RenderContext, &mut Widgets<'a>, &VisualView<S>, &Tokens) -> R,
32    ) -> R {
33        f(self.render, &mut self.widgets, self.view, self.tokens)
34    }
35}
36
37impl<'a, S: Spec> ContentCx<'a> for OverlayCx<'a, S> {
38    type Spec = S;
39
40    fn with_paint<R>(
41        &mut self,
42        f: impl FnOnce(&mut dyn RenderContext, &mut Widgets<'a>, &VisualView<S>, &Tokens) -> R,
43    ) -> R {
44        f(self.render, &mut self.widgets, self.view, self.tokens)
45    }
46}