Keep RichTextLabel visible character properties in sync
The RichTextLabel class is inconsistent in how it updates the
visible_characters and percent_visible properties when either is changed.
To keep both properties consistent, update percent_visible when setting the
visible_characters property.
For both properties, when setting one, notify change for the other.
Docs updated for member set_visible_characters on RichTextLabel class.
(cherry picked from commit 463e2002ab
)
This commit is contained in:
parent
32a0a50fcf
commit
d73281a350
2 changed files with 11 additions and 0 deletions
|
@ -330,6 +330,7 @@
|
||||||
</member>
|
</member>
|
||||||
<member name="visible_characters" type="int" setter="set_visible_characters" getter="get_visible_characters" default="-1">
|
<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.
|
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>
|
</member>
|
||||||
</members>
|
</members>
|
||||||
<signals>
|
<signals>
|
||||||
|
|
|
@ -2688,6 +2688,7 @@ void RichTextLabel::set_percent_visible(float p_percent) {
|
||||||
visible_characters = get_total_character_count() * p_percent;
|
visible_characters = get_total_character_count() * p_percent;
|
||||||
percent_visible = p_percent;
|
percent_visible = p_percent;
|
||||||
}
|
}
|
||||||
|
_change_notify("visible_characters");
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2870,6 +2871,15 @@ void RichTextLabel::_bind_methods() {
|
||||||
|
|
||||||
void RichTextLabel::set_visible_characters(int p_visible) {
|
void RichTextLabel::set_visible_characters(int p_visible) {
|
||||||
visible_characters = 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();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue