// Copyright © SixtyFPS GmbH // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial import { Typography, Palette, Icons } from "styling.slint"; import { MenuBorder, ListItem, FocusBorder } from "components.slint"; import { ComboBoxBase } from "../common/combobox-base.slint"; export component ComboBox { private property background: Palette.surface; callback selected <=> i-base.selected; in property <[string]> model <=> i-base.model; in property enabled <=> i-base.enabled; out property has-focus <=> i-base.has-focus; in-out property current-index <=> i-base.current-index; in-out property current-value <=> i-base.current-value; min-width: max(160px, i-layout.min-width); min-height: max(22px, i-layout.min-height); horizontal-stretch: 1; vertical-stretch: 0; forward-focus: i-base; i-base := ComboBoxBase { width: 100%; height: 100%; show-popup => { i-popup.show(); } } FocusBorder { x: (parent.width - self.width) / 2; y: (parent.height - self.height) / 2; width: parent.width + 6px; height: parent.height + 6px; border-radius: 8px; has-focus: root.has-focus; } Rectangle { drop-shadow-blur: 0.25px; drop-shadow-color: #00000066; drop-shadow-offset-y: 0.25px; border-radius: 5px; background: root.background; Rectangle { drop-shadow-blur: 1px; drop-shadow-color: #00000026; drop-shadow-offset-y: 1px; border-radius: parent.border-radius; background: root.background; border-width: 1px; border-color: Palette.decent-border; opacity: root.enabled ? 1 : 0.5; } } i-layout := HorizontalLayout { padding-left: 8px; padding-right: 8px; padding-top: 4px; padding-bottom: 4px; spacing: 4px; i-text := Text { horizontal-alignment: left; vertical-alignment: center; font-size: Typography.body.font-size; font-weight: Typography.body.font-weight; color: Palette.foreground; text: root.current-value; } Rectangle { y: (parent.height - self.height) / 2; width: 16px; height: self.width; if (root.enabled) : Rectangle { width: 100%; height: 100%; drop-shadow-blur: 3px; drop-shadow-color: #00000066; drop-shadow-offset-y: 0.5px; border-radius: 4px; background: Palette.accent; Rectangle { drop-shadow-blur: 2px; drop-shadow-color: #00000026; drop-shadow-offset-y: 1px; border-radius: parent.border-radius; background: parent.background; } Rectangle { drop-shadow-blur: 1px; drop-shadow-color: #00000026; drop-shadow-offset-y: 0.5px; border-radius: parent.border-radius; background: parent.background; } Rectangle { border-radius: parent.border-radius; background: Palette.dimmer; opacity: 0.17; } } VerticalLayout { padding: 4px; spacing: 4px; i-top-icon := Image { x: (parent.width - self.width) / 2; colorize: Palette.on-surface; source: Icons.chevron-up; } i-bottom-icon := Image { x: (parent.width - self.width) / 2; colorize: Palette.on-surface; source: Icons.chevron-down; } } } } i-popup := PopupWindow { x: 0; y: parent.height + 6px; min-width: root.width; MenuBorder { VerticalLayout { padding: 4px; for value[index] in root.model : ListItem { padding-horizontal: 0; text: value; selected: index == root.current-index; clicked => { i-base.select(index); } } } } } states [ disabled when !root.enabled : { i-text.color: Palette.foreground-secondary; i-top-icon.colorize: Palette.foreground-secondary; i-bottom-icon.colorize: Palette.foreground-secondary; root.background: Palette.surface-tertiary; } pressed when i-base.pressed : { root.background: Palette.surface-secondary; } ] }