slint/internal/compiler/widgets/qt/tabwidget.slint
2025-01-06 09:30:11 +01:00

61 lines
1.9 KiB
Text

// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
import { TabBarBase } from "../common/tabwidget-base.slint";
export component TabWidgetImpl inherits NativeTabWidget { }
export component TabImpl inherits NativeTab {
accessible-role: tab;
accessible-enabled: root.enabled;
accessible-label <=> root.title;
accessible-item-index: root.tab-index;
accessible-item-selectable: true;
accessible-item-selected: root.tab-index == root.current;
accessible-action-default => {
root.current = root.tab-index;
root.current-focused = root.tab-index;
}
}
export component TabBarImpl inherits TabBarBase {
// injected properties:
// The currently focused tab
in-out property <int> current-focused: i-focus-scope.has-focus ? root.current : -1;
accessible-role: tab-list;
accessible-delegate-focus: root.current;
accessible-item-count: root.num-tabs;
Rectangle {
// The breeze style draws outside of the tab bar, which is clip by default with Qt
clip: true;
HorizontalLayout {
// Qt renders Tabs next to each other and renders "spacing" as part of the tab itself
spacing: 0px;
alignment: NativeStyleMetrics.tab-bar-alignment;
@children
}
}
i-focus-scope := FocusScope {
x: 0;
// Do not react on clicks
width: 0px;
key-pressed(event) => {
if (event.text == Key.LeftArrow) {
root.current = root.previous-tab();
return accept;
}
if (event.text == Key.RightArrow) {
root.current = root.next-tab();
return accept;
}
return reject;
}
}
}
export component TabWidget inherits TabWidget { }