summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
authorMicky <micheledevita2@gmail.com>2022-08-20 23:17:55 +0200
committerMicky <micheledevita2@gmail.com>2022-08-22 12:03:03 +0200
commit9a63792a08dc6a0c850add836a066222ef6b3b62 (patch)
tree6473d99e7c7f61480a18b450783d3977cd08fa36 /scene/gui
parent8a1e5980116355024cd7a7ce0c15db7d4ecb200a (diff)
Clamp Label's `percent_visible` properly between 0 and 1.0
Also applies to RichTextLabel
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/label.cpp8
-rw-r--r--scene/gui/rich_text_label.cpp10
2 files changed, 13 insertions, 5 deletions
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp
index e7f48beb00..4ef1e48a32 100644
--- a/scene/gui/label.cpp
+++ b/scene/gui/label.cpp
@@ -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;
}
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index 984f20ee58..ab466089a7 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -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();