// Copyright © SixtyFPS GmbH // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial export component ComboBoxBase { in property <[string]> model; in property enabled <=> i-focus-scope.enabled; out property has-focus: i-focus-scope.has-focus && root.enabled; out property pressed <=> i-touch-area.pressed; out property has-hover: i-touch-area.has-hover; in-out property current-index: 0; in-out property current-value: root.model[root.current-index]; callback selected(/* current-value */ string); callback show-popup(); public function select(index: int) { if (!root.enabled) { return; } root.current-index = index; root.current-value = root.model[root.current-index]; root.selected(root.current-value); } public function move-selection-up() { root.select(Math.max(root.current-index - 1, 0)); } public function move-selection-down() { root.select(Math.min(root.current-index + 1, root.model.length - 1)); } private property scroll-delta: 2px; forward-focus: i-focus-scope; i-focus-scope := FocusScope { key-pressed(event) => { if (!self.enabled) { return reject; } if (event.text == Key.UpArrow) { root.move-selection-up(); return accept; } else if (event.text == Key.DownArrow) { root.move-selection-down(); return accept; } else if (event.text == Key.Return) { root.show-popup(); } return reject; } i-touch-area := TouchArea { enabled: root.enabled; clicked => { root.focus(); root.show-popup(); } scroll-event(event) => { if (event.delta-y < -root.scroll-delta) { root.move-selection-down(); return accept; } if (event.delta-y > root.scroll-delta) { root.move-selection-up(); return accept; } reject } } } }