diff --git a/doc/base/classes.xml b/doc/base/classes.xml
index 438ca6baa87..289c9869174 100644
--- a/doc/base/classes.xml
+++ b/doc/base/classes.xml
@@ -14976,26 +14976,28 @@
- Set the alignmend mode to any of the ALIGN_* enumeration values.
+ Sets the alignment mode to any of the ALIGN_* enumeration values.
- Return the alignmend mode (any of the ALIGN_* enumeration values).
+ Return the alignment mode (any of the ALIGN_* enumeration values).
+ Sets the vertical alignment mode to any of the VALIGN_* enumeration values.
+ Return the vertical alignment mode (any of the VALIGN_* enumeration values).
@@ -15026,16 +15028,32 @@
Return the state of the [i]autowrap[/i] mode (see [method set_autowrap]).
+
+
+
+
+ Cuts off the rest of the text if it is too wide.
+
+
+
+
+
+
+ Return true if text would be cut off if it is too wide.
+
+
+ Display text in all capitals.
+ Return true if text is displayed in all capitals.
@@ -15056,24 +15074,63 @@
+ Return the total length of the text.
-
+
+ Restricts the number of characters to display. Set to -1 to disable.
+
+
+
+
+
+
+ Return the restricted number of characters to display. Returns -1 if unrestricted.
+ Restricts the number of characters to display (as a percentage of the total text).
+ Return the restricted number of characters to display (as a percentage of the total text).
+
+
+
+
+
+
+ Restricts the number of lines to display. Set to -1 to disable.
+
+
+
+
+
+
+ Return the restricted number of lines to display. Returns -1 if unrestricted.
+
+
+
+
+
+
+ Sets the number of lines to skip before displaying. Useful for scrolling text.
+
+
+
+
+
+
+ Return the the number of lines to skipped before displaying.
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp
index e7af4fa3490..002e49cbcfb 100644
--- a/scene/gui/label.cpp
+++ b/scene/gui/label.cpp
@@ -33,15 +33,15 @@
void Label::set_autowrap(bool p_autowrap) {
-
+
autowrap=p_autowrap;
word_cache_dirty=true;
minimum_size_changed();
-
-
+ update();
+
}
bool Label::has_autowrap() const {
-
+
return autowrap;
}
@@ -51,6 +51,7 @@ void Label::set_uppercase(bool p_uppercase) {
uppercase=p_uppercase;
word_cache_dirty=true;
minimum_size_changed();
+ update();
}
bool Label::is_uppercase() const {
@@ -66,19 +67,18 @@ int Label::get_line_height() const {
void Label::_notification(int p_what) {
-
- if (p_what==NOTIFICATION_DRAW) {
-
- if (clip && !autowrap)
- VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(),true);
+ if (p_what==NOTIFICATION_DRAW) {
+
+ if (clip || autowrap)
+ VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(),true);
if (word_cache_dirty)
regenerate_word_cache();
-
+
RID ci = get_canvas_item();
-
+
Size2 string_size;
Size2 size=get_size();
@@ -91,38 +91,43 @@ void Label::_notification(int p_what) {
VisualServer::get_singleton()->canvas_item_set_distance_field_mode(get_canvas_item(),font.is_valid() && font->is_distance_field_hint());
int font_h = font->get_height();
- int line_from=(int)get_val(); // + p_exposed.pos.y / font_h;
int lines_visible = size.y/font_h;
- int line_to=(int)get_val() + lines_visible; //p_exposed.pos.y+p_exposed.size.height / font_h;
int space_w=font->get_char_size(' ').width;
- int lines_total = get_max();
int chars_total=0;
int vbegin=0,vsep=0;
-
- if (lines_total && lines_total < lines_visible) {
+ if (lines_visible > line_count) {
+ lines_visible = line_count;
+
+ }
+
+ if (max_lines_visible >= 0 && lines_visible > max_lines_visible) {
+ lines_visible = max_lines_visible;
+
+ }
+
+ if (lines_visible > 0) {
switch(valign) {
case VALIGN_TOP: {
-
//nothing
} break;
case VALIGN_CENTER: {
-
- vbegin=(lines_visible-lines_total) * font_h / 2;
+ vbegin=(size.y - lines_visible * font_h) / 2;
vsep=0;
+
} break;
case VALIGN_BOTTOM: {
- vbegin=(lines_visible-lines_total) * font_h;
+ vbegin=size.y - lines_visible * font_h;
vsep=0;
} break;
case VALIGN_FILL: {
vbegin=0;
- if (lines_total>1) {
- vsep=(lines_visible-lines_total) * font_h / (lines_total-1);
+ if (lines_visible>1) {
+ vsep=(size.y - lines_visible * font_h) / (lines_visible - 1);
} else {
vsep=0;
}
@@ -130,20 +135,21 @@ void Label::_notification(int p_what) {
} break;
}
}
-
-
+
+
WordCache *wc = word_cache;
if (!wc)
return;
-
+
int c = 0;
int line=0;
+ int line_to=lines_skipped + (lines_visible>0?lines_visible:1);
while(wc) {
/* handle lines not meant to be drawn quickly */
- if (line>line_to)
+ if (line>=line_to)
break;
- if (linechar_pos>=0)
wc=wc->next;
if (wc)
@@ -151,36 +157,36 @@ void Label::_notification(int p_what) {
line++;
continue;
}
-
+
/* handle lines normally */
-
+
if (wc->char_pos<0) {
//empty line
wc=wc->next;
line++;
continue;
}
-
+
WordCache *from=wc;
WordCache *to=wc;
-
+
int taken=0;
int spaces=0;
while(to && to->char_pos>=0) {
-
+
taken+=to->pixel_width;
if (to!=from && to->space_count) {
spaces+=to->space_count;
}
to=to->next;
}
-
+
bool can_fill = to && to->char_pos==WordCache::CHAR_WRAPLINE;
float x_ofs=0;
-
+
switch (align) {
-
+
case ALIGN_FILL:
case ALIGN_LEFT: {
@@ -198,16 +204,16 @@ void Label::_notification(int p_what) {
} break;
}
-
- int y_ofs=(line-(int)get_val())*font_h + font->get_ascent();
+
+ int y_ofs=(line-lines_skipped)*font_h + font->get_ascent();
y_ofs+=vbegin + line*vsep;
-
+
while(from!=to) {
-
+
// draw a word
int pos = from->char_pos;
if (from->char_pos<0) {
-
+
ERR_PRINT("BUG");
return;
}
@@ -221,15 +227,15 @@ void Label::_notification(int p_what) {
}
-
-
-
+
+
+
if (font_color_shadow.a>0) {
-
+
int chars_total_shadow = chars_total; //save chars drawn
float x_ofs_shadow=x_ofs;
for (int i=0;iword_len;i++) {
-
+
if (visible_chars < 0 || chars_total_shadowword_len;i++) {
@@ -268,73 +274,73 @@ void Label::_notification(int p_what) {
}
from=from->next;
}
-
+
wc=to?to->next:0;
line++;
-
- }
+
+ }
}
-
+
if (p_what==NOTIFICATION_THEME_CHANGED) {
word_cache_dirty=true;
update();
}
if (p_what==NOTIFICATION_RESIZED) {
-
+
word_cache_dirty=true;
}
-
+
}
Size2 Label::get_minimum_size() const {
-
+
if (autowrap)
return Size2(1,1);
else {
-
+
// don't want to mutable everything
- if(word_cache_dirty)
+ if(word_cache_dirty)
const_cast