diff options
author | Zher Huei Lee <lee.zh.92@gmail.com> | 2015-09-08 10:10:58 +0100 |
---|---|---|
committer | Zher Huei Lee <lee.zh.92@gmail.com> | 2015-09-08 10:17:28 +0100 |
commit | 564f3e0302217695eb3eba4d1e148f677a8b75b4 (patch) | |
tree | 43799b148e183de46aeaea9bb336cb4cf71b1ede /scene | |
parent | a0ba13464362c286915f6a83702957668a50b62a (diff) |
fix minsize-related issues with Label
- fixed end of string adding to Label minsize
- exposed set_clip_text() and is_clipping_text() to the script side
- text would now never stick outside its boundaries
- label min-height is now restricted by max_lines_visible
Diffstat (limited to 'scene')
-rw-r--r-- | scene/gui/label.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index a20e8194ba..002e49cbcf 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -70,10 +70,9 @@ void Label::_notification(int p_what) { if (p_what==NOTIFICATION_DRAW) { - if (clip && !autowrap) + if (clip || autowrap) VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(),true); - if (word_cache_dirty) regenerate_word_cache(); @@ -317,9 +316,9 @@ int Label::get_longest_line_width() const { int max_line_width=0; int line_width=0; - for (int i=0;i<text.size()+1;i++) { + for (int i=0;i<text.size();i++) { - CharType current=i<text.length()?text[i]:' '; //always a space at the end, so the algo works + CharType current=text[i]; if (uppercase) current=String::char_uppercase(current); @@ -486,10 +485,11 @@ void Label::regenerate_word_cache() { if (!autowrap) { minsize.width=width; - minsize.height=font->get_height()*line_count; - } else { - minsize.width=0; - minsize.height=0; + if (max_lines_visible > 0 && line_count > max_lines_visible) { + minsize.height=font->get_height()*max_lines_visible; + } else { + minsize.height=font->get_height()*line_count; + } } word_cache_dirty=false; @@ -538,8 +538,6 @@ void Label::set_text(const String& p_string) { void Label::set_clip_text(bool p_clip) { - if (clip==p_clip) - return; clip=p_clip; update(); minimum_size_changed(); @@ -631,6 +629,8 @@ void Label::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_text"),&Label::get_text); ObjectTypeDB::bind_method(_MD("set_autowrap","enable"),&Label::set_autowrap); ObjectTypeDB::bind_method(_MD("has_autowrap"),&Label::has_autowrap); + ObjectTypeDB::bind_method(_MD("set_clip_text","enable"),&Label::set_clip_text); + ObjectTypeDB::bind_method(_MD("is_clipping_text"),&Label::is_clipping_text); ObjectTypeDB::bind_method(_MD("set_uppercase","enable"),&Label::set_uppercase); ObjectTypeDB::bind_method(_MD("is_uppercase"),&Label::is_uppercase); ObjectTypeDB::bind_method(_MD("get_line_height"),&Label::get_line_height); @@ -659,6 +659,7 @@ void Label::_bind_methods() { ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "align", PROPERTY_HINT_ENUM,"Left,Center,Right,Fill" ),_SCS("set_align"),_SCS("get_align") ); ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "valign", PROPERTY_HINT_ENUM,"Top,Center,Bottom,Fill" ),_SCS("set_valign"),_SCS("get_valign") ); ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "autowrap"),_SCS("set_autowrap"),_SCS("has_autowrap") ); + ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "clip_text"),_SCS("set_clip_text"),_SCS("is_clipping_text") ); ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "uppercase"),_SCS("set_uppercase"),_SCS("is_uppercase") ); ADD_PROPERTY( PropertyInfo( Variant::REAL, "percent_visible", PROPERTY_HINT_RANGE,"0,1,0.001"),_SCS("set_percent_visible"),_SCS("get_percent_visible") ); ADD_PROPERTY( PropertyInfo( Variant::INT, "lines_skipped", PROPERTY_HINT_RANGE,"0,999,1"),_SCS("set_lines_skipped"),_SCS("get_lines_skipped") ); |