// Copyright © SixtyFPS GmbH // SPDX-License-Identifier: MIT import { Palette } from "std-widgets.slint"; import { UsecasesPalette } from "styling.slint"; // copied from common that is not public now component LineEditBase inherits Rectangle { in property placeholder-text; in property font-size <=> text-input.font-size; in_out property text <=> text-input.text; in property placeholder-color; in property enabled <=> text-input.enabled; in property has-focus: text-input.has-focus; in property input-type <=> text-input.input-type; in property horizontal-alignment <=> text-input.horizontal-alignment; in property read-only <=> text-input.read-only; in property font-weight <=> text-input.font-weight; in property text-color; in property selection-background-color <=> text-input.selection-background-color; in property selection-foreground-color <=> 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) { text-input.set-selection-offsets(start, end); } public function select-all() { text-input.select-all(); } public function clear-selection() { text-input.clear-selection(); } public function cut() { text-input.cut(); } public function copy() { text-input.copy(); } public function paste() { text-input.paste(); } min-height: text-input.preferred-height; min-width: max(50px, placeholder.min-width); clip: true; forward-focus: text-input; placeholder := Text { width: 100%; height: 100%; vertical-alignment: center; text: (root.text == "" && text-input.preedit-text == "") ? root.placeholder-text : ""; font-size: text-input.font-size; font-italic: text-input.font-italic; font-weight: text-input.font-weight; font-family: text-input.font-family; color: root.placeholder-color; horizontal-alignment: root.horizontal-alignment; } 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); } } } export component ExtendedLineEdit { in property enabled <=> base.enabled; in property input-type <=> base.input-type; in property horizontal-alignment <=> base.horizontal-alignment; in property read-only <=> base.read-only; in property font-size <=> base.font-size; in property placeholder-text <=> base.placeholder-text; out property has-focus <=> base.has-focus; in-out property text <=> base.text; property style-min-height: UsecasesPalette.use-material ? 56px : 32px; callback accepted <=> base.accepted; callback edited <=> base.edited; accessible-role: text-input; accessible-value <=> text; public function set-selection-offsets(start: int, end: int) { base.set-selection-offsets(start, end); } public function select-all() { base.select-all(); } public function clear-selection() { base.clear-selection(); } public function cut() { base.cut(); } public function copy() { base.copy(); } public function paste() { base.paste(); } vertical-stretch: 0; horizontal-stretch: 1; min-width: max(160px, layout.min-width); min-height: max(root.style-min-height, layout.min-height); forward-focus: base; states [ disabled when !root.enabled : { root.opacity: 0.5; } ] background := Rectangle { border-radius: UsecasesPalette.use-material ? 4px : 8px; background: UsecasesPalette.use-material ? transparent : Palette.control-background; border-width: root.has-focus && UsecasesPalette.use-material ? 2px : 1px; border-color: UsecasesPalette.control-divider; layout := HorizontalLayout { padding-left: 16px; padding-right: 16px; spacing: 8px; HorizontalLayout { @children } base := LineEditBase { font-size: 15 * 0.0769rem; font-weight: 400; selection-background-color: Palette.selection-background; selection-foreground-color: Palette.accent-foreground; text-color: Palette.foreground; placeholder-color: UsecasesPalette.placeholder-foreground; margin: layout.padding-left + layout.padding-right; } } if root.has-focus && root.enabled : Rectangle { width: parent.width + 2px; height: parent.height + 2px; border-radius: parent.border-radius + 2px; border-color: UsecasesPalette.state-focus; border-width: 1px; } } }