Skip to content

Commit

Permalink
Fix binding loop
Browse files Browse the repository at this point in the history
  • Loading branch information
fieldOfView committed Mar 25, 2022
1 parent 1fb00e1 commit 6a2aab7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
9 changes: 6 additions & 3 deletions UM/Qt/qml/UM/Menu.qml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ Menu
}

// Automatically set the width to fit the widest MenuItem
// https://martin.rpdev.net/2018/03/13/qt-quick-controls-2-automatically-set-the-width-of-menus.html
// Based on https://martin.rpdev.net/2018/03/13/qt-quick-controls-2-automatically-set-the-width-of-menus.html
width:
{
var result = 0;
var padding = 0;
for (var i = 0; i < count; ++i) {
var item = itemAt(i);
result = Math.max(item.contentItem.implicitWidth, result);
padding = Math.max(item.padding, padding);
if (item.hasOwnProperty("contentWidth"))
{
result = Math.max(item.contentWidth, result);
padding = Math.max(item.padding, padding);
}
}
return result + padding * 2;
}
Expand Down
18 changes: 14 additions & 4 deletions UM/Qt/qml/UM/MenuItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ MenuItem
property alias shortcut: _shortcut.sequence
property bool indicatorVisible: root.icon.source.length > 0 || root.checkable
height: visible ? UM.Theme.getSize("context_menu").height : 0
property int contentWidth:
{
// This is the width of all the items in the contentItem except the filler
return leftSpacer.width + label.width + middleSpacer.width + shortcutLabel.width + rightSpacer.width
}

Shortcut
{
id: _shortcut
Expand Down Expand Up @@ -55,14 +61,15 @@ MenuItem

Item
{
// Spacer
// Left side margin
id: leftSpacer
width: root.indicatorVisible ? root.indicator.width + UM.Theme.getSize("default_margin").width : UM.Theme.getSize("default_margin").width
}

UM.Label
{
id: label
text: replaceText(root.text)
Layout.fillWidth: true
Layout.fillHeight:true
elide: Label.ElideRight
wrapMode: Text.NoWrap
Expand All @@ -75,13 +82,15 @@ MenuItem

Item
{
// Right side margin
width: UM.Theme.getSize("default_margin").width
// Middle margin
id: middleSpacer
width: visible ? UM.Theme.getSize("default_margin").width : 0
visible: _shortcut.nativeText != "" || root.subMenu
}

UM.Label
{
id: shortcutLabel
Layout.fillHeight: true
text: _shortcut.nativeText
color: UM.Theme.getColor("text_lighter")
Expand All @@ -90,6 +99,7 @@ MenuItem
Item
{
// Right side margin
id: rightSpacer
width: UM.Theme.getSize("default_margin").width
}
}
Expand Down

0 comments on commit 6a2aab7

Please sign in to comment.