diff options
author | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2016-07-18 23:31:06 +0200 |
---|---|---|
committer | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2016-07-18 23:33:06 +0200 |
commit | 78819b6b542ab4396d6909db7885498e0d692626 (patch) | |
tree | de39cb28bdeaa93d10041653ecc850b9999380a6 /scene | |
parent | 6a5e11c075b6bc48d23267c03a66e613dee2bf55 (diff) |
Label: Added `get_visible_line_count` method
Diffstat (limited to 'scene')
-rw-r--r-- | scene/gui/label.cpp | 16 | ||||
-rw-r--r-- | scene/gui/label.h | 1 |
2 files changed, 17 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); diff --git a/scene/gui/label.h b/scene/gui/label.h index 3c14add60d..b472eca1a2 100644 --- a/scene/gui/label.h +++ b/scene/gui/label.h @@ -132,6 +132,7 @@ public: int get_line_height() const; int get_line_count() const; + int get_visible_line_count() const; Label(const String& p_text=String()); ~Label(); |