// Copyright © SixtyFPS GmbH // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial import { CosmicFontSettings, CosmicPalette, Icons } from "styling.slint"; import { MenuBorder, ListItem, StateLayerBase } from "components.slint"; import { ComboBoxBase } from "../common/combobox-base.slint"; export component ComboBox { in property <[string]> model <=> base.model; in property enabled <=> base.enabled; out property has-focus <=> base.has-focus; in-out property current-index <=> base.current-index; in-out property current-value <=> base.current-value; callback selected <=> base.selected; min-width: max(160px, layout.min-height); min-height: max(32px, layout.min-height); horizontal-stretch: 1; vertical-stretch: 0; forward-focus: base; states [ disabled when !root.enabled : { opacity: 0.5; } ] base := ComboBoxBase { width: 100%; height: 100%; show-popup => { popup.show(); } } background := Rectangle { border-radius: 16px; background: CosmicPalette.control-background; border-width: 1px; border-color: CosmicPalette.border; layout := HorizontalLayout { padding-left: 16px; padding-right: 16px; spacing: 10px; text := Text { horizontal-alignment: left; vertical-alignment: center; font-size: CosmicFontSettings.body.font-size; font-weight: CosmicFontSettings.body.font-weight; color: CosmicPalette.control-foreground; text: root.current-value; } Path { y: (parent.height - self.height) / 2; width: 10px; height: 5px; fill: CosmicPalette.control-foreground; commands: "M 0 0 L 10 0 L 5 5 Z"; } } StateLayerBase { width: 100%; height: 100%; border-radius: background.border-radius; pressed: base.pressed; has-focus: base.has-focus; has-hover: base.has-hover; enabled: root.enabled; } } popup := PopupWindow { x: 0; y: root.height + 4px; width: root.width; MenuBorder { VerticalLayout { padding: 8px; for value[index] in root.model : ListItem { item: { text: value }; is-selected: index == root.current-index; has-hover: touch-area.has-hover; pressed: touch-area.pressed; touch-area := TouchArea { clicked => { base.select(index); } } } } } } }