| 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 { CosmicFontSettings, CosmicPalette } 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 | root.opacity: 0.5; |
| 65 | } |
| 66 | ] |
| 67 | |
| 68 | base := TextEditBase { |
| 69 | width: 100%; |
| 70 | height: 100%; |
| 71 | border-radius: 8px; |
| 72 | background: CosmicPalette.control-background; |
| 73 | border-width: 1px; |
| 74 | border-color: CosmicPalette.control-divider; |
| 75 | scroll-view-padding: 12px; |
| 76 | foreground: CosmicPalette.foreground; |
| 77 | font-size: CosmicFontSettings.body.font-size; |
| 78 | font-weight: CosmicFontSettings.body.font-weight; |
| 79 | selection-background-color: CosmicPalette.selection-background; |
| 80 | selection-foreground-color: CosmicPalette.selection-foreground; |
| 81 | placeholder-color: CosmicPalette.placeholder-foreground; |
| 82 | if root.has-focus && root.enabled: Rectangle { |
| 83 | width: parent.width + 2px; |
| 84 | height: parent.height + 2px; |
| 85 | border-radius: parent.border-radius + 2px; |
| 86 | border-color: CosmicPalette.state-focus; |
| 87 | border-width: 1px; |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |