-end
-
-# Manage a set of sprites to display some text
-class TextSprites
-
- # Font used to draw text
- var font: TileSetFont
-
- # Top left of the first character in UI coordinates
- var anchor: Point3d[Float]
-
- # Last set of sprites generated to display `text=`
- var sprites = new Array[Sprite]
-
- # Sprite set where to put created sprites
- #
- # Defaults to `app::ui_sprites`, but it could also be set to a
- # `app::sprites` or a custom collection.
- var target_sprite_set: Set[Sprite] = app.ui_sprites is lazy, writable
-
- private var cached_text: nullable Text = ""
-
- # Last text drawn
- fun text: nullable Text do return cached_text
-
- # Update the text displayed by inserting new sprites into `app.ui_sprites`
- #
- # Does not redraw if `text` has not changed.
- fun text=(text: nullable Text)
- is autoinit do
- # Don't redraw if text hasn't changed
- if text == cached_text then return
- cached_text = text
-
- # Clean up last used sprites
- for s in sprites do if target_sprite_set.has(s) then target_sprite_set.remove s
- sprites.clear
-
- if text == null then return