mirror of
				https://github.com/slint-ui/slint.git
				synced 2025-10-29 19:17:05 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			90 lines
		
	
	
	
		
			3.1 KiB
		
	
	
	
		
			Text
		
	
	
	
	
	
			
		
		
	
	
			90 lines
		
	
	
	
		
			3.1 KiB
		
	
	
	
		
			Text
		
	
	
	
	
	
| // Copyright © SixtyFPS GmbH <info@slint.dev>
 | |
| // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
 | |
| 
 | |
| import { CosmicFontSettings, CosmicPalette } from "styling.slint";
 | |
| import { ScrollView } from "scrollview.slint";
 | |
| import { TextEditBase } from "../common/textedit-base.slint";
 | |
| 
 | |
| export component TextEdit {
 | |
|     in property <TextWrap> wrap <=> base.wrap;
 | |
|     in property <TextHorizontalAlignment> horizontal-alignment <=> base.horizontal-alignment;
 | |
|     in property <bool> read-only <=> base.read-only;
 | |
|     in property <length> font-size <=> base.font-size;
 | |
|     in property <bool> enabled <=> base.enabled;
 | |
|     in property <string> placeholder-text <=> base.placeholder-text;
 | |
|     in-out property <bool> has-focus: base.has-focus;
 | |
|     out property <length> visible-width <=> base.visible-width;
 | |
|     out property <length> visible-height <=> base.visible-height;
 | |
|     in-out property <string> text <=> base.text;
 | |
|     in-out property <length> viewport-x <=> base.viewport-x;
 | |
|     in-out property <length> viewport-y <=> base.viewport-y;
 | |
|     in-out property <length> viewport-width <=> base.viewport-width;
 | |
|     in-out property <length> viewport-height <=> base.viewport-height;
 | |
| 
 | |
|     callback edited <=> base.edited;
 | |
|     callback key-pressed <=> base.key-pressed;
 | |
|     callback key-released <=> base.key-released;
 | |
| 
 | |
|     accessible-role: AccessibleRole.text-input;
 | |
|     accessible-enabled: root.enabled;
 | |
|     accessible-value <=> text;
 | |
|     accessible-placeholder-text: text == "" ? placeholder-text : "";
 | |
|     accessible-read-only: root.read-only;
 | |
| 
 | |
|     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();
 | |
|     }
 | |
| 
 | |
|     forward-focus: base;
 | |
|     horizontal-stretch: 1;
 | |
|     vertical-stretch: 1;
 | |
| 
 | |
|     states [
 | |
|         disabled when !root.enabled: {
 | |
|             root.opacity: 0.5;
 | |
|         }
 | |
|     ]
 | |
| 
 | |
|     base := TextEditBase {
 | |
|         width: 100%;
 | |
|         height: 100%;
 | |
|         border-radius: 8px;
 | |
|         background: CosmicPalette.control-background;
 | |
|         border-width: 1px;
 | |
|         border-color: CosmicPalette.control-divider;
 | |
|         scroll-view-padding: 12px;
 | |
|         foreground: CosmicPalette.foreground;
 | |
|         font-size: CosmicFontSettings.body.font-size;
 | |
|         font-weight: CosmicFontSettings.body.font-weight;
 | |
|         selection-background-color: CosmicPalette.selection-background;
 | |
|         selection-foreground-color: CosmicPalette.selection-foreground;
 | |
|         placeholder-color: CosmicPalette.placeholder-foreground;
 | |
|         if root.has-focus && root.enabled: Rectangle {
 | |
|             width: parent.width + 2px;
 | |
|             height: parent.height + 2px;
 | |
|             border-radius: parent.border-radius + 2px;
 | |
|             border-color: CosmicPalette.state-focus;
 | |
|             border-width: 1px;
 | |
|         }
 | |
|     }
 | |
| }
 | 
