summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Verschelde <remi@verschelde.fr>2021-01-15 00:59:26 +0100
committerGitHub <noreply@github.com>2021-01-15 00:59:26 +0100
commit64ba83a096783c7bb3d4c20c6bec29699687d228 (patch)
treef3efb6816478bd2caa89b01565ab8ddc4ef56a48
parent011d201046d3957e5232435fd560f803798c26f9 (diff)
parent463e2002abc0ecd7439fbf00966cef83842babce (diff)
downloadredot-engine-64ba83a096783c7bb3d4c20c6bec29699687d228.tar.gz
Merge pull request #44870 from alexpech12/fix-rich-text-label-set-visible-characters
Keep RichTextLabel visible character properties in sync
-rw-r--r--doc/classes/RichTextLabel.xml1
-rw-r--r--scene/gui/rich_text_label.cpp10
2 files changed, 11 insertions, 0 deletions
diff --git a/doc/classes/RichTextLabel.xml b/doc/classes/RichTextLabel.xml
index 147e41bf1b..a182abc17b 100644
--- a/doc/classes/RichTextLabel.xml
+++ b/doc/classes/RichTextLabel.xml
@@ -455,6 +455,7 @@
</member>
<member name="visible_characters" type="int" setter="set_visible_characters" getter="get_visible_characters" default="-1">
The restricted number of characters to display in the label. If [code]-1[/code], all characters will be displayed.
+ [b]Note:[/b] Setting this property updates [member percent_visible] based on current [method get_total_character_count].
</member>
</members>
<signals>
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index a1aa72b29a..05ca97491b 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -3677,6 +3677,7 @@ void RichTextLabel::set_percent_visible(float p_percent) {
}
main->first_invalid_line = 0; //invalidate ALL
_validate_line_caches(main);
+ _change_notify("visible_characters");
update();
}
}
@@ -3890,6 +3891,15 @@ void RichTextLabel::_bind_methods() {
void RichTextLabel::set_visible_characters(int p_visible) {
visible_characters = p_visible;
+ if (p_visible == -1) {
+ percent_visible = 1;
+ } else {
+ int total_char_count = get_total_character_count();
+ if (total_char_count > 0) {
+ percent_visible = (float)p_visible / (float)total_char_count;
+ }
+ }
+ _change_notify("percent_visible");
update();
}