slint/internal/compiler/widgets/qt/tabwidget.slint
2024-10-25 10:20:09 +02:00

53 lines
1.6 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;
}
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;
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 { }