// Copyright © SixtyFPS GmbH // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial import { CosmicPalette, CosmicFontSettings } from "styling.slint"; import { StateLayerBase } from "components.slint"; export component TabWidgetImpl inherits Rectangle { in property tabbar-preferred-height; in property tabbar-preferred-width; in property content-min-height; in property content-min-width; in property current-index; in property current-focused; out property content-x: 0; out property content-y: root.tabbar-preferred-height; out property content-height: root.height - root.tabbar-preferred-height; out property content-width: root.width; out property tabbar-x: 0; out property tabbar-y: 0; out property tabbar-height: root.tabbar-preferred-height; out property tabbar-width: root.width; preferred-width: root.content-min-width; min-width: max(root.content-min-width, root.tabbar-preferred-width); preferred-height: root.content-min-height + root.tabbar-preferred-height; min-height: root.content-min-height + root.tabbar-preferred-height; } export component TabImpl inherits Rectangle { in property current-focused; // The currently focused tab in property tab-index; // The index of this tab in property num-tabs; // The total number of tabs in property title <=> text.text; in property enabled: true; out property has-focus: root.current-focused == root.tab-index; in-out property current; // The currently selected tab private property show-left-border: root.tab-index == 0 || root.is-current; private property show-right-border: root.current != root.tab-index + 1; private property is-current: root.tab-index == root.current; min-width: max(160px, text.min-width); min-height: max(24px, text.min-height); horizontal-stretch: 0; vertical-stretch: 1; accessible-role: tab; accessible-label: root.title; Rectangle { clip: true; width: 100%; height: 100%; background := Rectangle { y: 1px; width: 100%; height: parent.height + self.border-radius; background: CosmicPalette.control-background; } } StateLayerBase { width: 100%; height: 100%; has-hover: touch-area.has-hover; pressed: touch-area.pressed; checked: root.is-current; } touch-area := TouchArea { enabled <=> root.enabled; clicked => { root.current = root.tab-index; } } layout := HorizontalLayout { padding-left: 12px; padding-right: 8px; text := Text { vertical-alignment: center; horizontal-alignment: left; font-size: CosmicFontSettings.body.font-size; font-weight:CosmicFontSettings.body.font-weight; color: root.is-current ? CosmicPalette.accent-background : CosmicPalette.control-foreground; } } if (root.show-left-border) : Rectangle { x: 0; width: 4px; height: root.is-current ? root.height : 16px; background: root.is-current ? CosmicPalette.accent-background : CosmicPalette.border; border-radius: root.is-current ? 0 : 2px; } if (root.show-right-border) : Rectangle { x: parent.width - self.width; width: 4px; height: root.is-current ? root.height : 16px; background: root.is-current ? CosmicPalette.accent-background : CosmicPalette.border; border-radius: root.is-current ? 0 : 2px; } } export component TabBarImpl { // injected properties: in-out property current; // The currently selected tab in-out property current-focused: focus-scope.has-focus ? focus-scope.focused-tab : -1; // The currently focused tab in-out property num-tabs; // The total number of tabs accessible-role: tab; accessible-delegate-focus: root.current-focused >= 0 ? root.current-focused : root.current; preferred-height: 24px; background := Rectangle { border-radius: 8px; background: focus-scope.has-focus ? CosmicPalette.accent-background : CosmicPalette.control-background; Rectangle { y: background.height - self.height; height: background.border-radius; background: parent.background; } } Rectangle { clip: true; HorizontalLayout { // fix for gap between top and bottom padding-top: -1px; padding-bottom: -1px; padding-left: 64px; padding-right: 64px; @children } } if (focus-scope.has-focus) : Rectangle { y: root.height - self.height; height: 1px; background: CosmicPalette.accent-background; } focus-scope := FocusScope { property focused-tab: 0; x: 0; width: 0px; // Do not react on clicks key-pressed(event) => { if (event.text == "\n") { root.current = root.current-focused; return accept; } if (event.text == Key.LeftArrow) { self.focused-tab = Math.max(self.focused-tab - 1, 0); return accept; } if (event.text == Key.RightArrow) { self.focused-tab = Math.min(self.focused-tab + 1, root.num-tabs - 1); return accept; } return reject; } key-released(event) => { if (event.text == " ") { root.current = root.current-focused; return accept; } return reject; } } } export component TabWidget inherits TabWidget {}