slint/internal/compiler/widgets/qt/tabwidget.slint

48 lines
No EOL
1.6 KiB
Text

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