diff options
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/button.cpp | 10 | ||||
-rw-r--r-- | scene/gui/button.h | 6 | ||||
-rw-r--r-- | scene/gui/color_picker.cpp | 4 | ||||
-rw-r--r-- | scene/gui/control.cpp | 4 | ||||
-rw-r--r-- | scene/gui/dialogs.cpp | 4 | ||||
-rw-r--r-- | scene/gui/item_list.cpp | 4 | ||||
-rw-r--r-- | scene/gui/item_list.h | 6 | ||||
-rw-r--r-- | scene/gui/label.cpp | 79 | ||||
-rw-r--r-- | scene/gui/label.h | 46 | ||||
-rw-r--r-- | scene/gui/popup_menu.cpp | 9 | ||||
-rw-r--r-- | scene/gui/popup_menu.h | 3 | ||||
-rw-r--r-- | scene/gui/rich_text_label.cpp | 41 | ||||
-rw-r--r-- | scene/gui/rich_text_label.h | 29 |
13 files changed, 93 insertions, 152 deletions
diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp index 0d21d82896..1371c9cd57 100644 --- a/scene/gui/button.cpp +++ b/scene/gui/button.cpp @@ -35,7 +35,7 @@ Size2 Button::get_minimum_size() const { Size2 minsize = text_buf->get_size(); - if (clip_text || overrun_behavior != TextParagraph::OVERRUN_NO_TRIMMING) { + if (clip_text || overrun_behavior != TextServer::OVERRUN_NO_TRIMMING) { minsize.width = 0; } @@ -292,9 +292,9 @@ void Button::_notification(int p_what) { icon_ofs.x = 0.0; } int text_clip = size.width - style->get_minimum_size().width - icon_ofs.width; - text_buf->set_width((clip_text || overrun_behavior != TextParagraph::OVERRUN_NO_TRIMMING) ? text_clip : -1); + text_buf->set_width((clip_text || overrun_behavior != TextServer::OVERRUN_NO_TRIMMING) ? text_clip : -1); - int text_width = MAX(1, (clip_text || overrun_behavior != TextParagraph::OVERRUN_NO_TRIMMING) ? MIN(text_clip, text_buf->get_size().x) : text_buf->get_size().x); + int text_width = MAX(1, (clip_text || overrun_behavior != TextServer::OVERRUN_NO_TRIMMING) ? MIN(text_clip, text_buf->get_size().x) : text_buf->get_size().x); if (_internal_margin[SIDE_LEFT] > 0) { text_clip -= _internal_margin[SIDE_LEFT] + get_theme_constant(SNAME("h_separation")); @@ -367,7 +367,7 @@ void Button::_shape() { text_buf->set_text_overrun_behavior(overrun_behavior); } -void Button::set_text_overrun_behavior(TextParagraph::OverrunBehavior p_behavior) { +void Button::set_text_overrun_behavior(TextServer::OverrunBehavior p_behavior) { if (overrun_behavior != p_behavior) { overrun_behavior = p_behavior; _shape(); @@ -377,7 +377,7 @@ void Button::set_text_overrun_behavior(TextParagraph::OverrunBehavior p_behavior } } -TextParagraph::OverrunBehavior Button::get_text_overrun_behavior() const { +TextServer::OverrunBehavior Button::get_text_overrun_behavior() const { return overrun_behavior; } diff --git a/scene/gui/button.h b/scene/gui/button.h index 175785a35c..a1d71195cb 100644 --- a/scene/gui/button.h +++ b/scene/gui/button.h @@ -46,7 +46,7 @@ private: Dictionary opentype_features; String language; TextDirection text_direction = TEXT_DIRECTION_AUTO; - TextParagraph::OverrunBehavior overrun_behavior = TextParagraph::OVERRUN_NO_TRIMMING; + TextServer::OverrunBehavior overrun_behavior = TextServer::OVERRUN_NO_TRIMMING; Ref<Texture2D> icon; bool expand_icon = false; @@ -72,8 +72,8 @@ public: void set_text(const String &p_text); String get_text() const; - void set_text_overrun_behavior(TextParagraph::OverrunBehavior p_behavior); - TextParagraph::OverrunBehavior get_text_overrun_behavior() const; + void set_text_overrun_behavior(TextServer::OverrunBehavior p_behavior); + TextServer::OverrunBehavior get_text_overrun_behavior() const; void set_text_direction(TextDirection p_text_direction); TextDirection get_text_direction() const; diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 5fff1e1df3..28d645e8f6 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -1108,7 +1108,7 @@ void ColorPicker::_screen_input(const Ref<InputEvent> &p_event) { Ref<Image> img = r->get_texture()->get_image(); if (img.is_valid() && !img->is_empty()) { Vector2 ofs = mev->get_global_position() - r->get_visible_rect().get_position(); - Color c = img->get_pixel(ofs.x, r->get_visible_rect().size.height - ofs.y); + Color c = img->get_pixel(ofs.x, ofs.y); set_pick_color(c); } @@ -1135,6 +1135,8 @@ void ColorPicker::_screen_pick_pressed() { screen->connect("gui_input", callable_mp(this, &ColorPicker::_screen_input)); // It immediately toggles off in the first press otherwise. screen->call_deferred(SNAME("connect"), "hidden", Callable(btn_pick, "set_pressed"), varray(false)); + } else { + screen->show(); } screen->raise(); #ifndef _MSC_VER diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 3db1719226..5ddc38a0b9 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -478,6 +478,10 @@ void Control::_validate_property(PropertyInfo &property) const { } } + if (property.name == "scale") { + property.hint = PROPERTY_HINT_LINK; + } + // Validate which positioning properties should be displayed depending on the parent and the layout mode. Node *parent_node = get_parent_control(); if (!parent_node) { diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index 0bb96a18a5..192d214262 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -154,11 +154,11 @@ bool AcceptDialog::get_close_on_escape() const { } void AcceptDialog::set_autowrap(bool p_autowrap) { - label->set_autowrap_mode(p_autowrap ? Label::AUTOWRAP_WORD : Label::AUTOWRAP_OFF); + label->set_autowrap_mode(p_autowrap ? TextServer::AUTOWRAP_WORD : TextServer::AUTOWRAP_OFF); } bool AcceptDialog::has_autowrap() { - return label->get_autowrap_mode() != Label::AUTOWRAP_OFF; + return label->get_autowrap_mode() != TextServer::AUTOWRAP_OFF; } void AcceptDialog::register_text_enter(Control *p_line_edit) { diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index 0c95dabfb5..aeb5338022 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -1550,7 +1550,7 @@ bool ItemList::has_auto_height() const { return auto_height; } -void ItemList::set_text_overrun_behavior(TextParagraph::OverrunBehavior p_behavior) { +void ItemList::set_text_overrun_behavior(TextServer::OverrunBehavior p_behavior) { if (text_overrun_behavior != p_behavior) { text_overrun_behavior = p_behavior; for (int i = 0; i < items.size(); i++) { @@ -1561,7 +1561,7 @@ void ItemList::set_text_overrun_behavior(TextParagraph::OverrunBehavior p_behavi } } -TextParagraph::OverrunBehavior ItemList::get_text_overrun_behavior() const { +TextServer::OverrunBehavior ItemList::get_text_overrun_behavior() const { return text_overrun_behavior; } diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h index ffbe7d055a..a15b090149 100644 --- a/scene/gui/item_list.h +++ b/scene/gui/item_list.h @@ -99,7 +99,7 @@ private: SelectMode select_mode = SELECT_SINGLE; IconMode icon_mode = ICON_MODE_LEFT; VScrollBar *scroll_bar = nullptr; - TextParagraph::OverrunBehavior text_overrun_behavior = TextParagraph::OVERRUN_TRIM_ELLIPSIS; + TextServer::OverrunBehavior text_overrun_behavior = TextServer::OVERRUN_TRIM_ELLIPSIS; uint64_t search_time_msec = 0; String search_string; @@ -188,8 +188,8 @@ public: void set_item_custom_fg_color(int p_idx, const Color &p_custom_fg_color); Color get_item_custom_fg_color(int p_idx) const; - void set_text_overrun_behavior(TextParagraph::OverrunBehavior p_behavior); - TextParagraph::OverrunBehavior get_text_overrun_behavior() const; + void set_text_overrun_behavior(TextServer::OverrunBehavior p_behavior); + TextServer::OverrunBehavior get_text_overrun_behavior() const; void select(int p_idx, bool p_single = true); void deselect(int p_idx); diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index eda3d40f63..82ab7c2e18 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -36,19 +36,19 @@ #include "servers/text_server.h" -void Label::set_autowrap_mode(Label::AutowrapMode p_mode) { +void Label::set_autowrap_mode(TextServer::AutowrapMode p_mode) { if (autowrap_mode != p_mode) { autowrap_mode = p_mode; lines_dirty = true; } update(); - if (clip || overrun_behavior != OVERRUN_NO_TRIMMING) { + if (clip || overrun_behavior != TextServer::OVERRUN_NO_TRIMMING) { update_minimum_size(); } } -Label::AutowrapMode Label::get_autowrap_mode() const { +TextServer::AutowrapMode Label::get_autowrap_mode() const { return autowrap_mode; } @@ -96,7 +96,7 @@ void Label::_shape() { int font_size = get_theme_font_size(SNAME("font_size")); ERR_FAIL_COND(font.is_null()); String text = (uppercase) ? TS->string_to_upper(xl_text, lang) : xl_text; - if (visible_chars >= 0 && visible_chars_behavior == VC_CHARS_BEFORE_SHAPING) { + if (visible_chars >= 0 && visible_chars_behavior == TextServer::VC_CHARS_BEFORE_SHAPING) { text = text.substr(0, visible_chars); } if (dirty) { @@ -121,16 +121,16 @@ void Label::_shape() { uint16_t autowrap_flags = TextServer::BREAK_MANDATORY; switch (autowrap_mode) { - case AUTOWRAP_WORD_SMART: + case TextServer::AUTOWRAP_WORD_SMART: autowrap_flags = TextServer::BREAK_WORD_BOUND_ADAPTIVE | TextServer::BREAK_MANDATORY; break; - case AUTOWRAP_WORD: + case TextServer::AUTOWRAP_WORD: autowrap_flags = TextServer::BREAK_WORD_BOUND | TextServer::BREAK_MANDATORY; break; - case AUTOWRAP_ARBITRARY: + case TextServer::AUTOWRAP_ARBITRARY: autowrap_flags = TextServer::BREAK_GRAPHEME_BOUND | TextServer::BREAK_MANDATORY; break; - case AUTOWRAP_OFF: + case TextServer::AUTOWRAP_OFF: break; } PackedInt32Array line_breaks = TS->shaped_text_get_line_breaks(text_rid, width, 0, autowrap_flags); @@ -146,7 +146,7 @@ void Label::_shape() { return; } - if (autowrap_mode == AUTOWRAP_OFF) { + if (autowrap_mode == TextServer::AUTOWRAP_OFF) { minsize.width = 0.0f; for (int i = 0; i < lines_rid.size(); i++) { if (minsize.width < TS->shaped_text_get_size(lines_rid[i]).x) { @@ -156,31 +156,31 @@ void Label::_shape() { } if (lines_dirty) { - uint16_t overrun_flags = TextServer::OVERRUN_NO_TRIMMING; + uint16_t overrun_flags = TextServer::OVERRUN_NO_TRIM; switch (overrun_behavior) { - case OVERRUN_TRIM_WORD_ELLIPSIS: + case TextServer::OVERRUN_TRIM_WORD_ELLIPSIS: overrun_flags |= TextServer::OVERRUN_TRIM; overrun_flags |= TextServer::OVERRUN_TRIM_WORD_ONLY; overrun_flags |= TextServer::OVERRUN_ADD_ELLIPSIS; break; - case OVERRUN_TRIM_ELLIPSIS: + case TextServer::OVERRUN_TRIM_ELLIPSIS: overrun_flags |= TextServer::OVERRUN_TRIM; overrun_flags |= TextServer::OVERRUN_ADD_ELLIPSIS; break; - case OVERRUN_TRIM_WORD: + case TextServer::OVERRUN_TRIM_WORD: overrun_flags |= TextServer::OVERRUN_TRIM; overrun_flags |= TextServer::OVERRUN_TRIM_WORD_ONLY; break; - case OVERRUN_TRIM_CHAR: + case TextServer::OVERRUN_TRIM_CHAR: overrun_flags |= TextServer::OVERRUN_TRIM; break; - case OVERRUN_NO_TRIMMING: + case TextServer::OVERRUN_NO_TRIMMING: break; } // Fill after min_size calculation. - if (autowrap_mode != AUTOWRAP_OFF) { + if (autowrap_mode != TextServer::AUTOWRAP_OFF) { int visible_lines = get_visible_line_count(); bool lines_hidden = visible_lines > 0 && visible_lines < lines_rid.size(); if (lines_hidden) { @@ -215,7 +215,7 @@ void Label::_shape() { _update_visible(); - if (autowrap_mode == AUTOWRAP_OFF || !clip || overrun_behavior == OVERRUN_NO_TRIMMING) { + if (autowrap_mode == TextServer::AUTOWRAP_OFF || !clip || overrun_behavior == TextServer::OVERRUN_NO_TRIMMING) { update_minimum_size(); } } @@ -326,9 +326,9 @@ void Label::_notification(int p_what) { } int last_line = MIN(lines_rid.size(), lines_visible + lines_skipped); - bool trim_chars = (visible_chars >= 0) && (visible_chars_behavior == VC_CHARS_AFTER_SHAPING); - bool trim_glyphs_ltr = (visible_chars >= 0) && ((visible_chars_behavior == VC_GLYPHS_LTR) || ((visible_chars_behavior == VC_GLYPHS_AUTO) && !rtl_layout)); - bool trim_glyphs_rtl = (visible_chars >= 0) && ((visible_chars_behavior == VC_GLYPHS_RTL) || ((visible_chars_behavior == VC_GLYPHS_AUTO) && rtl_layout)); + bool trim_chars = (visible_chars >= 0) && (visible_chars_behavior == TextServer::VC_CHARS_AFTER_SHAPING); + bool trim_glyphs_ltr = (visible_chars >= 0) && ((visible_chars_behavior == TextServer::VC_GLYPHS_LTR) || ((visible_chars_behavior == TextServer::VC_GLYPHS_AUTO) && !rtl_layout)); + bool trim_glyphs_rtl = (visible_chars >= 0) && ((visible_chars_behavior == TextServer::VC_GLYPHS_RTL) || ((visible_chars_behavior == TextServer::VC_GLYPHS_AUTO) && rtl_layout)); // Get real total height. int total_glyphs = 0; @@ -377,7 +377,7 @@ void Label::_notification(int p_what) { ofs.y += TS->shaped_text_get_ascent(lines_rid[i]) + font->get_spacing(TextServer::SPACING_TOP); switch (horizontal_alignment) { case HORIZONTAL_ALIGNMENT_FILL: - if (rtl && autowrap_mode != AUTOWRAP_OFF) { + if (rtl && autowrap_mode != TextServer::AUTOWRAP_OFF) { ofs.x = int(size.width - style->get_margin(SIDE_RIGHT) - line_size.width); } else { ofs.x = style->get_offset().x; @@ -554,10 +554,10 @@ Size2 Label::get_minimum_size() const { min_size.height = MAX(min_size.height, font->get_height(get_theme_font_size(SNAME("font_size"))) + font->get_spacing(TextServer::SPACING_TOP) + font->get_spacing(TextServer::SPACING_BOTTOM)); Size2 min_style = get_theme_stylebox(SNAME("normal"))->get_minimum_size(); - if (autowrap_mode != AUTOWRAP_OFF) { - return Size2(1, (clip || overrun_behavior != OVERRUN_NO_TRIMMING) ? 1 : min_size.height) + min_style; + if (autowrap_mode != TextServer::AUTOWRAP_OFF) { + return Size2(1, (clip || overrun_behavior != TextServer::OVERRUN_NO_TRIMMING) ? 1 : min_size.height) + min_style; } else { - if (clip || overrun_behavior != OVERRUN_NO_TRIMMING) { + if (clip || overrun_behavior != TextServer::OVERRUN_NO_TRIMMING) { min_size.width = 1; } return min_size + min_style; @@ -719,18 +719,18 @@ bool Label::is_clipping_text() const { return clip; } -void Label::set_text_overrun_behavior(Label::OverrunBehavior p_behavior) { +void Label::set_text_overrun_behavior(TextServer::OverrunBehavior p_behavior) { if (overrun_behavior != p_behavior) { overrun_behavior = p_behavior; lines_dirty = true; } update(); - if (clip || overrun_behavior != OVERRUN_NO_TRIMMING) { + if (clip || overrun_behavior != TextServer::OVERRUN_NO_TRIMMING) { update_minimum_size(); } } -Label::OverrunBehavior Label::get_text_overrun_behavior() const { +TextServer::OverrunBehavior Label::get_text_overrun_behavior() const { return overrun_behavior; } @@ -746,7 +746,7 @@ void Label::set_visible_characters(int p_amount) { } else { percent_visible = 1.0; } - if (visible_chars_behavior == VC_CHARS_BEFORE_SHAPING) { + if (visible_chars_behavior == TextServer::VC_CHARS_BEFORE_SHAPING) { dirty = true; } update(); @@ -766,7 +766,7 @@ void Label::set_percent_visible(float p_percent) { visible_chars = get_total_character_count() * p_percent; percent_visible = p_percent; } - if (visible_chars_behavior == VC_CHARS_BEFORE_SHAPING) { + if (visible_chars_behavior == TextServer::VC_CHARS_BEFORE_SHAPING) { dirty = true; } update(); @@ -777,11 +777,11 @@ float Label::get_percent_visible() const { return percent_visible; } -Label::VisibleCharactersBehavior Label::get_visible_characters_behavior() const { +TextServer::VisibleCharactersBehavior Label::get_visible_characters_behavior() const { return visible_chars_behavior; } -void Label::set_visible_characters_behavior(Label::VisibleCharactersBehavior p_behavior) { +void Label::set_visible_characters_behavior(TextServer::VisibleCharactersBehavior p_behavior) { if (visible_chars_behavior != p_behavior) { visible_chars_behavior = p_behavior; dirty = true; @@ -909,23 +909,6 @@ void Label::_bind_methods() { ClassDB::bind_method(D_METHOD("set_structured_text_bidi_override_options", "args"), &Label::set_structured_text_bidi_override_options); ClassDB::bind_method(D_METHOD("get_structured_text_bidi_override_options"), &Label::get_structured_text_bidi_override_options); - BIND_ENUM_CONSTANT(AUTOWRAP_OFF); - BIND_ENUM_CONSTANT(AUTOWRAP_ARBITRARY); - BIND_ENUM_CONSTANT(AUTOWRAP_WORD); - BIND_ENUM_CONSTANT(AUTOWRAP_WORD_SMART); - - BIND_ENUM_CONSTANT(OVERRUN_NO_TRIMMING); - BIND_ENUM_CONSTANT(OVERRUN_TRIM_CHAR); - BIND_ENUM_CONSTANT(OVERRUN_TRIM_WORD); - BIND_ENUM_CONSTANT(OVERRUN_TRIM_ELLIPSIS); - BIND_ENUM_CONSTANT(OVERRUN_TRIM_WORD_ELLIPSIS); - - BIND_ENUM_CONSTANT(VC_CHARS_BEFORE_SHAPING); - BIND_ENUM_CONSTANT(VC_CHARS_AFTER_SHAPING); - BIND_ENUM_CONSTANT(VC_GLYPHS_AUTO); - BIND_ENUM_CONSTANT(VC_GLYPHS_LTR); - BIND_ENUM_CONSTANT(VC_GLYPHS_RTL); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "text", PROPERTY_HINT_MULTILINE_TEXT, "", PROPERTY_USAGE_DEFAULT_INTL), "set_text", "get_text"); ADD_PROPERTY(PropertyInfo(Variant::INT, "horizontal_alignment", PROPERTY_HINT_ENUM, "Left,Center,Right,Fill"), "set_horizontal_alignment", "get_horizontal_alignment"); ADD_PROPERTY(PropertyInfo(Variant::INT, "vertical_alignment", PROPERTY_HINT_ENUM, "Top,Center,Bottom,Fill"), "set_vertical_alignment", "get_vertical_alignment"); diff --git a/scene/gui/label.h b/scene/gui/label.h index f7b725928f..fac3d75a1b 100644 --- a/scene/gui/label.h +++ b/scene/gui/label.h @@ -36,38 +36,14 @@ class Label : public Control { GDCLASS(Label, Control); -public: - enum AutowrapMode { - AUTOWRAP_OFF, - AUTOWRAP_ARBITRARY, - AUTOWRAP_WORD, - AUTOWRAP_WORD_SMART - }; - - enum OverrunBehavior { - OVERRUN_NO_TRIMMING, - OVERRUN_TRIM_CHAR, - OVERRUN_TRIM_WORD, - OVERRUN_TRIM_ELLIPSIS, - OVERRUN_TRIM_WORD_ELLIPSIS, - }; - - enum VisibleCharactersBehavior { - VC_CHARS_BEFORE_SHAPING, - VC_CHARS_AFTER_SHAPING, - VC_GLYPHS_AUTO, - VC_GLYPHS_LTR, - VC_GLYPHS_RTL, - }; - private: HorizontalAlignment horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT; VerticalAlignment vertical_alignment = VERTICAL_ALIGNMENT_TOP; String text; String xl_text; - AutowrapMode autowrap_mode = AUTOWRAP_OFF; + TextServer::AutowrapMode autowrap_mode = TextServer::AUTOWRAP_OFF; bool clip = false; - OverrunBehavior overrun_behavior = OVERRUN_NO_TRIMMING; + TextServer::OverrunBehavior overrun_behavior = TextServer::OVERRUN_NO_TRIMMING; Size2 minsize; bool uppercase = false; @@ -85,7 +61,7 @@ private: float percent_visible = 1.0; - VisibleCharactersBehavior visible_chars_behavior = VC_CHARS_BEFORE_SHAPING; + TextServer::VisibleCharactersBehavior visible_chars_behavior = TextServer::VC_CHARS_BEFORE_SHAPING; int visible_chars = -1; int lines_skipped = 0; int max_lines_visible = -1; @@ -130,14 +106,14 @@ public: void set_structured_text_bidi_override_options(Array p_args); Array get_structured_text_bidi_override_options() const; - void set_autowrap_mode(AutowrapMode p_mode); - AutowrapMode get_autowrap_mode() const; + void set_autowrap_mode(TextServer::AutowrapMode p_mode); + TextServer::AutowrapMode get_autowrap_mode() const; void set_uppercase(bool p_uppercase); bool is_uppercase() const; - VisibleCharactersBehavior get_visible_characters_behavior() const; - void set_visible_characters_behavior(VisibleCharactersBehavior p_behavior); + TextServer::VisibleCharactersBehavior get_visible_characters_behavior() const; + void set_visible_characters_behavior(TextServer::VisibleCharactersBehavior p_behavior); void set_visible_characters(int p_amount); int get_visible_characters() const; @@ -146,8 +122,8 @@ public: void set_clip_text(bool p_clip); bool is_clipping_text() const; - void set_text_overrun_behavior(OverrunBehavior p_behavior); - OverrunBehavior get_text_overrun_behavior() const; + void set_text_overrun_behavior(TextServer::OverrunBehavior p_behavior); + TextServer::OverrunBehavior get_text_overrun_behavior() const; void set_percent_visible(float p_percent); float get_percent_visible() const; @@ -166,8 +142,4 @@ public: ~Label(); }; -VARIANT_ENUM_CAST(Label::AutowrapMode); -VARIANT_ENUM_CAST(Label::OverrunBehavior); -VARIANT_ENUM_CAST(Label::VisibleCharactersBehavior); - #endif diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index c9eecf54dd..5931c112eb 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -1274,6 +1274,11 @@ Ref<Shortcut> PopupMenu::get_item_shortcut(int p_idx) const { return items[p_idx].shortcut; } +int PopupMenu::get_item_horizontal_offset(int p_idx) const { + ERR_FAIL_INDEX_V(p_idx, items.size(), 0); + return items[p_idx].h_ofs; +} + int PopupMenu::get_item_state(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, items.size(), -1); return items[p_idx].state; @@ -1339,7 +1344,7 @@ void PopupMenu::set_item_shortcut(int p_idx, const Ref<Shortcut> &p_shortcut, bo control->update(); } -void PopupMenu::set_item_h_offset(int p_idx, int p_offset) { +void PopupMenu::set_item_horizontal_offset(int p_idx, int p_offset) { if (p_idx < 0) { p_idx += get_item_count(); } @@ -1862,6 +1867,7 @@ void PopupMenu::_bind_methods() { ClassDB::bind_method(D_METHOD("set_item_as_radio_checkable", "index", "enable"), &PopupMenu::set_item_as_radio_checkable); ClassDB::bind_method(D_METHOD("set_item_tooltip", "index", "tooltip"), &PopupMenu::set_item_tooltip); ClassDB::bind_method(D_METHOD("set_item_shortcut", "index", "shortcut", "global"), &PopupMenu::set_item_shortcut, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("set_item_horizontal_offset", "index", "offset"), &PopupMenu::set_item_horizontal_offset); ClassDB::bind_method(D_METHOD("set_item_multistate", "index", "state"), &PopupMenu::set_item_multistate); ClassDB::bind_method(D_METHOD("set_item_shortcut_disabled", "index", "disabled"), &PopupMenu::set_item_shortcut_disabled); @@ -1887,6 +1893,7 @@ void PopupMenu::_bind_methods() { ClassDB::bind_method(D_METHOD("is_item_shortcut_disabled", "index"), &PopupMenu::is_item_shortcut_disabled); ClassDB::bind_method(D_METHOD("get_item_tooltip", "index"), &PopupMenu::get_item_tooltip); ClassDB::bind_method(D_METHOD("get_item_shortcut", "index"), &PopupMenu::get_item_shortcut); + ClassDB::bind_method(D_METHOD("get_item_horizontal_offset", "index"), &PopupMenu::get_item_horizontal_offset); ClassDB::bind_method(D_METHOD("set_current_index", "index"), &PopupMenu::set_current_index); ClassDB::bind_method(D_METHOD("get_current_index"), &PopupMenu::get_current_index); diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h index 53bc5a8c22..8218c6122e 100644 --- a/scene/gui/popup_menu.h +++ b/scene/gui/popup_menu.h @@ -186,7 +186,7 @@ public: void set_item_as_radio_checkable(int p_idx, bool p_radio_checkable); void set_item_tooltip(int p_idx, const String &p_tooltip); void set_item_shortcut(int p_idx, const Ref<Shortcut> &p_shortcut, bool p_global = false); - void set_item_h_offset(int p_idx, int p_offset); + void set_item_horizontal_offset(int p_idx, int p_offset); void set_item_multistate(int p_idx, int p_state); void toggle_item_multistate(int p_idx); void set_item_shortcut_disabled(int p_idx, bool p_disabled); @@ -212,6 +212,7 @@ public: bool is_item_shortcut_disabled(int p_idx) const; String get_item_tooltip(int p_idx) const; Ref<Shortcut> get_item_shortcut(int p_idx) const; + int get_item_horizontal_offset(int p_idx) const; int get_item_state(int p_idx) const; void set_current_index(int p_idx); diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 4a0edd85f5..0516c8e722 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -426,16 +426,16 @@ float RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font> uint16_t autowrap_flags = TextServer::BREAK_MANDATORY; switch (autowrap_mode) { - case AUTOWRAP_WORD_SMART: + case TextServer::AUTOWRAP_WORD_SMART: autowrap_flags = TextServer::BREAK_WORD_BOUND_ADAPTIVE | TextServer::BREAK_MANDATORY; break; - case AUTOWRAP_WORD: + case TextServer::AUTOWRAP_WORD: autowrap_flags = TextServer::BREAK_WORD_BOUND | TextServer::BREAK_MANDATORY; break; - case AUTOWRAP_ARBITRARY: + case TextServer::AUTOWRAP_ARBITRARY: autowrap_flags = TextServer::BREAK_GRAPHEME_BOUND | TextServer::BREAK_MANDATORY; break; - case AUTOWRAP_OFF: + case TextServer::AUTOWRAP_OFF: break; } @@ -462,7 +462,7 @@ float RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font> Item *it_to = (p_line + 1 < (int)p_frame->lines.size()) ? p_frame->lines[p_line + 1].from : nullptr; int remaining_characters = visible_characters - l.char_offset; for (Item *it = l.from; it && it != it_to; it = _get_next_item(it)) { - if (visible_chars_behavior == VC_CHARS_BEFORE_SHAPING && visible_characters >= 0 && remaining_characters <= 0) { + if (visible_chars_behavior == TextServer::VC_CHARS_BEFORE_SHAPING && visible_characters >= 0 && remaining_characters <= 0) { break; } switch (it->type) { @@ -501,7 +501,7 @@ float RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font> Dictionary font_ftr = _find_font_features(it); String lang = _find_language(it); String tx = t->text; - if (visible_chars_behavior == VC_CHARS_BEFORE_SHAPING && visible_characters >= 0 && remaining_characters >= 0) { + if (visible_chars_behavior == TextServer::VC_CHARS_BEFORE_SHAPING && visible_characters >= 0 && remaining_characters >= 0) { tx = tx.substr(0, remaining_characters); } remaining_characters -= tx.length(); @@ -707,9 +707,9 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o bool rtl = (l.text_buf->get_direction() == TextServer::DIRECTION_RTL); bool lrtl = is_layout_rtl(); - bool trim_chars = (visible_characters >= 0) && (visible_chars_behavior == VC_CHARS_AFTER_SHAPING); - bool trim_glyphs_ltr = (visible_characters >= 0) && ((visible_chars_behavior == VC_GLYPHS_LTR) || ((visible_chars_behavior == VC_GLYPHS_AUTO) && !lrtl)); - bool trim_glyphs_rtl = (visible_characters >= 0) && ((visible_chars_behavior == VC_GLYPHS_RTL) || ((visible_chars_behavior == VC_GLYPHS_AUTO) && lrtl)); + bool trim_chars = (visible_characters >= 0) && (visible_chars_behavior == TextServer::VC_CHARS_AFTER_SHAPING); + bool trim_glyphs_ltr = (visible_characters >= 0) && ((visible_chars_behavior == TextServer::VC_GLYPHS_LTR) || ((visible_chars_behavior == TextServer::VC_GLYPHS_AUTO) && !lrtl)); + bool trim_glyphs_rtl = (visible_characters >= 0) && ((visible_chars_behavior == TextServer::VC_GLYPHS_RTL) || ((visible_chars_behavior == TextServer::VC_GLYPHS_AUTO) && lrtl)); int total_glyphs = (trim_glyphs_ltr || trim_glyphs_rtl) ? get_total_glyph_count() : 0; int visible_glyphs = total_glyphs * percent_visible; @@ -4752,7 +4752,7 @@ String RichTextLabel::get_language() const { return language; } -void RichTextLabel::set_autowrap_mode(RichTextLabel::AutowrapMode p_mode) { +void RichTextLabel::set_autowrap_mode(TextServer::AutowrapMode p_mode) { if (autowrap_mode != p_mode) { _stop_thread(); @@ -4763,7 +4763,7 @@ void RichTextLabel::set_autowrap_mode(RichTextLabel::AutowrapMode p_mode) { } } -RichTextLabel::AutowrapMode RichTextLabel::get_autowrap_mode() const { +TextServer::AutowrapMode RichTextLabel::get_autowrap_mode() const { return autowrap_mode; } @@ -4778,7 +4778,7 @@ void RichTextLabel::set_percent_visible(float p_percent) { visible_characters = get_total_character_count() * p_percent; percent_visible = p_percent; } - if (visible_chars_behavior == VC_CHARS_BEFORE_SHAPING) { + if (visible_chars_behavior == TextServer::VC_CHARS_BEFORE_SHAPING) { main->first_invalid_line.store(0); //invalidate ALL _validate_line_caches(); } @@ -5032,11 +5032,6 @@ void RichTextLabel::_bind_methods() { ADD_SIGNAL(MethodInfo("finished")); - BIND_ENUM_CONSTANT(AUTOWRAP_OFF); - BIND_ENUM_CONSTANT(AUTOWRAP_ARBITRARY); - BIND_ENUM_CONSTANT(AUTOWRAP_WORD); - BIND_ENUM_CONSTANT(AUTOWRAP_WORD_SMART); - BIND_ENUM_CONSTANT(LIST_NUMBERS); BIND_ENUM_CONSTANT(LIST_LETTERS); BIND_ENUM_CONSTANT(LIST_ROMAN); @@ -5069,19 +5064,13 @@ void RichTextLabel::_bind_methods() { BIND_ENUM_CONSTANT(ITEM_HINT); BIND_ENUM_CONSTANT(ITEM_DROPCAP); BIND_ENUM_CONSTANT(ITEM_CUSTOMFX); - - BIND_ENUM_CONSTANT(VC_CHARS_BEFORE_SHAPING); - BIND_ENUM_CONSTANT(VC_CHARS_AFTER_SHAPING); - BIND_ENUM_CONSTANT(VC_GLYPHS_AUTO); - BIND_ENUM_CONSTANT(VC_GLYPHS_LTR); - BIND_ENUM_CONSTANT(VC_GLYPHS_RTL); } -RichTextLabel::VisibleCharactersBehavior RichTextLabel::get_visible_characters_behavior() const { +TextServer::VisibleCharactersBehavior RichTextLabel::get_visible_characters_behavior() const { return visible_chars_behavior; } -void RichTextLabel::set_visible_characters_behavior(RichTextLabel::VisibleCharactersBehavior p_behavior) { +void RichTextLabel::set_visible_characters_behavior(TextServer::VisibleCharactersBehavior p_behavior) { if (visible_chars_behavior != p_behavior) { _stop_thread(); @@ -5105,7 +5094,7 @@ void RichTextLabel::set_visible_characters(int p_visible) { percent_visible = (float)p_visible / (float)total_char_count; } } - if (visible_chars_behavior == VC_CHARS_BEFORE_SHAPING) { + if (visible_chars_behavior == TextServer::VC_CHARS_BEFORE_SHAPING) { main->first_invalid_line.store(0); //invalidate ALL _validate_line_caches(); } diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index 93e57058b0..c697320976 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -40,13 +40,6 @@ class RichTextLabel : public Control { GDCLASS(RichTextLabel, Control); public: - enum AutowrapMode { - AUTOWRAP_OFF, - AUTOWRAP_ARBITRARY, - AUTOWRAP_WORD, - AUTOWRAP_WORD_SMART - }; - enum ListType { LIST_NUMBERS, LIST_LETTERS, @@ -84,14 +77,6 @@ public: ITEM_CUSTOMFX }; - enum VisibleCharactersBehavior { - VC_CHARS_BEFORE_SHAPING, - VC_CHARS_AFTER_SHAPING, - VC_GLYPHS_AUTO, - VC_GLYPHS_LTR, - VC_GLYPHS_RTL, - }; - enum MenuItems { MENU_COPY, MENU_SELECT_ALL, @@ -384,7 +369,7 @@ private: VScrollBar *vscroll = nullptr; - AutowrapMode autowrap_mode = AUTOWRAP_WORD_SMART; + TextServer::AutowrapMode autowrap_mode = TextServer::AUTOWRAP_WORD_SMART; bool scroll_visible = false; bool scroll_follow = false; @@ -460,7 +445,7 @@ private: int visible_characters = -1; float percent_visible = 1.0; - VisibleCharactersBehavior visible_chars_behavior = VC_CHARS_BEFORE_SHAPING; + TextServer::VisibleCharactersBehavior visible_chars_behavior = TextServer::VC_CHARS_BEFORE_SHAPING; bool _is_click_inside_selection() const; void _find_click(ItemFrame *p_frame, const Point2i &p_click, ItemFrame **r_click_frame = nullptr, int *r_click_line = nullptr, Item **r_click_item = nullptr, int *r_click_char = nullptr, bool *r_outside = nullptr); @@ -664,8 +649,8 @@ public: void set_language(const String &p_language); String get_language() const; - void set_autowrap_mode(AutowrapMode p_mode); - AutowrapMode get_autowrap_mode() const; + void set_autowrap_mode(TextServer::AutowrapMode p_mode); + TextServer::AutowrapMode get_autowrap_mode() const; void set_structured_text_bidi_override(TextServer::StructuredTextParser p_parser); TextServer::StructuredTextParser get_structured_text_bidi_override() const; @@ -683,8 +668,8 @@ public: void set_percent_visible(float p_percent); float get_percent_visible() const; - VisibleCharactersBehavior get_visible_characters_behavior() const; - void set_visible_characters_behavior(VisibleCharactersBehavior p_behavior); + TextServer::VisibleCharactersBehavior get_visible_characters_behavior() const; + void set_visible_characters_behavior(TextServer::VisibleCharactersBehavior p_behavior); void set_effects(Array p_effects); Array get_effects(); @@ -698,9 +683,7 @@ public: ~RichTextLabel(); }; -VARIANT_ENUM_CAST(RichTextLabel::AutowrapMode); VARIANT_ENUM_CAST(RichTextLabel::ListType); VARIANT_ENUM_CAST(RichTextLabel::ItemType); -VARIANT_ENUM_CAST(RichTextLabel::VisibleCharactersBehavior); #endif // RICH_TEXT_LABEL_H |