45 lines
1.3 KiB
QML
45 lines
1.3 KiB
QML
import QtQuick
|
|
import "."
|
|
|
|
// Rectangular tray + square thumb toggle, per DESIGN.md: 36x20 tray, 12x12
|
|
// thumb that translates (never curves) between two hard-stop positions.
|
|
Item {
|
|
id: toggle
|
|
|
|
// Controlled component: clicking never mutates `checked` itself, it
|
|
// only requests a change via `toggled()` - the caller owns the real
|
|
// state (usually a live system property) and rebinds `checked` to it.
|
|
property bool checked: false
|
|
property color onColor: Theme.colors.success
|
|
signal toggled()
|
|
|
|
implicitWidth: 36
|
|
implicitHeight: 20
|
|
|
|
Rectangle {
|
|
anchors.fill: parent
|
|
color: toggle.checked ? toggle.onColor : Theme.colors.surface
|
|
border.width: Theme.geometry.borderWidth
|
|
border.color: Theme.colors.crust
|
|
|
|
Behavior on color { ColorAnimation { duration: Theme.animation.durationFast } }
|
|
|
|
Rectangle {
|
|
id: thumb
|
|
width: 12
|
|
height: 12
|
|
y: (parent.height - height) / 2
|
|
x: toggle.checked ? parent.width - width - 4 : 4
|
|
color: Theme.colors.crust
|
|
|
|
Behavior on x { NumberAnimation { duration: Theme.animation.durationFast; easing.type: Easing.Linear } }
|
|
}
|
|
}
|
|
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
cursorShape: Qt.PointingHandCursor
|
|
onClicked: toggle.toggled()
|
|
}
|
|
}
|