-Added diectly editable expressions on node to VSEditor, closes #6392
-Added ability for LineEdit to expand to fit text
This commit is contained in:
parent
181fdce1e9
commit
405f6af79c
5 changed files with 94 additions and 25 deletions
|
@ -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>()) {
|
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>()) {
|
if (node->cast_to<VisualScriptComment>()) {
|
||||||
Ref<VisualScriptComment> vsc=node;
|
Ref<VisualScriptComment> vsc=node;
|
||||||
gnode->set_comment(true);
|
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() {
|
void VisualScriptEditor::_available_node_doubleclicked() {
|
||||||
|
|
||||||
TreeItem *item = nodes->get_selected();
|
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("_button_resource_previewed",&VisualScriptEditor::_button_resource_previewed);
|
||||||
ObjectTypeDB::bind_method("_port_action_menu",&VisualScriptEditor::_port_action_menu);
|
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("_selected_connect_node_method_or_setget",&VisualScriptEditor::_selected_connect_node_method_or_setget);
|
||||||
|
ObjectTypeDB::bind_method("_expression_text_changed",&VisualScriptEditor::_expression_text_changed);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -168,6 +168,7 @@ class VisualScriptEditor : public ScriptEditorBase {
|
||||||
|
|
||||||
void _member_button(Object *p_item, int p_column, int p_button);
|
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;
|
String revert_on_drag;
|
||||||
|
|
|
@ -120,7 +120,7 @@ void VisualScriptExpression::_get_property_list( List<PropertyInfo> *p_list) con
|
||||||
argt+=","+Variant::get_type_name(Variant::Type(i));
|
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,"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::INT,"input_count",PROPERTY_HINT_RANGE,"0,64,1"));
|
||||||
p_list->push_back(PropertyInfo(Variant::BOOL,"sequenced"));
|
p_list->push_back(PropertyInfo(Variant::BOOL,"sequenced"));
|
||||||
|
|
|
@ -193,8 +193,8 @@ void LineEdit::_input_event(InputEvent p_event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
set_cursor_pos(0);
|
set_cursor_pos(0);
|
||||||
emit_signal("text_changed",text);
|
_text_changed();
|
||||||
_change_notify("text");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -215,8 +215,7 @@ void LineEdit::_input_event(InputEvent p_event) {
|
||||||
selection_clear();
|
selection_clear();
|
||||||
undo_text = text;
|
undo_text = text;
|
||||||
text = text.substr(0,cursor_pos);
|
text = text.substr(0,cursor_pos);
|
||||||
emit_signal("text_changed",text);
|
_text_changed();
|
||||||
_change_notify("text");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
|
@ -475,9 +474,7 @@ void LineEdit::_input_event(InputEvent p_event) {
|
||||||
selection_delete();
|
selection_delete();
|
||||||
CharType ucodestr[2]={(CharType)k.unicode,0};
|
CharType ucodestr[2]={(CharType)k.unicode,0};
|
||||||
append_at_cursor(ucodestr);
|
append_at_cursor(ucodestr);
|
||||||
emit_signal("text_changed",text);
|
_text_changed();
|
||||||
_change_notify("text");
|
|
||||||
|
|
||||||
accept_event();
|
accept_event();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -725,8 +722,7 @@ void LineEdit::paste_text() {
|
||||||
if(selection.enabled) selection_delete();
|
if(selection.enabled) selection_delete();
|
||||||
append_at_cursor(paste_buffer);
|
append_at_cursor(paste_buffer);
|
||||||
|
|
||||||
emit_signal("text_changed",text);
|
_text_changed();
|
||||||
_change_notify("text");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -750,9 +746,7 @@ void LineEdit::undo() {
|
||||||
set_cursor_pos(old_cursor_pos);
|
set_cursor_pos(old_cursor_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
emit_signal("text_changed",text);
|
_text_changed();
|
||||||
_change_notify("text");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LineEdit::shift_selection_check_pre(bool p_shift) {
|
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());
|
// set_window_pos(cursor_pos-get_window_length());
|
||||||
}
|
}
|
||||||
|
|
||||||
emit_signal("text_changed",text);
|
_text_changed();
|
||||||
_change_notify("text");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LineEdit::delete_text(int p_from_column, int p_to_column) {
|
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;
|
window_pos=cursor_pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit_signal("text_changed",text);
|
_text_changed();
|
||||||
_change_notify("text");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LineEdit::set_text(String p_text) {
|
void LineEdit::set_text(String p_text) {
|
||||||
|
@ -930,8 +922,7 @@ void LineEdit::set_text(String p_text) {
|
||||||
void LineEdit::clear() {
|
void LineEdit::clear() {
|
||||||
|
|
||||||
clear_internal();
|
clear_internal();
|
||||||
emit_signal("text_changed",text);
|
_text_changed();
|
||||||
_change_notify("text");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String LineEdit::get_text() const {
|
String LineEdit::get_text() const {
|
||||||
|
@ -1070,7 +1061,17 @@ Size2 LineEdit::get_minimum_size() const {
|
||||||
|
|
||||||
Size2 min=style->get_minimum_size();
|
Size2 min=style->get_minimum_size();
|
||||||
min.height+=font->get_height();
|
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;
|
return min;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1226,6 +1227,29 @@ PopupMenu *LineEdit::get_menu() const {
|
||||||
}
|
}
|
||||||
#endif
|
#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() {
|
void LineEdit::_bind_methods() {
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("_toggle_draw_caret"),&LineEdit::_toggle_draw_caret);
|
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("get_placeholder_alpha"),&LineEdit::get_placeholder_alpha);
|
||||||
ObjectTypeDB::bind_method(_MD("set_cursor_pos","pos"),&LineEdit::set_cursor_pos);
|
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("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_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_get_blink_enabled"),&LineEdit::cursor_get_blink_enabled);
|
||||||
ObjectTypeDB::bind_method(_MD("cursor_set_blink_speed", "blink_speed"),&LineEdit::cursor_set_blink_speed);
|
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_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_PROPERTYNO( PropertyInfo( Variant::BOOL, "editable" ), _SCS("set_editable"),_SCS("is_editable") );
|
||||||
ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "secret" ), _SCS("set_secret"),_SCS("is_secret") );
|
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::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_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") );
|
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_separator();
|
||||||
menu->add_item(TTR("Undo"),MENU_UNDO,KEY_MASK_CMD|KEY_Z);
|
menu->add_item(TTR("Undo"),MENU_UNDO,KEY_MASK_CMD|KEY_Z);
|
||||||
menu->connect("item_pressed",this,"menu_option");
|
menu->connect("item_pressed",this,"menu_option");
|
||||||
|
expand_to_text_length=false;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,6 +90,11 @@ private:
|
||||||
} selection;
|
} selection;
|
||||||
|
|
||||||
Timer *caret_blink_timer;
|
Timer *caret_blink_timer;
|
||||||
|
|
||||||
|
|
||||||
|
void _text_changed();
|
||||||
|
bool expand_to_text_length;
|
||||||
|
|
||||||
bool caret_blink_enabled;
|
bool caret_blink_enabled;
|
||||||
bool draw_caret;
|
bool draw_caret;
|
||||||
bool window_has_focus;
|
bool window_has_focus;
|
||||||
|
@ -169,6 +174,9 @@ public:
|
||||||
|
|
||||||
virtual Size2 get_minimum_size() const;
|
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;
|
virtual bool is_text_field() const;
|
||||||
LineEdit();
|
LineEdit();
|
||||||
~LineEdit();
|
~LineEdit();
|
||||||
|
|
Loading…
Reference in a new issue