slint/internal/compiler/widgets/fluent-base/combobox.slint
Florian Blasius 6da8120dfa
added palette global (#3984)
* Update docs/reference/src/language/builtins/globals.md

Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>

* Update docs/reference/src/language/builtins/globals.md

Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>

* Update docs/reference/src/language/builtins/globals.md

Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>

* Update docs/reference/src/language/builtins/globals.md

Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>

* Update docs/reference/src/language/builtins/globals.md

Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>


---------

Co-authored-by: Florian Blasius <florian.blasius@slint-ui.com>
Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>
Co-authored-by: Florian Blasius <flovansl@fedora.fritz.box>
2023-12-11 14:44:05 +00:00

114 lines
3.7 KiB
Text

// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
import { FluentFontSettings, FluentPalette, Icons } from "styling.slint";
import { MenuBorder, ListItem, FocusBorder } from "components.slint";
import { ComboBoxBase } from "../common/combobox-base.slint";
export component ComboBox {
in property <[string]> model <=> i-base.model;
in property <bool> enabled <=> i-base.enabled;
out property <bool> has-focus <=> i-base.has-focus;
in-out property <int> current-index <=> i-base.current-index;
in-out property <string> current-value <=> i-base.current-value;
callback selected <=> i-base.selected;
min-width: max(160px, i-layout.min-height);
min-height: max(32px, i-layout.min-height);
horizontal-stretch: 1;
vertical-stretch: 0;
forward-focus: i-base;
states [
disabled when !root.enabled : {
i-background.background: FluentPalette.control-disabled;
i-background.border-color: FluentPalette.border;
i-text.color: FluentPalette.text-disabled;
i-icon.colorize: FluentPalette.text-disabled;
}
pressed when i-base.pressed : {
i-background.background: FluentPalette.control-alt-tertiary;
i-background.border-color: FluentPalette.border;
i-text.color: FluentPalette.text-secondary;
i-icon.colorize: FluentPalette.text-tertiary;
}
hover when i-base.has-hover : {
i-background.background: FluentPalette.control-secondary;
}
]
i-base := ComboBoxBase {
width: 100%;
height: 100%;
show-popup => {
i-popup.show();
}
}
i-background := Rectangle {
border-radius: 3px;
background: FluentPalette.control-background;
border-width: 1px;
border-color: FluentPalette.control-border;
animate border-color { duration: 200ms; }
i-layout := HorizontalLayout {
padding-left: 11px;
padding-right: 11px;
spacing: 8px;
i-text := Text {
horizontal-alignment: left;
vertical-alignment: center;
font-size: FluentFontSettings.body.font-size;
font-weight: FluentFontSettings.body.font-weight;
color: FluentPalette.control-foreground;
text: root.current-value;
}
i-icon := Image {
colorize: FluentPalette.text-secondary;
width: 12px;
source: Icons.dropdown;
y: 2px;
animate colorize { duration: 150ms; }
}
}
}
// focus border
if (root.has-focus && root.enabled) : FocusBorder {
border-radius: i-background.border-radius;
}
i-popup := PopupWindow {
x: 0;
// Position the popup so that the first element is over the popup.
// Ideally it should be so that the current element is over the popup.
y: -4px;
width: root.width;
MenuBorder {
VerticalLayout {
padding: 4px;
for value[index] in root.model : ListItem {
item: { text: value };
is-selected: index == root.current-index;
has-hover: i-touch-area.has-hover;
pressed: i-touch-area.pressed;
i-touch-area := TouchArea {
clicked => {
i-base.select(index);
}
}
}
}
}
}
}