summaryrefslogtreecommitdiff
path: root/scene/gui/label.cpp
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2016-07-19 07:38:06 +0200
committerGitHub <noreply@github.com>2016-07-19 07:38:06 +0200
commit17f86eee33c06b45457eeb2c154592e56fe31959 (patch)
tree3ddf75e0e1e6305c8fd09cbe416221242767e9c4 /scene/gui/label.cpp
parent569541bafcefb45f5fd94e54f5aeba5d8c25ae33 (diff)
parent78819b6b542ab4396d6909db7885498e0d692626 (diff)
Merge pull request #5792 from neikeq/pr-issue-3868
Label: Added `get_visible_line_count` method
Diffstat (limited to 'scene/gui/label.cpp')
-rw-r--r--scene/gui/label.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp
index 0431d824fa..4c025e92df 100644
--- a/scene/gui/label.cpp
+++ b/scene/gui/label.cpp
@@ -356,6 +356,21 @@ int Label::get_line_count() const {
return line_count;
}
+int Label::get_visible_line_count() const {
+
+ int line_spacing = get_constant("line_spacing");
+ int font_h = get_font("font")->get_height()+line_spacing;
+ int lines_visible = (get_size().y+line_spacing)/font_h;
+
+ if (lines_visible > line_count)
+ lines_visible = line_count;
+
+ if (max_lines_visible >= 0 && lines_visible > max_lines_visible)
+ lines_visible = max_lines_visible;
+
+ return lines_visible;
+}
+
void Label::regenerate_word_cache() {
while (word_cache) {
@@ -640,6 +655,7 @@ void Label::_bind_methods() {
ObjectTypeDB::bind_method(_MD("is_uppercase"),&Label::is_uppercase);
ObjectTypeDB::bind_method(_MD("get_line_height"),&Label::get_line_height);
ObjectTypeDB::bind_method(_MD("get_line_count"),&Label::get_line_count);
+ ObjectTypeDB::bind_method(_MD("get_visible_line_count"),&Label::get_visible_line_count);
ObjectTypeDB::bind_method(_MD("get_total_character_count"),&Label::get_total_character_count);
ObjectTypeDB::bind_method(_MD("set_visible_characters","amount"),&Label::set_visible_characters);
ObjectTypeDB::bind_method(_MD("get_visible_characters"),&Label::get_visible_characters);