Skip to content

Commit

Permalink
Use a SpinBox in the inspector array resize dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
fire-forge committed Jul 10, 2022
1 parent ccd9378 commit d6188b4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 38 deletions.
53 changes: 19 additions & 34 deletions editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1521,12 +1521,11 @@ void EditorInspectorArray::_rmb_popup_id_pressed(int p_id) {
_clear_array();
break;
case OPTION_RESIZE_ARRAY:
new_size = count;
new_size_line_edit->set_text(Variant(new_size));
new_size_spin_box->set_value(count);
resize_dialog->get_ok_button()->set_disabled(true);
resize_dialog->popup_centered();
new_size_line_edit->grab_focus();
new_size_line_edit->select_all();
resize_dialog->popup_centered(Size2i(250, 0) * EDSCALE);
new_size_spin_box->get_line_edit()->grab_focus();
new_size_spin_box->get_line_edit()->select_all();
break;
default:
break;
Expand Down Expand Up @@ -1852,36 +1851,21 @@ int EditorInspectorArray::_drop_position() const {
return -1;
}

void EditorInspectorArray::_new_size_line_edit_text_changed(String p_text) {
bool valid = false;
if (p_text.is_valid_int()) {
int val = p_text.to_int();
if (val > 0 && val != count) {
valid = true;
}
void EditorInspectorArray::_resize_dialog_confirmed() {
if (int(new_size_spin_box->get_value()) == count) {
return;
}
resize_dialog->get_ok_button()->set_disabled(!valid);

resize_dialog->hide();
_resize_array(int(new_size_spin_box->get_value()));
}

void EditorInspectorArray::_new_size_line_edit_text_submitted(String p_text) {
bool valid = false;
if (p_text.is_valid_int()) {
int val = p_text.to_int();
if (val > 0 && val != count) {
new_size = val;
valid = true;
}
}
if (valid) {
resize_dialog->hide();
_resize_array(new_size);
} else {
new_size_line_edit->set_text(Variant(new_size));
}
void EditorInspectorArray::_new_size_spin_box_value_changed(float p_value) {
resize_dialog->get_ok_button()->set_disabled(int(p_value) == count);
}

void EditorInspectorArray::_resize_dialog_confirmed() {
_new_size_line_edit_text_submitted(new_size_line_edit->get_text());
void EditorInspectorArray::_new_size_spin_box_text_submitted(String p_text) {
_resize_dialog_confirmed();
}

void EditorInspectorArray::_setup() {
Expand Down Expand Up @@ -2124,10 +2108,11 @@ EditorInspectorArray::EditorInspectorArray() {
VBoxContainer *resize_dialog_vbox = memnew(VBoxContainer);
resize_dialog->add_child(resize_dialog_vbox);

new_size_line_edit = memnew(LineEdit);
new_size_line_edit->connect("text_changed", callable_mp(this, &EditorInspectorArray::_new_size_line_edit_text_changed));
new_size_line_edit->connect("text_submitted", callable_mp(this, &EditorInspectorArray::_new_size_line_edit_text_submitted));
resize_dialog_vbox->add_margin_child(TTRC("New Size:"), new_size_line_edit);
new_size_spin_box = memnew(SpinBox);
new_size_spin_box->set_max(16384);
new_size_spin_box->connect("value_changed", callable_mp(this, &EditorInspectorArray::_new_size_spin_box_value_changed));
new_size_spin_box->get_line_edit()->connect("text_submitted", callable_mp(this, &EditorInspectorArray::_new_size_spin_box_text_submitted));
resize_dialog_vbox->add_margin_child(TTRC("New Size:"), new_size_spin_box);

vbox->connect("visibility_changed", callable_mp(this, &EditorInspectorArray::_vbox_visibility_changed));
}
Expand Down
8 changes: 4 additions & 4 deletions editor/editor_inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "scene/gui/option_button.h"
#include "scene/gui/panel_container.h"
#include "scene/gui/scroll_container.h"
#include "scene/gui/spin_box.h"
#include "scene/gui/texture_rect.h"

class UndoRedo;
Expand Down Expand Up @@ -319,8 +320,7 @@ class EditorInspectorArray : public EditorInspectorSection {
Button *add_button = nullptr;

AcceptDialog *resize_dialog = nullptr;
int new_size = 0;
LineEdit *new_size_line_edit = nullptr;
SpinBox *new_size_spin_box = nullptr;

// Pagination
int page_length = 5;
Expand Down Expand Up @@ -371,8 +371,8 @@ class EditorInspectorArray : public EditorInspectorSection {
Array _extract_properties_as_array(const List<PropertyInfo> &p_list);
int _drop_position() const;

void _new_size_line_edit_text_changed(String p_text);
void _new_size_line_edit_text_submitted(String p_text);
void _new_size_spin_box_value_changed(float p_value);
void _new_size_spin_box_text_submitted(String p_text);
void _resize_dialog_confirmed();

void _update_elements_visibility();
Expand Down

0 comments on commit d6188b4

Please sign in to comment.