// Copyright © SixtyFPS GmbH // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial import { MaterialPalette, MaterialFontSettings } from "styling.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 <=> i-text.text; in property enabled: true; in-out property current; // The currently selected tab private property has-focus: root.current-focused == root.tab-index; private property active: root.tab-index == root.current; height: 48px; accessible-role: tab; accessible-label: root.title; i-container := Rectangle { background: MaterialPalette.alternate-background; } i-state-layer := Rectangle { opacity: !i-touch-area.pressed ? !i-touch-area.has-hover ? 0 : 0.08 : 0.12; width: 100%; height: 100%; border-radius: i-container.border-radius; background: MaterialPalette.accent-background; animate opacity { duration: 250ms; easing: ease; } } i-layout := HorizontalLayout { padding-left: 16px; padding-right: 16px; i-text := Text { vertical-alignment: center; color: !root.active ? MaterialPalette.control-foreground : MaterialPalette.accent-background; // FIXME after Roboto font can be loaded //font-family: MaterialFontSettings.title-small.font; font-size: MaterialFontSettings.title-small.font-size; font-weight: MaterialFontSettings.title-small.font-weight; animate color { duration: 250ms; easing: ease; } } } i-indicator := Rectangle { opacity: !root.active ? 0 : 1; width: 100%; height: 3px; y: parent.height - self.height; background: MaterialPalette.accent-background; animate opacity { duration: 250ms; easing: ease; } } i-touch-area := TouchArea { enabled <=> root.enabled; clicked => { root.current = root.tab-index; } } } export component TabBarImpl { // injected properties: in-out property current; // The currently selected tab in-out property current-focused: i-focus-scope.has-focus ? i-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; HorizontalLayout { alignment: start; @children } i-focus-scope := FocusScope { property focused-tab: 0; x: 0; width: 0; // 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 {}