Skip to main content

TabBar (탭바) Widget Control

info

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.

info

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 ControlKindSignatureDescription
setTabsMethodsetTabs(tabs): voidReplaces every tab with a list
addMethodadd(tab): voidAdds one tab at the end
changeTabMethodchangeTab(index, tab): voidReplaces the tab at a specific position
getTextMethodgetText(index): stringReturns that tab's label text
indexPropertynumber (Read/write)Index of the currently selected tab
onChangedEventonChanged = (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 replace
    • tab: 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)

note

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.