add new snippet 'snippets/toast' (like android 'Toast')

This commit is contained in:
pls.153 2023-03-15 08:34:54 +01:00
parent 61831ba362
commit a58948b9d0
6 changed files with 99 additions and 20 deletions

View file

@ -1,19 +0,0 @@
(in-package :qml-user)
(defun request ()
"Runs request in a thread, returns after thread finished."
(q> |playing| "busy" t) ; start animation
(let (response)
;; worker thread
(mp:process-run-function
:request
(lambda ()
(sleep 3) ; working hard...
(setf response :ok)
(qexit)))
;; main thread
(qexec (* 60 1000)) ; timeout (ms)
(q> |playing| "busy" nil) ; stop animation
response))
(qsingle-shot 1000 'request)

View file

@ -1 +1,19 @@
(load "lisp/main.lisp") (in-package :qml-user)
(defun request ()
"Runs request in a thread, returns after thread finished."
(q> |playing| "busy" t) ; start animation
(let (response)
;; worker thread
(mp:process-run-function
:request
(lambda ()
(sleep 3) ; working hard...
(setf response :ok)
(qexit)))
;; main thread
(qexec (* 60 1000)) ; timeout (ms)
(q> |playing| "busy" nil) ; stop animation
response))
(qsingle-shot 1000 'request)

View file

@ -0,0 +1,60 @@
import QtQuick 2.15
Rectangle {
id: toast
objectName: "toast"
x: (parent.width - width) / 2
y: (parent.height - height) / 2
z: 99
width: msg.contentWidth + 70
height: msg.contentHeight + 30
color: "#303030"
border.width: 2
border.color: "white"
radius: height / 2
opacity: 0
visible: false
function message(text) { // called from Lisp
toast.visible = true
msg.text = text
anim.start()
}
Text {
id: msg
font.pixelSize: 16
font.bold: true
anchors.centerIn: parent
color: "white"
wrapMode: Text.WordWrap
width: toast.parent.width - 2 * toast.radius - 10
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
SequentialAnimation {
id: anim
onFinished: { toast.visible = false }
OpacityAnimator {
from: 0
to: 0.8
target: toast
easing.type: Easing.InOutQuart
duration: 500
}
PauseAnimation {
duration: 3000
}
OpacityAnimator {
from: 0.8
to: 0
target: toast
easing.type: Easing.InOutQuart
duration: 1500
}
}
}

View file

@ -0,0 +1,9 @@
import QtQuick 2.15
import 'ext/' as Ext
Rectangle {
width: 300
height: 500
Ext.Toast {}
}

4
snippets/toast/readme.md Normal file
View file

@ -0,0 +1,4 @@
Description
-----------
An info message similar to a `Toast` on android.

7
snippets/toast/run.lisp Normal file
View file

@ -0,0 +1,7 @@
(in-package :qml-user)
(defun toast (message)
(qjs |message| "toast" message))
(qsingle-shot 1000 (lambda () (toast "You look tired, go get some coffee.")))