1    def get_size_atom (control : Control) =
2        let atom = Atom<(u32, u32)> (control.width, control.height)
3        control.subscribe { _, event -> case event of
4            SizeEvent/Width _ | SizeEvent/Height _ ->
5                atom.set (control.width, control.height)
6    
7            else -> () }
8    
9        atom
10   
11   type Control
12       var maybe_drawable : Option<Drawable> = None
13   
14   type ControlMaterial = Material
15   
16   type QuadControl
17       let material : ControlMaterial @auto
18   
19       val memory@atom = size@atom
20           |> map { s ->
21               if s.width == 0 || s.height == 0
22               then None
23               else Some s }
24   
25           |> option_map_discard { s ->
26               let w = s.width
27               let h = s.height
28               let quad = Quad.create
29                   up_left = Vector3.new
30                   up_right = Vector3 w.as<f32> 0 0
31                   down_left = Vector3 0 h.as<f32> 0
32                   down_right = Vector3 w.as<f32> h.as<f32> 0
33                   color = Vector3.gray 0.3
34   
35               MeshMemory.from_quad quad }
36   
37       let drawable = Drawable
38           mesh = Mesh.from_memory memory@atom
39           material = material.unwrap
40   
41       maybe_drawable = drawable
42   
43   type TriangleControl
44       let material : ControlMaterial @auto
45   
46       let size = get_size_atom self
47       val memory@atom = (size, color@atom)
48           |> to_atom
49           |> map { (w, h), c -> if w == 0 || h == 0 then None else Some (w, h, c) }
50           |> option_map_discard { w, h, c ->
51               let triangle = Triangle.create
52                   up_left = Vector3 0 h.as<f32> 0
53                   down_left = Vector3 w.as<f32> h.as<f32> 0
54                   down_right = Vector3 w.as<f32> 0 0
55                   color = c
56   
57               MeshMemory.from_triangle triangle }
58   
59       let drawable = Drawable
60           mesh = Mesh.from_memory memory@atom
61           material = material.unwrap
62   
63       maybe_drawable = drawable
64