summaryrefslogtreecommitdiff
path: root/scene/gui/label.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/label.cpp')
-rw-r--r--scene/gui/label.cpp28
1 files changed, 16 insertions, 12 deletions
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp
index cf7303cbe7..e1f77594da 100644
--- a/scene/gui/label.cpp
+++ b/scene/gui/label.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -85,7 +85,7 @@ void Label::_notification(int p_what) {
Size2 string_size;
Size2 size = get_size();
-
+ Ref<StyleBox> style = get_stylebox("normal");
Ref<Font> font = get_font("font");
Color font_color = get_color("font_color");
Color font_color_shadow = get_color("font_color_shadow");
@@ -93,6 +93,8 @@ void Label::_notification(int p_what) {
Point2 shadow_ofs(get_constant("shadow_offset_x"), get_constant("shadow_offset_y"));
int line_spacing = get_constant("line_spacing");
+ style->draw(ci, Rect2(Point2(0, 0), get_size()));
+
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() + line_spacing;
@@ -193,21 +195,20 @@ void Label::_notification(int p_what) {
case ALIGN_FILL:
case ALIGN_LEFT: {
- x_ofs = 0;
+ x_ofs = style->get_offset().x;
} break;
case ALIGN_CENTER: {
x_ofs = int(size.width - (taken + spaces * space_w)) / 2;
-
} break;
case ALIGN_RIGHT: {
- x_ofs = int(size.width - (taken + spaces * space_w));
-
+ x_ofs = int(size.width - style->get_margin(MARGIN_RIGHT) - (taken + spaces * space_w));
} break;
}
- int y_ofs = (line - lines_skipped) * font_h + font->get_ascent();
+ int y_ofs = style->get_offset().y;
+ y_ofs += (line - lines_skipped) * font_h + font->get_ascent();
y_ofs += vbegin + line * vsep;
while (from != to) {
@@ -288,8 +289,10 @@ void Label::_notification(int p_what) {
Size2 Label::get_minimum_size() const {
+ Size2 min_style = get_stylebox("normal")->get_minimum_size();
+
if (autowrap)
- return Size2(1, clip ? 1 : minsize.height);
+ return Size2(1, clip ? 1 : minsize.height) + min_style;
else {
// don't want to mutable everything
@@ -299,7 +302,7 @@ Size2 Label::get_minimum_size() const {
Size2 ms = minsize;
if (clip)
ms.width = 1;
- return ms;
+ return ms + min_style;
}
}
@@ -350,7 +353,7 @@ 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;
+ int lines_visible = (get_size().height - get_stylebox("normal")->get_minimum_size().height + line_spacing) / font_h;
if (lines_visible > line_count)
lines_visible = line_count;
@@ -370,7 +373,8 @@ void Label::regenerate_word_cache() {
memdelete(current);
}
- int width = autowrap ? get_size().width : get_longest_line_width();
+ Ref<StyleBox> style = get_stylebox("normal");
+ int width = autowrap ? (get_size().width - style->get_minimum_size().width) : get_longest_line_width();
Ref<Font> font = get_font("font");
int current_word_size = 0;
@@ -397,7 +401,7 @@ void Label::regenerate_word_cache() {
bool separatable = (current >= 0x2E08 && current <= 0xFAFF) || (current >= 0xFE30 && current <= 0xFE4F);
//current>=33 && (current < 65||current >90) && (current<97||current>122) && (current<48||current>57);
bool insert_newline = false;
- int char_width;
+ int char_width = 0;
if (current < 33) {