import { Theme, ActionButton } from "theme.slint"; export component DeviceSelect inherits Rectangle { in property <[string]> model; in-out property current-index; callback selected(string); height: 34px; background: Theme.bg-interactive; border-radius: 6px; border-width: 1px; border-color: keyboard.has-focus ? Theme.accent : Theme.border; accessible-role: combobox; HorizontalLayout { padding-left: 11px; padding-right: 11px; Text { text: root.model[root.current-index]; color: Theme.text-primary; font-size: Math.max(11px, Theme.font-size * 0.8125); vertical-alignment: center; overflow: elide; horizontal-stretch: 1; } Text { text: "⌄"; color: Theme.text-muted; width: 16px; vertical-alignment: center; } } TouchArea { clicked => { keyboard.focus(); popup.show(); } } keyboard := FocusScope { key-pressed(event) => { if event.text == " " || event.text == "\n" { popup.show(); return accept; } if event.text == Key.DownArrow || event.text == Key.UpArrow { root.current-index = Math.clamp(root.current-index + (event.text == Key.DownArrow ? 1 : -1), 0, root.model.length - 1); root.selected(root.model[root.current-index]); return accept; } return reject; } } popup := PopupWindow { x: 0px; y: root.height + 3px; width: root.width; height: Math.min(root.model.length * 36px + 12px, 264px); Rectangle { background: Theme.bg-surface; border-radius: 6px; border-width: 1px; border-color: Theme.border; Flickable { content-width: self.width; VerticalLayout { padding: 6px; spacing: 3px; for item[index] in root.model: ActionButton { text: item; active: index == root.current-index; clicked => { root.current-index = index; root.selected(item); popup.close(); } } } } } } } export component AudioSlider inherits Rectangle { in property minimum: 0; in property maximum: 100; in-out property value; callback changed(float); height: 26px; border-width: keyboard.has-focus ? 1px : 0px; border-color: Theme.accent; border-radius: 5px; Rectangle { x: 8px; y: 11px; width: parent.width - 16px; height: 4px; background: Theme.bg-rail; border-radius: 2px; } Rectangle { x: 8px; y: 11px; width: (parent.width - 16px) * (root.value - root.minimum) / (root.maximum - root.minimum); height: 4px; background: Theme.accent; border-radius: 2px; } Rectangle { x: 1px + (parent.width - 16px) * (root.value - root.minimum) / (root.maximum - root.minimum); y: 5px; width: 16px; height: 16px; border-radius: 8px; background: Theme.text-primary; border-width: 3px; border-color: Theme.accent; } touch := TouchArea { pointer-event(event) => { if event.button == PointerEventButton.left && event.kind == PointerEventKind.down { keyboard.focus(); root.update-value(root.minimum + Math.clamp((self.mouse-x - 8px) / (root.width - 16px), 0, 1) * (root.maximum - root.minimum)); } } moved => { if self.pressed { root.update-value(root.minimum + Math.clamp((self.mouse-x - 8px) / (root.width - 16px), 0, 1) * (root.maximum - root.minimum)); } } } keyboard := FocusScope { key-pressed(event) => { if event.text == Key.LeftArrow || event.text == Key.RightArrow { root.update-value(root.value + (event.text == Key.RightArrow ? 1 : -1)); return accept; } return reject; } } function update-value(value: float) { root.value = Math.clamp(value, root.minimum, root.maximum); root.changed(root.value); } } export component ThemeInput inherits Rectangle { in-out property text; in property placeholder-text; in property input-type: InputType.text; in property read-only: false; callback accepted(); callback edited(string); height: 38px; background: Theme.bg-interactive; border-radius: 6px; border-width: 1px; border-color: editor.has-focus ? Theme.accent : Theme.border; Text { x: 12px; y: 0px; width: parent.width - 24px; height: parent.height; visible: root.text == "" && !editor.has-focus; text: root.placeholder-text; color: Theme.text-muted; font-size: Math.max(12px, Theme.font-size - 2px); vertical-alignment: center; overflow: elide; } editor := TextInput { x: 12px; y: (parent.height - self.height) / 2; width: parent.width - 24px; height: self.preferred-height; text <=> root.text; input-type: root.input-type; read-only: root.read-only; single-line: true; color: Theme.text-primary; selection-background-color: Theme.selected; selection-foreground-color: Theme.text-primary; font-size: Math.max(12px, Theme.font-size - 2px); accepted => { root.accepted(); } edited => { root.edited(self.text); } } forward-focus: editor; } export component ThemeEditor inherits Rectangle { in-out property text; in property read-only: false; in property monospace: true; callback edited(string); min-height: 80px; preferred-height: 220px; background: Theme.bg-interactive; border-radius: 7px; border-width: 1px; border-color: editor.has-focus ? Theme.accent : Theme.border; Flickable { x: 12px; y: 10px; width: parent.width - 24px; height: parent.height - 20px; content-width: self.width; content-height: Math.max(self.height, editor.preferred-height); editor := TextInput { width: parent.width; height: Math.max(parent.height, self.preferred-height); text <=> root.text; read-only: root.read-only; single-line: false; color: Theme.text-primary; font-size: Math.max(12px, Theme.font-size - 3px); font-family: root.monospace ? "monospace" : "sans-serif"; selection-background-color: Theme.selected; selection-foreground-color: Theme.text-primary; wrap: word-wrap; edited => { root.edited(self.text); } } } forward-focus: editor; }