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 { HGridLayout {
id: buttonGrid id: buttonGrid
visible: buttonModel.length > 0 visible: buttonModel.length > 0
flow: width >= buttonRepeater.childrenImplicitWidth ? flow: width >= buttonRepeater.summedImplicitWidth ?
GridLayout.LeftToRight : GridLayout.TopToBottom GridLayout.LeftToRight : GridLayout.TopToBottom
HRepeater { HRepeater {

View File

@ -7,25 +7,34 @@ import QtQuick 2.12
Repeater { Repeater {
id: repeater id: repeater
readonly property int childrenImplicitWidth: {
let total = 0
for (let i = 0; i < repeater.count; i++) { readonly property var childrenImplicitWidth: {
let item = repeater.itemAt(i) const widths = []
if (item && item.implicitWidth) total += item.implicitWidth
for (let i = 0; i < repeater.count; i++) {
const item = repeater.itemAt(i)
if (item)
widths.push(item.implicitWidth > 0 ? item.implicitWidth : 0)
} }
return total return widths
} }
readonly property int childrenWidth: { readonly property var childrenWidth: {
let total = 0 const widths = []
for (let i = 0; i < repeater.count; i++) { for (let i = 0; i < repeater.count; i++) {
let item = repeater.itemAt(i) const item = repeater.itemAt(i)
if (item && item.width) total += item.width 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" saveName: "roomPane"
edge: Qt.RightEdge edge: Qt.RightEdge
defaultSize: buttonRepeater.childrenImplicitWidth defaultSize: buttonRepeater.summedImplicitWidth
minimumSize: minimumSize:
buttonRepeater.count > 0 ? buttonRepeater.itemAt(0).implicitWidth : 0 buttonRepeater.count > 0 ? buttonRepeater.itemAt(0).implicitWidth : 0

View File

@ -143,7 +143,7 @@ HRowLayout {
parent.paintedWidth + parent.paintedWidth +
parent.leftPadding + parent.rightPadding, parent.leftPadding + parent.rightPadding,
linksRepeater.childrenWidth + linksRepeater.summedWidth +
(pureMedia ? 0 : parent.leftPadding + parent.rightPadding), (pureMedia ? 0 : parent.leftPadding + parent.rightPadding),
) )
height: contentColumn.height 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) { function isEmptyObject(obj) {
return Object.entries(obj).length === 0 && obj.constructor === Object return Object.entries(obj).length === 0 && obj.constructor === Object
} }