mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-28 18:52:16 +00:00
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
172 lines
5.6 KiB
Text
172 lines
5.6 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
|
|
|
|
export component LineEditBase inherits Rectangle {
|
|
in property <string> placeholder-text;
|
|
in property <length> font-size <=> text-input.font-size;
|
|
in-out property <string> text <=> text-input.text;
|
|
in-out property <brush> placeholder-color;
|
|
in property <bool> enabled <=> text-input.enabled;
|
|
out property <bool> has-focus: text-input.has-focus;
|
|
in property <InputType> input-type <=> text-input.input-type;
|
|
in property <TextHorizontalAlignment> horizontal-alignment <=> text-input.horizontal-alignment;
|
|
in property <bool> read-only <=> text-input.read-only;
|
|
in property <int> font-weight <=> text-input.font-weight;
|
|
in property <brush> text-color;
|
|
in property <color> selection-background-color <=> text-input.selection-background-color;
|
|
in property <color> selection-foreground-color <=> text-input.selection-foreground-color;
|
|
in property <length> margin;
|
|
|
|
callback accepted(text: string);
|
|
callback edited(text: string);
|
|
callback key-pressed(event: KeyEvent) -> EventResult;
|
|
callback key-released(event: KeyEvent) -> EventResult;
|
|
|
|
public function set-selection-offsets(start: int, end: int) {
|
|
text-input.set-selection-offsets(start, end);
|
|
}
|
|
|
|
public function select-all() {
|
|
text-input.select-all();
|
|
}
|
|
|
|
public function clear-selection() {
|
|
text-input.clear-selection();
|
|
}
|
|
|
|
public function cut() {
|
|
text-input.cut();
|
|
}
|
|
|
|
public function copy() {
|
|
text-input.copy();
|
|
}
|
|
|
|
public function paste() {
|
|
text-input.paste();
|
|
}
|
|
|
|
// on width < 1px or if the `TextInput` is clipped it cannot be focused therefore min-width 1px
|
|
min-width: 1px;
|
|
min-height: text-input.preferred-height;
|
|
clip: true;
|
|
forward-focus: text-input;
|
|
|
|
placeholder := Text {
|
|
width: 100%;
|
|
height: 100%;
|
|
vertical-alignment: center;
|
|
text: (root.text == "" && text-input.preedit-text == "") ? root.placeholder-text : "";
|
|
font-size: text-input.font-size;
|
|
font-italic: text-input.font-italic;
|
|
font-weight: text-input.font-weight;
|
|
font-family: text-input.font-family;
|
|
color: root.placeholder-color;
|
|
horizontal-alignment: root.horizontal-alignment;
|
|
// `accessible-placeholder-text` is set on LineEdit already
|
|
accessible-role: none;
|
|
}
|
|
|
|
ContextMenuArea {
|
|
enabled: root.enabled;
|
|
Menu {
|
|
MenuItem {
|
|
title: @tr("Cut");
|
|
enabled: !root.read-only && root.enabled;
|
|
activated => {
|
|
text-input.cut();
|
|
}
|
|
}
|
|
|
|
MenuItem {
|
|
title: @tr("Copy");
|
|
enabled: !root.text.is-empty;
|
|
activated => {
|
|
text-input.copy();
|
|
}
|
|
}
|
|
|
|
MenuItem {
|
|
title: @tr("Paste");
|
|
enabled: !root.read-only && root.enabled;
|
|
activated => {
|
|
text-input.paste();
|
|
}
|
|
}
|
|
|
|
MenuItem {
|
|
title: @tr("Select All");
|
|
enabled: !root.text.is-empty;
|
|
activated => {
|
|
text-input.select-all();
|
|
}
|
|
}
|
|
}
|
|
|
|
text-input := TextInput {
|
|
property <length> computed-x;
|
|
|
|
x: min(0px, max(parent.width - self.width - self.text-cursor-width, self.computed-x));
|
|
width: max(parent.width - self.text-cursor-width, self.preferred-width);
|
|
height: 100%;
|
|
vertical-alignment: center;
|
|
single-line: true;
|
|
color: root.text-color;
|
|
// Disable TextInput's built-in accessibility support as the widget takes care of that.
|
|
accessible-role: none;
|
|
|
|
cursor-position-changed(cursor-position) => {
|
|
if cursor-position.x + self.computed_x < root.margin {
|
|
self.computed_x = - cursor-position.x + root.margin;
|
|
} else if cursor-position.x + self.computed_x > parent.width - root.margin - self.text-cursor-width {
|
|
self.computed_x = parent.width - cursor-position.x - root.margin - self.text-cursor-width;
|
|
}
|
|
}
|
|
|
|
accepted => {
|
|
root.accepted(self.text);
|
|
}
|
|
|
|
edited => {
|
|
root.edited(self.text);
|
|
}
|
|
|
|
key-pressed(event) => {
|
|
root.key-pressed(event)
|
|
}
|
|
|
|
key-released(event) => {
|
|
root.key-released(event)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
export component LineEditClearIcon inherits Image {
|
|
in-out property <string> text;
|
|
in-out property <InputType> input-type;
|
|
callback clear();
|
|
|
|
vertical-alignment: center;
|
|
visible: !text.is-empty && input-type != InputType.password;
|
|
TouchArea {
|
|
clicked => { root.clear(); }
|
|
}
|
|
}
|
|
|
|
export component LineEditPasswordIcon inherits Image {
|
|
callback show-password-changed(bool);
|
|
in property <bool> show-password;
|
|
in property <image> show-password-image;
|
|
in property <image> hide-password-image;
|
|
private property <bool> internal-show-password : show-password;
|
|
|
|
source: internal-show-password ? hide-password-image : show-password-image;
|
|
vertical-alignment: center;
|
|
TouchArea {
|
|
clicked => {
|
|
internal-show-password = !internal-show-password;
|
|
root.show-password-changed(internal-show-password);
|
|
}
|
|
}
|
|
}
|