Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix editor spin slider RTL and margin #91384

Merged
merged 1 commit into from
May 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading