The third nested popup will now always try to stay withen the vertical space of the root materials popup.

See CURA-9522 for diagrams and more information.

CURA-9522
This commit is contained in:
Joey de l'Arago 2022-12-08 16:18:58 +01:00
parent 4e8e5c2bf0
commit 4f4d2431fa
2 changed files with 24 additions and 5 deletions

View File

@ -16,6 +16,7 @@ Cura.MenuItem
id: materialBrandMenu id: materialBrandMenu
overrideShowArrow: true overrideShowArrow: true
property var rootHeight
property var materialTypesModel property var materialTypesModel
text: materialTypesModel.name text: materialTypesModel.name
@ -36,6 +37,7 @@ Cura.MenuItem
UM.Label UM.Label
{ {
id: brandLableText
text: replaceText(materialBrandMenu.text) text: replaceText(materialBrandMenu.text)
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight:true Layout.fillHeight:true
@ -248,6 +250,8 @@ Cura.MenuItem
height: materialColorsList.height + padding * 2 height: materialColorsList.height + padding * 2
x: parent.width x: parent.width
y: { y: {
// This popup will always try to stay within the vertical space of the parent of MaterialBrandMenu
// If it is larger than the parent, it will expand downwards.
var popupHeight = model.colors.count * UM.Theme.getSize("menu").height var popupHeight = model.colors.count * UM.Theme.getSize("menu").height
var spaceToBottom = materialTypesList.height - parent.y // Space from hovered item to bottom of list var spaceToBottom = materialTypesList.height - parent.y // Space from hovered item to bottom of list
@ -257,11 +261,25 @@ Cura.MenuItem
} }
else else
{ {
// The popup is longer than the distance between the hovered item and the bottom of the item list. var yAlignedWithTopOfRootPopup = - materialBrandMenu.y - UM.Theme.getSize("default_lining").height
// This pushes the popup upwards until the bottom lines up with the parent bottom.
// Only when popup is longer than the parent, the popup will flow out below the parent. if (popupHeight > rootHeight && popupHeight > menuPopup.height)
var topOfParent = parent.y + UM.Theme.getSize("default_lining").height {
return -Math.min(parent.y - (materialTypesList.height - popupHeight - UM.Theme.getSize("default_lining").height), topOfParent) // The popup is taller than the root material popup and the popup is taller than it's parent popup
// This means it should align with the top of the root popup
if (menuPopup.height < rootHeight)
{
//The root is larger than than the parent popup. Align with root top
return -materialBrandMenu.y - UM.Theme.getSize("default_lining").height
}
else
{
// The parent popup is larger than the root we only have to align to the top of the parent
return -brandMaterialBase.y - UM.Theme.getSize("default_lining").height
}
}
// The bottom of the popup is aligned with the bottom of the parent popup
return materialTypesList.height - parent.y - popupHeight - UM.Theme.getSize("default_lining").height
} }
} }

View File

@ -101,6 +101,7 @@ Cura.Menu
delegate: Cura.MaterialBrandMenu delegate: Cura.MaterialBrandMenu
{ {
materialTypesModel: model materialTypesModel: model
rootHeight: materialMenu.height
} }
onObjectAdded: function(index, object) { materialMenu.insertItem(index + 4, object)} onObjectAdded: function(index, object) { materialMenu.insertItem(index + 4, object)}
onObjectRemoved: function(index, object) { materialMenu.removeItem(index) } onObjectRemoved: function(index, object) { materialMenu.removeItem(index) }