| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/gui/control.h" |
| 34 |
#include "scene/gui/popup_menu.h" |
| 35 |
|
| 36 |
class LineEdit : public Control { |
| 37 |
GDCLASS(LineEdit, Control); |
| 38 |
|
| 39 |
public: |
| 40 |
enum MenuItems { |
| 41 |
MENU_CUT, |
| 42 |
MENU_COPY, |
| 43 |
MENU_PASTE, |
| 44 |
MENU_CLEAR, |
| 45 |
MENU_SELECT_ALL, |
| 46 |
MENU_UNDO, |
| 47 |
MENU_REDO, |
| 48 |
MENU_SUBMENU_TEXT_DIR, |
| 49 |
MENU_DIR_INHERITED, |
| 50 |
MENU_DIR_AUTO, |
| 51 |
MENU_DIR_LTR, |
| 52 |
MENU_DIR_RTL, |
| 53 |
MENU_DISPLAY_UCC, |
| 54 |
MENU_SUBMENU_INSERT_UCC, |
| 55 |
MENU_INSERT_LRM, |
| 56 |
MENU_INSERT_RLM, |
| 57 |
MENU_INSERT_LRE, |
| 58 |
MENU_INSERT_RLE, |
| 59 |
MENU_INSERT_LRO, |
| 60 |
MENU_INSERT_RLO, |
| 61 |
MENU_INSERT_PDF, |
| 62 |
MENU_INSERT_ALM, |
| 63 |
MENU_INSERT_LRI, |
| 64 |
MENU_INSERT_RLI, |
| 65 |
MENU_INSERT_FSI, |
| 66 |
MENU_INSERT_PDI, |
| 67 |
MENU_INSERT_ZWJ, |
| 68 |
MENU_INSERT_ZWNJ, |
| 69 |
MENU_INSERT_WJ, |
| 70 |
MENU_INSERT_SHY, |
| 71 |
MENU_EMOJI_AND_SYMBOL, |
| 72 |
MENU_MAX |
| 73 |
}; |
| 74 |
|
| 75 |
enum VirtualKeyboardType { |
| 76 |
KEYBOARD_TYPE_DEFAULT, |
| 77 |
KEYBOARD_TYPE_MULTILINE, |
| 78 |
KEYBOARD_TYPE_NUMBER, |
| 79 |
KEYBOARD_TYPE_NUMBER_DECIMAL, |
| 80 |
KEYBOARD_TYPE_PHONE, |
| 81 |
KEYBOARD_TYPE_EMAIL_ADDRESS, |
| 82 |
KEYBOARD_TYPE_PASSWORD, |
| 83 |
KEYBOARD_TYPE_URL |
| 84 |
}; |
| 85 |
|
| 86 |
enum ExpandMode { |
| 87 |
EXPAND_MODE_ORIGINAL_SIZE, |
| 88 |
EXPAND_MODE_FIT_TO_TEXT, |
| 89 |
EXPAND_MODE_FIT_TO_LINE_EDIT, |
| 90 |
}; |
| 91 |
|
| 92 |
private: |
| 93 |
HorizontalAlignment alignment = HORIZONTAL_ALIGNMENT_LEFT; |
| 94 |
|
| 95 |
bool editing = false; |
| 96 |
bool keep_editing_on_text_submit = false; |
| 97 |
bool editable = false; |
| 98 |
bool pass = false; |
| 99 |
bool text_changed_dirty = false; |
| 100 |
ExpandMode icon_expand_mode = EXPAND_MODE_ORIGINAL_SIZE; |
| 101 |
|
| 102 |
enum AltInputMode { |
| 103 |
ALT_INPUT_NONE, |
| 104 |
ALT_INPUT_UNICODE, |
| 105 |
ALT_INPUT_OEM, |
| 106 |
ALT_INPUT_WIN, |
| 107 |
}; |
| 108 |
|
| 109 |
AltInputMode alt_mode = ALT_INPUT_NONE; |
| 110 |
bool alt_start = false; |
| 111 |
bool alt_start_no_hold = false; |
| 112 |
uint32_t alt_code = 0; |
| 113 |
|
| 114 |
String undo_text; |
| 115 |
String text; |
| 116 |
String placeholder; |
| 117 |
String placeholder_translated; |
| 118 |
String secret_character = U"•"; |
| 119 |
String ime_text; |
| 120 |
Point2 ime_selection; |
| 121 |
|
| 122 |
RID text_rid; |
| 123 |
RID accessibility_text_root_element; |
| 124 |
float full_width = 0.0; |
| 125 |
|
| 126 |
bool selecting_enabled = true; |
| 127 |
bool deselect_on_focus_loss_enabled = true; |
| 128 |
bool drag_and_drop_selection_enabled = true; |
| 129 |
|
| 130 |
bool context_menu_enabled = true; |
| 131 |
bool emoji_menu_enabled = true; |
| 132 |
bool backspace_deletes_composite_character_enabled = false; |
| 133 |
PopupMenu *menu = nullptr; |
| 134 |
PopupMenu *menu_dir = nullptr; |
| 135 |
PopupMenu *menu_ctl = nullptr; |
| 136 |
|
| 137 |
bool caret_mid_grapheme_enabled = false; |
| 138 |
|
| 139 |
int caret_column = 0; |
| 140 |
float scroll_offset = 0.0; |
| 141 |
int max_length = 0; |
| 142 |
|
| 143 |
String language; |
| 144 |
TextDirection text_direction = TEXT_DIRECTION_AUTO; |
| 145 |
TextDirection input_direction = TEXT_DIRECTION_LTR; |
| 146 |
TextServer::StructuredTextParser st_parser = TextServer::STRUCTURED_TEXT_DEFAULT; |
| 147 |
Array st_args; |
| 148 |
bool draw_control_chars = false; |
| 149 |
|
| 150 |
bool expand_to_text_length = false; |
| 151 |
bool window_has_focus = true; |
| 152 |
|
| 153 |
bool clear_button_enabled = false; |
| 154 |
|
| 155 |
bool shortcut_keys_enabled = true; |
| 156 |
|
| 157 |
bool virtual_keyboard_enabled = true; |
| 158 |
bool virtual_keyboard_show_on_focus = true; |
| 159 |
VirtualKeyboardType virtual_keyboard_type = KEYBOARD_TYPE_DEFAULT; |
| 160 |
|
| 161 |
bool middle_mouse_paste_enabled = true; |
| 162 |
|
| 163 |
bool drag_action = false; |
| 164 |
bool drag_caret_force_displayed = false; |
| 165 |
|
| 166 |
Ref<Texture2D> right_icon; |
| 167 |
bool flat = false; |
| 168 |
float right_icon_scale = 1.0; |
| 169 |
|
| 170 |
struct Selection { |
| 171 |
int begin = 0; |
| 172 |
int end = 0; |
| 173 |
int start_column = 0; |
| 174 |
bool enabled = false; |
| 175 |
bool creating = false; |
| 176 |
bool double_click = false; |
| 177 |
bool drag_attempt = false; |
| 178 |
} selection; |
| 179 |
|
| 180 |
struct TextOperation { |
| 181 |
int caret_column = 0; |
| 182 |
float scroll_offset = 0.0; |
| 183 |
String text; |
| 184 |
}; |
| 185 |
List<TextOperation> undo_stack; |
| 186 |
List<TextOperation>::Element *undo_stack_pos = nullptr; |
| 187 |
|
| 188 |
struct ClearButtonStatus { |
| 189 |
bool press_attempt = false; |
| 190 |
bool pressing_inside = false; |
| 191 |
} clear_button_status; |
| 192 |
|
| 193 |
uint64_t last_dblclk = 0; |
| 194 |
Vector2 last_dblclk_pos; |
| 195 |
|
| 196 |
bool caret_blink_enabled = false; |
| 197 |
bool caret_force_displayed = false; |
| 198 |
bool draw_caret = true; |
| 199 |
float caret_blink_interval = 0.65; |
| 200 |
double caret_blink_timer = 0.0; |
| 201 |
bool caret_can_draw = false; |
| 202 |
|
| 203 |
bool pending_select_all_on_focus = false; |
| 204 |
bool select_all_on_focus = false; |
| 205 |
|
| 206 |
struct ThemeCache { |
| 207 |
Ref<StyleBox> normal; |
| 208 |
Ref<StyleBox> read_only; |
| 209 |
Ref<StyleBox> focus; |
| 210 |
|
| 211 |
Ref<Font> font; |
| 212 |
int font_size = 0; |
| 213 |
Color font_color; |
| 214 |
Color font_uneditable_color; |
| 215 |
Color font_selected_color; |
| 216 |
int font_outline_size; |
| 217 |
Color font_outline_color; |
| 218 |
Color font_placeholder_color; |
| 219 |
int caret_width = 0; |
| 220 |
Color caret_color; |
| 221 |
int minimum_character_width = 0; |
| 222 |
Color selection_color; |
| 223 |
|
| 224 |
Ref<Texture2D> clear_icon; |
| 225 |
Color clear_button_color; |
| 226 |
Color clear_button_color_pressed; |
| 227 |
|
| 228 |
float base_scale = 1.0; |
| 229 |
} theme_cache; |
| 230 |
|
| 231 |
void _close_ime_window(); |
| 232 |
void _update_ime_window_position(); |
| 233 |
|
| 234 |
void _clear_undo_stack(); |
| 235 |
void _clear_redo(); |
| 236 |
void _create_undo_state(); |
| 237 |
|
| 238 |
Key _get_menu_action_accelerator(const String &p_action); |
| 239 |
void _generate_context_menu(); |
| 240 |
void _update_context_menu(); |
| 241 |
|
| 242 |
void _shape(); |
| 243 |
void _fit_to_width(); |
| 244 |
void _text_changed(); |
| 245 |
void _emit_text_change(); |
| 246 |
|
| 247 |
void shift_selection_check_pre(bool); |
| 248 |
void shift_selection_check_post(bool); |
| 249 |
|
| 250 |
void selection_fill_at_caret(); |
| 251 |
void set_scroll_offset(float p_pos); |
| 252 |
float get_scroll_offset() const; |
| 253 |
|
| 254 |
void set_caret_at_pixel_pos(int p_x); |
| 255 |
Vector2 get_caret_pixel_pos(); |
| 256 |
|
| 257 |
void _reset_caret_blink_timer(); |
| 258 |
void _toggle_draw_caret(); |
| 259 |
void _validate_caret_can_draw(); |
| 260 |
|
| 261 |
void clear_internal(); |
| 262 |
|
| 263 |
void _editor_settings_changed(); |
| 264 |
|
| 265 |
void _swap_current_input_direction(); |
| 266 |
void _move_caret_left(bool p_select, bool p_move_by_word = false); |
| 267 |
void _move_caret_right(bool p_select, bool p_move_by_word = false); |
| 268 |
void _move_caret_start(bool p_select); |
| 269 |
void _move_caret_end(bool p_select); |
| 270 |
void _backspace(bool p_word = false, bool p_all_to_left = false); |
| 271 |
void _delete(bool p_word = false, bool p_all_to_right = false); |
| 272 |
void _texture_changed(); |
| 273 |
|
| 274 |
void _edit(bool p_show_virtual_keyboard = true, bool p_hide_focus = false); |
| 275 |
Point2 _get_right_icon_size(Ref<Texture2D> p_right_icon) const; |
| 276 |
|
| 277 |
protected: |
| 278 |
bool _is_over_clear_button(const Point2 &p_pos) const; |
| 279 |
|
| 280 |
virtual void _update_theme_item_cache() override; |
| 281 |
|
| 282 |
void _notification(int p_what); |
| 283 |
void _validate_property(PropertyInfo &p_property) const; |
| 284 |
static void _bind_methods(); |
| 285 |
|
| 286 |
#ifndef DISABLE_DEPRECATED |
| 287 |
void _edit_bind_compat_111117(); |
| 288 |
static void _bind_compatibility_methods(); |
| 289 |
#endif |
| 290 |
|
| 291 |
virtual void unhandled_key_input(const Ref<InputEvent> &p_event) override; |
| 292 |
virtual void gui_input(const Ref<InputEvent> &p_event) override; |
| 293 |
|
| 294 |
void _accessibility_action_set_selection(const Variant &p_data); |
| 295 |
void _accessibility_action_replace_selected(const Variant &p_data); |
| 296 |
void _accessibility_action_set_value(const Variant &p_data); |
| 297 |
void _accessibility_action_menu(const Variant &p_data); |
| 298 |
|
| 299 |
public: |
| 300 |
void edit(bool p_hide_focus = false); |
| 301 |
void unedit(); |
| 302 |
bool is_editing() const; |
| 303 |
void set_keep_editing_on_text_submit(bool p_enabled); |
| 304 |
bool is_editing_kept_on_text_submit() const; |
| 305 |
|
| 306 |
bool has_ime_text() const; |
| 307 |
void cancel_ime(); |
| 308 |
void apply_ime(); |
| 309 |
|
| 310 |
void set_horizontal_alignment(HorizontalAlignment p_alignment); |
| 311 |
HorizontalAlignment get_horizontal_alignment() const; |
| 312 |
|
| 313 |
virtual Variant get_drag_data(const Point2 &p_point) override; |
| 314 |
virtual bool can_drop_data(const Point2 &p_point, const Variant &p_data) const override; |
| 315 |
virtual void drop_data(const Point2 &p_point, const Variant &p_data) override; |
| 316 |
|
| 317 |
virtual CursorShape get_cursor_shape(const Point2 &p_pos) const override; |
| 318 |
|
| 319 |
void menu_option(int p_option); |
| 320 |
void set_context_menu_enabled(bool p_enable); |
| 321 |
bool is_context_menu_enabled(); |
| 322 |
PopupMenu *get_menu() const; |
| 323 |
bool is_menu_visible() const; |
| 324 |
|
| 325 |
void show_emoji_and_symbol_picker(); |
| 326 |
|
| 327 |
void set_emoji_menu_enabled(bool p_enabled); |
| 328 |
bool is_emoji_menu_enabled() const; |
| 329 |
|
| 330 |
void set_backspace_deletes_composite_character_enabled(bool p_enabled); |
| 331 |
bool is_backspace_deletes_composite_character_enabled() const; |
| 332 |
|
| 333 |
void select(int p_from = 0, int p_to = -1); |
| 334 |
void select_all(); |
| 335 |
void selection_delete(); |
| 336 |
void deselect(); |
| 337 |
bool has_selection() const; |
| 338 |
String get_selected_text(); |
| 339 |
int get_selection_from_column() const; |
| 340 |
int get_selection_to_column() const; |
| 341 |
|
| 342 |
void delete_char(); |
| 343 |
void delete_text(int p_from_column, int p_to_column); |
| 344 |
|
| 345 |
void _set_text(String p_text, bool p_emit_signal = false); |
| 346 |
void set_text(String p_text); |
| 347 |
String get_text() const; |
| 348 |
void set_text_with_selection(const String &p_text); |
| 349 |
|
| 350 |
void set_text_direction(TextDirection p_text_direction); |
| 351 |
TextDirection get_text_direction() const; |
| 352 |
|
| 353 |
void set_language(const String &p_language); |
| 354 |
String get_language() const; |
| 355 |
|
| 356 |
void set_draw_control_chars(bool p_draw_control_chars); |
| 357 |
bool get_draw_control_chars() const; |
| 358 |
|
| 359 |
void set_structured_text_bidi_override(TextServer::StructuredTextParser p_parser); |
| 360 |
TextServer::StructuredTextParser get_structured_text_bidi_override() const; |
| 361 |
|
| 362 |
void set_structured_text_bidi_override_options(const Array &p_args); |
| 363 |
Array get_structured_text_bidi_override_options() const; |
| 364 |
|
| 365 |
void set_placeholder(String p_text); |
| 366 |
String get_placeholder() const; |
| 367 |
|
| 368 |
void set_caret_column(int p_column); |
| 369 |
int get_caret_column() const; |
| 370 |
int get_next_composite_character_column(int p_column) const; |
| 371 |
int get_previous_composite_character_column(int p_column) const; |
| 372 |
|
| 373 |
void set_max_length(int p_max_length); |
| 374 |
int get_max_length() const; |
| 375 |
|
| 376 |
void insert_text_at_caret(String p_text); |
| 377 |
void clear(); |
| 378 |
|
| 379 |
void set_caret_mid_grapheme_enabled(const bool p_enabled); |
| 380 |
bool is_caret_mid_grapheme_enabled() const; |
| 381 |
|
| 382 |
bool is_caret_blink_enabled() const; |
| 383 |
void set_caret_blink_enabled(const bool p_enabled); |
| 384 |
|
| 385 |
float get_caret_blink_interval() const; |
| 386 |
void set_caret_blink_interval(const float p_interval); |
| 387 |
|
| 388 |
void set_caret_force_displayed(const bool p_enabled); |
| 389 |
bool is_caret_force_displayed() const; |
| 390 |
|
| 391 |
void copy_text(); |
| 392 |
void cut_text(); |
| 393 |
void paste_text(); |
| 394 |
bool has_undo() const; |
| 395 |
bool has_redo() const; |
| 396 |
void undo(); |
| 397 |
void redo(); |
| 398 |
|
| 399 |
void set_editable(bool p_editable); |
| 400 |
bool is_editable() const; |
| 401 |
|
| 402 |
void set_secret(bool p_secret); |
| 403 |
bool is_secret() const; |
| 404 |
|
| 405 |
void set_secret_character(const String &p_string); |
| 406 |
String get_secret_character() const; |
| 407 |
|
| 408 |
virtual Size2 get_minimum_size() const override; |
| 409 |
|
| 410 |
void set_expand_to_text_length_enabled(bool p_enabled); |
| 411 |
bool is_expand_to_text_length_enabled() const; |
| 412 |
|
| 413 |
void set_clear_button_enabled(bool p_enabled); |
| 414 |
bool is_clear_button_enabled() const; |
| 415 |
|
| 416 |
void set_shortcut_keys_enabled(bool p_enabled); |
| 417 |
bool is_shortcut_keys_enabled() const; |
| 418 |
|
| 419 |
void set_virtual_keyboard_enabled(bool p_enable); |
| 420 |
bool is_virtual_keyboard_enabled() const; |
| 421 |
|
| 422 |
void set_virtual_keyboard_show_on_focus(bool p_show_on_focus); |
| 423 |
bool get_virtual_keyboard_show_on_focus() const; |
| 424 |
|
| 425 |
void set_virtual_keyboard_type(VirtualKeyboardType p_type); |
| 426 |
VirtualKeyboardType get_virtual_keyboard_type() const; |
| 427 |
|
| 428 |
void set_middle_mouse_paste_enabled(bool p_enabled); |
| 429 |
bool is_middle_mouse_paste_enabled() const; |
| 430 |
|
| 431 |
void set_selecting_enabled(bool p_enabled); |
| 432 |
bool is_selecting_enabled() const; |
| 433 |
|
| 434 |
void set_deselect_on_focus_loss_enabled(const bool p_enabled); |
| 435 |
bool is_deselect_on_focus_loss_enabled() const; |
| 436 |
|
| 437 |
void set_drag_and_drop_selection_enabled(const bool p_enabled); |
| 438 |
bool is_drag_and_drop_selection_enabled() const; |
| 439 |
|
| 440 |
void set_right_icon(const Ref<Texture2D> &p_icon); |
| 441 |
Ref<Texture2D> get_right_icon(); |
| 442 |
|
| 443 |
void set_icon_expand_mode(ExpandMode p_mode); |
| 444 |
ExpandMode get_icon_expand_mode() const; |
| 445 |
|
| 446 |
void set_right_icon_scale(float p_scale); |
| 447 |
float get_right_icon_scale() const; |
| 448 |
|
| 449 |
void set_flat(bool p_enabled); |
| 450 |
bool is_flat() const; |
| 451 |
|
| 452 |
void set_select_all_on_focus(bool p_enabled); |
| 453 |
bool is_select_all_on_focus() const; |
| 454 |
void clear_pending_select_all_on_focus(); |
| 455 |
|
| 456 |
virtual bool is_text_field() const override; |
| 457 |
|
| 458 |
PackedStringArray get_configuration_warnings() const override; |
| 459 |
|
| 460 |
void show_virtual_keyboard(); |
| 461 |
|
| 462 |
LineEdit(const String &p_placeholder = String()); |
| 463 |
~LineEdit(); |
| 464 |
}; |
| 465 |
|
| 466 |
VARIANT_ENUM_CAST(LineEdit::MenuItems); |
| 467 |
VARIANT_ENUM_CAST(LineEdit::VirtualKeyboardType); |
| 468 |
VARIANT_ENUM_CAST(LineEdit::ExpandMode); |