import { Nine, Theme } from "base.slint";
import { Pieces } from "pieces.slint";
import { ToolButton } from "tool-button.slint";
export component TextField {
forward-focus: input;
in-out property <string> text;
in property <bool> enabled: true;
in property <bool> focused: false;
in property <bool> autofocus: false;
// Bumped by Ctrl+F while the field is already open: take the focus back.
in property <int> focus-tick;
changed focus-tick => { input.focus(); }
in property <bool> search: false;
in property <bool> caret: false;
callback edited(string); callback accepted(string);
preferred-height: 28px;
property <bool> active: root.focused || input.has-focus;
init => { if root.focused || root.autofocus { input.focus(); } }
Nine { x: -4px; y: -4px; width: root.width + 8px; height: root.height + 8px; source: root.search ? Pieces.search-popup-textfield-default-shadow : Pieces.textbox-default-shadow; }
Nine { width: root.width; height: root.height; source: root.search ? (root.active ? Pieces.search-popup-textfield-focused-base : !root.enabled ? Pieces.search-popup-textfield-disabled-base : Pieces.search-popup-textfield-default-base) : root.active ? Pieces.textbox-focused-base : !root.enabled ? Pieces.textbox-disabled-base : Pieces.textbox-default-base; }
input := TextInput { x: root.search ? 3px : 8px; width: root.width - self.x - 4px; height: root.height; text <=> root.text; enabled: root.enabled; font-family: Theme.font; font-size: 14px; color: root.active ? #000000 : #ffffff; vertical-alignment: center; single-line: true; edited => { root.edited(self.text); } accepted => { root.accepted(self.text); } }
if root.caret: Rectangle { x: 7px; y: 4px; width: 1px; height: root.height - 7px; background: #1c1c1c; }
}
export component SearchField {
in-out property <string> text;
in property <bool> focused: false;
in property <bool> caret: false;
callback edited(string); callback accepted(string);
preferred-width: 132px; preferred-height: 28px;
TextField { x: 0px; y: -1px; width: root.width - 28px; height: root.height; search: true; focused: root.focused; caret: root.caret; text <=> root.text; edited(v) => { root.edited(v); } accepted(v) => { root.accepted(v); } }
ToolButton { x: root.width - 28px; y: -1px; width: 28px; height: root.height; state: "clicked"; clicked => { root.accepted(root.text); } }
}