summaryrefslogtreecommitdiffstats
path: root/scene/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/base_button.cpp1
-rw-r--r--scene/gui/code_edit.cpp4
-rw-r--r--scene/gui/graph_edit.cpp2
-rw-r--r--scene/gui/option_button.cpp2
-rw-r--r--scene/gui/popup_menu.cpp18
-rw-r--r--scene/gui/spin_box.cpp38
-rw-r--r--scene/gui/spin_box.h2
-rw-r--r--scene/gui/text_edit.cpp7
8 files changed, 55 insertions, 19 deletions
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp
index 1a168ff994..77fb6547ae 100644
--- a/scene/gui/base_button.cpp
+++ b/scene/gui/base_button.cpp
@@ -207,6 +207,7 @@ void BaseButton::set_disabled(bool p_disabled) {
status.pressing_inside = false;
}
queue_redraw();
+ update_minimum_size();
}
bool BaseButton::is_disabled() const {
diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp
index da59dac3b9..090bdee26f 100644
--- a/scene/gui/code_edit.cpp
+++ b/scene/gui/code_edit.cpp
@@ -1500,9 +1500,9 @@ void CodeEdit::_line_number_draw_callback(int p_line, int p_gutter, const Rect2
ofs.y += TS->shaped_text_get_ascent(text_rid);
if (rtl) {
- ofs.x = p_region.position.x;
- } else {
ofs.x = p_region.get_end().x - text_size.width;
+ } else {
+ ofs.x = p_region.position.x;
}
Color number_color = get_line_gutter_item_color(p_line, line_number_gutter);
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
index d717e6132e..e60e3cbcd9 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -3003,5 +3003,5 @@ GraphEdit::GraphEdit() {
set_clip_contents(true);
- arranger = Ref<GraphEditArranger>(memnew(GraphEditArranger(this)));
+ arranger.instantiate(this);
}
diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp
index 5d62fe39ef..eddaeb3826 100644
--- a/scene/gui/option_button.cpp
+++ b/scene/gui/option_button.cpp
@@ -180,7 +180,7 @@ bool OptionButton::_set(const StringName &p_name, const Variant &p_value) {
}
void OptionButton::_focused(int p_which) {
- emit_signal(SNAME("item_focused"), p_which);
+ emit_signal(SNAME("item_focused"), popup->get_item_index(p_which));
}
void OptionButton::_selected(int p_which) {
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp
index fd135119e3..82aebcd2a5 100644
--- a/scene/gui/popup_menu.cpp
+++ b/scene/gui/popup_menu.cpp
@@ -476,7 +476,7 @@ void PopupMenu::_input_from_window_internal(const Ref<InputEvent> &p_event) {
for (int i = search_from; i < items.size(); i++) {
if (!items[i].separator && !items[i].disabled) {
mouse_over = i;
- emit_signal(SNAME("id_focused"), i);
+ emit_signal(SNAME("id_focused"), items[i].id);
scroll_to_item(i);
control->queue_redraw();
set_input_as_handled();
@@ -490,7 +490,7 @@ void PopupMenu::_input_from_window_internal(const Ref<InputEvent> &p_event) {
for (int i = 0; i < search_from; i++) {
if (!items[i].separator && !items[i].disabled) {
mouse_over = i;
- emit_signal(SNAME("id_focused"), i);
+ emit_signal(SNAME("id_focused"), items[i].id);
scroll_to_item(i);
control->queue_redraw();
set_input_as_handled();
@@ -514,7 +514,7 @@ void PopupMenu::_input_from_window_internal(const Ref<InputEvent> &p_event) {
for (int i = search_from; i >= 0; i--) {
if (!items[i].separator && !items[i].disabled) {
mouse_over = i;
- emit_signal(SNAME("id_focused"), i);
+ emit_signal(SNAME("id_focused"), items[i].id);
scroll_to_item(i);
control->queue_redraw();
set_input_as_handled();
@@ -528,7 +528,7 @@ void PopupMenu::_input_from_window_internal(const Ref<InputEvent> &p_event) {
for (int i = items.size() - 1; i >= search_from; i--) {
if (!items[i].separator && !items[i].disabled) {
mouse_over = i;
- emit_signal(SNAME("id_focused"), i);
+ emit_signal(SNAME("id_focused"), items[i].id);
scroll_to_item(i);
control->queue_redraw();
set_input_as_handled();
@@ -694,7 +694,7 @@ void PopupMenu::_input_from_window_internal(const Ref<InputEvent> &p_event) {
if (items[i].text.findn(search_string) == 0) {
mouse_over = i;
- emit_signal(SNAME("id_focused"), i);
+ emit_signal(SNAME("id_focused"), items[i].id);
scroll_to_item(i);
control->queue_redraw();
set_input_as_handled();
@@ -1093,7 +1093,7 @@ void PopupMenu::_notification(int p_what) {
for (int i = search_from; i < items.size(); i++) {
if (!items[i].separator && !items[i].disabled) {
mouse_over = i;
- emit_signal(SNAME("id_focused"), i);
+ emit_signal(SNAME("id_focused"), items[i].id);
scroll_to_item(i);
control->queue_redraw();
match_found = true;
@@ -1106,7 +1106,7 @@ void PopupMenu::_notification(int p_what) {
for (int i = 0; i < search_from; i++) {
if (!items[i].separator && !items[i].disabled) {
mouse_over = i;
- emit_signal(SNAME("id_focused"), i);
+ emit_signal(SNAME("id_focused"), items[i].id);
scroll_to_item(i);
control->queue_redraw();
break;
@@ -1126,7 +1126,7 @@ void PopupMenu::_notification(int p_what) {
for (int i = search_from; i >= 0; i--) {
if (!items[i].separator && !items[i].disabled) {
mouse_over = i;
- emit_signal(SNAME("id_focused"), i);
+ emit_signal(SNAME("id_focused"), items[i].id);
scroll_to_item(i);
control->queue_redraw();
match_found = true;
@@ -1139,7 +1139,7 @@ void PopupMenu::_notification(int p_what) {
for (int i = items.size() - 1; i >= search_from; i--) {
if (!items[i].separator && !items[i].disabled) {
mouse_over = i;
- emit_signal(SNAME("id_focused"), i);
+ emit_signal(SNAME("id_focused"), items[i].id);
scroll_to_item(i);
control->queue_redraw();
break;
diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp
index e6bd7d46a0..895f9907ad 100644
--- a/scene/gui/spin_box.cpp
+++ b/scene/gui/spin_box.cpp
@@ -43,7 +43,11 @@ Size2 SpinBox::get_minimum_size() const {
}
void SpinBox::_update_text(bool p_keep_line_edit) {
- String value = String::num(get_value(), Math::range_step_decimals(get_step()));
+ double step = get_step();
+ if (use_custom_arrow_step && custom_arrow_step != 0.0) {
+ step = custom_arrow_step;
+ }
+ String value = String::num(get_value(), Math::range_step_decimals(step));
if (is_localizing_numeral_system()) {
value = TS->format_number(value);
}
@@ -77,6 +81,9 @@ void SpinBox::_text_submitted(const String &p_string) {
text = text.trim_prefix(prefix + " ").trim_suffix(" " + suffix);
Error err = expr->parse(text);
+
+ use_custom_arrow_step = false;
+
if (err != OK) {
// If the expression failed try without converting commas to dots - they might have been for parameter separation.
text = p_string;
@@ -116,8 +123,13 @@ void SpinBox::_line_edit_input(const Ref<InputEvent> &p_event) {
void SpinBox::_range_click_timeout() {
if (!drag.enabled && Input::get_singleton()->is_mouse_button_pressed(MouseButton::LEFT)) {
bool up = get_local_mouse_position().y < (get_size().height / 2);
- double step = get_custom_arrow_step() != 0.0 ? get_custom_arrow_step() : get_step();
- set_value(get_value() + (up ? step : -step));
+ double step = get_step();
+ // Arrow button is being pressed, so we also need to set the step to the same value as custom_arrow_step if its not 0.
+ double temp_step = get_custom_arrow_step() != 0.0 ? get_custom_arrow_step() : get_step();
+ _set_step_no_signal(temp_step);
+ set_value(get_value() + (up ? temp_step : -temp_step));
+ _set_step_no_signal(step);
+ use_custom_arrow_step = true;
if (range_click_timer->is_one_shot()) {
range_click_timer->set_wait_time(0.075);
@@ -158,8 +170,7 @@ void SpinBox::gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseButton> mb = p_event;
Ref<InputEventMouseMotion> mm = p_event;
- double step = get_custom_arrow_step() != 0.0 ? get_custom_arrow_step() : get_step();
-
+ double step = get_step();
Vector2 mpos;
bool mouse_on_up_button = false;
bool mouse_on_down_button = false;
@@ -179,7 +190,12 @@ void SpinBox::gui_input(const Ref<InputEvent> &p_event) {
line_edit->grab_focus();
if (mouse_on_up_button || mouse_on_down_button) {
- set_value(get_value() + (mouse_on_up_button ? step : -step));
+ // Arrow button is being pressed, so step is being changed temporarily.
+ double temp_step = get_custom_arrow_step() != 0.0 ? get_custom_arrow_step() : get_step();
+ _set_step_no_signal(temp_step);
+ set_value(get_value() + (mouse_on_up_button ? temp_step : -temp_step));
+ _set_step_no_signal(step);
+ use_custom_arrow_step = true;
}
state_cache.up_button_pressed = mouse_on_up_button;
state_cache.down_button_pressed = mouse_on_down_button;
@@ -195,17 +211,20 @@ void SpinBox::gui_input(const Ref<InputEvent> &p_event) {
case MouseButton::RIGHT: {
line_edit->grab_focus();
if (mouse_on_up_button || mouse_on_down_button) {
+ use_custom_arrow_step = false;
set_value(mouse_on_up_button ? get_max() : get_min());
}
} break;
case MouseButton::WHEEL_UP: {
if (line_edit->is_editing()) {
+ use_custom_arrow_step = false;
set_value(get_value() + step * mb->get_factor());
accept_event();
}
} break;
case MouseButton::WHEEL_DOWN: {
if (line_edit->is_editing()) {
+ use_custom_arrow_step = false;
set_value(get_value() - step * mb->get_factor());
accept_event();
}
@@ -245,6 +264,7 @@ void SpinBox::gui_input(const Ref<InputEvent> &p_event) {
if (drag.enabled) {
drag.diff_y += mm->get_relative().y;
double diff_y = -0.01 * Math::pow(ABS(drag.diff_y), 1.8) * SIGN(drag.diff_y);
+ use_custom_arrow_step = false;
set_value(CLAMP(drag.base_val + step * diff_y, get_min(), get_max()));
} else if (drag.allowed && drag.capture_pos.distance_to(mm->get_position()) > 2) {
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
@@ -521,6 +541,12 @@ void SpinBox::_update_buttons_state_for_current_value() {
}
}
+void SpinBox::_set_step_no_signal(double p_step) {
+ set_block_signals(true);
+ set_step(p_step);
+ set_block_signals(false);
+}
+
void SpinBox::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_horizontal_alignment", "alignment"), &SpinBox::set_horizontal_alignment);
ClassDB::bind_method(D_METHOD("get_horizontal_alignment"), &SpinBox::get_horizontal_alignment);
diff --git a/scene/gui/spin_box.h b/scene/gui/spin_box.h
index 5aa2b5fa36..17efa331cf 100644
--- a/scene/gui/spin_box.h
+++ b/scene/gui/spin_box.h
@@ -68,6 +68,7 @@ class SpinBox : public Range {
String suffix;
String last_updated_text;
double custom_arrow_step = 0.0;
+ bool use_custom_arrow_step = false;
void _line_edit_input(const Ref<InputEvent> &p_event);
@@ -135,6 +136,7 @@ class SpinBox : public Range {
void _mouse_exited();
void _update_buttons_state_for_current_value();
+ void _set_step_no_signal(double p_step);
protected:
virtual void gui_input(const Ref<InputEvent> &p_event) override;
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index dcf8dcac26..526c2a9b36 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -334,6 +334,7 @@ void TextEdit::Text::clear() {
max_line_width_dirty = true;
max_line_height_dirty = true;
+ total_visible_line_count = 0;
Line line;
line.gutters.resize(gutter_count);
@@ -423,6 +424,10 @@ void TextEdit::Text::remove_range(int p_from_line, int p_to_line) {
for (int i = p_from_line; i < p_to_line; i++) {
const Line &text_line = text[i];
+ if (text_line.hidden) {
+ continue;
+ }
+
if (text_line.height == max_line_height) {
max_line_height_dirty = true;
}
@@ -437,6 +442,8 @@ void TextEdit::Text::remove_range(int p_from_line, int p_to_line) {
text.write[(i - diff) + 1] = text[i + 1];
}
text.resize(text.size() - diff);
+
+ ERR_FAIL_COND(total_visible_line_count < 0); // BUG
}
void TextEdit::Text::add_gutter(int p_at) {