Normalize bar icon size and alignment
This commit is contained in:
17 files changed
+540
-116
No files matched your search
@@ -65,11 +65,31 @@ Item {
|
||||
// Width of the painted label, for bar chrome that wants to line up with the
|
||||
// text rather than with the slot it sits in. Zero on icon-only buttons.
|
||||
readonly property real labelWidth: label.visible ? label.implicitWidth : 0
|
||||
readonly property bool iconLabel: labelVisible && isIconGlyph(text)
|
||||
readonly property real iconPaintedWidth: iconLabel && iconLoader.item ? iconLoader.item.paintedWidth : 0
|
||||
readonly property real iconPaintedHeight: iconLabel && iconLoader.item ? iconLoader.item.paintedHeight : 0
|
||||
readonly property real iconCenterErrorX: iconLabel && iconLoader.item
|
||||
? iconLoader.x + iconLoader.item.paintedCenterX - width / 2 : 0
|
||||
readonly property real iconCenterErrorY: iconLabel && iconLoader.item
|
||||
? iconLoader.y + iconLoader.item.paintedCenterY - height / 2 : 0
|
||||
|
||||
function isIconGlyph(value) {
|
||||
var text = String(value || "")
|
||||
if (!text) return false
|
||||
var code = text.codePointAt(0)
|
||||
if (text.length !== (code > 0xffff ? 2 : 1)) return false
|
||||
return (code >= 0xe000 && code <= 0xf8ff)
|
||||
|| (code >= 0xf0000 && code <= 0xffffd)
|
||||
|| (code >= 0x100000 && code <= 0x10fffd)
|
||||
|| (code >= 0x2190 && code <= 0x2bff)
|
||||
}
|
||||
|
||||
visible: hasVisualContent || keepSpace
|
||||
opacity: !hasVisualContent || concealed ? 0 : (dimmed ? 0.45 : 1)
|
||||
implicitWidth: fixedWidth > 0 ? fixedWidth : (vertical ? barSize : Math.max(12, label.implicitWidth + scaledHorizontalMargin * 2))
|
||||
implicitHeight: fixedHeight > 0 ? fixedHeight : (vertical ? Math.max(12, label.implicitHeight + scaledVerticalPadding * 2) : barSize)
|
||||
implicitWidth: fixedWidth > 0 ? fixedWidth
|
||||
: (vertical ? barSize : (iconLabel ? Style.bar.iconSlot : Math.max(12, label.implicitWidth + scaledHorizontalMargin * 2)))
|
||||
implicitHeight: fixedHeight > 0 ? fixedHeight
|
||||
: (vertical ? (iconLabel ? Style.bar.iconSlot : Math.max(12, label.implicitHeight + scaledVerticalPadding * 2)) : barSize)
|
||||
|
||||
Behavior on opacity {
|
||||
NumberAnimation { duration: Style.duration(140); easing.type: Easing.OutCubic }
|
||||
@@ -78,7 +98,7 @@ Item {
|
||||
Text {
|
||||
id: label
|
||||
textFormat: Text.PlainText
|
||||
visible: root.labelVisible
|
||||
visible: root.labelVisible && !root.iconLabel
|
||||
anchors.centerIn: parent
|
||||
// Centering the line box puts the figures above the bar's middle, since
|
||||
// the box keeps room for descenders. Center the figure height instead, so
|
||||
@@ -106,6 +126,25 @@ Item {
|
||||
font: label.font
|
||||
}
|
||||
|
||||
Loader {
|
||||
id: iconLoader
|
||||
active: root.iconLabel
|
||||
width: Style.bar.iconCanvas
|
||||
height: Style.bar.iconCanvas
|
||||
x: (root.width - width) / 2
|
||||
y: (root.height - height) / 2
|
||||
sourceComponent: Component {
|
||||
OpticalGlyph {
|
||||
text: root.text
|
||||
fontFamily: root.fontFamily
|
||||
fontSize: root.fontSize
|
||||
paintedSize: Style.bar.iconSize
|
||||
color: root.active && root.useActiveColor ? root.activeColor : root.foreground
|
||||
rotation: root.textRotation
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: mouseArea
|
||||
anchors.fill: parent
|
||||
|
||||
Reference in new issue
Block a user