Skip to content

Commit

Permalink
[Controls] Prevent the filter text field from being out of the window
Browse files Browse the repository at this point in the history
The filter text field is now always placed at the position of the
attribute, meaning it is always in sight. The list of values is
then either dropped downwards or opened upwards depending on its
size and where there is the most free space.
  • Loading branch information
cbentejac committed Aug 19, 2024
1 parent 5367948 commit d83e908
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions meshroom/ui/qml/Controls/FilterComboBox.qml
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,33 @@ ComboBox {

popup: Popup {
width: combo.width
implicitHeight: contentItem.implicitHeight
implicitHeight: contentItem.implicitHeight

x: 0
y: 0

onAboutToShow: {
filterTextArea.forceActiveFocus()

if (mapToGlobal(popup.x, popup.y).y + root.implicitHeight * (model.length + 1) > _window.contentItem.height) {
y = -((combo.height * (combo.model.length + 1) > _window.contentItem.height) ? _window.contentItem.height*2/3 : combo.height * (combo.model.length + 1))
var dropDown = true
var posY = mapToGlobal(popup.x, popup.y).y

/* If the list will go out of the screen by dropping down AND if there is more space up than down,
* then open it upwards.
* Having both conditions allows to naturally drop down short lists that are visually located close
* to the lower border of the window, while opening upwards long lists that are in that same location
* AND opening these same lists downwards if they are located closer to the upper border.
*/
if (posY + listView.implicitHeight > _window.contentItem.height && posY > _window.contentItem.height / 2) {
dropDown = false
}

if (dropDown) {
listView.anchors.bottom = undefined
listView.anchors.top = filterTextArea.bottom
} else {
y = 0
listView.anchors.bottom = filterTextArea.top
listView.anchors.top = undefined
}
}

Expand Down Expand Up @@ -141,9 +159,14 @@ ComboBox {
clip: true
anchors.left: parent.left
anchors.right: parent.right
anchors.top: filterTextArea.bottom

implicitHeight: (combo.height * (combo.model.length + 1) > _window.contentItem.height) ? _window.contentItem.height*2/3 : contentHeight
implicitHeight: {
if (combo.height * (combo.model.length + 1) > _window.contentItem.height) {
return _window.contentItem.height * 2 / 3
} else {
return contentHeight
}
}
model: combo.popup.visible ? combo.delegateModel : null

ScrollBar.vertical: ScrollBar {
Expand Down

0 comments on commit d83e908

Please sign in to comment.