Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add inner_item_margin_* Theme constants to the Tree control #75460

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions doc/classes/Tree.xml
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,18 @@
<theme_item name="icon_max_width" data_type="constant" type="int" default="0">
The maximum allowed width of the icon in item's cells. This limit is applied on top of the default size of the icon, but before the value set with [method TreeItem.set_icon_max_width]. The height is adjusted according to the icon's ratio.
</theme_item>
<theme_item name="inner_item_margin_bottom" data_type="constant" type="int" default="0">
The inner bottom margin of an item.
</theme_item>
<theme_item name="inner_item_margin_left" data_type="constant" type="int" default="0">
The inner left margin of an item.
</theme_item>
<theme_item name="inner_item_margin_right" data_type="constant" type="int" default="0">
The inner right margin of an item.
</theme_item>
<theme_item name="inner_item_margin_top" data_type="constant" type="int" default="0">
The inner top margin of an item.
</theme_item>
<theme_item name="item_margin" data_type="constant" type="int" default="16">
The horizontal margin at the start of an item. This is used when folding is enabled for the item.
</theme_item>
Expand Down
4 changes: 4 additions & 0 deletions editor/editor_themes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,10 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
theme->set_constant("h_separation", "Tree", 6 * EDSCALE);
theme->set_constant("guide_width", "Tree", border_width);
theme->set_constant("item_margin", "Tree", 3 * default_margin_size * EDSCALE);
theme->set_constant("inner_item_margin_bottom", "Tree", (default_margin_size + extra_spacing) * EDSCALE);
theme->set_constant("inner_item_margin_left", "Tree", (default_margin_size + extra_spacing) * EDSCALE);
theme->set_constant("inner_item_margin_right", "Tree", (default_margin_size + extra_spacing) * EDSCALE);
theme->set_constant("inner_item_margin_top", "Tree", (default_margin_size + extra_spacing) * EDSCALE);
theme->set_constant("button_margin", "Tree", default_margin_size * EDSCALE);
theme->set_constant("scroll_border", "Tree", 40 * EDSCALE);
theme->set_constant("scroll_speed", "Tree", 12);
Expand Down
11 changes: 7 additions & 4 deletions scene/gui/tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1652,6 +1652,10 @@ void Tree::_update_theme_item_cache() {
theme_cache.drop_position_color = get_theme_color(SNAME("drop_position_color"));
theme_cache.h_separation = get_theme_constant(SNAME("h_separation"));
theme_cache.v_separation = get_theme_constant(SNAME("v_separation"));
theme_cache.inner_item_margin_bottom = get_theme_constant(SNAME("inner_item_margin_bottom"));
theme_cache.inner_item_margin_left = get_theme_constant(SNAME("inner_item_margin_left"));
theme_cache.inner_item_margin_right = get_theme_constant(SNAME("inner_item_margin_right"));
theme_cache.inner_item_margin_top = get_theme_constant(SNAME("inner_item_margin_top"));
theme_cache.item_margin = get_theme_constant(SNAME("item_margin"));
theme_cache.button_margin = get_theme_constant(SNAME("button_margin"));
theme_cache.icon_max_width = get_theme_constant(SNAME("icon_max_width"));
Expand Down Expand Up @@ -1789,13 +1793,14 @@ int Tree::get_item_height(TreeItem *p_item) const {
void Tree::draw_item_rect(TreeItem::Cell &p_cell, const Rect2i &p_rect, const Color &p_color, const Color &p_icon_color, int p_ol_size, const Color &p_ol_color) {
ERR_FAIL_COND(theme_cache.font.is_null());

Rect2i rect = p_rect;
Rect2i rect = p_rect.grow_individual(-theme_cache.inner_item_margin_left, -theme_cache.inner_item_margin_top, -theme_cache.inner_item_margin_right, -theme_cache.inner_item_margin_bottom);
Size2 ts = p_cell.text_buf->get_size();
bool rtl = is_layout_rtl();

int w = 0;
Size2i bmsize;
if (!p_cell.icon.is_null()) {
Size2i bmsize = _get_cell_icon_size(p_cell);
bmsize = _get_cell_icon_size(p_cell);
w += bmsize.width + theme_cache.h_separation;
if (rect.size.width > 0 && (w + ts.width) > rect.size.width) {
ts.width = rect.size.width - w;
Expand Down Expand Up @@ -1834,8 +1839,6 @@ void Tree::draw_item_rect(TreeItem::Cell &p_cell, const Rect2i &p_rect, const Co
}

if (!p_cell.icon.is_null()) {
Size2i bmsize = _get_cell_icon_size(p_cell);

p_cell.draw_icon(ci, rect.position + Size2i(0, Math::floor((real_t)(rect.size.y - bmsize.y) / 2)), bmsize, p_icon_color);
rect.position.x += bmsize.x + theme_cache.h_separation;
rect.size.x -= bmsize.x + theme_cache.h_separation;
Expand Down
4 changes: 4 additions & 0 deletions scene/gui/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,10 @@ class Tree : public Control {

int h_separation = 0;
int v_separation = 0;
int inner_item_margin_bottom = 0;
int inner_item_margin_left = 0;
int inner_item_margin_right = 0;
int inner_item_margin_top = 0;
int item_margin = 0;
int button_margin = 0;
int icon_max_width = 0;
Expand Down
4 changes: 4 additions & 0 deletions scene/resources/default_theme/default_theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,10 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
theme->set_constant("h_separation", "Tree", 4 * scale);
theme->set_constant("v_separation", "Tree", 4 * scale);
theme->set_constant("item_margin", "Tree", 16 * scale);
theme->set_constant("inner_item_margin_bottom", "Tree", 0);
theme->set_constant("inner_item_margin_left", "Tree", 0);
theme->set_constant("inner_item_margin_right", "Tree", 0);
theme->set_constant("inner_item_margin_top", "Tree", 0);
theme->set_constant("button_margin", "Tree", 4 * scale);
theme->set_constant("draw_relationship_lines", "Tree", 0);
theme->set_constant("relationship_line_width", "Tree", 1);
Expand Down