// Copyright © SixtyFPS GmbH // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.0 OR LicenseRef-Slint-commercial import { Typography, Palette } from "styling.slint"; export component LineEdit { callback accepted(string /* text */); callback edited(string /* text */); in property enabled <=> i-text-input.enabled; in property input-type <=> i-text-input.input-type; in property horizontal-alignment <=> i-text-input.horizontal-alignment; in property read-only <=> i-text-input.read-only; in property font-size <=> i-text-input.font-size; in property placeholder-text <=> i-placeholder.text; out property has-focus <=> i-text-input.has-focus; in-out property text <=> i-text-input.text; vertical-stretch: 0; horizontal-stretch: 1; min-width: max(160px, i-layout.min-height); min-height: max(32px, i-layout.min-height); forward-focus: i-text-input; i-background := Rectangle { border-radius: 4px; background: Palette.control-default; border-width: 1px; border-color: Palette.text-control-border; i-layout := HorizontalLayout { padding-left: 12px; padding-right: 12px; Rectangle { clip: true; i-placeholder := Text { width: 100%; height: 100%; color: Palette.text-secondary; font-size: Typography.body.font-size; font-weight: Typography.body.font-weight; visible: root.text == ""; vertical-alignment: center; } i-text-input := TextInput { property computed_x; property padding-outer: i-layout.padding-left + i-layout.padding-right; x: min(0px, max(parent.width - self.width, self.computed_x)); width: max(parent.width, self.preferred-width); height: 100%; color: Palette.text-primary; vertical-alignment: center; font-size: Typography.body.font-size; font-weight: Typography.body.font-weight; selection-background-color: Palette.accent-selected-text; selection-foreground-color: self.color; accepted => { root.accepted(self.text); } edited => { root.edited(self.text); } cursor-position-changed(cpos) => { if (cpos.x + self.computed_x < self.padding-outer) { self.computed_x = - cpos.x + self.padding-outer; } else if (cpos.x + self.computed_x > parent.width - self.padding-outer) { self.computed_x = parent.width - cpos.x - self.padding-outer; } } } } } i-focus-border := Rectangle { x: parent.border-radius; y: parent.height - self.height; width: parent.width - 2 * parent.border-radius; height: 2px; } } public function select-all() { i-text-input.select-all(); } public function cut() { i-text-input.cut(); } public function copy() { i-text-input.copy(); } public function paste() { i-text-input.paste(); } states [ disabled when !root.enabled : { i-background.background: Palette.control-disabled; i-background.border-color: Palette.control-stroke; i-text-input.color: Palette.text-disabled; i-placeholder.color: Palette.text-disabled; } focused when root.has-focus : { i-background.background: Palette.control-input-active; i-background.border-color: Palette.control-stroke; i-focus-border.background: Palette.accent-default; i-placeholder.color: Palette.text-tertiary; } ] }