feat: apply tabular number formatting to timestamp (#6062)

This commit is contained in:
pajlada
2025-03-12 15:02:06 +01:00
committed by GitHub
parent 59e93d41d3
commit eff4e34ec6
147 changed files with 187 additions and 165 deletions
+1 -1
View File
@@ -1026,7 +1026,7 @@ TextElement *TimestampElement::formatTime(const QTime &time)
QString format = locale.toString(time, getSettings()->timestampFormat);
return new TextElement(format, MessageElementFlag::Timestamp,
MessageColor::System, FontStyle::ChatMedium);
MessageColor::System, FontStyle::TimestampMedium);
}
QJsonObject TimestampElement::toJson() const
+20 -1
View File
@@ -70,6 +70,7 @@ float fontSize(FontStyle style)
case FontStyle::ChatMedium:
case FontStyle::ChatMediumBold:
case FontStyle::ChatMediumItalic:
case FontStyle::TimestampMedium:
return chatSize();
case FontStyle::ChatLarge:
return 1.2F * chatSize();
@@ -99,6 +100,7 @@ int fontWeight(FontStyle style)
case FontStyle::ChatMediumItalic:
case FontStyle::ChatLarge:
case FontStyle::ChatVeryLarge:
case FontStyle::TimestampMedium:
return getSettings()->chatFontWeight.getValue();
case FontStyle::ChatMediumBold:
@@ -129,6 +131,7 @@ bool isItalic(FontStyle style)
case FontStyle::ChatMediumBold:
case FontStyle::ChatLarge:
case FontStyle::ChatVeryLarge:
case FontStyle::TimestampMedium:
case FontStyle::UiMedium:
case FontStyle::UiMediumBold:
case FontStyle::UiTabs:
@@ -157,6 +160,7 @@ QString fontFamily(FontStyle style)
case FontStyle::ChatMediumItalic:
case FontStyle::ChatLarge:
case FontStyle::ChatVeryLarge:
case FontStyle::TimestampMedium:
return getSettings()->chatFontFamily.getValue();
case FontStyle::UiMedium:
@@ -229,12 +233,27 @@ Fonts::FontData &Fonts::getOrCreateFontData(FontStyle type, float scale)
Fonts::FontData Fonts::createFontData(FontStyle type, float scale)
{
return QFont{
QFont font{
fontFamily(type),
static_cast<int>(fontSize(type) * scale),
fontWeight(type),
isItalic(type),
};
switch (type)
{
case FontStyle::TimestampMedium: {
#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
// Apply the OpenType feature `tnum` to timestamp fonts
// https://sparanoid.com/lab/opentype-features/#tnum
auto tag = QFont::Tag("tnum");
font.setFeature(tag, 1);
#endif
}
break;
}
return font;
}
} // namespace chatterino
+2
View File
@@ -24,6 +24,8 @@ enum class FontStyle : uint8_t {
ChatLarge,
ChatVeryLarge,
TimestampMedium,
UiMedium,
UiMediumBold,
UiTabs,