qml: resize menus according to content
This commit is contained in:
@@ -139,7 +139,8 @@ Item {
|
|||||||
color: "#44000000"
|
color: "#44000000"
|
||||||
}
|
}
|
||||||
|
|
||||||
width: parent.width / 2
|
property int implicitChildrenWidth: 64
|
||||||
|
width: implicitChildrenWidth + 60 + constants.paddingLarge
|
||||||
|
|
||||||
MenuItem {
|
MenuItem {
|
||||||
icon.color: action.enabled ? 'transparent' : Material.iconDisabledColor
|
icon.color: action.enabled ? 'transparent' : Material.iconDisabledColor
|
||||||
@@ -204,6 +205,25 @@ Item {
|
|||||||
function deselect() {
|
function deselect() {
|
||||||
currentIndex = -1
|
currentIndex = -1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// determine widest element and store in implicitChildrenWidth
|
||||||
|
function updateImplicitWidth() {
|
||||||
|
for (let i = 0; i < menu.count; i++) {
|
||||||
|
var item = menu.itemAt(i)
|
||||||
|
var txt = item.text
|
||||||
|
var txtwidth = fontMetrics.advanceWidth(txt)
|
||||||
|
if (txtwidth > menu.implicitChildrenWidth) {
|
||||||
|
menu.implicitChildrenWidth = txtwidth
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FontMetrics {
|
||||||
|
id: fontMetrics
|
||||||
|
font: menu.font
|
||||||
|
}
|
||||||
|
|
||||||
|
Component.onCompleted: updateImplicitWidth()
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ ApplicationWindow
|
|||||||
property var _exceptionDialog
|
property var _exceptionDialog
|
||||||
|
|
||||||
property QtObject appMenu: Menu {
|
property QtObject appMenu: Menu {
|
||||||
|
id: menu
|
||||||
|
|
||||||
parent: Overlay.overlay
|
parent: Overlay.overlay
|
||||||
dim: true
|
dim: true
|
||||||
modal: true
|
modal: true
|
||||||
@@ -46,7 +48,8 @@ ApplicationWindow
|
|||||||
color: "#44000000"
|
color: "#44000000"
|
||||||
}
|
}
|
||||||
|
|
||||||
id: menu
|
property int implicitChildrenWidth: 64
|
||||||
|
width: implicitChildrenWidth + 60 + constants.paddingLarge
|
||||||
|
|
||||||
MenuItem {
|
MenuItem {
|
||||||
icon.color: action.enabled ? 'transparent' : Material.iconDisabledColor
|
icon.color: action.enabled ? 'transparent' : Material.iconDisabledColor
|
||||||
@@ -82,6 +85,25 @@ ApplicationWindow
|
|||||||
stack.pushOnRoot(url)
|
stack.pushOnRoot(url)
|
||||||
currentIndex = -1
|
currentIndex = -1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// determine widest element and store in implicitChildrenWidth
|
||||||
|
function updateImplicitWidth() {
|
||||||
|
for (let i = 0; i < menu.count; i++) {
|
||||||
|
var item = menu.itemAt(i)
|
||||||
|
var txt = item.text
|
||||||
|
var txtwidth = fontMetrics.advanceWidth(txt)
|
||||||
|
if (txtwidth > menu.implicitChildrenWidth) {
|
||||||
|
menu.implicitChildrenWidth = txtwidth
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FontMetrics {
|
||||||
|
id: fontMetrics
|
||||||
|
font: menu.font
|
||||||
|
}
|
||||||
|
|
||||||
|
Component.onCompleted: updateImplicitWidth()
|
||||||
}
|
}
|
||||||
|
|
||||||
function openAppMenu() {
|
function openAppMenu() {
|
||||||
|
|||||||
Reference in New Issue
Block a user