You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-12 13:20:55 +00:00
Merge pull request #75340 from Barugon/tree_colunm_title_alignment
Implement column title alignment for `Tree`
This commit is contained in:
@@ -100,6 +100,13 @@
|
|||||||
Returns the column's title.
|
Returns the column's title.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="get_column_title_alignment" qualifiers="const">
|
||||||
|
<return type="int" enum="HorizontalAlignment" />
|
||||||
|
<param index="0" name="column" type="int" />
|
||||||
|
<description>
|
||||||
|
Returns the column title alignment.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="get_column_title_direction" qualifiers="const">
|
<method name="get_column_title_direction" qualifiers="const">
|
||||||
<return type="int" enum="Control.TextDirection" />
|
<return type="int" enum="Control.TextDirection" />
|
||||||
<param index="0" name="column" type="int" />
|
<param index="0" name="column" type="int" />
|
||||||
@@ -288,6 +295,14 @@
|
|||||||
Sets the title of a column.
|
Sets the title of a column.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="set_column_title_alignment">
|
||||||
|
<return type="void" />
|
||||||
|
<param index="0" name="column" type="int" />
|
||||||
|
<param index="1" name="title_alignment" type="int" enum="HorizontalAlignment" />
|
||||||
|
<description>
|
||||||
|
Sets the column title alignment. Note that [constant @GlobalScope.HORIZONTAL_ALIGNMENT_FILL] is not supported for column titles.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="set_column_title_direction">
|
<method name="set_column_title_direction">
|
||||||
<return type="void" />
|
<return type="void" />
|
||||||
<param index="0" name="column" type="int" />
|
<param index="0" name="column" type="int" />
|
||||||
|
|||||||
@@ -4047,7 +4047,24 @@ void Tree::_notification(int p_what) {
|
|||||||
int clip_w = tbrect.size.width - sb->get_minimum_size().width;
|
int clip_w = tbrect.size.width - sb->get_minimum_size().width;
|
||||||
columns.write[i].text_buf->set_width(clip_w);
|
columns.write[i].text_buf->set_width(clip_w);
|
||||||
|
|
||||||
Vector2 text_pos = tbrect.position + Point2i(sb->get_offset().x + (tbrect.size.width - columns[i].text_buf->get_size().x) / 2, (tbrect.size.height - columns[i].text_buf->get_size().y) / 2);
|
Vector2 text_pos = Point2i(tbrect.position.x, tbrect.position.y + (tbrect.size.height - columns[i].text_buf->get_size().y) / 2);
|
||||||
|
switch (columns[i].title_alignment) {
|
||||||
|
case HorizontalAlignment::HORIZONTAL_ALIGNMENT_LEFT: {
|
||||||
|
text_pos.x += cache.rtl ? tbrect.size.width - (sb->get_offset().x + columns[i].text_buf->get_size().x) : sb->get_offset().x;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case HorizontalAlignment::HORIZONTAL_ALIGNMENT_RIGHT: {
|
||||||
|
text_pos.x += cache.rtl ? sb->get_offset().x : tbrect.size.width - (sb->get_offset().x + columns[i].text_buf->get_size().x);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default: {
|
||||||
|
text_pos.x += sb->get_offset().x + (tbrect.size.width - columns[i].text_buf->get_size().x) / 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (theme_cache.font_outline_size > 0 && theme_cache.font_outline_color.a > 0) {
|
if (theme_cache.font_outline_size > 0 && theme_cache.font_outline_color.a > 0) {
|
||||||
columns[i].text_buf->draw_outline(ci, text_pos, theme_cache.font_outline_size, theme_cache.font_outline_color);
|
columns[i].text_buf->draw_outline(ci, text_pos, theme_cache.font_outline_size, theme_cache.font_outline_color);
|
||||||
}
|
}
|
||||||
@@ -4689,6 +4706,27 @@ String Tree::get_column_title(int p_column) const {
|
|||||||
return columns[p_column].title;
|
return columns[p_column].title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Tree::set_column_title_alignment(int p_column, HorizontalAlignment p_alignment) {
|
||||||
|
ERR_FAIL_INDEX(p_column, columns.size());
|
||||||
|
|
||||||
|
if (p_alignment == HORIZONTAL_ALIGNMENT_FILL) {
|
||||||
|
WARN_PRINT("HORIZONTAL_ALIGNMENT_FILL is not supported for column titles.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (columns[p_column].title_alignment == p_alignment) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
columns.write[p_column].title_alignment = p_alignment;
|
||||||
|
update_column(p_column);
|
||||||
|
queue_redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
HorizontalAlignment Tree::get_column_title_alignment(int p_column) const {
|
||||||
|
ERR_FAIL_INDEX_V(p_column, columns.size(), HorizontalAlignment::HORIZONTAL_ALIGNMENT_CENTER);
|
||||||
|
return columns[p_column].title_alignment;
|
||||||
|
}
|
||||||
|
|
||||||
void Tree::set_column_title_direction(int p_column, Control::TextDirection p_text_direction) {
|
void Tree::set_column_title_direction(int p_column, Control::TextDirection p_text_direction) {
|
||||||
ERR_FAIL_INDEX(p_column, columns.size());
|
ERR_FAIL_INDEX(p_column, columns.size());
|
||||||
ERR_FAIL_COND((int)p_text_direction < -1 || (int)p_text_direction > 3);
|
ERR_FAIL_COND((int)p_text_direction < -1 || (int)p_text_direction > 3);
|
||||||
@@ -5219,6 +5257,9 @@ void Tree::_bind_methods() {
|
|||||||
ClassDB::bind_method(D_METHOD("set_column_title", "column", "title"), &Tree::set_column_title);
|
ClassDB::bind_method(D_METHOD("set_column_title", "column", "title"), &Tree::set_column_title);
|
||||||
ClassDB::bind_method(D_METHOD("get_column_title", "column"), &Tree::get_column_title);
|
ClassDB::bind_method(D_METHOD("get_column_title", "column"), &Tree::get_column_title);
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("set_column_title_alignment", "column", "title_alignment"), &Tree::set_column_title_alignment);
|
||||||
|
ClassDB::bind_method(D_METHOD("get_column_title_alignment", "column"), &Tree::get_column_title_alignment);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("set_column_title_direction", "column", "direction"), &Tree::set_column_title_direction);
|
ClassDB::bind_method(D_METHOD("set_column_title_direction", "column", "direction"), &Tree::set_column_title_direction);
|
||||||
ClassDB::bind_method(D_METHOD("get_column_title_direction", "column"), &Tree::get_column_title_direction);
|
ClassDB::bind_method(D_METHOD("get_column_title_direction", "column"), &Tree::get_column_title_direction);
|
||||||
|
|
||||||
|
|||||||
@@ -435,6 +435,7 @@ private:
|
|||||||
bool expand = true;
|
bool expand = true;
|
||||||
bool clip_content = false;
|
bool clip_content = false;
|
||||||
String title;
|
String title;
|
||||||
|
HorizontalAlignment title_alignment = HORIZONTAL_ALIGNMENT_CENTER;
|
||||||
Ref<TextLine> text_buf;
|
Ref<TextLine> text_buf;
|
||||||
String language;
|
String language;
|
||||||
Control::TextDirection text_direction = Control::TEXT_DIRECTION_INHERITED;
|
Control::TextDirection text_direction = Control::TEXT_DIRECTION_INHERITED;
|
||||||
@@ -684,6 +685,9 @@ public:
|
|||||||
void set_column_title(int p_column, const String &p_title);
|
void set_column_title(int p_column, const String &p_title);
|
||||||
String get_column_title(int p_column) const;
|
String get_column_title(int p_column) const;
|
||||||
|
|
||||||
|
void set_column_title_alignment(int p_column, HorizontalAlignment p_alignment);
|
||||||
|
HorizontalAlignment get_column_title_alignment(int p_column) const;
|
||||||
|
|
||||||
void set_column_title_direction(int p_column, Control::TextDirection p_text_direction);
|
void set_column_title_direction(int p_column, Control::TextDirection p_text_direction);
|
||||||
Control::TextDirection get_column_title_direction(int p_column) const;
|
Control::TextDirection get_column_title_direction(int p_column) const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user