-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
250 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import QtQuick | ||
import QtQuick.Layouts | ||
|
||
Item { | ||
id: root | ||
|
||
readonly property int columns: 2 | ||
readonly property int rows: 2 | ||
property int spacing: 2 | ||
property int count: 4 | ||
|
||
required property Component delegate | ||
|
||
onCountChanged: updateCount(); | ||
onChildrenChanged: updateLayout(); | ||
onWidthChanged: updateLayout() | ||
onHeightChanged: updateLayout() | ||
onSpacingChanged: updateLayout() | ||
Component.onCompleted: updateCount(); | ||
|
||
function updateCount() { | ||
if(root.delegate === null) { | ||
return; | ||
} | ||
|
||
for(let i = 0; i < root.children.length; i++) { | ||
root.children[i].destroy(); | ||
} | ||
|
||
for(let i = 0; i < root.count; i++) { | ||
root.delegate.createObject(root); | ||
} | ||
} | ||
|
||
function updateLayout() { | ||
for(let i = 0; i < root.children.length; i++) { | ||
let cell = calcCell(i); | ||
let item = root.children[i]; | ||
item.x = cell.x; | ||
item.y = cell.y; | ||
item.width = cell.width; | ||
item.height = cell.height; | ||
} | ||
} | ||
|
||
function calcCell(index) { | ||
const maxColumns = root.columns; | ||
const maxRows = Math.ceil(Math.max(root.rows, root.count / root.columns)); | ||
|
||
let column = index % maxColumns; | ||
let row = root.count > 2 ? Math.floor(index / maxColumns) : index; | ||
|
||
// For 1 count, consume the whole size of the containing item. | ||
let cellX = 0; | ||
let cellY = 0; | ||
let cellWidth = root.width; | ||
let cellHeight = root.height; | ||
|
||
if(root.count >= 2) { | ||
// All items' heights will be relative to the number of rows in the grid. | ||
cellHeight = (cellHeight - (root.spacing * (maxRows - 1))) / maxRows; | ||
cellY = row * (cellHeight + root.spacing); | ||
|
||
// Only change the width from the maximum width if we aren't the last item of an uneven count. | ||
// Otherwise, the last item will remain the maximum width of the grid. | ||
if(root.count > 2 && (root.count % 2 === 0 || index !== root.count - 1)) { | ||
cellWidth = (cellWidth - (root.spacing * maxColumns - 1)) / maxColumns; | ||
cellX = column * (cellWidth + (root.spacing * maxColumns - 1)); | ||
} | ||
} | ||
|
||
return { x: cellX, y: cellY, width: cellWidth, height: cellHeight }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import QtQuick | ||
import QtQuick.Window | ||
|
||
Item { | ||
id: root | ||
|
||
readonly property string statePressed: "pressed" | ||
readonly property string stateReleased: "released" | ||
readonly property real layoutFactor: 0.8 | ||
readonly property real aspectRatio: Qt.platform.os == "android" ? Screen.width / Screen.height : Screen.height / Screen.width | ||
property color background: "white" | ||
property color foreground: "black" | ||
required property ListModel model | ||
|
||
state: root.stateReleased | ||
|
||
onStateChanged: { | ||
if(root.state === root.statePressed) { | ||
layout.count = 0; | ||
} | ||
} | ||
|
||
Component { | ||
id: componentRect | ||
Rectangle { | ||
color: "transparent" | ||
radius: 3 | ||
border.color: root.foreground | ||
border.width: 2 | ||
} | ||
} | ||
|
||
LayoutEDH { | ||
id: layout | ||
|
||
anchors.centerIn: parent | ||
width: root.width * root.layoutFactor * root.aspectRatio | ||
height: root.height * root.layoutFactor | ||
spacing: 1 | ||
delegate: componentRect | ||
} | ||
|
||
TapHandler { | ||
gesturePolicy: TapHandler.WithinBounds | ||
|
||
onTapped: { | ||
root.state = root.state === root.statePressed ? root.stateReleased : root.statePressed; | ||
} | ||
} | ||
|
||
PathView { | ||
id: path | ||
|
||
anchors.centerIn: parent | ||
|
||
property real radius: 0 | ||
|
||
onRadiusChanged: { | ||
if(radius === 0) { | ||
if(root.state === root.stateReleased) { | ||
layout.count = root.model.count; | ||
} | ||
} | ||
} | ||
|
||
state: root.state | ||
|
||
states: [ | ||
State { | ||
name: root.statePressed | ||
|
||
PropertyChanges { | ||
target: path | ||
radius: 80 | ||
} | ||
} | ||
] | ||
|
||
transitions: Transition { | ||
NumberAnimation { | ||
property: "radius" | ||
duration: 350 | ||
} | ||
} | ||
|
||
model: [1, 2, 3, 4, 5, 6] | ||
|
||
delegate: Rectangle { | ||
id: rect | ||
width: root.width | ||
height: width | ||
radius: width / 2 | ||
color: root.background | ||
visible: path.radius > 0 | ||
|
||
required property int index | ||
required property int modelData | ||
|
||
onVisibleChanged: { | ||
if(visible === true) { | ||
rect.z = rect.modelData === root.model.count ? 1 : 0; | ||
} | ||
} | ||
|
||
Connections { | ||
target: root.model | ||
|
||
function onCountChanged() { | ||
rect.z = 0; | ||
} | ||
} | ||
|
||
LayoutEDH { | ||
anchors.centerIn: parent | ||
width: layout.width | ||
height: layout.height | ||
count: modelData | ||
spacing: 1 | ||
delegate: componentRect | ||
} | ||
|
||
TapHandler { | ||
gesturePolicy: TapHandler.WithinBounds | ||
|
||
onTapped: { | ||
Actions.setPlayerTotal(rect.modelData); | ||
root.state = root.stateReleased; | ||
rect.z = 1; | ||
} | ||
} | ||
} | ||
|
||
path: Path { | ||
PathAngleArc { | ||
id: radial | ||
|
||
radiusX: path.radius | ||
radiusY: path.radius | ||
startAngle: -90 | ||
sweepAngle: 360 | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters