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 selection : Option<(TextPos, TextPos)> = None 10 val changed = Stream<()>.new 11 12 var margin = num/Thickness.new 13 var has_text = false 14 15 def bounds (pos : TextPos) = Bounds 16 left = pos.char.as<f32> * font.advance |> as<u32> + margin.left 17 right = (pos.char.as<f32> + 1) * font.advance |> as<u32> + margin.left 18 up = margin.up + pos.line * font.line_height 19 down = margin.up + (pos.line + 1) * font.line_height 20 21 def update self = 22 self.has_text = true 23 let max_length = self.text.max_of { _.length } 24 let width = max_length.as<f32> * self.font.advance |> as<u32> 25 + self.margin.left + self.margin.right 26 self.set_fixed_width width 27 28 let height = self.font.line_height * self.text.size 29 + self.margin.up + self.margin.down * 20 30 self.set_fixed_height height 31 self.changed.push 32 33 def Control.measure w h = 34 measure_width = 0 35 measure_height = 0 36 37 def Control.arrange = () 38