| 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 { FluentFontSettings, FluentPalette } from "styling.slint" ; |
| 5 | import { ScrollView } from "scrollview.slint" ; |
| 6 | import { TextEditBase } from "../common/textedit-base.slint" ; |
| 7 | |
| 8 | export component TextEdit { |
| 9 | in property <TextWrap> wrap <=> base.wrap; |
| 10 | in property <TextHorizontalAlignment> horizontal-alignment <=> base.horizontal-alignment; |
| 11 | in property <bool> read-only <=> base.read-only; |
| 12 | in property <length> font-size <=> base.font-size; |
| 13 | in property <bool> enabled <=> base.enabled; |
| 14 | in property <string> placeholder-text <=> base.placeholder-text; |
| 15 | in-out property <bool> has-focus: base.has-focus; |
| 16 | out property <length> visible-width <=> base.visible-width; |
| 17 | out property <length> visible-height <=> base.visible-height; |
| 18 | in-out property <string> text <=> base.text; |
| 19 | in-out property <length> viewport-x <=> base.viewport-x; |
| 20 | in-out property <length> viewport-y <=> base.viewport-y; |
| 21 | in-out property <length> viewport-width <=> base.viewport-width; |
| 22 | in-out property <length> viewport-height <=> base.viewport-height; |
| 23 | |
| 24 | callback edited <=> base.edited; |
| 25 | callback key-pressed <=> base.key-pressed; |
| 26 | callback key-released <=> base.key-released; |
| 27 | |
| 28 | accessible-role: AccessibleRole.text-input; |
| 29 | accessible-enabled: root.enabled; |
| 30 | accessible-value <=> text; |
| 31 | accessible-placeholder-text: text == "" ? placeholder-text : "" ; |
| 32 | accessible-read-only: root.read-only; |
| 33 | |
| 34 | public function set-selection-offsets(start: int, end: int) { |
| 35 | base.set-selection-offsets(start, end); |
| 36 | } |
| 37 | |
| 38 | public function select-all() { |
| 39 | base.select-all(); |
| 40 | } |
| 41 | |
| 42 | public function clear-selection() { |
| 43 | base.clear-selection(); |
| 44 | } |
| 45 | |
| 46 | public function cut() { |
| 47 | base.cut(); |
| 48 | } |
| 49 | |
| 50 | public function copy() { |
| 51 | base.copy(); |
| 52 | } |
| 53 | |
| 54 | public function paste() { |
| 55 | base.paste(); |
| 56 | } |
| 57 | |
| 58 | forward-focus: base; |
| 59 | horizontal-stretch: 1; |
| 60 | vertical-stretch: 1; |
| 61 | |
| 62 | states [ |
| 63 | disabled when !root.enabled: { |
| 64 | base.background: FluentPalette.control-disabled; |
| 65 | base.border-color: FluentPalette.border; |
| 66 | base.foreground: FluentPalette.text-disabled; |
| 67 | base.selection-foreground-color: FluentPalette.text-accent-foreground-disabled; |
| 68 | } |
| 69 | focused when root.has-focus: { |
| 70 | base.background: FluentPalette.control-input-active; |
| 71 | base.border-color: FluentPalette.border; |
| 72 | i-focus-border.background: FluentPalette.accent-background; |
| 73 | } |
| 74 | ] |
| 75 | |
| 76 | base := TextEditBase { |
| 77 | width: 100%; |
| 78 | height: 100%; |
| 79 | background: FluentPalette.control-background; |
| 80 | border-radius: 4px; |
| 81 | border-width: 1px; |
| 82 | border-color: FluentPalette.text-control-border; |
| 83 | scroll-view-padding: 12px; |
| 84 | foreground: FluentPalette.foreground; |
| 85 | font-size: FluentFontSettings.body.font-size; |
| 86 | font-weight: FluentFontSettings.body.font-weight; |
| 87 | placeholder-color: FluentPalette.text-secondary; |
| 88 | selection-background-color: FluentPalette.selection-background; |
| 89 | selection-foreground-color: FluentPalette.selection-foreground; |
| 90 | |
| 91 | i-focus-border := Rectangle { |
| 92 | x: parent.border-radius; |
| 93 | y: parent.height - self.height; |
| 94 | width: parent.width - 2 * parent.border-radius; |
| 95 | height: 2px; |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |