Fluid 1.3.0
Material Design for QtQuick and Qml
Loading...
Searching...
No Matches
AutomaticGrid.qml
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2018 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
2// SPDX-FileCopyrightText: 2018 Michael Spencer <sonrisesoftware@gmail.com>
3// SPDX-License-Identifier: MPL-2.0
4
5import QtQuick
6
41Grid {
42 id: grid
43 Accessible.ignored: true
44
50 default property alias delegate: repeater.delegate
51
55 property real cellWidth
56
60 property real cellHeight
61
69 property alias model: repeater.model
70
74 property real widthOverride: parent.width
75
79 property real heightOverride: parent.height
80
84 property real minColumnSpacing
85
86 columns: {
87 var flooredResult = Math.floor(widthOverride / cellWidth);
88 if (flooredResult >= 1 && flooredResult <= repeater.count)
89 if ((widthOverride - (flooredResult * cellWidth)) / (flooredResult + 1) < minColumnSpacing)
90 return flooredResult - 1;
91 else
92 return flooredResult;
93 else if (flooredResult > repeater.count)
94 return repeater.count;
95 else
96 return 1;
97 }
98
99 columnSpacing: (widthOverride - (columns * cellWidth)) / (columns + 1) < (minColumnSpacing / 2) ? (minColumnSpacing / 2) : (widthOverride - (columns * cellWidth)) / (columns + 1)
100 width: widthOverride - 2 * columnSpacing
101
102 Repeater {
103 id: repeater
104 }
105}