Merge pull request #64670 from Mickeon/fix-label-visibile-percent

Clamp Label's `percent_visible` properly between 0 and 1.0
This commit is contained in:
Yuri Sizov 2022-08-22 15:41:31 +03:00 committed by GitHub
commit 69c9d1f8e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 6 deletions

View File

@ -481,7 +481,7 @@
If [code]true[/code], the label uses the custom font color.
</member>
<member name="percent_visible" type="float" setter="set_percent_visible" getter="get_percent_visible" default="1.0">
The range of characters to display, as a [float] between 0.0 and 1.0. When assigned an out of range value, it's the same as assigning 1.0.
The range of characters to display, as a [float] between 0.0 and 1.0.
[b]Note:[/b] Setting this property updates [member visible_characters] based on current [method get_total_character_count].
</member>
<member name="progress_bar_delay" type="int" setter="set_progress_bar_delay" getter="get_progress_bar_delay" default="1000">

View File

@ -764,13 +764,17 @@ int Label::get_visible_characters() const {
void Label::set_percent_visible(float p_percent) {
if (percent_visible != p_percent) {
if (p_percent < 0 || p_percent >= 1) {
if (percent_visible >= 1.0) {
visible_chars = -1;
percent_visible = 1;
percent_visible = 1.0;
} else if (percent_visible < 0.0) {
visible_chars = 0;
percent_visible = 0.0;
} else {
visible_chars = get_total_character_count() * p_percent;
percent_visible = p_percent;
}
if (visible_chars_behavior == TextServer::VC_CHARS_BEFORE_SHAPING) {
dirty = true;
}

View File

@ -4912,15 +4912,19 @@ void RichTextLabel::set_percent_visible(float p_percent) {
if (percent_visible != p_percent) {
_stop_thread();
if (p_percent < 0 || p_percent >= 1) {
if (percent_visible >= 1.0) {
visible_characters = -1;
percent_visible = 1;
percent_visible = 1.0;
} else if (percent_visible < 0.0) {
visible_characters = 0;
percent_visible = 0.0;
} else {
visible_characters = get_total_character_count() * p_percent;
percent_visible = p_percent;
}
if (visible_chars_behavior == TextServer::VC_CHARS_BEFORE_SHAPING) {
main->first_invalid_line.store(0); //invalidate ALL
main->first_invalid_line.store(0); // Invalidate ALL.
_validate_line_caches();
}
update();