Merge pull request #10096 from toger5/label_stylebox

fixed Import LineEdit to label + label stylebox
This commit is contained in:
Rémi Verschelde 2017-08-31 13:58:52 +02:00 committed by GitHub
commit b7f4dcbdd1
4 changed files with 19 additions and 13 deletions

View file

@ -28,6 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#include "import_dock.h" #include "import_dock.h"
#include "editor_node.h"
class ImportDockParameters : public Object { class ImportDockParameters : public Object {
GDCLASS(ImportDockParameters, Object) GDCLASS(ImportDockParameters, Object)
@ -365,8 +366,8 @@ void ImportDock::initialize_import_options() const {
ImportDock::ImportDock() { ImportDock::ImportDock() {
imported = memnew(LineEdit); imported = memnew(Label);
imported->set_editable(false); imported->add_style_override("normal", EditorNode::get_singleton()->get_gui_base()->get_stylebox("normal", "LineEdit"));
add_child(imported); add_child(imported);
HBoxContainer *hb = memnew(HBoxContainer); HBoxContainer *hb = memnew(HBoxContainer);
add_margin_child(TTR("Import As:"), hb); add_margin_child(TTR("Import As:"), hb);

View file

@ -41,7 +41,7 @@ class ImportDockParameters;
class ImportDock : public VBoxContainer { class ImportDock : public VBoxContainer {
GDCLASS(ImportDock, VBoxContainer) GDCLASS(ImportDock, VBoxContainer)
LineEdit *imported; Label *imported;
OptionButton *import_as; OptionButton *import_as;
MenuButton *preset; MenuButton *preset;
PropertyEditor *import_opts; PropertyEditor *import_opts;

View file

@ -85,7 +85,7 @@ void Label::_notification(int p_what) {
Size2 string_size; Size2 string_size;
Size2 size = get_size(); Size2 size = get_size();
Ref<StyleBox> style = get_stylebox("normal");
Ref<Font> font = get_font("font"); Ref<Font> font = get_font("font");
Color font_color = get_color("font_color"); Color font_color = get_color("font_color");
Color font_color_shadow = get_color("font_color_shadow"); 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")); Point2 shadow_ofs(get_constant("shadow_offset_x"), get_constant("shadow_offset_y"));
int line_spacing = get_constant("line_spacing"); 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()); 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; int font_h = font->get_height() + line_spacing;
@ -193,21 +195,20 @@ void Label::_notification(int p_what) {
case ALIGN_FILL: case ALIGN_FILL:
case ALIGN_LEFT: { case ALIGN_LEFT: {
x_ofs = 0; x_ofs = style->get_offset().x;
} break; } break;
case ALIGN_CENTER: { case ALIGN_CENTER: {
x_ofs = int(size.width - (taken + spaces * space_w)) / 2; x_ofs = int(size.width - (taken + spaces * space_w)) / 2;
} break; } break;
case ALIGN_RIGHT: { 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; } 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; y_ofs += vbegin + line * vsep;
while (from != to) { while (from != to) {
@ -288,8 +289,10 @@ void Label::_notification(int p_what) {
Size2 Label::get_minimum_size() const { Size2 Label::get_minimum_size() const {
Size2 min_style = get_stylebox("normal")->get_minimum_size();
if (autowrap) if (autowrap)
return Size2(1, clip ? 1 : minsize.height); return Size2(1, clip ? 1 : minsize.height) + min_style;
else { else {
// don't want to mutable everything // don't want to mutable everything
@ -299,7 +302,7 @@ Size2 Label::get_minimum_size() const {
Size2 ms = minsize; Size2 ms = minsize;
if (clip) if (clip)
ms.width = 1; 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 line_spacing = get_constant("line_spacing");
int font_h = get_font("font")->get_height() + 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) if (lines_visible > line_count)
lines_visible = line_count; lines_visible = line_count;
@ -370,7 +373,8 @@ void Label::regenerate_word_cache() {
memdelete(current); 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"); Ref<Font> font = get_font("font");
int current_word_size = 0; int current_word_size = 0;

View file

@ -408,6 +408,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
// Label // Label
theme->set_stylebox("normal", "Label", memnew(StyleBoxEmpty));
theme->set_font("font", "Label", default_font); theme->set_font("font", "Label", default_font);
theme->set_color("font_color", "Label", Color(1, 1, 1)); theme->set_color("font_color", "Label", Color(1, 1, 1));