// Copyright © SixtyFPS GmbH // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial import { md } from "md.slint"; // Single line text input field with Material Design Outline TextField look and feel. export LineEdit := Rectangle { property font-size <=> input.font-size; property text <=> input.text; property placeholder-text <=> placeholder.text; property has-focus: input.has-focus; property enabled <=> input.enabled; property input-type <=> input.input-type; property horizontal-alignment <=> input.horizontal-alignment; property read-only <=> input.read-only; callback accepted <=> input.accepted; callback edited <=> input.edited; min-width: 120px; height: 56px; forward-focus: input; container := Rectangle { width: 100%; height: 100%; border-radius: 4px; border-width: 1px; border-color: md.sys.color.outline; } layout := HorizontalLayout { padding-left: 16px; padding-right: 16px; Rectangle { clip: true; input := TextInput { property computed_x; property padding-outer: layout.padding-left + layout.padding-right; x: min(0px, max(parent.width - width, computed_x)); width: max(parent.width, preferred-width); height: 100%; color: md.sys.color.on-surface; vertical-alignment: center; // FIXME after Roboto font can be loaded //font-family: md.sys.typescale.body-large.font; font-size: md.sys.typescale.body-large.size; font-weight: md.sys.typescale.body-large.weight; cursor-position-changed(cpos) => { if (cpos.x + computed_x < padding-outer) { computed_x = - cpos.x + padding-outer; } else if (cpos.x + computed_x > parent.width - padding-outer) { computed_x = parent.width - cpos.x - padding-outer; } } } placeholder := Text { width: 100%; height: 100%; color: md.sys.color.outline-variant; font-family: md.sys.typescale.body-large.font; font-size: md.sys.typescale.body-large.size; font-weight: md.sys.typescale.body-large.weight; visible: false; vertical-alignment: center; states [ empty when input.text == "" : { visible: true; } ] } } } states [ disabled when !enabled : { container.border-color: md.sys.color.on-surface; container.opacity: 0.38; input.opacity: 0.38; placeholder.opacity: 0.38; } focused when has-focus : { container.border-width: 2px; container.border-color: md.sys.color.primary; input.color: md.sys.color.primary; } ] }