Skip to content

Commit

Permalink
Merge pull request #84845 from DarkMessiah/tree-disabled-checkbox
Browse files Browse the repository at this point in the history
Implement disabled state for Checkbox in Tree
  • Loading branch information
YuriSizov committed Dec 19, 2023
2 parents 921c400 + ff8797e commit 7aae85e
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 14 deletions.
18 changes: 15 additions & 3 deletions doc/classes/Tree.xml
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,9 @@
<theme_item name="font_color" data_type="color" type="Color" default="Color(0.7, 0.7, 0.7, 1)">
Default text [Color] of the item.
</theme_item>
<theme_item name="font_disabled_color" data_type="color" type="Color" default="Color(0.875, 0.875, 0.875, 0.5)">
Text [Color] for a [constant TreeItem.CELL_MODE_CHECK] mode cell when it's non-editable (see [method TreeItem.set_editable]).
</theme_item>
<theme_item name="font_outline_color" data_type="color" type="Color" default="Color(1, 1, 1, 1)">
The tint of text outline of the item.
</theme_item>
Expand Down Expand Up @@ -619,16 +622,25 @@
The arrow icon used when a foldable item is collapsed (for right-to-left layouts).
</theme_item>
<theme_item name="checked" data_type="icon" type="Texture2D">
The check icon to display when the [constant TreeItem.CELL_MODE_CHECK] mode cell is checked.
The check icon to display when the [constant TreeItem.CELL_MODE_CHECK] mode cell is checked and editable (see [method TreeItem.set_editable]).
</theme_item>
<theme_item name="checked_disabled" data_type="icon" type="Texture2D">
The check icon to display when the [constant TreeItem.CELL_MODE_CHECK] mode cell is checked and non-editable (see [method TreeItem.set_editable]).
</theme_item>
<theme_item name="indeterminate" data_type="icon" type="Texture2D">
The check icon to display when the [constant TreeItem.CELL_MODE_CHECK] mode cell is indeterminate.
The check icon to display when the [constant TreeItem.CELL_MODE_CHECK] mode cell is indeterminate and editable (see [method TreeItem.set_editable]).
</theme_item>
<theme_item name="indeterminate_disabled" data_type="icon" type="Texture2D">
The check icon to display when the [constant TreeItem.CELL_MODE_CHECK] mode cell is indeterminate and non-editable (see [method TreeItem.set_editable]).
</theme_item>
<theme_item name="select_arrow" data_type="icon" type="Texture2D">
The arrow icon to display for the [constant TreeItem.CELL_MODE_RANGE] mode cell.
</theme_item>
<theme_item name="unchecked" data_type="icon" type="Texture2D">
The check icon to display when the [constant TreeItem.CELL_MODE_CHECK] mode cell is unchecked.
The check icon to display when the [constant TreeItem.CELL_MODE_CHECK] mode cell is unchecked and editable (see [method TreeItem.set_editable]).
</theme_item>
<theme_item name="unchecked_disabled" data_type="icon" type="Texture2D">
The check icon to display when the [constant TreeItem.CELL_MODE_CHECK] mode cell is unchecked and non-editable (see [method TreeItem.set_editable]).
</theme_item>
<theme_item name="updown" data_type="icon" type="Texture2D">
The updown arrow icon to display for the [constant TreeItem.CELL_MODE_RANGE] mode cell.
Expand Down
4 changes: 4 additions & 0 deletions editor/editor_themes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1423,8 +1423,11 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {

// Tree
theme->set_icon("checked", "Tree", theme->get_icon(SNAME("GuiChecked"), EditorStringName(EditorIcons)));
theme->set_icon("checked_disabled", "Tree", theme->get_icon(SNAME("GuiCheckedDisabled"), EditorStringName(EditorIcons)));
theme->set_icon("indeterminate", "Tree", theme->get_icon(SNAME("GuiIndeterminate"), EditorStringName(EditorIcons)));
theme->set_icon("indeterminate_disabled", "Tree", theme->get_icon(SNAME("GuiIndeterminateDisabled"), EditorStringName(EditorIcons)));
theme->set_icon("unchecked", "Tree", theme->get_icon(SNAME("GuiUnchecked"), EditorStringName(EditorIcons)));
theme->set_icon("unchecked_disabled", "Tree", theme->get_icon(SNAME("GuiUncheckedDisabled"), EditorStringName(EditorIcons)));
theme->set_icon("arrow", "Tree", theme->get_icon(SNAME("GuiTreeArrowDown"), EditorStringName(EditorIcons)));
theme->set_icon("arrow_collapsed", "Tree", theme->get_icon(SNAME("GuiTreeArrowRight"), EditorStringName(EditorIcons)));
theme->set_icon("arrow_collapsed_mirrored", "Tree", theme->get_icon(SNAME("GuiTreeArrowLeft"), EditorStringName(EditorIcons)));
Expand All @@ -1437,6 +1440,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
theme->set_color("custom_button_font_highlight", "Tree", font_hover_color);
theme->set_color("font_color", "Tree", font_color);
theme->set_color("font_selected_color", "Tree", mono_color);
theme->set_color("font_disabled_color", "Tree", font_disabled_color);
theme->set_color("font_outline_color", "Tree", font_outline_color);
theme->set_color("title_button_color", "Tree", font_color);
theme->set_color("drop_position_color", "Tree", accent_color);
Expand Down
1 change: 1 addition & 0 deletions editor/icons/GuiIndeterminateDisabled.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 25 additions & 10 deletions scene/gui/tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2195,27 +2195,38 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
draw_item_rect(p_item->cells.write[i], item_rect, cell_color, icon_col, outline_size, font_outline_color);
} break;
case TreeItem::CELL_MODE_CHECK: {
Ref<Texture2D> checked = theme_cache.checked;
Ref<Texture2D> unchecked = theme_cache.unchecked;
Ref<Texture2D> indeterminate = theme_cache.indeterminate;
Point2i check_ofs = item_rect.position;
check_ofs.y += Math::floor((real_t)(item_rect.size.y - checked->get_height()) / 2);
check_ofs.y += Math::floor((real_t)(item_rect.size.y - theme_cache.checked->get_height()) / 2);

if (p_item->cells[i].indeterminate) {
indeterminate->draw(ci, check_ofs);
} else if (p_item->cells[i].checked) {
checked->draw(ci, check_ofs);
if (p_item->cells[i].editable) {
if (p_item->cells[i].indeterminate) {
theme_cache.indeterminate->draw(ci, check_ofs);
} else if (p_item->cells[i].checked) {
theme_cache.checked->draw(ci, check_ofs);
} else {
theme_cache.unchecked->draw(ci, check_ofs);
}
} else {
unchecked->draw(ci, check_ofs);
if (p_item->cells[i].indeterminate) {
theme_cache.indeterminate_disabled->draw(ci, check_ofs);
} else if (p_item->cells[i].checked) {
theme_cache.checked_disabled->draw(ci, check_ofs);
} else {
theme_cache.unchecked_disabled->draw(ci, check_ofs);
}
}

int check_w = checked->get_width() + theme_cache.h_separation;
int check_w = theme_cache.checked->get_width() + theme_cache.h_separation;

text_pos.x += check_w;

item_rect.size.x -= check_w;
item_rect.position.x += check_w;

if (!p_item->cells[i].editable) {
cell_color = theme_cache.font_disabled_color;
}

draw_item_rect(p_item->cells.write[i], item_rect, cell_color, icon_col, outline_size, font_outline_color);

} break;
Expand Down Expand Up @@ -5535,7 +5546,10 @@ void Tree::_bind_methods() {

BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, Tree, checked);
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, Tree, unchecked);
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, Tree, checked_disabled);
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, Tree, unchecked_disabled);
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, Tree, indeterminate);
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, Tree, indeterminate_disabled);
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, Tree, arrow);
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, Tree, arrow_collapsed);
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, Tree, arrow_collapsed_mirrored);
Expand All @@ -5549,6 +5563,7 @@ void Tree::_bind_methods() {

BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Tree, font_color);
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Tree, font_selected_color);
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Tree, font_disabled_color);
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Tree, drop_position_color);
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Tree, h_separation);
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Tree, v_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 @@ -536,7 +536,10 @@ class Tree : public Control {

Ref<Texture2D> checked;
Ref<Texture2D> unchecked;
Ref<Texture2D> checked_disabled;
Ref<Texture2D> unchecked_disabled;
Ref<Texture2D> indeterminate;
Ref<Texture2D> indeterminate_disabled;
Ref<Texture2D> arrow;
Ref<Texture2D> arrow_collapsed;
Ref<Texture2D> arrow_collapsed_mirrored;
Expand All @@ -545,6 +548,7 @@ class Tree : public Control {

Color font_color;
Color font_selected_color;
Color font_disabled_color;
Color guide_color;
Color drop_position_color;
Color relationship_line_color;
Expand Down
4 changes: 4 additions & 0 deletions scene/theme/default_theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,11 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
theme->set_stylebox("custom_button_hover", "Tree", button_hover);

theme->set_icon("checked", "Tree", icons["checked"]);
theme->set_icon("checked_disabled", "Tree", icons["checked_disabled"]);
theme->set_icon("unchecked", "Tree", icons["unchecked"]);
theme->set_icon("unchecked_disabled", "Tree", icons["unchecked_disabled"]);
theme->set_icon("indeterminate", "Tree", icons["indeterminate"]);
theme->set_icon("indeterminate_disabled", "Tree", icons["indeterminate_disabled"]);
theme->set_icon("updown", "Tree", icons["updown"]);
theme->set_icon("select_arrow", "Tree", icons["option_button_arrow"]);
theme->set_icon("arrow", "Tree", icons["arrow_down"]);
Expand All @@ -789,6 +792,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
theme->set_color("title_button_color", "Tree", control_font_color);
theme->set_color("font_color", "Tree", control_font_low_color);
theme->set_color("font_selected_color", "Tree", control_font_pressed_color);
theme->set_color("font_disabled_color", "Tree", control_font_disabled_color);
theme->set_color("font_outline_color", "Tree", Color(1, 1, 1));
theme->set_color("guide_color", "Tree", Color(0.7, 0.7, 0.7, 0.25));
theme->set_color("drop_position_color", "Tree", Color(1, 1, 1));
Expand Down
2 changes: 1 addition & 1 deletion scene/theme/icons/indeterminate.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions scene/theme/icons/indeterminate_disabled.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7aae85e

Please sign in to comment.