Skip to content

Commit

Permalink
Merge pull request #27 from OverloadedOrama/show-more-than-one-tab
Browse files Browse the repository at this point in the history
Add an option to always have the tabs visible, if a panel has more than one tab
  • Loading branch information
gilzoide authored Feb 18, 2024
2 parents 63943c3 + 7018c0d commit ddff84a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
28 changes: 15 additions & 13 deletions addons/dockable_container/dockable_container.gd
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,18 @@ const DragNDropPanel := preload("drag_n_drop_panel.gd")
_tabs_visible = value
for i in range(1, _panel_container.get_child_count()):
var panel := _panel_container.get_child(i) as DockablePanel
panel.tabs_visible = value
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 _hide_single_tab
set(value):
_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:
Expand All @@ -49,6 +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 _hide_single_tab := false
var _current_panel_index := 0
var _current_split_index := 0
var _children_names := {}
Expand Down Expand Up @@ -187,17 +199,6 @@ func set_layout(value: DockableLayout) -> void:
queue_sort()


func set_tab_alignment(value: TabBar.AlignmentMode) -> void:
_tab_align = value
for i in range(1, _panel_container.get_child_count()):
var panel = _panel_container.get_child(i)
panel.tab_alignment = value


func get_tab_align() -> int:
return _tab_align


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()):
Expand Down Expand Up @@ -396,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)
Expand Down
22 changes: 22 additions & 0 deletions addons/dockable_container/dockable_panel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

0 comments on commit ddff84a

Please sign in to comment.