import { ComboBox } from "std-widgets.slint"; import { Theme } from "theme.slint"; export component ActionButton inherits Rectangle { in property text; in property enabled: true; in property primary: false; in property destructive: false; callback clicked(); min-height: Theme.touch-target; min-width: max(Theme.android ? 48px : 44px, label.preferred-width + 24px); preferred-height: Theme.touch-target; border-radius: primary ? self.height / 2 : 4px; background: primary ? (destructive ? Theme.error : Theme.tint) : (touch.has-hover || focus.has-focus ? Theme.bg : transparent); border-width: focus.has-focus || Theme.high-contrast ? 2px : 0px; border-color: Theme.outline; opacity: enabled ? 1 : 0.45; accessible-role: button; accessible-label: text; accessible-enabled: enabled; accessible-action-default => { if root.enabled { root.clicked(); } } label := Text { text: root.text; color: root.primary ? (Theme.dark ? Theme.contrast : #fff) : (root.destructive ? Theme.error : Theme.fg); font-family: Theme.font-family; font-size: Theme.font-size; horizontal-alignment: center; vertical-alignment: center; overflow: elide; } focus := FocusScope { enabled: root.enabled; key-pressed(event) => { if event.text == "\n" || event.text == " " { root.clicked(); return accept; } return reject; } } touch := TouchArea { enabled: root.enabled; clicked => { focus.focus(); root.clicked(); } } } export component TextField inherits Rectangle { in-out property text; in property placeholder; in property secret: false; in property enabled: true; out property has-focus: input.has-focus; callback edited(string); callback accepted(); min-height: Theme.touch-target; preferred-height: Theme.touch-target; background: Theme.bg; border-radius: 4px; forward-focus: input; border-width: input.has-focus || Theme.high-contrast ? 2px : 1px; border-color: input.has-focus ? Theme.tint : Theme.outline; if root.text == "" && input.preedit-text == "": Text { x: 10px; width: parent.width - 20px; text: root.placeholder; color: Theme.muted; vertical-alignment: center; font-family: Theme.font-family; font-size: Theme.font-size; overflow: elide; } input := TextInput { x: 10px; width: parent.width - 20px; text <=> root.text; single-line: true; input-type: root.secret ? InputType.password : InputType.text; enabled: root.enabled; color: Theme.fg; font-family: Theme.font-family; font-size: Theme.font-size; vertical-alignment: center; selection-background-color: Theme.tint; selection-foreground-color: Theme.contrast; edited => { root.edited(self.text); } accepted => { root.accepted(); } accessible-label: root.placeholder; } } export component Toggle inherits Rectangle { in-out property checked; in property enabled: true; in property label; callback toggled(bool); min-width: Theme.android ? 48px : 44px; min-height: Theme.touch-target; preferred-width: 48px; accessible-role: checkbox; accessible-label: label; accessible-checked: checked; accessible-enabled: enabled; accessible-action-default => { if root.enabled { root.checked = !root.checked; root.toggled(root.checked); } } Rectangle { width: 40px; height: 20px; x: (parent.width - self.width)/2; y: (parent.height - self.height)/2; border-radius: 10px; background: root.checked ? Theme.success : Theme.contrast; border-width: focus.has-focus || Theme.high-contrast ? 2px : 1px; border-color: Theme.outline; Rectangle { x: root.checked ? 22px : 2px; y: 2px; width: 16px; height: 16px; border-radius: 8px; background: Theme.fg; } } focus := FocusScope { enabled: root.enabled; key-pressed(e) => { if e.text == " " { root.checked = !root.checked; root.toggled(root.checked); return accept; } return reject; } } TouchArea { enabled: root.enabled; clicked => { focus.focus(); root.checked = !root.checked; root.toggled(root.checked); } } } export component Choice inherits Rectangle { in property <[string]> values; in-out property current-index; in property enabled: true; in property label; callback selected(int); min-height: Theme.touch-target; preferred-height: Theme.touch-target; forward-focus: input; // ComboBox normalizes its local model/index internally. Never let those writes sever // the caller's authoritative selected-index binding during a snapshot/model update. changed current-index => { input.current-index = root.current-index; } changed values => { input.current-index = root.current-index; } input := ComboBox { model: root.values; current-index: root.current-index; enabled: root.enabled; accessible-label: root.label; selected(value) => { root.selected(self.current-index); } } }