diff options
author | Stanislav Labzyuk <stanislav.labzyuk@gmail.com> | 2023-11-13 14:38:56 +0100 |
---|---|---|
committer | Stanislav Labzyuk <stanislav.labzyuk@gmail.com> | 2023-11-15 17:13:34 +0100 |
commit | ff8797e98099f7472f95278ba89b9c8d93929d50 (patch) | |
tree | 50e834a6bbf60196cb7403ade090c76b5644cdb8 | |
parent | 59457685c18e2d729eea50c751c11f049a7186f0 (diff) | |
download | redot-engine-ff8797e98099f7472f95278ba89b9c8d93929d50.tar.gz |
Implement disabled state for Checkbox in Tree
-rw-r--r-- | doc/classes/Tree.xml | 18 | ||||
-rw-r--r-- | editor/editor_themes.cpp | 4 | ||||
-rw-r--r-- | editor/icons/GuiIndeterminateDisabled.svg | 1 | ||||
-rw-r--r-- | scene/gui/tree.cpp | 35 | ||||
-rw-r--r-- | scene/gui/tree.h | 4 | ||||
-rw-r--r-- | scene/theme/default_theme.cpp | 4 | ||||
-rw-r--r-- | scene/theme/icons/indeterminate.svg | 2 | ||||
-rw-r--r-- | scene/theme/icons/indeterminate_disabled.svg | 1 |
8 files changed, 55 insertions, 14 deletions
diff --git a/doc/classes/Tree.xml b/doc/classes/Tree.xml index e322e3adc0..bf5a504aba 100644 --- a/doc/classes/Tree.xml +++ b/doc/classes/Tree.xml @@ -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> @@ -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. diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index 0dd787f0ea..68f4a4a6f3 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -1421,8 +1421,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))); @@ -1435,6 +1438,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); diff --git a/editor/icons/GuiIndeterminateDisabled.svg b/editor/icons/GuiIndeterminateDisabled.svg new file mode 100644 index 0000000000..edaf69f7a1 --- /dev/null +++ b/editor/icons/GuiIndeterminateDisabled.svg @@ -0,0 +1 @@ +<svg height="16" width="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><rect x="1" y="1" rx="2.33" height="14" width="14" fill="#808080"/><path d="M3 7h10v2H3z" fill="#b3b3b3"/></svg> diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index a4c239cf53..205064e98b 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -2187,27 +2187,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; @@ -5525,7 +5536,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); @@ -5539,6 +5553,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); diff --git a/scene/gui/tree.h b/scene/gui/tree.h index 4a5814c45c..2dda408dd7 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -536,7 +536,10 @@ private: 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; @@ -545,6 +548,7 @@ private: Color font_color; Color font_selected_color; + Color font_disabled_color; Color guide_color; Color drop_position_color; Color relationship_line_color; diff --git a/scene/theme/default_theme.cpp b/scene/theme/default_theme.cpp index ddec5e826b..09fb5aba0d 100644 --- a/scene/theme/default_theme.cpp +++ b/scene/theme/default_theme.cpp @@ -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"]); @@ -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)); diff --git a/scene/theme/icons/indeterminate.svg b/scene/theme/icons/indeterminate.svg index 2a742e1475..e6e8dec5ed 100644 --- a/scene/theme/icons/indeterminate.svg +++ b/scene/theme/icons/indeterminate.svg @@ -1 +1 @@ -<svg height="16" viewBox="0 0 16 15.999999" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m3.3333333 1c-1.2887 0-2.3333333 1.0446683-2.3333333 2.3333333v9.3333337c0 1.2887 1.0446683 2.333333 2.3333333 2.333333h9.3333337c1.2887 0 2.333333-1.044668 2.333333-2.333333v-9.3333337c0-1.2887-1.044668-2.3333333-2.333333-2.3333333z" fill="#fff" fill-opacity=".75" stroke-width="1.16667"/><path d="m3 7h10v2h-10z" fill="#1a1a1a" stroke-linecap="square" stroke-opacity=".75" stroke-width="2"/></svg> +<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><rect x="1" y="1" width="14" height="14" rx="2.333" fill="#fff" fill-opacity=".75"/><path d="m3 7h10v2h-10z" fill="#1a1a1a"/></svg> diff --git a/scene/theme/icons/indeterminate_disabled.svg b/scene/theme/icons/indeterminate_disabled.svg new file mode 100644 index 0000000000..f238f6f31c --- /dev/null +++ b/scene/theme/icons/indeterminate_disabled.svg @@ -0,0 +1 @@ +<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><rect x="1" y="1" width="14" height="14" rx="2.333" fill="#fff" fill-opacity=".37"/><path d="m3 7h10v2h-10z" fill="#1a1a1a" fill-opacity=".5"/></svg> |