Skip to content

Commit

Permalink
fix(core/tree): handle regression on tab_bar.hide_when=single_tab; ad…
Browse files Browse the repository at this point in the history
…d test
  • Loading branch information
aravinda0 committed Mar 6, 2024
1 parent 7df12a9 commit 63a3946
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/qtile_bonsai/core/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,8 @@ def _add_tab(
"must be provided."
)

self._ensure_tab_bar_restored(tc)

tc_rect = Rect.from_rect(tc.principal_rect) if tc_rect is None else tc_rect
bar_rect = tc.tab_bar.box.principal_rect
tc_content_rect = Rect(
Expand All @@ -795,8 +797,6 @@ def _transform_tab(t: Tab):

added_nodes = []

self._ensure_tab_bar_restored(tc)

# Handle the need for a T under the TC
if isinstance(insert_node, Tab):
t = insert_node
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/core/test_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -4058,6 +4058,22 @@ def test_padding_with_list(self, tree: Tree):
assert tc1.tab_bar.box.padding.as_list() == [1, 2, 3, 4]
assert tc2.tab_bar.box.padding.as_list() == [5, 6, 7, 8]

def test_when_hide_when_is_single_tab_then_first_tab_should_have_bar_hidden_and_second_tab_should_make_it_visible(
self, tree: Tree
):
tree.set_config("tab_bar.hide_when", "single_tab")

p1 = tree.tab()

# bar should not be consuming space
assert p1.principal_rect == Rect(0, 0, 400, 300)

p2 = tree.tab()

# bar should now be taking up space
assert p1.principal_rect == Rect(0, 20, 400, 280)
assert p2.principal_rect == Rect(0, 20, 400, 280)


class TestIterWalk:
def test_new_tree_instance_has_no_nodes(self, tree: Tree):
Expand Down

0 comments on commit 63a3946

Please sign in to comment.