From 9fdc4874b242d55696f0c0d8c15cf1408a6eaa28 Mon Sep 17 00:00:00 2001 From: toger5 Date: Fri, 4 Aug 2017 20:16:04 +0200 Subject: [PATCH] fixed Import LineEdit to label + label stylebox - added a normal stylebox to label. default is StyleBoxEmpty - changed drawing so that it draws correct with styleboxes with margins - changed the LineEdit in the import to use a label with the lineEdit stylebox --- editor/import_dock.cpp | 5 ++-- editor/import_dock.h | 2 +- scene/gui/label.cpp | 24 +++++++++++-------- .../resources/default_theme/default_theme.cpp | 1 + 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/editor/import_dock.cpp b/editor/import_dock.cpp index a4f744aa844..c8b259ab31e 100644 --- a/editor/import_dock.cpp +++ b/editor/import_dock.cpp @@ -28,6 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "import_dock.h" +#include "editor_node.h" class ImportDockParameters : public Object { GDCLASS(ImportDockParameters, Object) @@ -365,8 +366,8 @@ void ImportDock::initialize_import_options() const { ImportDock::ImportDock() { - imported = memnew(LineEdit); - imported->set_editable(false); + imported = memnew(Label); + imported->add_style_override("normal", EditorNode::get_singleton()->get_gui_base()->get_stylebox("normal", "LineEdit")); add_child(imported); HBoxContainer *hb = memnew(HBoxContainer); add_margin_child(TTR("Import As:"), hb); diff --git a/editor/import_dock.h b/editor/import_dock.h index 4844fc07ea2..e2956ea2d40 100644 --- a/editor/import_dock.h +++ b/editor/import_dock.h @@ -41,7 +41,7 @@ class ImportDockParameters; class ImportDock : public VBoxContainer { GDCLASS(ImportDock, VBoxContainer) - LineEdit *imported; + Label *imported; OptionButton *import_as; MenuButton *preset; PropertyEditor *import_opts; diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index 874156821ea..7234ff034e7 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -85,7 +85,7 @@ void Label::_notification(int p_what) { Size2 string_size; Size2 size = get_size(); - + Ref style = get_stylebox("normal"); Ref 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 style = get_stylebox("normal"); + int width = autowrap ? (get_size().width - style->get_minimum_size().width) : get_longest_line_width(); Ref font = get_font("font"); int current_word_size = 0; diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 03288e45bfb..545b86f7c60 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -408,6 +408,7 @@ void fill_default_theme(Ref &theme, const Ref &default_font, const // Label + theme->set_stylebox("normal", "Label", memnew(StyleBoxEmpty)); theme->set_font("font", "Label", default_font); theme->set_color("font_color", "Label", Color(1, 1, 1));