From 912b52a6a53adb28914ab8930caf3e71685dcb32 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pa=CC=84vels=20Nadtoc=CC=8Cajevs?=
<7645683+bruvzg@users.noreply.github.com>
Date: Mon, 10 Feb 2025 08:41:31 +0200
Subject: [PATCH] Expose `OVERRUN_ENFORCE_ELLIPSIS` flag to the controls.
---
doc/classes/TextServer.xml | 10 ++++++++--
scene/gui/button.cpp | 2 +-
scene/gui/item_list.cpp | 2 +-
scene/gui/label.cpp | 13 ++++++++++++-
scene/resources/text_line.cpp | 13 ++++++++++++-
scene/resources/text_paragraph.cpp | 13 ++++++++++++-
servers/text_server.cpp | 2 ++
servers/text_server.h | 2 ++
8 files changed, 50 insertions(+), 7 deletions(-)
diff --git a/doc/classes/TextServer.xml b/doc/classes/TextServer.xml
index bc7dc8ab93f..f6f1ad8e538 100644
--- a/doc/classes/TextServer.xml
+++ b/doc/classes/TextServer.xml
@@ -1970,10 +1970,16 @@
Trims the text per word.
- Trims the text per character and adds an ellipsis to indicate that parts are hidden.
+ Trims the text per character and adds an ellipsis to indicate that parts are hidden if trimmed text is 6 characters or longer.
- Trims the text per word and adds an ellipsis to indicate that parts are hidden.
+ Trims the text per word and adds an ellipsis to indicate that parts are hidden if trimmed text is 6 characters or longer.
+
+
+ Trims the text per character and adds an ellipsis to indicate that parts are hidden regardless of trimmed text length.
+
+
+ Trims the text per word and adds an ellipsis to indicate that parts are hidden regardless of trimmed text length.
No trimming is performed.
diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp
index 8975b85e108..738637ef36a 100644
--- a/scene/gui/button.cpp
+++ b/scene/gui/button.cpp
@@ -791,7 +791,7 @@ void Button::_bind_methods() {
ADD_GROUP("Text Behavior", "");
ADD_PROPERTY(PropertyInfo(Variant::INT, "alignment", PROPERTY_HINT_ENUM, "Left,Center,Right"), "set_text_alignment", "get_text_alignment");
- 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_PROPERTY(PropertyInfo(Variant::INT, "text_overrun_behavior", PROPERTY_HINT_ENUM, "Trim Nothing,Trim Characters,Trim Words,Ellipsis (6+ Characters),Word Ellipsis (6+ Characters),Ellipsis (Always),Word Ellipsis (Always)"), "set_text_overrun_behavior", "get_text_overrun_behavior");
ADD_PROPERTY(PropertyInfo(Variant::INT, "autowrap_mode", PROPERTY_HINT_ENUM, "Off,Arbitrary,Word,Word (Smart)"), "set_autowrap_mode", "get_autowrap_mode");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_text"), "set_clip_text", "get_clip_text");
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp
index f2598a2d132..cb262efd705 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -2080,7 +2080,7 @@ void ItemList::_bind_methods() {
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_width"), "set_auto_width", "has_auto_width");
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_PROPERTY(PropertyInfo(Variant::INT, "text_overrun_behavior", PROPERTY_HINT_ENUM, "Trim Nothing,Trim Characters,Trim Words,Ellipsis (6+ Characters),Word Ellipsis (6+ Characters),Ellipsis (Always),Word Ellipsis (Always)"), "set_text_overrun_behavior", "get_text_overrun_behavior");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "wraparound_items"), "set_wraparound_items", "has_wraparound_items");
ADD_ARRAY_COUNT("Items", "item_count", "set_item_count", "get_item_count", "item_");
ADD_GROUP("Columns", "");
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp
index c3fe9283c6e..6cb32d86456 100644
--- a/scene/gui/label.cpp
+++ b/scene/gui/label.cpp
@@ -228,6 +228,17 @@ void Label::_shape() const {
if (para.lines_dirty) {
BitField overrun_flags = TextServer::OVERRUN_NO_TRIM;
switch (overrun_behavior) {
+ case TextServer::OVERRUN_TRIM_WORD_ELLIPSIS_FORCE: {
+ overrun_flags.set_flag(TextServer::OVERRUN_TRIM);
+ overrun_flags.set_flag(TextServer::OVERRUN_TRIM_WORD_ONLY);
+ overrun_flags.set_flag(TextServer::OVERRUN_ADD_ELLIPSIS);
+ overrun_flags.set_flag(TextServer::OVERRUN_ENFORCE_ELLIPSIS);
+ } break;
+ case TextServer::OVERRUN_TRIM_ELLIPSIS_FORCE: {
+ overrun_flags.set_flag(TextServer::OVERRUN_TRIM);
+ overrun_flags.set_flag(TextServer::OVERRUN_ADD_ELLIPSIS);
+ overrun_flags.set_flag(TextServer::OVERRUN_ENFORCE_ELLIPSIS);
+ } break;
case TextServer::OVERRUN_TRIM_WORD_ELLIPSIS:
overrun_flags.set_flag(TextServer::OVERRUN_TRIM);
overrun_flags.set_flag(TextServer::OVERRUN_TRIM_WORD_ONLY);
@@ -1333,7 +1344,7 @@ void Label::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::STRING, "paragraph_separator"), "set_paragraph_separator", "get_paragraph_separator");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_text"), "set_clip_text", "is_clipping_text");
- 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_PROPERTY(PropertyInfo(Variant::INT, "text_overrun_behavior", PROPERTY_HINT_ENUM, "Trim Nothing,Trim Characters,Trim Words,Ellipsis (6+ Characters),Word Ellipsis (6+ Characters),Ellipsis (Always),Word Ellipsis (Always)"), "set_text_overrun_behavior", "get_text_overrun_behavior");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "ellipsis_char"), "set_ellipsis_char", "get_ellipsis_char");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "uppercase"), "set_uppercase", "is_uppercase");
ADD_PROPERTY(PropertyInfo(Variant::PACKED_FLOAT32_ARRAY, "tab_stops"), "set_tab_stops", "get_tab_stops");
diff --git a/scene/resources/text_line.cpp b/scene/resources/text_line.cpp
index af241e4fa6a..b39d602681d 100644
--- a/scene/resources/text_line.cpp
+++ b/scene/resources/text_line.cpp
@@ -79,7 +79,7 @@ void TextLine::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_text_overrun_behavior", "overrun_behavior"), &TextLine::set_text_overrun_behavior);
ClassDB::bind_method(D_METHOD("get_text_overrun_behavior"), &TextLine::get_text_overrun_behavior);
- 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_PROPERTY(PropertyInfo(Variant::INT, "text_overrun_behavior", PROPERTY_HINT_ENUM, "Trim Nothing,Trim Characters,Trim Words,Ellipsis (6+ Characters),Word Ellipsis (6+ Characters),Ellipsis (Always),Word Ellipsis (Always)"), "set_text_overrun_behavior", "get_text_overrun_behavior");
ClassDB::bind_method(D_METHOD("set_ellipsis_char", "char"), &TextLine::set_ellipsis_char);
ClassDB::bind_method(D_METHOD("get_ellipsis_char"), &TextLine::get_ellipsis_char);
@@ -118,6 +118,17 @@ void TextLine::_shape() const {
BitField overrun_flags = TextServer::OVERRUN_NO_TRIM;
if (overrun_behavior != TextServer::OVERRUN_NO_TRIMMING) {
switch (overrun_behavior) {
+ case TextServer::OVERRUN_TRIM_WORD_ELLIPSIS_FORCE: {
+ overrun_flags.set_flag(TextServer::OVERRUN_TRIM);
+ overrun_flags.set_flag(TextServer::OVERRUN_TRIM_WORD_ONLY);
+ overrun_flags.set_flag(TextServer::OVERRUN_ADD_ELLIPSIS);
+ overrun_flags.set_flag(TextServer::OVERRUN_ENFORCE_ELLIPSIS);
+ } break;
+ case TextServer::OVERRUN_TRIM_ELLIPSIS_FORCE: {
+ overrun_flags.set_flag(TextServer::OVERRUN_TRIM);
+ overrun_flags.set_flag(TextServer::OVERRUN_ADD_ELLIPSIS);
+ overrun_flags.set_flag(TextServer::OVERRUN_ENFORCE_ELLIPSIS);
+ } break;
case TextServer::OVERRUN_TRIM_WORD_ELLIPSIS:
overrun_flags.set_flag(TextServer::OVERRUN_TRIM);
overrun_flags.set_flag(TextServer::OVERRUN_TRIM_WORD_ONLY);
diff --git a/scene/resources/text_paragraph.cpp b/scene/resources/text_paragraph.cpp
index e3f2ebcc70c..10e82d00b02 100644
--- a/scene/resources/text_paragraph.cpp
+++ b/scene/resources/text_paragraph.cpp
@@ -87,7 +87,7 @@ void TextParagraph::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_text_overrun_behavior", "overrun_behavior"), &TextParagraph::set_text_overrun_behavior);
ClassDB::bind_method(D_METHOD("get_text_overrun_behavior"), &TextParagraph::get_text_overrun_behavior);
- 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_PROPERTY(PropertyInfo(Variant::INT, "text_overrun_behavior", PROPERTY_HINT_ENUM, "Trim Nothing,Trim Characters,Trim Words,Ellipsis (6+ Characters),Word Ellipsis (6+ Characters),Ellipsis (Always),Word Ellipsis (Always)"), "set_text_overrun_behavior", "get_text_overrun_behavior");
ClassDB::bind_method(D_METHOD("set_ellipsis_char", "char"), &TextParagraph::set_ellipsis_char);
ClassDB::bind_method(D_METHOD("get_ellipsis_char"), &TextParagraph::get_ellipsis_char);
@@ -213,6 +213,17 @@ void TextParagraph::_shape_lines() const {
BitField overrun_flags = TextServer::OVERRUN_NO_TRIM;
if (overrun_behavior != TextServer::OVERRUN_NO_TRIMMING) {
switch (overrun_behavior) {
+ case TextServer::OVERRUN_TRIM_WORD_ELLIPSIS_FORCE: {
+ overrun_flags.set_flag(TextServer::OVERRUN_TRIM);
+ overrun_flags.set_flag(TextServer::OVERRUN_TRIM_WORD_ONLY);
+ overrun_flags.set_flag(TextServer::OVERRUN_ADD_ELLIPSIS);
+ overrun_flags.set_flag(TextServer::OVERRUN_ENFORCE_ELLIPSIS);
+ } break;
+ case TextServer::OVERRUN_TRIM_ELLIPSIS_FORCE: {
+ overrun_flags.set_flag(TextServer::OVERRUN_TRIM);
+ overrun_flags.set_flag(TextServer::OVERRUN_ADD_ELLIPSIS);
+ overrun_flags.set_flag(TextServer::OVERRUN_ENFORCE_ELLIPSIS);
+ } break;
case TextServer::OVERRUN_TRIM_WORD_ELLIPSIS:
overrun_flags.set_flag(TextServer::OVERRUN_TRIM);
overrun_flags.set_flag(TextServer::OVERRUN_TRIM_WORD_ONLY);
diff --git a/servers/text_server.cpp b/servers/text_server.cpp
index 83a53bfc7c1..5a44e5f1661 100644
--- a/servers/text_server.cpp
+++ b/servers/text_server.cpp
@@ -565,6 +565,8 @@ void TextServer::_bind_methods() {
BIND_ENUM_CONSTANT(OVERRUN_TRIM_WORD);
BIND_ENUM_CONSTANT(OVERRUN_TRIM_ELLIPSIS);
BIND_ENUM_CONSTANT(OVERRUN_TRIM_WORD_ELLIPSIS);
+ BIND_ENUM_CONSTANT(OVERRUN_TRIM_ELLIPSIS_FORCE);
+ BIND_ENUM_CONSTANT(OVERRUN_TRIM_WORD_ELLIPSIS_FORCE);
/* TextOverrunFlag */
BIND_BITFIELD_FLAG(OVERRUN_NO_TRIM);
diff --git a/servers/text_server.h b/servers/text_server.h
index 7f5211bb5f5..dca4746e17e 100644
--- a/servers/text_server.h
+++ b/servers/text_server.h
@@ -119,6 +119,8 @@ public:
OVERRUN_TRIM_WORD,
OVERRUN_TRIM_ELLIPSIS,
OVERRUN_TRIM_WORD_ELLIPSIS,
+ OVERRUN_TRIM_ELLIPSIS_FORCE,
+ OVERRUN_TRIM_WORD_ELLIPSIS_FORCE,
};
enum TextOverrunFlag {