Tab
Tab 是单个选项卡头元素。它显示文本标签,并根据空闲、悬停或选中状态切换背景纹理。选项卡通常在 TabView 内部管理,由其处理选择逻辑。
UIElement 中记录的所有内容(布局、样式、事件、数据绑定等)同样适用于此组件。
使用方法
选项卡通常与 TabView 一起创建:
XML
<tab-view>
<tab text="Settings">
<tab-content>
<!-- children of the Settings pane go here -->
</tab-content>
</tab>
<tab text="Info">
<tab-content>
<!-- children of the Info pane go here -->
</tab-content>
</tab>
</tab-view>
Tab 通常作为 <tab-view> 的直接 XML 子元素。<tab-content> 元素指定与此选项卡关联的内容面板。
| XML 属性 | 类型 | 描述 |
|---|---|---|
text |
string |
标签文本(字面量,不翻译)。 |
内部结构
| 索引 | 字段 | CSS 类名 | 描述 |
|---|---|---|---|
0 |
text |
.__tab_text__ |
显示选项卡文本的 Label 元素。 |
Tab 样式
TabStyle 与 Button 的三态纹理系统相似,但三种状态分别用于空闲、悬停和选中。
base-background
选项卡空闲时(未选中、未悬停)的背景。
默认值:Sprites.TAB_DARK
hover-background
鼠标悬停在选项卡上时的背景。
默认值:Sprites.TAB_WHITE
pressed-background
选项卡选中时的背景(pressed-background 属性被复用为选中状态)。
默认值:Sprites.TAB
CSS 状态
当选项卡被选中时,会获得 CSS 类 .__tab_selected__。关联的内容元素会获得 .__tab_content_selected__。
字段
| 名称 | 类型 | 访问权限 | 描述 |
|---|---|---|---|
text |
Label |
public final |
标签元素。 |
tabStyle |
TabStyle |
private(有 getter) |
当前选项卡样式。 |
方法
| 方法 | 返回值 | 描述 |
|---|---|---|
setText(String) |
Tab |
设置标签文本(字面量)。 |
setText(String, boolean) |
Tab |
设置标签文本。true = 可翻译。 |
setText(Component) |
Tab |
从 Component 设置标签。 |
setDynamicText(Supplier<Component>) |
Tab |
将标签绑定到数据供应器以实现实时更新。 |
textStyle(Consumer<TextElement.TextStyle>) |
Tab |
以流式方式配置标签的文本样式。 |
tabStyle(Consumer<TabStyle>) |
Tab |
以流式方式配置 TabStyle。 |
setOnTabSelected(Runnable) |
— | 当此选项卡被选中时调用的回调。 |
setOnTabUnselected(Runnable) |
— | 当此选项卡被取消选中时调用的回调。 |
getContent() |
UIElement(可空) |
返回来自父 TabView 的内容面板。 |
getTabView() |
TabView(可空) |
返回父 TabView。 |