1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use crate::*;
use std::any::{Any, TypeId};
pub struct DrawArgs<'a> {
pub cx: &'a mut Context,
pub vger: &'a mut Vger,
}
pub struct LayoutArgs<'a> {
pub sz: LocalSize,
pub cx: &'a mut Context,
pub text_bounds: &'a mut dyn FnMut(&str, u32, Option<f32>) -> LocalRect,
}
impl<'a> LayoutArgs<'a> {
pub fn size(&mut self, sz: LocalSize) -> LayoutArgs {
LayoutArgs {
sz,
cx: self.cx,
text_bounds: self.text_bounds,
}
}
}
/// Trait for the unit of UI composition.
pub trait View: private::Sealed + 'static {
/// Builds an AccessKit tree. The node ID for the subtree is returned. All generated nodes are accumulated.
fn access(
&self,
_id: ViewId,
_cx: &mut Context,
_nodes: &mut Vec<(accesskit::NodeId, accesskit::Node)>,
) -> Option<accesskit::NodeId> {
None
}
/// Accumulates information about menu bar commands.
fn commands(&self, _id: ViewId, _cx: &mut Context, _cmds: &mut Vec<CommandInfo>) {}
/// Determines dirty regions which need repainting.
fn dirty(&self, _id: ViewId, _xform: LocalToWorld, _cx: &mut Context) {}
/// Draws the view using vger.
fn draw(&self, id: ViewId, args: &mut DrawArgs);
/// Gets IDs for views currently in use.
///
/// Push onto map if the view stores layout or state info.
fn gc(&self, _id: ViewId, _cx: &mut Context, _map: &mut Vec<ViewId>) {}
/// Returns the topmost view which the point intersects.
fn hittest(&self, _id: ViewId, _pt: LocalPoint, _cx: &mut Context) -> Option<ViewId> {
None
}
/// For detecting flexible sized things in stacks.
fn is_flexible(&self) -> bool {
false
}
/// Lays out subviews and return the size of the view.
///
/// `sz` is the available size for the view
/// `vger` can be used to get text sizing
///
/// Note that we should probably have a separate text
/// sizing interface so we don't need a GPU and graphics
/// context set up to test layout.
fn layout(&self, id: ViewId, args: &mut LayoutArgs) -> LocalSize;
/// Processes an event.
fn process(
&self,
_event: &Event,
_id: ViewId,
_cx: &mut Context,
_actions: &mut Vec<Box<dyn Any>>,
) {
}
/// Returns the type ID of the underlying view.
fn tid(&self) -> TypeId {
TypeId::of::<Self>()
}
}