diff options
Diffstat (limited to 'editor/editor_spin_slider.cpp')
-rw-r--r-- | editor/editor_spin_slider.cpp | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/editor/editor_spin_slider.cpp b/editor/editor_spin_slider.cpp index fbc4a5ee5c..9197546772 100644 --- a/editor/editor_spin_slider.cpp +++ b/editor/editor_spin_slider.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -31,6 +31,7 @@ #include "editor_spin_slider.h" #include "core/math/expression.h" #include "core/os/input.h" +#include "editor_node.h" #include "editor_scale.h" String EditorSpinSlider::get_tooltip(const Point2 &p_pos) const { @@ -185,6 +186,19 @@ void EditorSpinSlider::_notification(int p_what) { } } + if (p_what == NOTIFICATION_READY) { + // Add a left margin to the stylebox to make the number align with the Label + // when it's edited. The LineEdit "focus" stylebox uses the "normal" stylebox's + // default margins. + Ref<StyleBoxFlat> stylebox = + EditorNode::get_singleton()->get_theme_base()->get_stylebox("normal", "LineEdit")->duplicate(); + // EditorSpinSliders with a label have more space on the left, so add an + // higher margin to match the location where the text begins. + // The margin values below were determined by empirical testing. + stylebox->set_default_margin(MARGIN_LEFT, (get_label() != String() ? 23 : 16) * EDSCALE); + value_input->add_style_override("normal", stylebox); + } + if (p_what == NOTIFICATION_DRAW) { updown_offset = -1; @@ -200,7 +214,7 @@ void EditorSpinSlider::_notification(int p_what) { int string_width = font->get_string_size(label).width; int number_width = get_size().width - sb->get_minimum_size().width - string_width - sep; - Ref<Texture> updown = get_icon("updown", "SpinBox"); + Ref<Texture2D> updown = get_icon("updown", "SpinBox"); if (get_step() == 1) { number_width -= updown->get_width(); @@ -233,7 +247,7 @@ void EditorSpinSlider::_notification(int p_what) { draw_string(font, Vector2(Math::round(sb->get_offset().x + string_width + sep), vofs), numstr, fc, number_width); if (get_step() == 1) { - Ref<Texture> updown2 = get_icon("updown", "SpinBox"); + Ref<Texture2D> updown2 = get_icon("updown", "SpinBox"); int updown_vofs = (get_size().height - updown2->get_height()) / 2; updown_offset = get_size().width - sb->get_margin(MARGIN_RIGHT) - updown2->get_width(); Color c(1, 1, 1); @@ -268,7 +282,7 @@ void EditorSpinSlider::_notification(int p_what) { } if (display_grabber) { - Ref<Texture> grabber_tex; + Ref<Texture2D> grabber_tex; if (mouse_over_grabber) { grabber_tex = get_icon("grabber_highlight", "HSlider"); } else { @@ -476,9 +490,9 @@ EditorSpinSlider::EditorSpinSlider() { grabber->hide(); grabber->set_as_toplevel(true); grabber->set_mouse_filter(MOUSE_FILTER_STOP); - grabber->connect("mouse_entered", this, "_grabber_mouse_entered"); - grabber->connect("mouse_exited", this, "_grabber_mouse_exited"); - grabber->connect("gui_input", this, "_grabber_gui_input"); + grabber->connect_compat("mouse_entered", this, "_grabber_mouse_entered"); + grabber->connect_compat("mouse_exited", this, "_grabber_mouse_exited"); + grabber->connect_compat("gui_input", this, "_grabber_gui_input"); mouse_over_spin = false; mouse_over_grabber = false; mousewheel_over_grabber = false; @@ -488,9 +502,9 @@ EditorSpinSlider::EditorSpinSlider() { add_child(value_input); value_input->set_as_toplevel(true); value_input->hide(); - value_input->connect("modal_closed", this, "_value_input_closed"); - value_input->connect("text_entered", this, "_value_input_entered"); - value_input->connect("focus_exited", this, "_value_focus_exited"); + value_input->connect_compat("modal_closed", this, "_value_input_closed"); + value_input->connect_compat("text_entered", this, "_value_input_entered"); + value_input->connect_compat("focus_exited", this, "_value_focus_exited"); value_input_just_closed = false; hide_slider = false; read_only = false; |