// Copyright © SixtyFPS GmbH // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial export component LineEditBase inherits Rectangle { in-out property placeholder-text; in-out property font-size <=> i-text-input.font-size; in-out property text <=> i-text-input.text; in-out property placeholder-color; in-out property enabled <=> i-text-input.enabled; in-out property has-focus: i-text-input.has-focus; in-out property input-type <=> i-text-input.input-type; in-out property horizontal-alignment <=> i-text-input.horizontal-alignment; in-out property read-only <=> i-text-input.read-only; in property font-weight <=> i-text-input.font-weight; in property text-color; in property selection-background-color <=> i-text-input.selection-background-color; in property selection-foreground-color <=> i-text-input.selection-foreground-color; in property margin; callback accepted( /* text */ string); callback edited(/* text */ string); public function set-selection-offsets(start: int, end: int) { i-text-input.set-selection-offsets(start, end); } public function select-all() { i-text-input.select-all(); } public function clear-selection() { i-text-input.clear-selection(); } public function cut() { i-text-input.cut(); } public function copy() { i-text-input.copy(); } public function paste() { i-text-input.paste(); } min-height: i-text-input.preferred-height; min-width: max(50px, i-placeholder.min-width); clip: true; forward-focus: i-text-input; i-placeholder := Text { width: 100%; height: 100%; vertical-alignment: center; text: (root.text == "" && i-text-input.preedit-text == "") ? root.placeholder-text : ""; font-size: i-text-input.font-size; font-italic: i-text-input.font-italic; font-weight: i-text-input.font-weight; font-family: i-text-input.font-family; color: root.placeholder-color; horizontal-alignment: root.horizontal-alignment; } i-text-input := TextInput { property computed-x; x: min(0px, max(parent.width - self.width - self.text-cursor-width, self.computed-x)); width: max(parent.width - self.text-cursor-width, self.preferred-width); height: 100%; vertical-alignment: center; single-line: true; color: root.text-color; cursor-position-changed(cpos) => { if (cpos.x + self.computed_x < root.margin) { self.computed_x = - cpos.x + root.margin; } else if (cpos.x + self.computed_x > parent.width - root.margin - self.text-cursor-width) { self.computed_x = parent.width - cpos.x - root.margin - self.text-cursor-width; } } accepted => { root.accepted(self.text); } edited => { root.edited(self.text); } } }