slint/internal/compiler/widgets/cupertino/combobox.slint
Olivier Goffart 2642a713fc
Some checks are pending
autofix.ci / format_fix (push) Waiting to run
autofix.ci / lint_typecheck (push) Waiting to run
CI / files-changed (push) Waiting to run
CI / build_and_test (--exclude bevy-example, ubuntu-22.04, 1.85) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, --exclude bevy-example, windows-2022, 1.85) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, macos-14, stable) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, beta) (push) Blocked by required conditions
CI / build_and_test (ubuntu-22.04, nightly) (push) Blocked by required conditions
CI / node_test (macos-14) (push) Blocked by required conditions
CI / node_test (ubuntu-22.04) (push) Blocked by required conditions
CI / python_test (ubuntu-22.04) (push) Blocked by required conditions
CI / cpp_test_driver (macos-13) (push) Blocked by required conditions
CI / cpp_test_driver (ubuntu-22.04) (push) Blocked by required conditions
CI / cpp_cmake (macos-14, 1.85) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, stable) (push) Blocked by required conditions
CI / node_test (windows-2022) (push) Blocked by required conditions
CI / python_test (macos-14) (push) Blocked by required conditions
CI / python_test (windows-2022) (push) Blocked by required conditions
CI / cpp_test_driver (windows-2022) (push) Blocked by required conditions
CI / docs (push) Blocked by required conditions
CI / wasm_demo (push) Blocked by required conditions
CI / updater_test (0.3.0) (push) Blocked by required conditions
CI / cpp_cmake (ubuntu-22.04, stable) (push) Blocked by required conditions
CI / cpp_cmake (windows-2022, nightly) (push) Blocked by required conditions
CI / cpp_package_test (push) Blocked by required conditions
CI / vsce_build_test (push) Blocked by required conditions
CI / mcu (pico-st7789, thumbv6m-none-eabi) (push) Blocked by required conditions
CI / mcu (pico2-st7789, thumbv8m.main-none-eabihf) (push) Blocked by required conditions
CI / mcu (stm32h735g, thumbv7em-none-eabihf) (push) Blocked by required conditions
CI / mcu-embassy (push) Blocked by required conditions
CI / ffi_32bit_build (push) Blocked by required conditions
CI / wasm (push) Blocked by required conditions
CI / tree-sitter (push) Blocked by required conditions
CI / fmt_test (push) Blocked by required conditions
CI / esp-idf-quick (push) Blocked by required conditions
CI / android (push) Blocked by required conditions
CI / miri (push) Blocked by required conditions
CI / test-figma-inspector (push) Blocked by required conditions
Cupertino ComboBox: remove height-for-height dependency
Fixes https://github.com/slint-ui/slint/issues/9219
2025-08-25 15:49:57 +02:00

214 lines
7.2 KiB
Text

// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
import { CupertinoFontSettings, CupertinoPalette, Icons, CupertinoSizeSettings } from "styling.slint";
import { MenuBorder, ListItem, FocusBorder } from "components.slint";
import { ComboBoxBase } from "../common/combobox-base.slint";
import { ScrollView } from "./scrollview.slint";
export component ComboBox {
in property <[string]> model <=> base.model;
in property <bool> enabled <=> base.enabled;
out property <bool> has-focus <=> base.has-focus;
in-out property <int> current-index <=> base.current-index;
in-out property <string> current-value <=> base.current-value;
callback selected <=> base.selected;
property <brush> background: CupertinoPalette.control-background;
property <length> popup-padding: 4px;
property <int> visible-items: min(6, model.length);
min-width: max(160px, layout.min-width);
min-height: max(22px, layout.min-height);
horizontal-stretch: 1;
vertical-stretch: 0;
forward-focus: base;
accessible-role: combobox;
accessible-enabled: root.enabled;
accessible-expandable: true;
accessible-expanded: base.popup-has-focus;
accessible-value <=> root.current-value;
accessible-action-expand => { base.show-popup(); }
states [
disabled when !root.enabled : {
text.color: CupertinoPalette.foreground-secondary;
top-icon.colorize: CupertinoPalette.foreground-secondary;
bottom-icon.colorize: CupertinoPalette.foreground-secondary;
root.background: CupertinoPalette.tertiary-control-background;
}
pressed when base.pressed : {
root.background: CupertinoPalette.secondary-control-background;
}
]
base := ComboBoxBase {
width: 100%;
height: 100%;
// Mac doesn't react on mouse wheel on the ComboBox.
scroll-delta: 1000000px;
show-popup => {
popup.show();
}
close-popup => {
popup.close();
}
}
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: CupertinoPalette.decent-border;
opacity: root.enabled ? 1 : 0.5;
}
}
layout := HorizontalLayout {
y: (parent.height - self.height) / 2;
padding-left: 8px;
padding-right: 8px;
padding-top: 4px;
padding-bottom: 4px;
spacing: 4px;
text := Text {
horizontal-stretch: 1;
horizontal-alignment: left;
vertical-alignment: center;
font-size: CupertinoFontSettings.body.font-size;
font-weight: CupertinoFontSettings.body.font-weight;
color: CupertinoPalette.foreground;
text: root.current-value;
accessible-role: none;
}
Rectangle {
min-width: 16px;
preferred-width: button-layout.preferred-width;
min-height: 16px;
horizontal-stretch: 0;
Rectangle {
x: 0px;
width: 100%;
y: (parent.height - self.height) / 2;
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: CupertinoPalette.accent-background;
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: CupertinoPalette.dimmer;
opacity: 0.17;
}
}
button-layout := VerticalLayout {
padding: 4px;
spacing: 4px;
top-icon := Image {
x: (parent.width - self.width) / 2;
colorize: CupertinoPalette.accent-foreground;
source: Icons.chevron-up;
accessible-role: none;
}
bottom-icon := Image {
x: (parent.width - self.width) / 2;
colorize: CupertinoPalette.accent-foreground;
source: Icons.chevron-down;
accessible-role: none;
}
}
}
}
}
popup := PopupWindow {
x: 0;
y: parent.height + 6px;
width: root.width;
height: root.visible-items * CupertinoSizeSettings.item-height + 2 * root.popup-padding;
forward-focus: inner-fs;
inner-fs := FocusScope {
focus-changed-event => {
base.popup-has-focus = self.has-focus;
}
key-pressed(event) => {
return base.popup-key-handler(event);
}
MenuBorder {
ScrollView {
VerticalLayout {
alignment: start;
padding: root.popup-padding;
for value[index] in root.model : ListItem {
padding-horizontal: 0;
item: { text: value };
is-selected: index == root.current-index;
has-hover: touch-area.has-hover;
pressed: touch-area.pressed;
pressed-x: touch-area.pressed-x;
pressed-y: touch-area.pressed-y;
touch-area := TouchArea {
clicked => {
base.select(index);
}
}
}
}
}
}
}
}
}