Improve HRepeater width properties

This commit is contained in:
miruka 2019-12-19 15:56:07 -04:00
parent 2229b41af1
commit be0541f2d9
5 changed files with 30 additions and 15 deletions

View File

@ -59,7 +59,7 @@ Rectangle {
HGridLayout {
id: buttonGrid
visible: buttonModel.length > 0
flow: width >= buttonRepeater.childrenImplicitWidth ?
flow: width >= buttonRepeater.summedImplicitWidth ?
GridLayout.LeftToRight : GridLayout.TopToBottom
HRepeater {

View File

@ -7,25 +7,34 @@ import QtQuick 2.12
Repeater {
id: repeater
readonly property int childrenImplicitWidth: {
let total = 0
readonly property var childrenImplicitWidth: {
const widths = []
for (let i = 0; i < repeater.count; i++) {
let item = repeater.itemAt(i)
if (item && item.implicitWidth) total += item.implicitWidth
const item = repeater.itemAt(i)
if (item)
widths.push(item.implicitWidth > 0 ? item.implicitWidth : 0)
}
return total
return widths
}
readonly property int childrenWidth: {
let total = 0
readonly property var childrenWidth: {
const widths = []
for (let i = 0; i < repeater.count; i++) {
let item = repeater.itemAt(i)
if (item && item.width) total += item.width
const item = repeater.itemAt(i)
if (item) widths.push(item.width > 0 ? item.width : 0)
}
return total
return widths
}
readonly property real summedWidth: utils.sum(childrenWidth)
readonly property real summedImplicitWidth:utils.sum(childrenImplicitWidth)
readonly property real thinestChild: Math.min(...childrenWidth)
readonly property real widestChild: Math.max(...childrenWidth)
}

View File

@ -10,7 +10,7 @@ HDrawer {
saveName: "roomPane"
edge: Qt.RightEdge
defaultSize: buttonRepeater.childrenImplicitWidth
defaultSize: buttonRepeater.summedImplicitWidth
minimumSize:
buttonRepeater.count > 0 ? buttonRepeater.itemAt(0).implicitWidth : 0

View File

@ -143,7 +143,7 @@ HRowLayout {
parent.paintedWidth +
parent.leftPadding + parent.rightPadding,
linksRepeater.childrenWidth +
linksRepeater.summedWidth +
(pureMedia ? 0 : parent.leftPadding + parent.rightPadding),
)
height: contentColumn.height

View File

@ -57,6 +57,12 @@ QtObject {
}
function sum(array) {
if (array.length < 1) return 0
return array.reduce((a, b) => (isNaN(a) ? 0 : a) + (isNaN(b) ? 0 : b))
}
function isEmptyObject(obj) {
return Object.entries(obj).length === 0 && obj.constructor === Object
}