Improve add item type UI in theme editor

This commit is contained in:
Haoyu Qiu 2021-07-20 13:52:22 +08:00
parent f131a77f46
commit 48af497e8c
2 changed files with 12 additions and 8 deletions

View file

@ -1375,12 +1375,15 @@ void ThemeItemEditorDialog::_item_tree_button_pressed(Object *p_item, int p_colu
_update_edit_item_tree(edited_item_type); _update_edit_item_tree(edited_item_type);
} }
void ThemeItemEditorDialog::_add_theme_type() { void ThemeItemEditorDialog::_add_theme_type(const String &p_new_text) {
edited_theme->add_icon_type(edit_add_type_value->get_text()); const String new_type = edit_add_type_value->get_text().strip_edges();
edited_theme->add_stylebox_type(edit_add_type_value->get_text()); edit_add_type_value->clear();
edited_theme->add_font_type(edit_add_type_value->get_text());
edited_theme->add_color_type(edit_add_type_value->get_text()); edited_theme->add_icon_type(new_type);
edited_theme->add_constant_type(edit_add_type_value->get_text()); edited_theme->add_stylebox_type(new_type);
edited_theme->add_font_type(new_type);
edited_theme->add_color_type(new_type);
edited_theme->add_constant_type(new_type);
_update_edit_types(); _update_edit_types();
// Force emit a change so that other parts of the editor can update. // Force emit a change so that other parts of the editor can update.
@ -1699,11 +1702,12 @@ ThemeItemEditorDialog::ThemeItemEditorDialog() {
edit_dialog_side_vb->add_child(edit_add_type_hb); edit_dialog_side_vb->add_child(edit_add_type_hb);
edit_add_type_value = memnew(LineEdit); edit_add_type_value = memnew(LineEdit);
edit_add_type_value->set_h_size_flags(Control::SIZE_EXPAND_FILL); edit_add_type_value->set_h_size_flags(Control::SIZE_EXPAND_FILL);
edit_add_type_value->connect("text_entered", this, "_add_theme_type");
edit_add_type_hb->add_child(edit_add_type_value); edit_add_type_hb->add_child(edit_add_type_value);
Button *edit_add_type_button = memnew(Button); Button *edit_add_type_button = memnew(Button);
edit_add_type_button->set_text(TTR("Add")); edit_add_type_button->set_text(TTR("Add"));
edit_add_type_hb->add_child(edit_add_type_button); edit_add_type_hb->add_child(edit_add_type_button);
edit_add_type_button->connect("pressed", this, "_add_theme_type"); edit_add_type_button->connect("pressed", this, "_add_theme_type", varray(""));
VBoxContainer *edit_items_vb = memnew(VBoxContainer); VBoxContainer *edit_items_vb = memnew(VBoxContainer);
edit_items_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL); edit_items_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);

View file

@ -230,7 +230,7 @@ class ThemeItemEditorDialog : public AcceptDialog {
void _update_edit_item_tree(String p_item_type); void _update_edit_item_tree(String p_item_type);
void _item_tree_button_pressed(Object *p_item, int p_column, int p_id); void _item_tree_button_pressed(Object *p_item, int p_column, int p_id);
void _add_theme_type(); void _add_theme_type(const String &p_new_text);
void _add_theme_item(Theme::DataType p_data_type, String p_item_name, String p_item_type); void _add_theme_item(Theme::DataType p_data_type, String p_item_name, String p_item_type);
void _remove_data_type_items(Theme::DataType p_data_type, String p_item_type); void _remove_data_type_items(Theme::DataType p_data_type, String p_item_type);
void _remove_class_items(); void _remove_class_items();