TabBar (탭바) Widget Control
Example file: 07_Work_with_Widgets/tabbar_buttontabbar_objet.lfp
The Widget Controls (Property · Method · Event) you use to control the TabBar widget from a script. For an introduction to the widget and how to use it, visit TabBar.
The tabbarID in the examples below is the name (ID) you assigned to the TabBar widget on the canvas. In a script, access it as widgetID.member.
Widget Control summary
| Widget Control | Kind | Signature | Description |
|---|---|---|---|
setTabs | Method | setTabs(tabs): void | Replaces every tab with a list |
add | Method | add(tab): void | Adds one tab at the end |
changeTab | Method | changeTab(index, tab): void | Replaces the tab at a specific position |
getText | Method | getText(index): string | Returns that tab's label text |
index | Property | number (Read/write) | Index of the currently selected tab |
onChanged | Event | onChanged = (index) => { ... } | Runs when the selected tab changes |
Property
index
The index of the currently selected tab, starting at 0. Write a value to switch to that tab.
- Type:
number - Access: Read / write
Example
// Switch to the second tab
tabbarID.index = 1;
// Read the current tab
const current = tabbarID.index;
Method
add
Adds one tab to the end of the list.
- Parameters
tab: Tab definition (label text)
- Returns: None (
void)
Example
tabbarID.add("Settings");
setTabs
Replaces every tab with the given list. An empty list is ignored.
- Parameters
tabs: List of tabs
- Returns: None (
void)
Example
tabbarID.setTabs(["Home", "Chart", "Settings"]);
changeTab
Replaces the tab at the given position (index). An index outside the valid range is ignored.
- Parameters
index(number): Position of the tab to replacetab: New tab definition (label text)
- Returns: None (
void)
Example
//Replace the tab at index 1 with 'Chart'
tabbarID.changeTab(1, "Chart");
getText
Returns the label text of the tab at the given index. Out of range, it returns an empty string ('').
- Parameters
index(number): Position of the tab to read
- Returns:
string- The tab's label text (''if out of range)
Example
const label = tabbarID.getText(0);
Event
onChanged
Runs when the selected tab changes.
- Kind: Event
- Handler arguments
index(number): Index of the newly selected tab
- Returns: None
Example
tabbarID.onChanged = (index) => {
// index: index of the newly selected tab
};
Common Widget Control (all widgets)
Every widget can also use common Widget Controls (Method) such as setProperty(name, value) / getProperty(name) / setStyleProperty(styleName, styleProperty, value). For the detailed rules, see the common Widget Control reference.