Use extern with custom font variables (#3)

This commit is contained in:
ilya-fedin 2020-03-06 21:57:39 +00:00 committed by GitHub
parent 8ce091c159
commit e6fdff4597
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 39 deletions

View file

@ -20,7 +20,7 @@
namespace style {
namespace internal {
bool GetUseSystemFont();
extern bool UseSystemFont;
namespace {
@ -32,7 +32,6 @@ auto PaletteChanges = rpl::event_stream<>();
auto ShortAnimationRunning = rpl::variable<bool>(false);
auto RunningShortAnimations = 0;
auto ResolvedMonospaceFont = style::font();
QString CustomMonospaceFont;
std::vector<internal::ModuleBase*> &StyleModules() {
static auto result = std::vector<internal::ModuleBase*>();
@ -58,7 +57,7 @@ void ResolveMonospaceFont() {
if (!CustomMonospaceFont.isEmpty()) {
tryFont(CustomMonospaceFont);
}
if (!GetUseSystemFont()) {
if (!UseSystemFont) {
tryFont("Consolas");
tryFont("Liberation Mono");
tryFont("Menlo");
@ -74,9 +73,7 @@ void ResolveMonospaceFont() {
} // namespace
void SetMonospaceFont(const QString &familyName) {
CustomMonospaceFont = familyName;
}
QString CustomMonospaceFont;
void registerModule(ModuleBase *module) {
StyleModules().push_back(module);

View file

@ -15,6 +15,8 @@
namespace style {
namespace internal {
extern QString CustomMonospaceFont;
// Objects of derived classes are created in global scope.
// They call [un]registerModule() in [de|con]structor.
class ModuleBase {
@ -25,8 +27,6 @@ public:
};
void SetMonospaceFont(const QString &familyName);
void registerModule(ModuleBase *module);
[[nodiscard]] QColor EnsureContrast(const QColor &over, const QColor &under);

View file

@ -167,38 +167,14 @@ QString FontTypeWindowsFallback[FontTypesCount] = {
bool Started = false;
QString Overrides[FontTypesCount];
} // namespace
QString CustomMainFont;
QString CustomSemiboldFont;
bool CustomSemiboldIsBold = false;
bool UseSystemFont = false;
bool UseOriginalMetrics = false;
} // namespace
bool GetUseSystemFont() {
return UseSystemFont;
}
void SetMainFont(const QString &familyName) {
CustomMainFont = familyName;
}
void SetSemiboldFont(const QString &familyName) {
CustomSemiboldFont = familyName;
}
void SetSemiboldIsBold(bool isBold) {
CustomSemiboldIsBold = isBold;
}
void SetUseSystemFont(bool isSystemFont) {
UseSystemFont = isSystemFont;
}
void SetUseOriginalMetrics(bool isOriginal) {
UseOriginalMetrics = isOriginal;
}
void StartFonts() {
if (Started) {
return;

View file

@ -14,11 +14,11 @@
namespace style {
namespace internal {
void SetMainFont(const QString &familyName);
void SetSemiboldFont(const QString &familyName);
void SetSemiboldIsBold(bool isBold);
void SetUseSystemFont(bool isSystemFont);
void SetUseOriginalMetrics(bool isOriginal);
extern QString CustomMainFont;
extern QString CustomSemiboldFont;
extern bool CustomSemiboldIsBold;
extern bool UseSystemFont;
extern bool UseOriginalMetrics;
void StartFonts();
[[nodiscard]] QString GetFontOverride(const QString &familyName, int32 flags = 0);