aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic-extension/classes/GUITextLabel.hpp
blob: b29870e983e7b04b513d1330218dbacb7f340bd1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#pragma once

#include <godot_cpp/classes/rich_text_label.hpp>

#include <openvic-simulation/interface/GUI.hpp>

namespace OpenVic {
   class GUITextLabel : public godot::RichTextLabel {
      GDCLASS(GUITextLabel, godot::RichTextLabel)

      using colour_instructions_t = std::vector<std::pair<int64_t, char>>;

      GUI::Text const* PROPERTY(gui_text);

      godot::String PROPERTY(text);
      godot::Dictionary PROPERTY(substitution_dict);
      godot::HorizontalAlignment PROPERTY(alignment);
      real_t font_height;
      GFX::Font::colour_codes_t const* colour_codes;
      int32_t PROPERTY(max_lines);

      bool update_queued;

   protected:
      static void _bind_methods();

      void _notification(int what);

   public:
      GUITextLabel();

      /* Reset gui_text to nullptr and reset current text. */
      void clear();

      /* Set the GUI::Text. */
      godot::Error set_gui_text(GUI::Text const* new_gui_text);

      /* Return the name of the GUI::Text, or an empty String if it's null. */
      godot::String get_gui_text_name() const;

      void set_text(godot::String const& new_text);
      void add_substitution(godot::String const& key, godot::String const& value);
      void set_substitution_dict(godot::Dictionary const& new_substitution_dict);
      void clear_substitutions();

      /* Any text going over this number of lines will be trimmed and replaced with an ellipsis.
       * Values less than 1 indicate no limit. Default value: 1. */
      void set_max_lines(int32_t new_max_lines);

   private:
      godot::Error _update_font();

      void _queue_update();
      void _update_text();
      void _generate_text(godot::String const& display_text, colour_instructions_t const& colour_instructions);
   };
}