mirror of
				https://github.com/slint-ui/slint.git
				synced 2025-10-30 03:27:22 +00:00 
			
		
		
		
	 41c5194c0a
			
		
	
	
		41c5194c0a
		
	
	
	
	
		
			
			The problem was that the `LineEditPasswordIcon` had an internal property that would get out of sync when the component is re-created. The component does get re-created in fluent depepending on the focus, and this is the case especially with wasm because of the hidden input that takes the focus. Fixes #9225
		
			
				
	
	
		
			112 lines
		
	
	
	
		
			4.1 KiB
		
	
	
	
		
			Text
		
	
	
	
	
	
			
		
		
	
	
			112 lines
		
	
	
	
		
			4.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 { MaterialPalette, MaterialFontSettings } from "styling.slint";
 | |
| import { LineEditBase, LineEditClearIcon, LineEditPasswordIcon } from "../common/lineedit-base.slint";
 | |
| 
 | |
| // Single line text input field with Material Design Outline TextField look and feel.
 | |
| export component LineEdit {
 | |
|     in property <length> font-size <=> base.font-size;
 | |
|     in property <string> placeholder-text <=> base.placeholder-text;
 | |
|     in property <bool> enabled <=> base.enabled;
 | |
|     in property <InputType> input-type;
 | |
|     in property horizontal-alignment <=> base.horizontal-alignment;
 | |
|     in property read-only <=> base.read-only;
 | |
|     out property <bool> has-focus: base.has-focus;
 | |
|     in-out property <string> text <=> base.text;
 | |
| 
 | |
|     callback accepted <=> base.accepted;
 | |
|     callback edited <=> base.edited;
 | |
|     callback key-pressed <=> base.key-pressed;
 | |
|     callback key-released <=> base.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) {
 | |
|         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();
 | |
|     }
 | |
| 
 | |
|     min-width: max(120px, layout.min-width);
 | |
|     min-height: max(56px, layout.min-height);
 | |
|     forward-focus: base;
 | |
| 
 | |
|     states [
 | |
|         disabled when !root.enabled : {
 | |
|             background.border-color: MaterialPalette.control-foreground;
 | |
|             background.opacity: 0.38;
 | |
|             base.opacity: 0.38;
 | |
|         }
 | |
|         focused when root.has-focus : {
 | |
|             background.border-width: 2px;
 | |
|             background.border-color: MaterialPalette.accent-background;
 | |
|         }
 | |
|     ]
 | |
| 
 | |
|     background := Rectangle {
 | |
|         width: 100%;
 | |
|         height: 100%;
 | |
|         border-radius: 4px;
 | |
|         border-width: 1px;
 | |
|         border-color: MaterialPalette.border;
 | |
| 
 | |
|         layout := HorizontalLayout {
 | |
|             padding-left: 16px;
 | |
|             padding-right: 16px;
 | |
| 
 | |
|             base := LineEditBase {
 | |
|                 input-type: root.input-type;
 | |
|                 text-color: MaterialPalette.foreground;
 | |
|                 font-size: MaterialFontSettings.body-large.font-size;
 | |
|                 font-weight: MaterialFontSettings.body-large.font-weight;
 | |
|                 selection-foreground-color: MaterialPalette.selection-foreground;
 | |
|                 margin: layout.padding-left + layout.padding-right;
 | |
|                 placeholder-color: MaterialPalette.border-variant;
 | |
|                 selection-background-color: MaterialPalette.selection-background;
 | |
|                 horizontal-stretch: 1;
 | |
|             }
 | |
| 
 | |
|             if !root.text.is-empty && root.input-type != InputType.password && root.enabled && !root.read-only: LineEditClearIcon {
 | |
|                 width: self.source.width * 1px;
 | |
|                 text: base.text;
 | |
|                 source: @image-url("_clear.svg");
 | |
|                 colorize: base.text-color;
 | |
|                 clear => {
 | |
|                     base.text = "";
 | |
|                     base.focus();
 | |
|                 }
 | |
|             }
 | |
| 
 | |
|             if root.input-type == InputType.password: LineEditPasswordIcon {
 | |
|                 width: self.source.width * 1px;
 | |
|                 show-password-image: @image-url("_visibility.svg");
 | |
|                 hide-password-image: @image-url("_visibility_off.svg");
 | |
|                 colorize: base.text-color;
 | |
|                 show-password: base.input-type != InputType.password;
 | |
|                 show-password-changed(show) => {
 | |
|                     base.input-type = show ? InputType.text : root.input-type;
 | |
|                     base.focus();
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| }
 |