Skip to content

1.6 DirectTabbedFrame

Fireclaw edited this page Jul 22, 2022 · 2 revisions

A frame that holds multiple tabs which the user can select to toggle between different contents.

It will automatically limit the amount of displayed tabs to the width of the frame and provide buttons to navigate through the tabs list.

Example

from DirectGuiExtension.DirectTabbedFrame import DirectTabbedFrame

# create a tabbed frame
tabbed_frame = DirectTabbedFrame()

# content can be anything that at least has a show and hide method
content = DirectFrame(frameSize=(-1,1,-1,0.8), frameColor=(1,0,1,1))

# add a tab that titled "My Tab" and which will show the content frame when clicked
tabbed_frame.add_tab("My Tab", content)

Options

tabHeight: Float
Height of the tab line (effectively the tabs scale)

showCloseOnTabs: Boolean
Determine if the close button on the tabs should be shown or not

selectedTabColor: Tuple of 4 or LVecBase4f
Frame color of the selected tab

unselectedTabColor: Tuple of 4 or LVecBase4f
Frame color of all other (not selected) tabs

Note: Additionally the frame has two buttons for navigating left and right if the tabs exceed the available width of the frame. Those buttons are prevTabButton and nextTabButton. They are DirectButtons and can be edited using the default way of direct gui elements, e.g. nextTabButton_frameColor for setting the right buttons frame color.

Variables

tab_list
List of all tabs stored in this tabbed frame

current_content
The displayed content of the currently selected tab

Functions

add_tab(string title, object content, func on_close_function)
Add a new tab with the given title to the list of tabs.
The tab will show/hide the content.
The on_close_function will be called just before the tab gets deleted and will get the tab passed as parameter. This function is optional and can be omitted.

select_tab(tab)
Set the passed tab as the selected one.

reposition_tabs
Recalculate all tabs position. Will be called on most relevant spots automatically.