Added additional functions to RichTextLabel:

* Added set_text function to RichTextLabel
* Added percent_visible attributes and functions to RichTextLabel
This should make switching from Label to RichTextLabel easier.

(cherry picked from commit d649140b9b)
This commit is contained in:
TwistedTwigleg 2017-07-03 15:59:58 -04:00 committed by Rémi Verschelde
parent 9060a18639
commit 41b8a28c5f
2 changed files with 37 additions and 2 deletions

View File

@ -1829,12 +1829,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() {
ObjectTypeDB::bind_method(_MD("_input_event"), &RichTextLabel::_input_event);
ObjectTypeDB::bind_method(_MD("_scroll_changed"), &RichTextLabel::_scroll_changed);
ObjectTypeDB::bind_method(_MD("get_text"), &RichTextLabel::get_text);
ObjectTypeDB::bind_method(_MD("add_text", "text"), &RichTextLabel::add_text);
ObjectTypeDB::bind_method(_MD("set_text", "text"), &RichTextLabel::set_text);
ObjectTypeDB::bind_method(_MD("add_image", "image:Texture"), &RichTextLabel::add_image);
ObjectTypeDB::bind_method(_MD("newline"), &RichTextLabel::add_newline);
ObjectTypeDB::bind_method(_MD("remove_line"), &RichTextLabel::remove_line);
@ -1880,6 +1905,9 @@ void RichTextLabel::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_visible_characters", "amount"), &RichTextLabel::set_visible_characters);
ObjectTypeDB::bind_method(_MD("get_visible_characters"), &RichTextLabel::get_visible_characters);
ObjectTypeDB::bind_method(_MD("set_percent_visible", "percent_visible"), &RichTextLabel::set_percent_visible);
ObjectTypeDB::bind_method(_MD("get_percent_visible"), &RichTextLabel::get_percent_visible);
ObjectTypeDB::bind_method(_MD("get_total_character_count"), &RichTextLabel::get_total_character_count);
ObjectTypeDB::bind_method(_MD("set_use_bbcode", "enable"), &RichTextLabel::set_use_bbcode);
@ -1887,7 +1915,9 @@ void RichTextLabel::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "bbcode/enabled"), _SCS("set_use_bbcode"), _SCS("is_using_bbcode"));
ADD_PROPERTY(PropertyInfo(Variant::STRING, "bbcode/bbcode", PROPERTY_HINT_MULTILINE_TEXT), _SCS("set_bbcode"), _SCS("get_bbcode"));
ADD_PROPERTY(PropertyInfo(Variant::INT, "visible_characters", PROPERTY_HINT_RANGE, "-1,128000,1"), _SCS("set_visible_characters"), _SCS("get_visible_characters"));
ADD_PROPERTY(PropertyInfo(Variant::REAL, "percent_visible", PROPERTY_HINT_RANGE, "0,1,0.001"), _SCS("set_percent_visible"), _SCS("get_percent_visible"));
ADD_SIGNAL(MethodInfo("meta_clicked", PropertyInfo(Variant::NIL, "meta")));
@ -1920,7 +1950,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 {
@ -1970,9 +1999,9 @@ RichTextLabel::RichTextLabel() {
selection.enabled = false;
visible_characters = -1;
percent_visible = 1;
}
RichTextLabel::~RichTextLabel() {
memdelete(main);
}

View File

@ -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();
};