diff options
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/control.cpp | 4 | ||||
-rw-r--r-- | scene/gui/file_dialog.cpp | 2 | ||||
-rw-r--r-- | scene/gui/item_list.cpp | 131 | ||||
-rw-r--r-- | scene/gui/item_list.h | 17 | ||||
-rw-r--r-- | scene/gui/line_edit.cpp | 17 | ||||
-rw-r--r-- | scene/gui/line_edit.h | 4 | ||||
-rw-r--r-- | scene/gui/rich_text_label.cpp | 25 | ||||
-rw-r--r-- | scene/gui/rich_text_label.h | 7 | ||||
-rw-r--r-- | scene/gui/tab_bar.cpp | 6 | ||||
-rw-r--r-- | scene/gui/text_edit.cpp | 20 | ||||
-rw-r--r-- | scene/gui/text_edit.h | 4 |
11 files changed, 173 insertions, 64 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 77a1efd021..582c8e5860 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -73,8 +73,8 @@ Dictionary Control::_edit_get_state() const { void Control::_edit_set_state(const Dictionary &p_state) { ERR_FAIL_COND((p_state.size() <= 0) || - !p_state.has("rotation") || !p_state.has("scale") || - !p_state.has("pivot") || !p_state.has("anchors") || !p_state.has("offsets")); + !p_state.has("rotation") || !p_state.has("scale") || + !p_state.has("pivot") || !p_state.has("anchors") || !p_state.has("offsets")); Dictionary state = p_state; set_rotation(state["rotation"]); diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index bb77da9548..5f9f09fc50 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -348,7 +348,7 @@ bool FileDialog::_is_open_should_be_disabled() { // Opening a file, but selected a folder? Forbidden. return ((mode == FILE_MODE_OPEN_FILE || mode == FILE_MODE_OPEN_FILES) && d["dir"]) || // Flipped case, also forbidden. - (mode == FILE_MODE_OPEN_DIR && !d["dir"]); + (mode == FILE_MODE_OPEN_DIR && !d["dir"]); } void FileDialog::_go_up() { diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index d10ad90c1f..4215c9aff4 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -55,16 +55,8 @@ void ItemList::_shape(int p_idx) { int ItemList::add_item(const String &p_item, const Ref<Texture2D> &p_texture, bool p_selectable) { Item item; item.icon = p_texture; - item.icon_transposed = false; - item.icon_region = Rect2i(); - item.icon_modulate = Color(1, 1, 1, 1); item.text = p_item; - item.text_buf.instantiate(); item.selectable = p_selectable; - item.selected = false; - item.disabled = false; - item.tooltip_enabled = true; - item.custom_bg = Color(0, 0, 0, 0); items.push_back(item); int item_id = items.size() - 1; @@ -72,27 +64,20 @@ int ItemList::add_item(const String &p_item, const Ref<Texture2D> &p_texture, bo update(); shape_changed = true; + notify_property_list_changed(); return item_id; } int ItemList::add_icon_item(const Ref<Texture2D> &p_item, bool p_selectable) { Item item; item.icon = p_item; - item.icon_transposed = false; - item.icon_region = Rect2i(); - item.icon_modulate = Color(1, 1, 1, 1); - //item.text=p_item; - item.text_buf.instantiate(); item.selectable = p_selectable; - item.selected = false; - item.disabled = false; - item.tooltip_enabled = true; - item.custom_bg = Color(0, 0, 0, 0); items.push_back(item); int item_id = items.size() - 1; update(); shape_changed = true; + notify_property_list_changed(); return item_id; } @@ -400,6 +385,15 @@ void ItemList::move_item(int p_from_idx, int p_to_idx) { update(); shape_changed = true; + notify_property_list_changed(); +} + +void ItemList::set_item_count(int p_count) { + ERR_FAIL_COND(p_count < 0); + items.resize(p_count); + update(); + shape_changed = true; + notify_property_list_changed(); } int ItemList::get_item_count() const { @@ -416,6 +410,7 @@ void ItemList::remove_item(int p_idx) { update(); shape_changed = true; defer_select_single = -1; + notify_property_list_changed(); } void ItemList::clear() { @@ -425,6 +420,7 @@ void ItemList::clear() { update(); shape_changed = true; defer_select_single = -1; + notify_property_list_changed(); } void ItemList::set_fixed_column_width(int p_size) { @@ -1446,32 +1442,6 @@ bool ItemList::is_anything_selected() { return false; } -void ItemList::_set_items(const Array &p_items) { - ERR_FAIL_COND(p_items.size() % 3); - clear(); - - for (int i = 0; i < p_items.size(); i += 3) { - String text = p_items[i + 0]; - Ref<Texture2D> icon = p_items[i + 1]; - bool disabled = p_items[i + 2]; - - int idx = get_item_count(); - add_item(text, icon); - set_item_disabled(idx, disabled); - } -} - -Array ItemList::_get_items() const { - Array items; - for (int i = 0; i < get_item_count(); i++) { - items.push_back(get_item_text(i)); - items.push_back(get_item_icon(i)); - items.push_back(is_item_disabled(i)); - } - - return items; -} - Size2 ItemList::get_minimum_size() const { if (auto_height) { return Size2(0, auto_height_value); @@ -1508,6 +1478,74 @@ TextParagraph::OverrunBehavior ItemList::get_text_overrun_behavior() const { return text_overrun_behavior; } +bool ItemList::_set(const StringName &p_name, const Variant &p_value) { + Vector<String> components = String(p_name).split("/", true, 2); + if (components.size() >= 2 && components[0].begins_with("item_") && components[0].trim_prefix("item_").is_valid_int()) { + int item_index = components[0].trim_prefix("item_").to_int(); + if (components[1] == "text") { + set_item_text(item_index, p_value); + return true; + } else if (components[1] == "icon") { + set_item_icon(item_index, p_value); + return true; + } else if (components[1] == "disabled") { + set_item_disabled(item_index, p_value); + return true; + } + } +#ifndef DISABLE_DEPRECATED + // Compatibility. + if (p_name == "items") { + Array arr = p_value; + ERR_FAIL_COND_V(arr.size() % 3, false); + clear(); + + for (int i = 0; i < arr.size(); i += 3) { + String text = arr[i + 0]; + Ref<Texture2D> icon = arr[i + 1]; + bool disabled = arr[i + 2]; + + int idx = get_item_count(); + add_item(text, icon); + set_item_disabled(idx, disabled); + } + } +#endif + return false; +} + +bool ItemList::_get(const StringName &p_name, Variant &r_ret) const { + Vector<String> components = String(p_name).split("/", true, 2); + if (components.size() >= 2 && components[0].begins_with("item_") && components[0].trim_prefix("item_").is_valid_int()) { + int item_index = components[0].trim_prefix("item_").to_int(); + if (components[1] == "text") { + r_ret = get_item_text(item_index); + return true; + } else if (components[1] == "icon") { + r_ret = get_item_icon(item_index); + return true; + } else if (components[1] == "disabled") { + r_ret = is_item_disabled(item_index); + return true; + } + } + return false; +} + +void ItemList::_get_property_list(List<PropertyInfo> *p_list) const { + for (int i = 0; i < items.size(); i++) { + p_list->push_back(PropertyInfo(Variant::STRING, vformat("item_%d/text", i))); + + PropertyInfo pi = PropertyInfo(Variant::OBJECT, vformat("item_%d/icon", i), PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"); + pi.usage &= ~(get_item_icon(i).is_null() ? PROPERTY_USAGE_STORAGE : 0); + p_list->push_back(pi); + + pi = PropertyInfo(Variant::BOOL, vformat("item_%d/disabled", i)); + pi.usage &= ~(!is_item_disabled(i) ? PROPERTY_USAGE_STORAGE : 0); + p_list->push_back(pi); + } +} + void ItemList::_bind_methods() { ClassDB::bind_method(D_METHOD("add_item", "text", "icon", "selectable"), &ItemList::add_item, DEFVAL(Variant()), DEFVAL(true)); ClassDB::bind_method(D_METHOD("add_icon_item", "icon", "selectable"), &ItemList::add_icon_item, DEFVAL(true)); @@ -1567,6 +1605,7 @@ void ItemList::_bind_methods() { ClassDB::bind_method(D_METHOD("move_item", "from_idx", "to_idx"), &ItemList::move_item); + ClassDB::bind_method(D_METHOD("set_item_count"), &ItemList::set_item_count); ClassDB::bind_method(D_METHOD("get_item_count"), &ItemList::get_item_count); ClassDB::bind_method(D_METHOD("remove_item", "idx"), &ItemList::remove_item); @@ -1614,20 +1653,16 @@ void ItemList::_bind_methods() { ClassDB::bind_method(D_METHOD("get_v_scroll"), &ItemList::get_v_scroll); - ClassDB::bind_method(D_METHOD("_set_items"), &ItemList::_set_items); - ClassDB::bind_method(D_METHOD("_get_items"), &ItemList::_get_items); - ClassDB::bind_method(D_METHOD("set_text_overrun_behavior", "overrun_behavior"), &ItemList::set_text_overrun_behavior); ClassDB::bind_method(D_METHOD("get_text_overrun_behavior"), &ItemList::get_text_overrun_behavior); - ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "items", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_items", "_get_items"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "select_mode", PROPERTY_HINT_ENUM, "Single,Multi"), "set_select_mode", "get_select_mode"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_reselect"), "set_allow_reselect", "get_allow_reselect"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_rmb_select"), "set_allow_rmb_select", "get_allow_rmb_select"); ADD_PROPERTY(PropertyInfo(Variant::INT, "max_text_lines", PROPERTY_HINT_RANGE, "1,10,1,or_greater"), "set_max_text_lines", "get_max_text_lines"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_height"), "set_auto_height", "has_auto_height"); ADD_PROPERTY(PropertyInfo(Variant::INT, "text_overrun_behavior", PROPERTY_HINT_ENUM, "Trim Nothing,Trim Characters,Trim Words,Ellipsis,Word Ellipsis"), "set_text_overrun_behavior", "get_text_overrun_behavior"); + ADD_ARRAY_COUNT("Items", "items_count", "set_item_count", "get_item_count", "item_"); ADD_GROUP("Columns", ""); ADD_PROPERTY(PropertyInfo(Variant::INT, "max_columns", PROPERTY_HINT_RANGE, "0,10,1,or_greater"), "set_max_columns", "get_max_columns"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "same_column_width"), "set_same_column_width", "is_same_column_width"); diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h index 148fa7ba9f..e780179e7b 100644 --- a/scene/gui/item_list.h +++ b/scene/gui/item_list.h @@ -54,7 +54,7 @@ private: Ref<Texture2D> icon; bool icon_transposed = false; Rect2i icon_region; - Color icon_modulate; + Color icon_modulate = Color(1, 1, 1, 1); Ref<Texture2D> tag_icon; String text; Ref<TextParagraph> text_buf; @@ -65,11 +65,11 @@ private: bool selectable = false; bool selected = false; bool disabled = false; - bool tooltip_enabled = false; + bool tooltip_enabled = true; Variant metadata; String tooltip; Color custom_fg; - Color custom_bg; + Color custom_bg = Color(0.0, 0.0, 0.0, 0.0); Rect2 rect_cache; Rect2 min_rect_cache; @@ -77,6 +77,10 @@ private: Size2 get_icon_size() const; bool operator<(const Item &p_another) const { return text < p_another.text; } + + Item() { + text_buf.instantiate(); + } }; int current = -1; @@ -119,14 +123,14 @@ private: bool do_autoscroll_to_bottom = false; - Array _get_items() const; - void _set_items(const Array &p_items); - void _scroll_changed(double); void _shape(int p_idx); protected: void _notification(int p_what); + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; + void _get_property_list(List<PropertyInfo> *p_list) const; static void _bind_methods(); public: @@ -199,6 +203,7 @@ public: void move_item(int p_from_idx, int p_to_idx); + void set_item_count(int p_count); int get_item_count() const; void remove_item(int p_idx); diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index dda1151273..8c33d306a1 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -920,6 +920,9 @@ void LineEdit::_notification(int p_what) { DisplayServer::get_singleton()->virtual_keyboard_hide(); } + if (deselect_on_focus_loss_enabled) { + deselect(); + } } break; case MainLoop::NOTIFICATION_OS_IME_UPDATE: { if (has_focus()) { @@ -1938,6 +1941,17 @@ bool LineEdit::is_selecting_enabled() const { return selecting_enabled; } +void LineEdit::set_deselect_on_focus_loss_enabled(const bool p_enabled) { + deselect_on_focus_loss_enabled = p_enabled; + if (p_enabled && selection.enabled && !has_focus()) { + deselect(); + } +} + +bool LineEdit::is_deselect_on_focus_loss_enabled() const { + return deselect_on_focus_loss_enabled; +} + void LineEdit::set_right_icon(const Ref<Texture2D> &p_icon) { if (right_icon == p_icon) { return; @@ -2196,6 +2210,8 @@ void LineEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("is_middle_mouse_paste_enabled"), &LineEdit::is_middle_mouse_paste_enabled); ClassDB::bind_method(D_METHOD("set_selecting_enabled", "enable"), &LineEdit::set_selecting_enabled); ClassDB::bind_method(D_METHOD("is_selecting_enabled"), &LineEdit::is_selecting_enabled); + ClassDB::bind_method(D_METHOD("set_deselect_on_focus_loss_enabled", "enable"), &LineEdit::set_deselect_on_focus_loss_enabled); + ClassDB::bind_method(D_METHOD("is_deselect_on_focus_loss_enabled"), &LineEdit::is_deselect_on_focus_loss_enabled); ClassDB::bind_method(D_METHOD("set_right_icon", "icon"), &LineEdit::set_right_icon); ClassDB::bind_method(D_METHOD("get_right_icon"), &LineEdit::get_right_icon); @@ -2251,6 +2267,7 @@ void LineEdit::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shortcut_keys_enabled"), "set_shortcut_keys_enabled", "is_shortcut_keys_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "middle_mouse_paste_enabled"), "set_middle_mouse_paste_enabled", "is_middle_mouse_paste_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "selecting_enabled"), "set_selecting_enabled", "is_selecting_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "deselect_on_focus_loss_enabled"), "set_deselect_on_focus_loss_enabled", "is_deselect_on_focus_loss_enabled"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "right_icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_right_icon", "get_right_icon"); ADD_PROPERTY(PropertyInfo(Variant::INT, "text_direction", PROPERTY_HINT_ENUM, "Auto,Left-to-Right,Right-to-Left,Inherited"), "set_text_direction", "get_text_direction"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "language"), "set_language", "get_language"); diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h index 94179ce05b..3364e02e01 100644 --- a/scene/gui/line_edit.h +++ b/scene/gui/line_edit.h @@ -97,6 +97,7 @@ private: float full_width = 0.0; bool selecting_enabled = true; + bool deselect_on_focus_loss_enabled = true; bool context_menu_enabled = true; PopupMenu *menu = nullptr; @@ -325,6 +326,9 @@ public: void set_selecting_enabled(bool p_enabled); bool is_selecting_enabled() const; + void set_deselect_on_focus_loss_enabled(const bool p_enabled); + bool is_deselect_on_focus_loss_enabled() const; + void set_right_icon(const Ref<Texture2D> &p_icon); Ref<Texture2D> get_right_icon(); diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 31767dd263..f1efbbda98 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -1491,7 +1491,13 @@ void RichTextLabel::_notification(int p_what) { _update_fx(main, dt); update(); } - } + } break; + case NOTIFICATION_FOCUS_EXIT: { + if (deselect_on_focus_loss_enabled) { + selection.active = false; + update(); + } + } break; } } @@ -3609,6 +3615,14 @@ void RichTextLabel::set_selection_enabled(bool p_enabled) { } } +void RichTextLabel::set_deselect_on_focus_loss_enabled(const bool p_enabled) { + deselect_on_focus_loss_enabled = p_enabled; + if (p_enabled && selection.active && !has_focus()) { + selection.active = false; + update(); + } +} + bool RichTextLabel::_search_table(ItemTable *p_table, List<Item *>::Element *p_from, const String &p_string, bool p_reverse_search) { List<Item *>::Element *E = p_from; while (E != nullptr) { @@ -3858,6 +3872,10 @@ bool RichTextLabel::is_selection_enabled() const { return selection.enabled; } +bool RichTextLabel::is_deselect_on_focus_loss_enabled() const { + return deselect_on_focus_loss_enabled; +} + int RichTextLabel::get_selection_from() const { if (!selection.active || !selection.enabled) { return -1; @@ -4111,6 +4129,9 @@ void RichTextLabel::_bind_methods() { ClassDB::bind_method(D_METHOD("set_selection_enabled", "enabled"), &RichTextLabel::set_selection_enabled); ClassDB::bind_method(D_METHOD("is_selection_enabled"), &RichTextLabel::is_selection_enabled); + ClassDB::bind_method(D_METHOD("set_deselect_on_focus_loss_enabled", "enable"), &RichTextLabel::set_deselect_on_focus_loss_enabled); + ClassDB::bind_method(D_METHOD("is_deselect_on_focus_loss_enabled"), &RichTextLabel::is_deselect_on_focus_loss_enabled); + ClassDB::bind_method(D_METHOD("get_selection_from"), &RichTextLabel::get_selection_from); ClassDB::bind_method(D_METHOD("get_selection_to"), &RichTextLabel::get_selection_to); @@ -4162,6 +4183,8 @@ void RichTextLabel::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "selection_enabled"), "set_selection_enabled", "is_selection_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "override_selected_font_color"), "set_override_selected_font_color", "is_overriding_selected_font_color"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "deselect_on_focus_loss_enabled"), "set_deselect_on_focus_loss_enabled", "is_deselect_on_focus_loss_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "custom_effects", PROPERTY_HINT_ARRAY_TYPE, vformat("%s/%s:%s", Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, "RichTextEffect"), (PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE)), "set_effects", "get_effects"); ADD_PROPERTY(PropertyInfo(Variant::INT, "text_direction", PROPERTY_HINT_ENUM, "Auto,Left-to-Right,Right-to-Left,Inherited"), "set_text_direction", "get_text_direction"); diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index 48186ca8b8..f3c4c11cc8 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -278,12 +278,12 @@ private: uint64_t offset_random(int index) { return (_current_rng >> (index % 64)) | - (_current_rng << (64 - (index % 64))); + (_current_rng << (64 - (index % 64))); } uint64_t offset_previous_random(int index) { return (_previous_rng >> (index % 64)) | - (_previous_rng << (64 - (index % 64))); + (_previous_rng << (64 - (index % 64))); } }; @@ -399,6 +399,7 @@ private: }; Selection selection; + bool deselect_on_focus_loss_enabled = true; int visible_characters = -1; float percent_visible = 1.0; @@ -551,6 +552,8 @@ public: int get_selection_to() const; String get_selected_text() const; void selection_copy(); + void set_deselect_on_focus_loss_enabled(const bool p_enabled); + bool is_deselect_on_focus_loss_enabled() const; void parse_bbcode(const String &p_bbcode); void append_text(const String &p_bbcode); diff --git a/scene/gui/tab_bar.cpp b/scene/gui/tab_bar.cpp index 78b58c773a..405fbdae75 100644 --- a/scene/gui/tab_bar.cpp +++ b/scene/gui/tab_bar.cpp @@ -175,7 +175,7 @@ void TabBar::gui_input(const Ref<InputEvent> &p_event) { if (cb_pressing && !mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_LEFT) { if (cb_hover != -1) { // pressed - emit_signal(SNAME("tab_closed"), cb_hover); + emit_signal(SNAME("tab_close_pressed"), cb_hover); } cb_pressing = false; @@ -222,7 +222,7 @@ void TabBar::gui_input(const Ref<InputEvent> &p_event) { } } - if (max_drawn_tab <= 0) { + if (tabs.is_empty()) { // Return early if there are no actual tabs to handle input for. return; } @@ -1172,7 +1172,7 @@ void TabBar::_bind_methods() { ADD_SIGNAL(MethodInfo("tab_changed", PropertyInfo(Variant::INT, "tab"))); ADD_SIGNAL(MethodInfo("tab_rmb_clicked", PropertyInfo(Variant::INT, "tab"))); - ADD_SIGNAL(MethodInfo("tab_closed", PropertyInfo(Variant::INT, "tab"))); + ADD_SIGNAL(MethodInfo("tab_close_pressed", PropertyInfo(Variant::INT, "tab"))); ADD_SIGNAL(MethodInfo("tab_hovered", PropertyInfo(Variant::INT, "tab"))); ADD_SIGNAL(MethodInfo("active_tab_rearranged", PropertyInfo(Variant::INT, "idx_to"))); ADD_SIGNAL(MethodInfo("tab_clicked", PropertyInfo(Variant::INT, "tab"))); diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 8cb3b23020..cb7a6c0978 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1364,6 +1364,10 @@ void TextEdit::_notification(int p_what) { if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD) && virtual_keyboard_enabled) { DisplayServer::get_singleton()->virtual_keyboard_hide(); } + + if (deselect_on_focus_loss_enabled) { + deselect(); + } } break; case MainLoop::NOTIFICATION_OS_IME_UPDATE: { if (has_focus()) { @@ -3669,6 +3673,17 @@ bool TextEdit::is_selecting_enabled() const { return selecting_enabled; } +void TextEdit::set_deselect_on_focus_loss_enabled(const bool p_enabled) { + deselect_on_focus_loss_enabled = p_enabled; + if (p_enabled && selection.active && !has_focus()) { + deselect(); + } +} + +bool TextEdit::is_deselect_on_focus_loss_enabled() const { + return deselect_on_focus_loss_enabled; +} + void TextEdit::set_override_selected_font_color(bool p_override_selected_font_color) { override_selected_font_color = p_override_selected_font_color; } @@ -4716,6 +4731,9 @@ void TextEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("set_selecting_enabled", "enable"), &TextEdit::set_selecting_enabled); ClassDB::bind_method(D_METHOD("is_selecting_enabled"), &TextEdit::is_selecting_enabled); + ClassDB::bind_method(D_METHOD("set_deselect_on_focus_loss_enabled", "enable"), &TextEdit::set_deselect_on_focus_loss_enabled); + ClassDB::bind_method(D_METHOD("is_deselect_on_focus_loss_enabled"), &TextEdit::is_deselect_on_focus_loss_enabled); + ClassDB::bind_method(D_METHOD("set_override_selected_font_color", "override"), &TextEdit::set_override_selected_font_color); ClassDB::bind_method(D_METHOD("is_overriding_selected_font_color"), &TextEdit::is_overriding_selected_font_color); @@ -4875,9 +4893,9 @@ void TextEdit::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "context_menu_enabled"), "set_context_menu_enabled", "is_context_menu_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shortcut_keys_enabled"), "set_shortcut_keys_enabled", "is_shortcut_keys_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "selecting_enabled"), "set_selecting_enabled", "is_selecting_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "deselect_on_focus_loss_enabled"), "set_deselect_on_focus_loss_enabled", "is_deselect_on_focus_loss_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "virtual_keyboard_enabled"), "set_virtual_keyboard_enabled", "is_virtual_keyboard_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "middle_mouse_paste_enabled"), "set_middle_mouse_paste_enabled", "is_middle_mouse_paste_enabled"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "wrap_mode", PROPERTY_HINT_ENUM, "None,Boundary"), "set_line_wrapping_mode", "get_line_wrapping_mode"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "override_selected_font_color"), "set_override_selected_font_color", "is_overriding_selected_font_color"); diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index 8823e44c0d..23f80efce0 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -395,6 +395,7 @@ private: } selection; bool selecting_enabled = true; + bool deselect_on_focus_loss_enabled = true; Color font_selected_color = Color(1, 1, 1); Color selection_color = Color(1, 1, 1); @@ -753,6 +754,9 @@ public: void set_selecting_enabled(const bool p_enabled); bool is_selecting_enabled() const; + void set_deselect_on_focus_loss_enabled(const bool p_enabled); + bool is_deselect_on_focus_loss_enabled() const; + void set_override_selected_font_color(bool p_override_selected_font_color); bool is_overriding_selected_font_color() const; |