mirror of
				https://github.com/slint-ui/slint.git
				synced 2025-10-31 12:04:33 +00:00 
			
		
		
		
	 085d122a04
			
		
	
	
		085d122a04
		
			
		
	
	
	
	
		
			
			- Take in account the scale factor (unfortunately we don't have access to the actual window scale factor so just use the Qt one) - Draw directly in the final SharedPixelBuffer - Use an intermediate Rectangle to center the image because otherwise we get height for width dependency that breaks layout.
		
			
				
	
	
		
			94 lines
		
	
	
	
		
			3.1 KiB
		
	
	
	
		
			Text
		
	
	
	
	
	
			
		
		
	
	
			94 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 { LineEditBase, LineEditClearIcon } from "../common/lineedit-base.slint";
 | |
| 
 | |
| export component LineEdit {
 | |
|     in property <length> font-size <=> inner.font-size;
 | |
|     in property <string> placeholder-text <=> inner.placeholder-text;
 | |
|     in property input-type <=> inner.input-type;
 | |
|     in property horizontal-alignment <=> inner.horizontal-alignment;
 | |
|     in property read-only <=> inner.read-only;
 | |
|     in property <bool> enabled: true;
 | |
|     out property <bool> has-focus <=> inner.has-focus;
 | |
|     in-out property <string> text <=> inner.text;
 | |
| 
 | |
|     callback accepted <=> inner.accepted;
 | |
|     callback edited <=> inner.edited;
 | |
|     callback key-pressed <=> inner.key-pressed;
 | |
|     callback key-released <=> inner.key-released;
 | |
|     accessible-role: text-input;
 | |
|     accessible-enabled: root.enabled;
 | |
|     accessible-value <=> text;
 | |
|     accessible-placeholder-text: text == "" ? placeholder-text : "";
 | |
|     accessible-read-only: root.read-only;
 | |
|     accessible-action-set-value(v) => { text = v; edited(v); }
 | |
| 
 | |
|     public function set-selection-offsets(start: int, end: int) {
 | |
|         inner.set-selection-offsets(start, end);
 | |
|     }
 | |
| 
 | |
|     public function select-all() {
 | |
|         inner.select-all();
 | |
|     }
 | |
| 
 | |
|     public function clear-selection() {
 | |
|         inner.clear-selection();
 | |
|     }
 | |
| 
 | |
|     public function cut() {
 | |
|         inner.cut();
 | |
|     }
 | |
| 
 | |
|     public function copy() {
 | |
|         inner.copy();
 | |
|     }
 | |
| 
 | |
|     public function paste() {
 | |
|         inner.paste();
 | |
|     }
 | |
| 
 | |
|     forward-focus: inner;
 | |
|     horizontal-stretch: 1;
 | |
|     vertical-stretch: 0;
 | |
|     min-width: max(160px, layout.min-height);
 | |
|     min-height: max(32px, layout.min-height);
 | |
| 
 | |
|     native := NativeLineEdit {
 | |
|         has-focus <=> root.has-focus;
 | |
|         enabled: root.enabled;
 | |
|         width: 100%;
 | |
|         height: 100%;
 | |
|     }
 | |
| 
 | |
|     layout := HorizontalLayout {
 | |
|         padding-left: native.native-padding-left;
 | |
|         padding-right: native.native-padding-right;
 | |
|         padding-top: native.native-padding-top;
 | |
|         padding-bottom: native.native-padding-bottom;
 | |
| 
 | |
|         inner := LineEditBase {
 | |
|             placeholder-color: self.enabled ? NativeStyleMetrics.placeholder-color : NativeStyleMetrics.placeholder-color-disabled;
 | |
|             text-color: self.enabled ? NativeStyleMetrics.textedit-text-color : NativeStyleMetrics.textedit-text-color-disabled;
 | |
|             enabled: root.enabled;
 | |
|             margin: layout.padding-left + layout.padding-right;
 | |
|         }
 | |
| 
 | |
|         if !root.text.is-empty && root.input-type != InputType.password && root.enabled && !root.read-only: Rectangle {
 | |
|             width: inner.min-height;
 | |
|             LineEditClearIcon {
 | |
|                 width: 100%;
 | |
|                 height: self.width;
 | |
|                 image-fit: ImageFit.contain;
 | |
|                 text: inner.text;
 | |
|                 source: native.clear-icon;
 | |
|                 colorize: inner.text-color;
 | |
|                 clear => {
 | |
|                     inner.text = "";
 | |
|                     inner.focus();
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
| 
 | |
|     }
 | |
| }
 |