Browse Source

Add a margin to EditorSpinSlider to visually line up the edited number

This means clicking on an EditorSpinSlider to edit its value will
no longer cause the number to be visually offset while it's
being edited.

(cherry picked from commit cc615fee5f88d543fb5877ddd0207b832772f7fe)
Hugo Locurcio 5 năm trước cách đây
mục cha
commit
3bdb39bec4
1 tập tin đã thay đổi với 14 bổ sung0 xóa
  1. 14 0
      editor/editor_spin_slider.cpp

+ 14 - 0
editor/editor_spin_slider.cpp

@@ -31,6 +31,7 @@
 #include "editor_spin_slider.h"
 #include "editor_spin_slider.h"
 #include "core/math/expression.h"
 #include "core/math/expression.h"
 #include "core/os/input.h"
 #include "core/os/input.h"
+#include "editor_node.h"
 #include "editor_scale.h"
 #include "editor_scale.h"
 
 
 String EditorSpinSlider::get_tooltip(const Point2 &p_pos) const {
 String EditorSpinSlider::get_tooltip(const Point2 &p_pos) const {
@@ -203,6 +204,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) {
 	if (p_what == NOTIFICATION_DRAW) {
 
 
 		updown_offset = -1;
 		updown_offset = -1;