| 1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
| 2 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 |
| 3 | |
| 4 | import { LineEditBase } from "../common/lineedit-base.slint" ; |
| 5 | |
| 6 | export component LineEdit { |
| 7 | in property <length> font-size <=> inner.font-size; |
| 8 | in property <string> placeholder-text <=> inner.placeholder-text; |
| 9 | in property input-type <=> inner.input-type; |
| 10 | in property horizontal-alignment <=> inner.horizontal-alignment; |
| 11 | in property read-only <=> inner.read-only; |
| 12 | in property <bool> enabled: true; |
| 13 | out property <bool> has-focus <=> inner.has-focus; |
| 14 | in-out property <string> text <=> inner.text; |
| 15 | |
| 16 | callback accepted <=> inner.accepted; |
| 17 | callback edited <=> inner.edited; |
| 18 | callback key-pressed <=> inner.key-pressed; |
| 19 | callback key-released <=> inner.key-released; |
| 20 | accessible-role: text-input; |
| 21 | accessible-enabled: root.enabled; |
| 22 | accessible-value <=> text; |
| 23 | accessible-placeholder-text: text == "" ? placeholder-text : "" ; |
| 24 | accessible-read-only: root.read-only; |
| 25 | accessible-action-set-value(v) => { text = v; edited(v); } |
| 26 | |
| 27 | public function set-selection-offsets(start: int, end: int) { |
| 28 | inner.set-selection-offsets(start, end); |
| 29 | } |
| 30 | |
| 31 | public function select-all() { |
| 32 | inner.select-all(); |
| 33 | } |
| 34 | |
| 35 | public function clear-selection() { |
| 36 | inner.clear-selection(); |
| 37 | } |
| 38 | |
| 39 | public function cut() { |
| 40 | inner.cut(); |
| 41 | } |
| 42 | |
| 43 | public function copy() { |
| 44 | inner.copy(); |
| 45 | } |
| 46 | |
| 47 | public function paste() { |
| 48 | inner.paste(); |
| 49 | } |
| 50 | |
| 51 | forward-focus: inner; |
| 52 | horizontal-stretch: 1; |
| 53 | vertical-stretch: 0; |
| 54 | min-width: max(160px, layout.min-height); |
| 55 | min-height: max(32px, layout.min-height); |
| 56 | |
| 57 | native := NativeLineEdit { |
| 58 | has-focus <=> root.has-focus; |
| 59 | enabled: root.enabled; |
| 60 | width: 100%; |
| 61 | height: 100%; |
| 62 | } |
| 63 | |
| 64 | layout := HorizontalLayout { |
| 65 | padding-left: native.native-padding-left; |
| 66 | padding-right: native.native-padding-right; |
| 67 | padding-top: native.native-padding-top; |
| 68 | padding-bottom: native.native-padding-bottom; |
| 69 | |
| 70 | inner := LineEditBase { |
| 71 | placeholder-color: self.enabled ? NativeStyleMetrics.placeholder-color : NativeStyleMetrics.placeholder-color-disabled; |
| 72 | text-color: self.enabled ? NativeStyleMetrics.textedit-text-color : NativeStyleMetrics.textedit-text-color-disabled; |
| 73 | enabled: root.enabled; |
| 74 | margin: layout.padding-left + layout.padding-right; |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | |