From 66ea1fcfe90eb21c14123847e93f5f6df0b522ae Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas Date: Sun, 18 Feb 2024 19:47:21 +0200 Subject: [PATCH] Update the DockableContainer plugin --- addons/README.md | 2 +- .../dockable_container/dockable_container.gd | 41 ++++++++----------- addons/dockable_container/dockable_panel.gd | 22 ++++++++++ src/UI/TopMenuContainer/TopMenuContainer.gd | 4 +- src/UI/UI.tscn | 3 +- 5 files changed, 42 insertions(+), 30 deletions(-) diff --git a/addons/README.md b/addons/README.md index 77fb78b9e..b2f9fa2e7 100644 --- a/addons/README.md +++ b/addons/README.md @@ -24,7 +24,7 @@ Files extracted from source: ## godot-dockable-container - Upstream: https://github.com/gilzoide/godot-dockable-container -- Version: Based on [274ea7264440003071bcd024f31e130c984df3c6](https://github.com/gilzoide/godot-dockable-container/pull/27/commits/274ea7264440003071bcd024f31e130c984df3c6) (PR #27), but with changes in layout.gd that add a `save_on_change` variable and a `save()` method. +- Version: Based on [ddff84aa31e466101b4a75c7ff68d3a82701e387](https://github.com/gilzoide/godot-dockable-container/commit/ddff84aa31e466101b4a75c7ff68d3a82701e387), but with changes in layout.gd that add a `save_on_change` variable and a `save()` method. - License: [CC0-1.0](https://github.com/gilzoide/godot-dockable-container/blob/main/LICENSE) ## SmartSlicer diff --git a/addons/dockable_container/dockable_container.gd b/addons/dockable_container/dockable_container.gd index 66e88cbca..3913a68f5 100644 --- a/addons/dockable_container/dockable_container.gd +++ b/addons/dockable_container/dockable_container.gd @@ -26,15 +26,21 @@ const DragNDropPanel := preload("drag_n_drop_panel.gd") get: return _tabs_visible set(value): - set_tabs_visible(value) -## Always ensure that tabs are visible if a panel has more than one tab. -## Only takes effect is [member tabs_visible] is [code]false[/code]. -@export var tabs_visible_if_more_than_one := false: + _tabs_visible = value + for i in range(1, _panel_container.get_child_count()): + var panel := _panel_container.get_child(i) as DockablePanel + panel.show_tabs = _tabs_visible +## If [code]true[/code] and a panel only has one tab, it keeps that tab hidden even if +## [member tabs_visible] is [code]true[/code]. +## Only takes effect is [member tabs_visible] is [code]true[/code]. +@export var hide_single_tab := false: get: - return _tabs_visible_if_more_than_one + return _hide_single_tab set(value): - _tabs_visible_if_more_than_one = value - set_tabs_visible(_tabs_visible) + _hide_single_tab = value + for i in range(1, _panel_container.get_child_count()): + var panel := _panel_container.get_child(i) as DockablePanel + panel.hide_single_tab = _hide_single_tab @export var rearrange_group := 0 @export var layout := DockableLayout.new(): get: @@ -54,7 +60,7 @@ var _drag_panel: DockablePanel var _tab_align := TabBar.ALIGNMENT_CENTER var _tabs_visible := true var _use_hidden_tabs_for_min_size := false -var _tabs_visible_if_more_than_one := false +var _hide_single_tab := false var _current_panel_index := 0 var _current_split_index := 0 var _children_names := {} @@ -193,20 +199,6 @@ func set_layout(value: DockableLayout) -> void: queue_sort() -func set_tabs_visible(value: bool) -> void: - _tabs_visible = value - for i in range(1, _panel_container.get_child_count()): - var panel := _panel_container.get_child(i) as DockablePanel - if _tabs_visible_if_more_than_one and panel.get_tab_count() > 1: - panel.tabs_visible = true - else: - panel.tabs_visible = value - - -func get_tabs_visible() -> bool: - return _tabs_visible - - func set_use_hidden_tabs_for_min_size(value: bool) -> void: _use_hidden_tabs_for_min_size = value for i in range(1, _panel_container.get_child_count()): @@ -330,8 +322,6 @@ func _resort() -> void: _untrack_children_after(_panel_container, _current_panel_index) _untrack_children_after(_split_container, _current_split_index) - if not tabs_visible and tabs_visible_if_more_than_one: - set_tabs_visible(_tabs_visible) ## Calculate DockablePanel and SplitHandle minimum sizes, skipping empty @@ -407,7 +397,8 @@ func _get_panel(idx: int) -> DockablePanel: return _panel_container.get_child(idx) var panel := DockablePanel.new() panel.tab_alignment = _tab_align - panel.tabs_visible = _tabs_visible + panel.show_tabs = _tabs_visible + panel.hide_single_tab = _hide_single_tab panel.use_hidden_tabs_for_min_size = _use_hidden_tabs_for_min_size panel.set_tabs_rearrange_group(maxi(0, rearrange_group)) _panel_container.add_child(panel) diff --git a/addons/dockable_container/dockable_panel.gd b/addons/dockable_container/dockable_panel.gd index bc4044da0..d522027dd 100644 --- a/addons/dockable_container/dockable_panel.gd +++ b/addons/dockable_container/dockable_panel.gd @@ -8,8 +8,22 @@ var leaf: DockableLayoutPanel: return get_leaf() set(value): set_leaf(value) +var show_tabs := true: + get: + return _show_tabs + set(value): + _show_tabs = value + _handle_tab_visibility() +var hide_single_tab := false: + get: + return _hide_single_tab + set(value): + _hide_single_tab = value + _handle_tab_visibility() var _leaf: DockableLayoutPanel +var _show_tabs := true +var _hide_single_tab := false func _ready() -> void: @@ -48,6 +62,7 @@ func track_nodes(nodes: Array[Control], new_leaf: DockableLayoutPanel) -> void: ref_control.reference_to = nodes[i] set_tab_title(i, nodes[i].name) set_leaf(new_leaf) + _handle_tab_visibility() func get_child_rect() -> Rect2: @@ -84,3 +99,10 @@ func _on_tab_changed(tab: int) -> void: var name_index_in_leaf := _leaf.find_name(tab_name) if name_index_in_leaf != tab: # NOTE: this handles added tabs (index == -1) tab_layout_changed.emit(tab) + + +func _handle_tab_visibility() -> void: + if _hide_single_tab and get_tab_count() == 1: + tabs_visible = false + else: + tabs_visible = _show_tabs diff --git a/src/UI/TopMenuContainer/TopMenuContainer.gd b/src/UI/TopMenuContainer/TopMenuContainer.gd index f137cd697..cdc73434b 100644 --- a/src/UI/TopMenuContainer/TopMenuContainer.gd +++ b/src/UI/TopMenuContainer/TopMenuContainer.gd @@ -536,8 +536,8 @@ func window_menu_id_pressed(id: int) -> void: Global.WindowMenu.WINDOW_OPACITY: window_opacity_dialog.popup() Global.WindowMenu.MOVABLE_PANELS: - main_ui.tabs_visible = !main_ui.tabs_visible - window_menu.set_item_checked(id, main_ui.tabs_visible) + main_ui.hide_single_tab = not main_ui.hide_single_tab + window_menu.set_item_checked(id, not main_ui.hide_single_tab) Global.WindowMenu.ZEN_MODE: _toggle_zen_mode() Global.WindowMenu.FULLSCREEN_MODE: diff --git a/src/UI/UI.tscn b/src/UI/UI.tscn index 7dca1ee79..86bba3744 100644 --- a/src/UI/UI.tscn +++ b/src/UI/UI.tscn @@ -252,8 +252,7 @@ offset_right = -8.0 size_flags_horizontal = 3 size_flags_vertical = 3 script = ExtResource("35") -tabs_visible = false -tabs_visible_if_more_than_one = true +hide_single_tab = true layout = SubResource("Resource_b6o2t") clone_layout_on_ready = false