1    type MenuItem =
2        inherit Container
3    
4        let overlay : Overlay @auto
5        val items @mut @dst = obs/List<Control>.new
6        var obs selected_item : Option<Control> = None
7        var obs text @mut = ""
8    
9        is_focusable = true
10       align_h = AlignH/Left
11       align_v = AlignV/Up
12   
13       let text_block = TextBlock.new
14       let popup = Stack.new
15       let popup_rectangle = Rectangle.new
16   
17       let stack = Stack
18           parent = self
19           text_block
20               color = Colors.menu_text
21               text@obs = text@obs
22           popup_rectangle
23               is_popup = true
24               is_visible = false
25               color = Colors.menu_popup_background
26               popup
27   
28       text_block.set_z Control.offset_z
29   
30       items |> bind { index control -> control.is_focusable = true
31                                                align_h = AlignH/Left
32                                        popup.items.add index control }
33                     { index control -> popup.items.remove index control }
34             |> push_token
35   
36       subscribe { _, event -> if event ? FlagEvent/IsFocused x then
37           popup_rectangle.is_visible = x
38           if x then
39               overlay.add popup_rectangle
40           else
41               overlay.remove popup_rectangle }
42   
43       def Container.get_slice =
44           SafeSlice<Control>.create stack@ptr 1
45   
46       def Control.measure w h =
47           measure_clamped stack w Control.max_size
48           measure_width = text_block.measure_width
49           measure_height = text_block.measure_height
50   
51       def Control.arrange =
52           arrange_measured stack
53