1    type TextDisplay @mut =
2        inherit Control
3    
4        var font : Font
5        var text = Slice<TextLine>.empty
6        var visible_up : u32 = 0
7        var visible_down : u32 = 0
8        var offset_y : u32 = 0
9        var should_align = false
10       var selection : Option<(TextPos, TextPos)> = None
11       val changed = Stream<()>.new
12   
13       var margin = Thickness.new
14       var has_text = false
15   
16       def bounds (pos : TextPos) = Bounds
17           left = pos.char.as<f32> * font.advance |> as<u32> + margin.left
18           right = (pos.char.as<f32> + 1) * font.advance |> as<u32> + margin.left
19           up = margin.up + pos.line * font.line_height
20           down = margin.up + (pos.line + 1) * font.line_height
21   
22       def update self =
23           self.has_text = true
24           let max_size = self.text.max_of { _.size }
25           let width = max_size.as<f32> * self.font.advance |> as<u32>
26                       + self.margin.left + self.margin.right
27           self.set_fixed_width width
28   
29           let height = self.font.line_height * self.text.size
30                        + self.margin.up + self.margin.down * 20
31           self.set_fixed_height height
32           self.changed.push
33   
34       def Control.measure w h =
35           measure_width = 0
36           measure_height = 0
37   
38       def Control.arrange = ()
39