diff options
-rw-r--r-- | scene/gui/rich_text_label.cpp | 33 | ||||
-rw-r--r-- | scene/gui/rich_text_label.h | 6 |
2 files changed, 37 insertions, 2 deletions
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 78ede6e494..c6b8398736 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -1822,12 +1822,37 @@ String RichTextLabel::get_text() { return text; } +void RichTextLabel::set_text(const String &p_string) { + clear(); + add_text(p_string); +} + +void RichTextLabel::set_percent_visible(float p_percent) { + + if (p_percent < 0 || p_percent >= 1) { + + visible_characters = -1; + percent_visible = 1; + + } else { + + visible_characters = get_total_character_count() * p_percent; + percent_visible = p_percent; + } + update(); +} + +float RichTextLabel::get_percent_visible() const { + return percent_visible; +} + void RichTextLabel::_bind_methods() { ClassDB::bind_method(D_METHOD("_gui_input"), &RichTextLabel::_gui_input); ClassDB::bind_method(D_METHOD("_scroll_changed"), &RichTextLabel::_scroll_changed); ClassDB::bind_method(D_METHOD("get_text"), &RichTextLabel::get_text); ClassDB::bind_method(D_METHOD("add_text", "text"), &RichTextLabel::add_text); + ClassDB::bind_method(D_METHOD("set_text", "text"), &RichTextLabel::set_text); ClassDB::bind_method(D_METHOD("add_image", "image:Texture"), &RichTextLabel::add_image); ClassDB::bind_method(D_METHOD("newline"), &RichTextLabel::add_newline); ClassDB::bind_method(D_METHOD("remove_line"), &RichTextLabel::remove_line); @@ -1873,6 +1898,9 @@ void RichTextLabel::_bind_methods() { ClassDB::bind_method(D_METHOD("set_visible_characters", "amount"), &RichTextLabel::set_visible_characters); ClassDB::bind_method(D_METHOD("get_visible_characters"), &RichTextLabel::get_visible_characters); + ClassDB::bind_method(D_METHOD("set_percent_visible", "percent_visible"), &RichTextLabel::set_percent_visible); + ClassDB::bind_method(D_METHOD("get_percent_visible"), &RichTextLabel::get_percent_visible); + ClassDB::bind_method(D_METHOD("get_total_character_count"), &RichTextLabel::get_total_character_count); ClassDB::bind_method(D_METHOD("set_use_bbcode", "enable"), &RichTextLabel::set_use_bbcode); @@ -1881,7 +1909,9 @@ void RichTextLabel::_bind_methods() { ADD_GROUP("BBCode", "bbcode_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "bbcode_enabled"), "set_use_bbcode", "is_using_bbcode"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "bbcode_text", PROPERTY_HINT_MULTILINE_TEXT), "set_bbcode", "get_bbcode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "visible_characters", PROPERTY_HINT_RANGE, "-1,128000,1"), "set_visible_characters", "get_visible_characters"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "percent_visible", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_percent_visible", "get_percent_visible"); ADD_SIGNAL(MethodInfo("meta_clicked", PropertyInfo(Variant::NIL, "meta"))); @@ -1914,7 +1944,6 @@ void RichTextLabel::set_visible_characters(int p_visible) { } int RichTextLabel::get_visible_characters() const { - return visible_characters; } int RichTextLabel::get_total_character_count() const { @@ -1964,11 +1993,11 @@ RichTextLabel::RichTextLabel() { selection.enabled = false; visible_characters = -1; + percent_visible = 1; set_clip_contents(true); } RichTextLabel::~RichTextLabel() { - memdelete(main); } diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index eedb7e54db..409a8f6b3f 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -258,6 +258,7 @@ private: Selection selection; int visible_characters; + float percent_visible; void _process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &y, int p_width, int p_line, ProcessMode p_mode, const Ref<Font> &p_base_font, const Color &p_base_color, const Point2i &p_click_pos = Point2i(), Item **r_click_item = NULL, int *r_click_char = NULL, bool *r_outside = NULL, int p_char_count = 0); void _find_click(ItemFrame *p_frame, const Point2i &p_click, Item **r_click_item = NULL, int *r_click_char = NULL, bool *r_outside = NULL); @@ -340,10 +341,15 @@ public: void set_bbcode(const String &p_bbcode); String get_bbcode() const; + void set_text(const String &p_string); + void set_visible_characters(int p_visible); int get_visible_characters() const; int get_total_character_count() const; + void set_percent_visible(float p_percent); + float get_percent_visible() const; + RichTextLabel(); ~RichTextLabel(); }; |