diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-09-06 20:34:24 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2016-09-06 20:34:24 -0300 |
commit | 405f6af79c32c575768f53661127cfd6aa4230f4 (patch) | |
tree | b6f145742a46aed20a01a1a76972813038d7362c | |
parent | 181fdce1e9c0b31f3a4ff14e25b2e0fec7108da0 (diff) |
-Added diectly editable expressions on node to VSEditor, closes #6392
-Added ability for LineEdit to expand to fit text
-rw-r--r-- | modules/visual_script/visual_script_editor.cpp | 41 | ||||
-rw-r--r-- | modules/visual_script/visual_script_editor.h | 1 | ||||
-rw-r--r-- | modules/visual_script/visual_script_expression.cpp | 2 | ||||
-rw-r--r-- | scene/gui/line_edit.cpp | 67 | ||||
-rw-r--r-- | scene/gui/line_edit.h | 8 |
5 files changed, 94 insertions, 25 deletions
diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 14708799af..acdcec7ae5 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -503,13 +503,21 @@ void VisualScriptEditor::_update_graph(int p_only_id) { } - Label *text = memnew( Label ); - text->set_text(node->get_text()); - gnode->add_child(text); if (node->cast_to<VisualScriptExpression>()) { - text->add_font_override("font",get_font("source","EditorFonts")); + + LineEdit *line_edit = memnew( LineEdit ); + line_edit->set_text(node->get_text()); + line_edit->set_expand_to_text_length(true); + line_edit->add_font_override("font",get_font("source","EditorFonts")); + gnode->add_child(line_edit); + line_edit->connect("text_changed",this,"_expression_text_changed",varray(E->get())); + } else { + Label *text = memnew( Label ); + text->set_text(node->get_text()); + gnode->add_child(text); } + if (node->cast_to<VisualScriptComment>()) { Ref<VisualScriptComment> vsc=node; gnode->set_comment(true); @@ -1201,6 +1209,30 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt } } +void VisualScriptEditor::_expression_text_changed(const String& p_text,int p_id) { + + Ref<VisualScriptExpression> vse = script->get_node(edited_func,p_id); + if (!vse.is_valid()) + return; + + + updating_graph=true; + + undo_redo->create_action(TTR("Change Expression"),UndoRedo::MERGE_ENDS); + undo_redo->add_do_property(vse.ptr(),"expression",p_text); + undo_redo->add_undo_property(vse.ptr(),"expression",vse->get("expression")); + undo_redo->add_do_method(this,"_update_graph",p_id); + undo_redo->add_undo_method(this,"_update_graph",p_id); + undo_redo->commit_action(); + + Node *node = graph->get_node(itos(p_id)); + if (node->cast_to<Control>()) + node->cast_to<Control>()->set_size(Vector2(1,1)); //shrink if text is smaller + + updating_graph=false; + +} + void VisualScriptEditor::_available_node_doubleclicked() { TreeItem *item = nodes->get_selected(); @@ -3224,6 +3256,7 @@ void VisualScriptEditor::_bind_methods() { ObjectTypeDB::bind_method("_button_resource_previewed",&VisualScriptEditor::_button_resource_previewed); ObjectTypeDB::bind_method("_port_action_menu",&VisualScriptEditor::_port_action_menu); ObjectTypeDB::bind_method("_selected_connect_node_method_or_setget",&VisualScriptEditor::_selected_connect_node_method_or_setget); + ObjectTypeDB::bind_method("_expression_text_changed",&VisualScriptEditor::_expression_text_changed); diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h index 5191ed540a..483ae1644c 100644 --- a/modules/visual_script/visual_script_editor.h +++ b/modules/visual_script/visual_script_editor.h @@ -168,6 +168,7 @@ class VisualScriptEditor : public ScriptEditorBase { void _member_button(Object *p_item, int p_column, int p_button); + void _expression_text_changed(const String& p_text,int p_id); String revert_on_drag; diff --git a/modules/visual_script/visual_script_expression.cpp b/modules/visual_script/visual_script_expression.cpp index f486cf1ab1..cc3b5f2174 100644 --- a/modules/visual_script/visual_script_expression.cpp +++ b/modules/visual_script/visual_script_expression.cpp @@ -120,7 +120,7 @@ void VisualScriptExpression::_get_property_list( List<PropertyInfo> *p_list) con argt+=","+Variant::get_type_name(Variant::Type(i)); } - p_list->push_back(PropertyInfo(Variant::STRING,"expression")); + p_list->push_back(PropertyInfo(Variant::STRING,"expression",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR)); p_list->push_back(PropertyInfo(Variant::INT,"out_type",PROPERTY_HINT_ENUM,argt)); p_list->push_back(PropertyInfo(Variant::INT,"input_count",PROPERTY_HINT_RANGE,"0,64,1")); p_list->push_back(PropertyInfo(Variant::BOOL,"sequenced")); diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 778e4cfa2a..c7a9a65632 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -193,8 +193,8 @@ void LineEdit::_input_event(InputEvent p_event) { } set_cursor_pos(0); - emit_signal("text_changed",text); - _change_notify("text"); + _text_changed(); + } @@ -215,8 +215,7 @@ void LineEdit::_input_event(InputEvent p_event) { selection_clear(); undo_text = text; text = text.substr(0,cursor_pos); - emit_signal("text_changed",text); - _change_notify("text"); + _text_changed(); } } break; @@ -475,9 +474,7 @@ void LineEdit::_input_event(InputEvent p_event) { selection_delete(); CharType ucodestr[2]={(CharType)k.unicode,0}; append_at_cursor(ucodestr); - emit_signal("text_changed",text); - _change_notify("text"); - + _text_changed(); accept_event(); } @@ -725,8 +722,7 @@ void LineEdit::paste_text() { if(selection.enabled) selection_delete(); append_at_cursor(paste_buffer); - emit_signal("text_changed",text); - _change_notify("text"); + _text_changed(); } @@ -750,9 +746,7 @@ void LineEdit::undo() { set_cursor_pos(old_cursor_pos); } - emit_signal("text_changed",text); - _change_notify("text"); - + _text_changed(); } void LineEdit::shift_selection_check_pre(bool p_shift) { @@ -881,8 +875,7 @@ void LineEdit::delete_char() { // set_window_pos(cursor_pos-get_window_length()); } - emit_signal("text_changed",text); - _change_notify("text"); + _text_changed(); } void LineEdit::delete_text(int p_from_column, int p_to_column) { @@ -914,8 +907,7 @@ void LineEdit::delete_text(int p_from_column, int p_to_column) { window_pos=cursor_pos; } - emit_signal("text_changed",text); - _change_notify("text"); + _text_changed(); } void LineEdit::set_text(String p_text) { @@ -930,8 +922,7 @@ void LineEdit::set_text(String p_text) { void LineEdit::clear() { clear_internal(); - emit_signal("text_changed",text); - _change_notify("text"); + _text_changed(); } String LineEdit::get_text() const { @@ -1070,7 +1061,17 @@ Size2 LineEdit::get_minimum_size() const { Size2 min=style->get_minimum_size(); min.height+=font->get_height(); - min.width+=get_constant("minimum_spaces")*font->get_char_size(' ').x; + + //minimum size of text + int space_size = font->get_char_size(' ').x; + int mstext = get_constant("minimum_spaces")*space_size; + + if (expand_to_text_length) { + mstext=MAX(mstext,font->get_string_size(text).x+space_size); //add a spce because some fonts are too exact + } + + min.width+=mstext; + return min; } @@ -1226,6 +1227,29 @@ PopupMenu *LineEdit::get_menu() const { } #endif + +void LineEdit::set_expand_to_text_length(bool p_len) { + + expand_to_text_length=p_len; + minimum_size_changed(); +} + +bool LineEdit::get_expand_to_text_length() const{ + + return expand_to_text_length; +} + + +void LineEdit::_text_changed() { + + if (expand_to_text_length) + minimum_size_changed(); + + emit_signal("text_changed",text); + _change_notify("text"); + +} + void LineEdit::_bind_methods() { ObjectTypeDB::bind_method(_MD("_toggle_draw_caret"),&LineEdit::_toggle_draw_caret); @@ -1248,6 +1272,8 @@ void LineEdit::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_placeholder_alpha"),&LineEdit::get_placeholder_alpha); ObjectTypeDB::bind_method(_MD("set_cursor_pos","pos"),&LineEdit::set_cursor_pos); ObjectTypeDB::bind_method(_MD("get_cursor_pos"),&LineEdit::get_cursor_pos); + ObjectTypeDB::bind_method(_MD("set_expand_to_text_length","pos"),&LineEdit::set_expand_to_text_length); + ObjectTypeDB::bind_method(_MD("get_expand_to_text_length"),&LineEdit::get_expand_to_text_length); ObjectTypeDB::bind_method(_MD("cursor_set_blink_enabled", "enable"),&LineEdit::cursor_set_blink_enabled); ObjectTypeDB::bind_method(_MD("cursor_get_blink_enabled"),&LineEdit::cursor_get_blink_enabled); ObjectTypeDB::bind_method(_MD("cursor_set_blink_speed", "blink_speed"),&LineEdit::cursor_set_blink_speed); @@ -1286,6 +1312,7 @@ void LineEdit::_bind_methods() { ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "max_length" ), _SCS("set_max_length"),_SCS("get_max_length") ); ADD_PROPERTYNO( PropertyInfo( Variant::BOOL, "editable" ), _SCS("set_editable"),_SCS("is_editable") ); ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "secret" ), _SCS("set_secret"),_SCS("is_secret") ); + ADD_PROPERTYNO( PropertyInfo( Variant::BOOL, "expand_to_len" ), _SCS("set_expand_to_text_length"),_SCS("get_expand_to_text_length") ); ADD_PROPERTY( PropertyInfo( Variant::INT,"focus_mode", PROPERTY_HINT_ENUM, "None,Click,All" ), _SCS("set_focus_mode"), _SCS("get_focus_mode") ); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret/caret_blink"), _SCS("cursor_set_blink_enabled"), _SCS("cursor_get_blink_enabled"));; ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "caret/caret_blink_speed",PROPERTY_HINT_RANGE,"0.1,10,0.1"), _SCS("cursor_set_blink_speed"),_SCS("cursor_get_blink_speed") ); @@ -1327,7 +1354,7 @@ LineEdit::LineEdit() { menu->add_separator(); menu->add_item(TTR("Undo"),MENU_UNDO,KEY_MASK_CMD|KEY_Z); menu->connect("item_pressed",this,"menu_option"); - + expand_to_text_length=false; } diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h index 112e4ad55e..47d5706bbe 100644 --- a/scene/gui/line_edit.h +++ b/scene/gui/line_edit.h @@ -90,6 +90,11 @@ private: } selection; Timer *caret_blink_timer; + + + void _text_changed(); + bool expand_to_text_length; + bool caret_blink_enabled; bool draw_caret; bool window_has_focus; @@ -169,6 +174,9 @@ public: virtual Size2 get_minimum_size() const; + void set_expand_to_text_length(bool p_len); + bool get_expand_to_text_length() const; + virtual bool is_text_field() const; LineEdit(); ~LineEdit(); |