mirror of
				https://github.com/slint-ui/slint.git
				synced 2025-10-31 12:04:33 +00:00 
			
		
		
		
	 9eb14714d9
			
		
	
	
		9eb14714d9
		
	
	
	
		
			
	
		
	
	
		
			Some checks failed
		
		
	
	autofix.ci / format_fix (push) Has been cancelled
				
			autofix.ci / lint_typecheck (push) Has been cancelled
				
			CI / files-changed (push) Has been cancelled
				
			CI / python_test (windows-2022) (push) Has been cancelled
				
			CI / build_and_test (--exclude bevy-example, ubuntu-22.04, 1.85) (push) Has been cancelled
				
			CI / cpp_cmake (ubuntu-22.04, stable) (push) Has been cancelled
				
			CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, --exclude bevy-example, windows-2022, 1.85) (push) Has been cancelled
				
			CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, macos-14, stable) (push) Has been cancelled
				
			CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, beta) (push) Has been cancelled
				
			CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, stable) (push) Has been cancelled
				
			CI / build_and_test (ubuntu-22.04, nightly) (push) Has been cancelled
				
			CI / node_test (macos-14) (push) Has been cancelled
				
			CI / node_test (ubuntu-22.04) (push) Has been cancelled
				
			CI / node_test (windows-2022) (push) Has been cancelled
				
			CI / python_test (macos-14) (push) Has been cancelled
				
			CI / python_test (ubuntu-22.04) (push) Has been cancelled
				
			CI / cpp_test_driver (macos-13) (push) Has been cancelled
				
			CI / cpp_test_driver (ubuntu-22.04) (push) Has been cancelled
				
			CI / cpp_test_driver (windows-2022) (push) Has been cancelled
				
			CI / cpp_cmake (macos-14, 1.85) (push) Has been cancelled
				
			CI / cpp_cmake (windows-2022, nightly) (push) Has been cancelled
				
			CI / cpp_package_test (push) Has been cancelled
				
			CI / vsce_build_test (push) Has been cancelled
				
			CI / mcu (pico-st7789, thumbv6m-none-eabi) (push) Has been cancelled
				
			CI / mcu (pico2-st7789, thumbv8m.main-none-eabihf) (push) Has been cancelled
				
			CI / mcu (stm32h735g, thumbv7em-none-eabihf) (push) Has been cancelled
				
			CI / mcu-embassy (push) Has been cancelled
				
			CI / ffi_32bit_build (push) Has been cancelled
				
			CI / docs (push) Has been cancelled
				
			CI / wasm (push) Has been cancelled
				
			CI / wasm_demo (push) Has been cancelled
				
			CI / tree-sitter (push) Has been cancelled
				
			CI / updater_test (0.3.0) (push) Has been cancelled
				
			CI / fmt_test (push) Has been cancelled
				
			CI / esp-idf-quick (push) Has been cancelled
				
			CI / android (push) Has been cancelled
				
			CI / miri (push) Has been cancelled
				
			CI / test-figma-inspector (push) Has been cancelled
				
			Material icons from https://github.com/marella/material-design-icons/tree/main/svg/outlined also used for cupertino. Fluent icons from https://fluenticons.co/outlined/ Cosmic icons extracted from https://gitlab.gnome.org/GNOME/adwaita-icon-theme/-/blob/master/src/symbolic/core.svg because there's no such icon in https://github.com/pop-os/cosmic-icons/tree/master/freedesktop/scalable ChangeLog: LineEdits with "input-type: password" now feature an icon to toggle password visibility
		
			
				
	
	
		
			110 lines
		
	
	
	
		
			3.9 KiB
		
	
	
	
		
			Text
		
	
	
	
	
	
			
		
		
	
	
			110 lines
		
	
	
	
		
			3.9 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;
 | |
|             }
 | |
| 
 | |
|             LineEditClearIcon {
 | |
|                 text: base.text;
 | |
|                 input-type: root.input-type;
 | |
|                 source: @image-url("_clear.svg");
 | |
|                 colorize: base.text-color;
 | |
|                 clear => {
 | |
|                     base.text = "";
 | |
|                     base.focus();
 | |
|                 }
 | |
|             }
 | |
| 
 | |
|             if root.input-type == InputType.password: LineEditPasswordIcon {
 | |
|                 show-password-image: @image-url("_visibility.svg");
 | |
|                 hide-password-image: @image-url("_visibility_off.svg");
 | |
|                 colorize: base.text-color;
 | |
|                 show-password-changed(show) => {
 | |
|                     base.input-type = show ? InputType.text : root.input-type;
 | |
|                     base.focus();
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| }
 |