|
2 | 2 | # SPDX-License-Identifier: GPL-3.0-only |
3 | 3 |
|
4 | 4 |
|
| 5 | +import math |
5 | 6 | import platform |
6 | 7 |
|
7 | 8 | from PySide6.QtCore import QSize, Qt |
8 | | -from PySide6.QtGui import QColor, QGuiApplication |
| 9 | +from PySide6.QtGui import QColor, QFont, QFontMetricsF, QGuiApplication |
9 | 10 |
|
10 | 11 | from tagstudio.core.library.alchemy.enums import TagColorEnum |
11 | 12 | from tagstudio.core.library.alchemy.models import TagColorGroup |
|
38 | 39 | CHECKBOX_SIZE = 20 # Checkboxes and radio buttons |
39 | 40 | FLAT_ICON_SIZE = 24 # Icons on flat icon-only buttons, like the mode rail's |
40 | 41 | CAPSULE_HEIGHT = 24 |
| 42 | +CAPSULE_FONT_SIZE = 13 |
| 43 | +CAPSULE_FONT_WEIGHT = QFont.Weight.DemiBold |
41 | 44 | SWATCH_SIZE = 24 |
42 | 45 | CHEVRON_SIZE = QSize(20, 20) |
43 | 46 |
|
@@ -108,17 +111,23 @@ def capsule_text_style( |
108 | 111 | ) -> str: |
109 | 112 | """Style used for Capsule text.""" |
110 | 113 | side_padding = 4 + (3 if is_pill else 0) |
| 114 | + # Set the font baseline depending on the metrics instead of a constant value |
| 115 | + font = QFont() |
| 116 | + font.setPixelSize(CAPSULE_FONT_SIZE) |
| 117 | + font.setWeight(CAPSULE_FONT_WEIGHT) |
| 118 | + metrics = QFontMetricsF(font) |
| 119 | + bottom_padding = math.floor(metrics.ascent() - metrics.descent() - metrics.capHeight()) |
111 | 120 | return f""" |
112 | 121 | QPushButton{{ |
113 | 122 | background: transparent; |
114 | 123 | color: rgba{text_color.toTuple()}; |
115 | | - font-weight: 600; |
| 124 | + font-weight: {CAPSULE_FONT_WEIGHT.value}; |
116 | 125 | border: 2px solid transparent; |
117 | 126 | border-radius: {RADIUS}px; |
118 | | - font-size: 13px; |
| 127 | + font-size: {CAPSULE_FONT_SIZE}px; |
119 | 128 | padding-right: {side_padding if right_padding is None else right_padding}px; |
120 | 129 | padding-left: {side_padding if left_padding is None else left_padding}px; |
121 | | - padding-bottom: {2 if platform.system() == "Windows" else 1}px; |
| 130 | + padding-bottom: {bottom_padding}px; |
122 | 131 | }} |
123 | 132 | QPushButton::pressed{{ |
124 | 133 | color: rgba{pressed_text_color.toTuple()}; |
|
0 commit comments