Allow open file button to resize depending on content items

This re-links the widths, heights and paddings such that we can later change the width of the button depending on its contents.
However there is a complication: Buttons automatically change the size of the contents based on the size of the button minus its padding. So making the size of the button in turn depend on its contents causes a binding loop.
To get around this binding loop, we need to manually calculate the size of the button, such that the size of the contents ends up exactly right.

Contributes to issue CURA-8008.
This commit is contained in:
Ghostkeeper 2021-07-08 16:24:23 +02:00
parent 920e220bdb
commit ffa89bb1a1
No known key found for this signature in database
GPG key ID: D2A8871EE34EC59A

View file

@ -77,14 +77,25 @@ Item
Button Button
{ {
id: openFileButton id: openFileButton
//Make the button square if the contents are.
leftPadding: topPadding
rightPadding: topPadding
bottomPadding: topPadding
height: UM.Theme.getSize("stage_menu").height height: UM.Theme.getSize("stage_menu").height
width: UM.Theme.getSize("stage_menu").height width: openFileIconContainer.width + leftPadding + rightPadding
onClicked: Cura.Actions.open.trigger() onClicked: Cura.Actions.open.trigger()
hoverEnabled: true hoverEnabled: true
contentItem: Item contentItem: Row
{ {
anchors.fill: parent Item
{
id: openFileIconContainer
height: parent.height
width: height //Square button.
UM.RecolorImage UM.RecolorImage
{ {
id: buttonIcon id: buttonIcon
@ -97,6 +108,7 @@ Item
sourceSize.height: height sourceSize.height: height
} }
} }
}
background: Rectangle background: Rectangle
{ {