Files
launcher/legacy/qt/qml/SearchField.qml
T
SpriteandClaude Sonnet 5.5 66e8e90da1 Move the existing launcher into legacy/
git mv of everything (web/ android/ qt/ wasi/ android-wasm/ tests/ ci/ pixi.toml
README) so history follows; legacy/ keeps its own .gitignore and a new root
.gitignore starts for the MoonBit project.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-23 00:55:15 +00:00

90 lines
3.0 KiB
QML

import QtQuick
// A rounded search box. Enter is "accepted"; the text is "text", and "shown" is what
// the box shows, including a word the keyboard is still composing (Android keyboards
// keep it out of "text" until it is committed).
Rectangle {
id: root
property alias text: input.text
property alias placeholder: hint.text
property alias input: input
readonly property string shown: input.displayText
property real fontSize: 16
signal accepted()
signal escaped()
implicitHeight: 44
radius: height / 2
color: Qt.rgba(1, 1, 1, .1)
border.color: Qt.rgba(1, 1, 1, .15)
border.width: 1
function focusNow() { input.forceActiveFocus(); Qt.inputMethod.show() }
// Empty the box, including a word still being composed, and keep typing in it.
// Android commits a composing word asynchronously, so it can land after the clear:
// clear again once it has.
function clearText() {
Qt.inputMethod.commit();
input.clear();
input.forceActiveFocus();
clearAgain.restart();
}
Timer { id: clearAgain; interval: 120; onTriggered: input.clear() }
TextInput {
id: input
anchors.left: parent.left
anchors.right: clear.left
anchors.leftMargin: 20
anchors.rightMargin: 0
anchors.verticalCenter: parent.verticalCenter
color: "white"
selectionColor: Qt.rgba(1, 1, 1, .35)
font.pixelSize: root.fontSize
clip: true
// No suggestions: Android keyboards then type straight into the box rather than
// composing words, so the list filters on every key.
inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhSensitiveData | Qt.ImhNoAutoUppercase
onAccepted: root.accepted()
Keys.onEscapePressed: root.escaped()
Text {
id: hint
anchors.fill: parent
verticalAlignment: Text.AlignVCenter
color: Qt.rgba(1, 1, 1, .6)
font.pixelSize: root.fontSize
visible: input.displayText.length === 0
}
}
// The clear button: a finger-sized target at the right end of the box.
Item {
id: clear
objectName: "searchClear"
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
width: visible ? 44 : 0
visible: input.displayText.length > 0
z: 1
// Drawn, not a glyph: phone fonts may have no ✕.
Repeater {
model: [45, -45]
Rectangle {
required property var modelData
anchors.centerIn: parent
width: 14
height: 2
radius: 1
rotation: modelData
antialiasing: true
color: Qt.rgba(1, 1, 1, .7)
}
}
MouseArea {
anchors.fill: parent
preventStealing: true
onPressed: (m) => m.accepted = true
onClicked: { root.clearText(); root.escaped() }
}
}
}