From 2f49643e51f746691c3d765dafaf9f0183886768 Mon Sep 17 00:00:00 2001 From: LemmyCook Date: Tue, 26 Aug 2025 14:25:36 -0400 Subject: [PATCH] NIconButton + NPill: improved vertical centering --- Widgets/NIconButton.qml | 10 ++++------ Widgets/NPill.qml | 5 ++++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Widgets/NIconButton.qml b/Widgets/NIconButton.qml index 0cccdfd..898dcf3 100644 --- a/Widgets/NIconButton.qml +++ b/Widgets/NIconButton.qml @@ -37,16 +37,14 @@ Rectangle { border.width: Math.max(1, Style.borderS * scaling) NIcon { - anchors.centerIn: parent - // Little hack to keep things centered at high scaling - anchors.horizontalCenterOffset: -1 * (scaling - 1.0) - anchors.verticalCenterOffset: 0 text: root.icon font.pointSize: root.fontPointSize * scaling color: root.hovering ? colorFgHover : colorFg - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter opacity: root.enabled ? Style.opacityFull : Style.opacityMedium + // Center horizontally + x: (root.width - width) / 2 + // Center vertically accounting for font metrics + y: (root.height - height) / 2 + (height - contentHeight) / 2 } NTooltip { diff --git a/Widgets/NPill.qml b/Widgets/NPill.qml index d361cee..addb6d7 100644 --- a/Widgets/NPill.qml +++ b/Widgets/NPill.qml @@ -103,7 +103,10 @@ Item { font.pointSize: Style.fontSizeM * scaling // When forced shown, use pill text color; otherwise accent color when hovered color: forceOpen ? textColor : (showPill ? iconTextColor : Color.mOnSurface) - anchors.centerIn: parent + // Center horizontally + x: (iconCircle.width - width) / 2 + // Center vertically accounting for font metrics + y: (iconCircle.height - height) / 2 + (height - contentHeight) / 2 } }