[TextServer] Add support for trimming edge spaces on line break.
This commit is contained in:
parent
1c037c89d4
commit
7aad14a4b6
9 changed files with 124 additions and 21 deletions
|
|
@ -544,7 +544,7 @@ void Button::_bind_methods() {
|
|||
|
||||
Button::Button(const String &p_text) {
|
||||
text_buf.instantiate();
|
||||
text_buf->set_break_flags(TextServer::BREAK_MANDATORY);
|
||||
text_buf->set_break_flags(TextServer::BREAK_MANDATORY | TextServer::BREAK_TRIM_EDGE_SPACES);
|
||||
set_mouse_filter(MOUSE_FILTER_STOP);
|
||||
|
||||
set_text(p_text);
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ void ItemList::_shape(int p_idx) {
|
|||
}
|
||||
item.text_buf->add_string(item.text, get_theme_font(SNAME("font")), get_theme_font_size(SNAME("font_size")), item.language);
|
||||
if (icon_mode == ICON_MODE_TOP && max_text_lines > 0) {
|
||||
item.text_buf->set_break_flags(TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND | TextServer::BREAK_GRAPHEME_BOUND);
|
||||
item.text_buf->set_break_flags(TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND | TextServer::BREAK_GRAPHEME_BOUND | TextServer::BREAK_TRIM_EDGE_SPACES);
|
||||
} else {
|
||||
item.text_buf->set_break_flags(TextServer::BREAK_NONE);
|
||||
}
|
||||
|
|
@ -532,7 +532,7 @@ void ItemList::set_max_text_lines(int p_lines) {
|
|||
max_text_lines = p_lines;
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
if (icon_mode == ICON_MODE_TOP && max_text_lines > 0) {
|
||||
items.write[i].text_buf->set_break_flags(TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND | TextServer::BREAK_GRAPHEME_BOUND);
|
||||
items.write[i].text_buf->set_break_flags(TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND | TextServer::BREAK_GRAPHEME_BOUND | TextServer::BREAK_TRIM_EDGE_SPACES);
|
||||
items.write[i].text_buf->set_max_lines_visible(p_lines);
|
||||
} else {
|
||||
items.write[i].text_buf->set_break_flags(TextServer::BREAK_NONE);
|
||||
|
|
@ -582,7 +582,7 @@ void ItemList::set_icon_mode(IconMode p_mode) {
|
|||
icon_mode = p_mode;
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
if (icon_mode == ICON_MODE_TOP && max_text_lines > 0) {
|
||||
items.write[i].text_buf->set_break_flags(TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND | TextServer::BREAK_GRAPHEME_BOUND);
|
||||
items.write[i].text_buf->set_break_flags(TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND | TextServer::BREAK_GRAPHEME_BOUND | TextServer::BREAK_TRIM_EDGE_SPACES);
|
||||
} else {
|
||||
items.write[i].text_buf->set_break_flags(TextServer::BREAK_NONE);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -143,8 +143,9 @@ void Label::_shape() {
|
|||
case TextServer::AUTOWRAP_OFF:
|
||||
break;
|
||||
}
|
||||
PackedInt32Array line_breaks = TS->shaped_text_get_line_breaks(text_rid, width, 0, autowrap_flags);
|
||||
autowrap_flags = autowrap_flags | TextServer::BREAK_TRIM_EDGE_SPACES;
|
||||
|
||||
PackedInt32Array line_breaks = TS->shaped_text_get_line_breaks(text_rid, width, 0, autowrap_flags);
|
||||
for (int i = 0; i < line_breaks.size(); i = i + 2) {
|
||||
RID line = TS->shaped_text_substr(text_rid, line_breaks[i], line_breaks[i + 1] - line_breaks[i]);
|
||||
lines_rid.push_back(line);
|
||||
|
|
|
|||
|
|
@ -453,6 +453,7 @@ float RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font>
|
|||
case TextServer::AUTOWRAP_OFF:
|
||||
break;
|
||||
}
|
||||
autowrap_flags = autowrap_flags | TextServer::BREAK_TRIM_EDGE_SPACES;
|
||||
|
||||
// Clear cache.
|
||||
l.text_buf->clear();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue