Skip to content

Commit

Permalink
Merge pull request #91384 from kitbdev/fix-spin-slider-margin
Browse files Browse the repository at this point in the history
Fix editor spin slider RTL and margin
  • Loading branch information
akien-mga committed May 2, 2024
2 parents a7029e4 + 5fd2373 commit a531452
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions editor/gui/editor_spin_slider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,16 @@ void EditorSpinSlider::gui_input(const Ref<InputEvent> &p_event) {
if (mb.is_valid()) {
if (mb->get_button_index() == MouseButton::LEFT) {
if (mb->is_pressed()) {
if (updown_offset != -1 && mb->get_position().x > updown_offset) {
//there is an updown, so use it.
if (updown_offset != -1 && ((!is_layout_rtl() && mb->get_position().x > updown_offset) || (is_layout_rtl() && mb->get_position().x < updown_offset))) {
// Updown pressed.
if (mb->get_position().y < get_size().height / 2) {
set_value(get_value() + get_step());
} else {
set_value(get_value() - get_step());
}
return;
} else {
_grab_start();
}
_grab_start();
} else {
_grab_end();
}
Expand Down Expand Up @@ -121,7 +120,7 @@ void EditorSpinSlider::gui_input(const Ref<InputEvent> &p_event) {
}
}
} else if (updown_offset != -1) {
bool new_hover = (mm->get_position().x > updown_offset);
bool new_hover = (!is_layout_rtl() && mm->get_position().x > updown_offset) || (is_layout_rtl() && mm->get_position().x < updown_offset);
if (new_hover != hover_updown) {
hover_updown = new_hover;
queue_redraw();
Expand Down Expand Up @@ -296,11 +295,9 @@ void EditorSpinSlider::_update_value_input_stylebox() {
// higher margin to match the location where the text begins.
// The margin values below were determined by empirical testing.
if (is_layout_rtl()) {
stylebox->set_content_margin(SIDE_LEFT, 0);
stylebox->set_content_margin(SIDE_RIGHT, (!get_label().is_empty() ? 23 : 16) * EDSCALE);
} else {
stylebox->set_content_margin(SIDE_LEFT, (!get_label().is_empty() ? 23 : 16) * EDSCALE);
stylebox->set_content_margin(SIDE_RIGHT, 0);
}

value_input->add_theme_style_override("normal", stylebox);
Expand Down Expand Up @@ -394,6 +391,9 @@ void EditorSpinSlider::_draw_spin_slider() {
c *= Color(1.2, 1.2, 1.2);
}
draw_texture(updown2, Vector2(updown_offset, updown_vofs), c);
if (rtl) {
updown_offset += updown2->get_width();
}
if (grabber->is_visible()) {
grabber->hide();
}
Expand Down Expand Up @@ -705,6 +705,7 @@ void EditorSpinSlider::_ensure_input_popup() {
}

value_input_popup = memnew(Control);
value_input_popup->set_anchors_and_offsets_preset(PRESET_FULL_RECT);
add_child(value_input_popup);

value_input = memnew(LineEdit);
Expand Down

0 comments on commit a531452

Please sign in to comment.