Skip to content

Commit 3327bb8

Browse files
committed
feat: dynamically set tag text color based on background luminance for improved readability.
1 parent d8c012c commit 3327bb8

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

library.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,10 @@ def paint(self, painter, option, index): # Overridden
353353
if tag_x + tag_width > option.rect.right(): break
354354
tag_rect = QRect(tag_x, tag_y, tag_width, tag_height)
355355
painter.setBrush(color); painter.setPen(Qt.PenStyle.NoPen); painter.drawRoundedRect(tag_rect, 6, 6)
356-
painter.setPen(QColor('#ffffff')); painter.drawText(tag_rect, Qt.AlignmentFlag.AlignCenter, name)
356+
r, g, b, _ = color.getRgb()
357+
luminance = 0.299 * r + 0.587 * g + 0.114 * b
358+
text_color = QColor('#000000') if luminance > 128 else QColor('#ffffff')
359+
painter.setPen(text_color); painter.drawText(tag_rect, Qt.AlignmentFlag.AlignCenter, name)
357360
tag_x += tag_width + 6
358361
painter.restore()
359362
# text_y += 20 # removed increment since markers are now separate

0 commit comments

Comments
 (0)