kvui: abstract away client tab additions #3950

This commit is contained in:
Silvris
2024-09-22 09:24:14 -05:00
committed by GitHub
parent 99c02a3eb3
commit f7ec3d7508
3 changed files with 12 additions and 10 deletions

13
kvui.py
View File

@@ -536,9 +536,8 @@ class GameManager(App):
# show Archipelago tab if other logging is present
self.tabs.add_widget(panel)
hint_panel = TabbedPanelItem(text="Hints")
self.log_panels["Hints"] = hint_panel.content = HintLog(self.json_to_kivy_parser)
self.tabs.add_widget(hint_panel)
hint_panel = self.add_client_tab("Hints", HintLog(self.json_to_kivy_parser))
self.log_panels["Hints"] = hint_panel.content
if len(self.logging_pairs) == 1:
self.tabs.default_tab_text = "Archipelago"
@@ -572,6 +571,14 @@ class GameManager(App):
return self.container
def add_client_tab(self, title: str, content: Widget) -> Widget:
"""Adds a new tab to the client window with a given title, and provides a given Widget as its content.
Returns the new tab widget, with the provided content being placed on the tab as content."""
new_tab = TabbedPanelItem(text=title)
new_tab.content = content
self.tabs.add_widget(new_tab)
return new_tab
def update_texts(self, dt):
if hasattr(self.tabs.content.children[0], "fix_heights"):
self.tabs.content.children[0].fix_heights() # TODO: remove this when Kivy fixes this upstream