Add placeholder property for line_edit
this useful for user input tip
This commit is contained in:
parent
2c59f77885
commit
081c400ac6
2 changed files with 27 additions and 5 deletions
|
@ -108,7 +108,7 @@ void LineEdit::_input_event(InputEvent p_event) {
|
||||||
selection.doubleclick=false;
|
selection.doubleclick=false;
|
||||||
|
|
||||||
if (OS::get_singleton()->has_virtual_keyboard())
|
if (OS::get_singleton()->has_virtual_keyboard())
|
||||||
OS::get_singleton()->show_virtual_keyboard(get_text(),get_global_rect());
|
OS::get_singleton()->show_virtual_keyboard(text,get_global_rect());
|
||||||
}
|
}
|
||||||
|
|
||||||
update();
|
update();
|
||||||
|
@ -634,14 +634,19 @@ void LineEdit::_notification(int p_what) {
|
||||||
Color font_color_selected=get_color("font_color_selected");
|
Color font_color_selected=get_color("font_color_selected");
|
||||||
Color cursor_color=get_color("cursor_color");
|
Color cursor_color=get_color("cursor_color");
|
||||||
|
|
||||||
|
const String& t = text.empty() ? placeholder : text;
|
||||||
|
// draw placeholder color
|
||||||
|
if(text.empty())
|
||||||
|
font_color.a *= 0.6;
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
|
|
||||||
//end of string, break!
|
//end of string, break!
|
||||||
if (char_ofs>=text.length())
|
if (char_ofs>=t.length())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
CharType cchar=pass?'*':text[char_ofs];
|
CharType cchar=pass?'*':t[char_ofs];
|
||||||
CharType next=pass?'*':text[char_ofs+1];
|
CharType next=pass?'*':t[char_ofs+1];
|
||||||
int char_width=font->get_char_size( cchar,next ).width;
|
int char_width=font->get_char_size( cchar,next ).width;
|
||||||
|
|
||||||
// end of widget, break!
|
// end of widget, break!
|
||||||
|
@ -678,7 +683,7 @@ void LineEdit::_notification(int p_what) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OS::get_singleton()->has_virtual_keyboard())
|
if (OS::get_singleton()->has_virtual_keyboard())
|
||||||
OS::get_singleton()->show_virtual_keyboard(get_text(),get_global_rect());
|
OS::get_singleton()->show_virtual_keyboard(text,get_global_rect());
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case NOTIFICATION_FOCUS_EXIT: {
|
case NOTIFICATION_FOCUS_EXIT: {
|
||||||
|
@ -938,6 +943,17 @@ String LineEdit::get_text() const {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LineEdit::set_placeholder(String p_text) {
|
||||||
|
|
||||||
|
placeholder = p_text;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
String LineEdit::get_placeholder() const {
|
||||||
|
|
||||||
|
return placeholder;
|
||||||
|
}
|
||||||
|
|
||||||
void LineEdit::set_cursor_pos(int p_pos) {
|
void LineEdit::set_cursor_pos(int p_pos) {
|
||||||
|
|
||||||
if (p_pos>(int)text.length())
|
if (p_pos>(int)text.length())
|
||||||
|
@ -1223,6 +1239,8 @@ void LineEdit::_bind_methods() {
|
||||||
ObjectTypeDB::bind_method(_MD("select_all"),&LineEdit::select_all);
|
ObjectTypeDB::bind_method(_MD("select_all"),&LineEdit::select_all);
|
||||||
ObjectTypeDB::bind_method(_MD("set_text","text"),&LineEdit::set_text);
|
ObjectTypeDB::bind_method(_MD("set_text","text"),&LineEdit::set_text);
|
||||||
ObjectTypeDB::bind_method(_MD("get_text"),&LineEdit::get_text);
|
ObjectTypeDB::bind_method(_MD("get_text"),&LineEdit::get_text);
|
||||||
|
ObjectTypeDB::bind_method(_MD("set_placeholder","text"),&LineEdit::set_placeholder);
|
||||||
|
ObjectTypeDB::bind_method(_MD("get_placeholder"),&LineEdit::get_placeholder);
|
||||||
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("cursor_set_blink_enabled", "enable"),&LineEdit::cursor_set_blink_enabled);
|
ObjectTypeDB::bind_method(_MD("cursor_set_blink_enabled", "enable"),&LineEdit::cursor_set_blink_enabled);
|
||||||
|
@ -1257,6 +1275,7 @@ void LineEdit::_bind_methods() {
|
||||||
BIND_CONSTANT( MENU_MAX );
|
BIND_CONSTANT( MENU_MAX );
|
||||||
|
|
||||||
ADD_PROPERTYNZ( PropertyInfo( Variant::STRING, "text" ), _SCS("set_text"),_SCS("get_text") );
|
ADD_PROPERTYNZ( PropertyInfo( Variant::STRING, "text" ), _SCS("set_text"),_SCS("get_text") );
|
||||||
|
ADD_PROPERTYNZ( PropertyInfo( Variant::STRING, "placeholder" ), _SCS("set_placeholder"),_SCS("get_placeholder") );
|
||||||
ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "align", PROPERTY_HINT_ENUM, "Left,Center,Right,Fill"), _SCS("set_align"), _SCS("get_align"));
|
ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "align", PROPERTY_HINT_ENUM, "Left,Center,Right,Fill"), _SCS("set_align"), _SCS("get_align"));
|
||||||
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") );
|
||||||
|
|
|
@ -67,6 +67,7 @@ private:
|
||||||
|
|
||||||
String undo_text;
|
String undo_text;
|
||||||
String text;
|
String text;
|
||||||
|
String placeholder;
|
||||||
|
|
||||||
PopupMenu *menu;
|
PopupMenu *menu;
|
||||||
|
|
||||||
|
@ -135,6 +136,8 @@ public:
|
||||||
void delete_text(int p_from_column, int p_to_column);
|
void delete_text(int p_from_column, int p_to_column);
|
||||||
void set_text(String p_text);
|
void set_text(String p_text);
|
||||||
String get_text() const;
|
String get_text() const;
|
||||||
|
void set_placeholder(String p_text);
|
||||||
|
String get_placeholder() const;
|
||||||
void set_cursor_pos(int p_pos);
|
void set_cursor_pos(int p_pos);
|
||||||
int get_cursor_pos() const;
|
int get_cursor_pos() const;
|
||||||
void set_max_length(int p_max_length);
|
void set_max_length(int p_max_length);
|
||||||
|
|
Loading…
Reference in a new issue