GUI: Fix text overlapping icon in `Tree`
This commit is contained in:
parent
6758a7f8c0
commit
07d23489f4
|
@ -339,6 +339,13 @@
|
||||||
Returns item's text base writing direction.
|
Returns item's text base writing direction.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="get_text_overrun_behavior" qualifiers="const">
|
||||||
|
<return type="int" enum="TextServer.OverrunBehavior" />
|
||||||
|
<param index="0" name="column" type="int" />
|
||||||
|
<description>
|
||||||
|
Returns the clipping behavior when the text exceeds the item's bounding rectangle in the given [param column]. By default it is [constant TextServer.OVERRUN_TRIM_ELLIPSIS].
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="get_tooltip_text" qualifiers="const">
|
<method name="get_tooltip_text" qualifiers="const">
|
||||||
<return type="String" />
|
<return type="String" />
|
||||||
<param index="0" name="column" type="int" />
|
<param index="0" name="column" type="int" />
|
||||||
|
@ -728,6 +735,14 @@
|
||||||
Sets item's text base writing direction.
|
Sets item's text base writing direction.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="set_text_overrun_behavior">
|
||||||
|
<return type="void" />
|
||||||
|
<param index="0" name="column" type="int" />
|
||||||
|
<param index="1" name="overrun_behavior" type="int" enum="TextServer.OverrunBehavior" />
|
||||||
|
<description>
|
||||||
|
Sets the clipping behavior when the text exceeds the item's bounding rectangle in the given [param column].
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="set_tooltip_text">
|
<method name="set_tooltip_text">
|
||||||
<return type="void" />
|
<return type="void" />
|
||||||
<param index="0" name="column" type="int" />
|
<param index="0" name="column" type="int" />
|
||||||
|
|
|
@ -352,6 +352,24 @@ TextServer::AutowrapMode TreeItem::get_autowrap_mode(int p_column) const {
|
||||||
return cells[p_column].autowrap_mode;
|
return cells[p_column].autowrap_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TreeItem::set_text_overrun_behavior(int p_column, TextServer::OverrunBehavior p_behavior) {
|
||||||
|
ERR_FAIL_INDEX(p_column, cells.size());
|
||||||
|
|
||||||
|
if (cells[p_column].text_buf->get_text_overrun_behavior() == p_behavior) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cells.write[p_column].text_buf->set_text_overrun_behavior(p_behavior);
|
||||||
|
cells.write[p_column].dirty = true;
|
||||||
|
_changed_notify(p_column);
|
||||||
|
cells.write[p_column].cached_minimum_size_dirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
TextServer::OverrunBehavior TreeItem::get_text_overrun_behavior(int p_column) const {
|
||||||
|
ERR_FAIL_INDEX_V(p_column, cells.size(), TextServer::OVERRUN_TRIM_ELLIPSIS);
|
||||||
|
return cells[p_column].text_buf->get_text_overrun_behavior();
|
||||||
|
}
|
||||||
|
|
||||||
void TreeItem::set_structured_text_bidi_override(int p_column, TextServer::StructuredTextParser p_parser) {
|
void TreeItem::set_structured_text_bidi_override(int p_column, TextServer::StructuredTextParser p_parser) {
|
||||||
ERR_FAIL_INDEX(p_column, cells.size());
|
ERR_FAIL_INDEX(p_column, cells.size());
|
||||||
|
|
||||||
|
@ -1512,6 +1530,9 @@ void TreeItem::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("set_autowrap_mode", "column", "autowrap_mode"), &TreeItem::set_autowrap_mode);
|
ClassDB::bind_method(D_METHOD("set_autowrap_mode", "column", "autowrap_mode"), &TreeItem::set_autowrap_mode);
|
||||||
ClassDB::bind_method(D_METHOD("get_autowrap_mode", "column"), &TreeItem::get_autowrap_mode);
|
ClassDB::bind_method(D_METHOD("get_autowrap_mode", "column"), &TreeItem::get_autowrap_mode);
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("set_text_overrun_behavior", "column", "overrun_behavior"), &TreeItem::set_text_overrun_behavior);
|
||||||
|
ClassDB::bind_method(D_METHOD("get_text_overrun_behavior", "column"), &TreeItem::get_text_overrun_behavior);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("set_structured_text_bidi_override", "column", "parser"), &TreeItem::set_structured_text_bidi_override);
|
ClassDB::bind_method(D_METHOD("set_structured_text_bidi_override", "column", "parser"), &TreeItem::set_structured_text_bidi_override);
|
||||||
ClassDB::bind_method(D_METHOD("get_structured_text_bidi_override", "column"), &TreeItem::get_structured_text_bidi_override);
|
ClassDB::bind_method(D_METHOD("get_structured_text_bidi_override", "column"), &TreeItem::get_structured_text_bidi_override);
|
||||||
|
|
||||||
|
@ -2096,7 +2117,12 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
|
||||||
buttons_width += button_size.width + theme_cache.button_margin;
|
buttons_width += button_size.width + theme_cache.button_margin;
|
||||||
}
|
}
|
||||||
|
|
||||||
p_item->cells.write[i].text_buf->set_width(item_width);
|
int text_width = item_width - theme_cache.inner_item_margin_left - theme_cache.inner_item_margin_right;
|
||||||
|
if (p_item->cells[i].icon.is_valid()) {
|
||||||
|
text_width -= p_item->cells[i].get_icon_size().x + theme_cache.h_separation;
|
||||||
|
}
|
||||||
|
|
||||||
|
p_item->cells.write[i].text_buf->set_width(text_width);
|
||||||
|
|
||||||
r_self_height = compute_item_height(p_item);
|
r_self_height = compute_item_height(p_item);
|
||||||
label_h = r_self_height + theme_cache.v_separation;
|
label_h = r_self_height + theme_cache.v_separation;
|
||||||
|
@ -2224,7 +2250,6 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
|
||||||
|
|
||||||
Point2i text_pos = item_rect.position;
|
Point2i text_pos = item_rect.position;
|
||||||
text_pos.y += Math::floor(p_draw_ofs.y) - _get_title_button_height();
|
text_pos.y += Math::floor(p_draw_ofs.y) - _get_title_button_height();
|
||||||
int text_width = p_item->cells[i].text_buf->get_size().x;
|
|
||||||
|
|
||||||
switch (p_item->cells[i].mode) {
|
switch (p_item->cells[i].mode) {
|
||||||
case TreeItem::CELL_MODE_STRING: {
|
case TreeItem::CELL_MODE_STRING: {
|
||||||
|
|
|
@ -117,6 +117,7 @@ private:
|
||||||
|
|
||||||
Cell() {
|
Cell() {
|
||||||
text_buf.instantiate();
|
text_buf.instantiate();
|
||||||
|
text_buf->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
Size2 get_icon_size() const;
|
Size2 get_icon_size() const;
|
||||||
|
@ -231,6 +232,9 @@ public:
|
||||||
void set_autowrap_mode(int p_column, TextServer::AutowrapMode p_mode);
|
void set_autowrap_mode(int p_column, TextServer::AutowrapMode p_mode);
|
||||||
TextServer::AutowrapMode get_autowrap_mode(int p_column) const;
|
TextServer::AutowrapMode get_autowrap_mode(int p_column) const;
|
||||||
|
|
||||||
|
void set_text_overrun_behavior(int p_column, TextServer::OverrunBehavior p_behavior);
|
||||||
|
TextServer::OverrunBehavior get_text_overrun_behavior(int p_column) const;
|
||||||
|
|
||||||
void set_structured_text_bidi_override(int p_column, TextServer::StructuredTextParser p_parser);
|
void set_structured_text_bidi_override(int p_column, TextServer::StructuredTextParser p_parser);
|
||||||
TextServer::StructuredTextParser get_structured_text_bidi_override(int p_column) const;
|
TextServer::StructuredTextParser get_structured_text_bidi_override(int p_column) const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue