diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2020-02-15 12:07:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-15 12:07:11 +0100 |
commit | 8aad43e0c12c4e85afa00fb7d8c59891190031ce (patch) | |
tree | 1b20b86c56b6538ea8b893912a8b0c4308af4f3c /editor/editor_spin_slider.cpp | |
parent | 7b6251d1886fa419e9be374cca0d2c40aa18dd24 (diff) | |
parent | cc615fee5f88d543fb5877ddd0207b832772f7fe (diff) |
Merge pull request #36231 from Calinou/editorspinslider-add-left-margin
Add a margin to EditorSpinSlider to visually line up the edited number
Diffstat (limited to 'editor/editor_spin_slider.cpp')
-rw-r--r-- | editor/editor_spin_slider.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/editor/editor_spin_slider.cpp b/editor/editor_spin_slider.cpp index bb8bcdfe6c..bdd5c57b43 100644 --- a/editor/editor_spin_slider.cpp +++ b/editor/editor_spin_slider.cpp @@ -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; |