mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-11-27 00:05:11 +00:00
NavigableToolButton bound its icon size to its background. Material's ToolButton background is half the button height while the content is square, but spans the full button width otherwise. When the window straddles a 2x and a 1x display, the header row briefly lays out at a smaller height, the content stops being square, and the icon width becomes the button width. The button's implicit width is then icon + padding, so every layout pass widens it by 12px without end and reloads the SVG icon at each new size. The UI hangs and memory grows until the process is killed. Size the icon from the button's own height instead. That height comes from Layout.preferredHeight, not from the icon, so there's no feedback loop, and the icon stays 30x30 in the 60px toolbar as before. Fixes #2092
38 lines
1.0 KiB
QML
38 lines
1.0 KiB
QML
import QtQuick 2.0
|
|
import QtQuick.Controls 2.2
|
|
import QtQuick.Layouts 1.3
|
|
|
|
ToolButton {
|
|
property string iconSource
|
|
|
|
activeFocusOnTab: true
|
|
|
|
icon.source: iconSource
|
|
// Size the icon from the button's height rather than its background.
|
|
// Material's background spans the full button width when the content
|
|
// isn't square, so binding the icon to it feeds the button's width back
|
|
// into its own implicit width and the toolbar layout grows without bound.
|
|
icon.width: height / 2
|
|
icon.height: height / 2
|
|
|
|
// This determines the size of the Material highlight. We increase it
|
|
// from the default because we use larger than normal icons for TV readability.
|
|
Layout.preferredHeight: parent.height
|
|
|
|
Keys.onReturnPressed: {
|
|
clicked()
|
|
}
|
|
|
|
Keys.onEnterPressed: {
|
|
clicked()
|
|
}
|
|
|
|
Keys.onRightPressed: {
|
|
nextItemInFocusChain(true).forceActiveFocus(Qt.TabFocus)
|
|
}
|
|
|
|
Keys.onLeftPressed: {
|
|
nextItemInFocusChain(false).forceActiveFocus(Qt.TabFocus)
|
|
}
|
|
}
|