mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 22:20:04 +00:00
Initial setup for font settings
This commit is contained in:
parent
e0aa327bb7
commit
ad1646d725
7 changed files with 192 additions and 23 deletions
|
|
@ -103,6 +103,7 @@ private:
|
|||
|
||||
#ifdef SETTINGS_INTERFACE_IMPLEMENTATION
|
||||
template class SettingsInterface<bool>;
|
||||
template class SettingsInterface<double>;
|
||||
template class SettingsInterface<std::int64_t>;
|
||||
template class SettingsInterface<std::string>;
|
||||
|
||||
|
|
|
|||
|
|
@ -12,10 +12,34 @@ namespace settings
|
|||
|
||||
static const std::string logPrefix_ = "scwx::qt::settings::text_settings";
|
||||
|
||||
static const std::string kAlteDIN1451Mittelscrhift_ {
|
||||
"Alte DIN 1451 Mittelschrift"};
|
||||
static const std::string kInconsolata_ {"Inconsolata"};
|
||||
|
||||
static const std::string kRegular_ {"Regular"};
|
||||
|
||||
static const std::unordered_map<types::FontCategory, std::string>
|
||||
kDefaultFontFamily_ {
|
||||
{types::FontCategory::Default, kAlteDIN1451Mittelscrhift_},
|
||||
{types::FontCategory::Tooltip, kInconsolata_}};
|
||||
static const std::unordered_map<types::FontCategory, std::string>
|
||||
kDefaultFontStyle_ {{types::FontCategory::Default, kRegular_},
|
||||
{types::FontCategory::Tooltip, kRegular_}};
|
||||
static const std::unordered_map<types::FontCategory, double>
|
||||
kDefaultFontPointSize_ {{types::FontCategory::Default, 12.0},
|
||||
{types::FontCategory::Tooltip, 10.5}};
|
||||
|
||||
class TextSettings::Impl
|
||||
{
|
||||
public:
|
||||
explicit Impl()
|
||||
struct FontData
|
||||
{
|
||||
SettingsVariable<std::string> fontFamily_ {"font_family"};
|
||||
SettingsVariable<std::string> fontStyle_ {"font_style"};
|
||||
SettingsVariable<double> fontPointSize_ {"font_point_size"};
|
||||
};
|
||||
|
||||
explicit Impl(TextSettings* self) : self_ {self}
|
||||
{
|
||||
std::string defaultTooltipMethodValue =
|
||||
types::GetTooltipMethodName(types::TooltipMethod::ImGui);
|
||||
|
|
@ -47,16 +71,24 @@ public:
|
|||
// No match found, invalid
|
||||
return false;
|
||||
});
|
||||
|
||||
InitializeFontVariables();
|
||||
}
|
||||
|
||||
~Impl() {}
|
||||
|
||||
void InitializeFontVariables();
|
||||
|
||||
TextSettings* self_;
|
||||
|
||||
std::unordered_map<types::FontCategory, FontData> fontData_ {};
|
||||
|
||||
SettingsVariable<std::int64_t> hoverTextWrap_ {"hover_text_wrap"};
|
||||
SettingsVariable<std::string> tooltipMethod_ {"tooltip_method"};
|
||||
};
|
||||
|
||||
TextSettings::TextSettings() :
|
||||
SettingsCategory("text"), p(std::make_unique<Impl>())
|
||||
SettingsCategory("text"), p(std::make_unique<Impl>(this))
|
||||
{
|
||||
RegisterVariables({&p->hoverTextWrap_, &p->tooltipMethod_});
|
||||
SetDefaults();
|
||||
|
|
@ -66,6 +98,50 @@ TextSettings::~TextSettings() = default;
|
|||
TextSettings::TextSettings(TextSettings&&) noexcept = default;
|
||||
TextSettings& TextSettings::operator=(TextSettings&&) noexcept = default;
|
||||
|
||||
void TextSettings::Impl::InitializeFontVariables()
|
||||
{
|
||||
for (auto fontCategory : types::FontCategoryIterator())
|
||||
{
|
||||
auto result = fontData_.emplace(fontCategory, FontData {});
|
||||
auto& pair = *result.first;
|
||||
auto& font = pair.second;
|
||||
|
||||
font.fontFamily_.SetDefault(kDefaultFontFamily_.at(fontCategory));
|
||||
font.fontStyle_.SetDefault(kDefaultFontStyle_.at(fontCategory));
|
||||
font.fontPointSize_.SetDefault(kDefaultFontPointSize_.at(fontCategory));
|
||||
|
||||
// String values must not be empty
|
||||
font.fontFamily_.SetValidator([](const std::string& value)
|
||||
{ return !value.empty(); });
|
||||
font.fontStyle_.SetValidator([](const std::string& value)
|
||||
{ return !value.empty(); });
|
||||
|
||||
// Font point size must be between 6 and 72
|
||||
font.fontPointSize_.SetMinimum(6.0);
|
||||
font.fontPointSize_.SetMaximum(72.0);
|
||||
|
||||
// TODO: Variable registration
|
||||
}
|
||||
}
|
||||
|
||||
SettingsVariable<std::string>&
|
||||
TextSettings::font_family(types::FontCategory fontCategory) const
|
||||
{
|
||||
return p->fontData_.at(fontCategory).fontFamily_;
|
||||
}
|
||||
|
||||
SettingsVariable<std::string>&
|
||||
TextSettings::font_style(types::FontCategory fontCategory) const
|
||||
{
|
||||
return p->fontData_.at(fontCategory).fontStyle_;
|
||||
}
|
||||
|
||||
SettingsVariable<double>&
|
||||
TextSettings::font_point_size(types::FontCategory fontCategory) const
|
||||
{
|
||||
return p->fontData_.at(fontCategory).fontPointSize_;
|
||||
}
|
||||
|
||||
SettingsVariable<std::int64_t>& TextSettings::hover_text_wrap() const
|
||||
{
|
||||
return p->hoverTextWrap_;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <scwx/qt/settings/settings_category.hpp>
|
||||
#include <scwx/qt/settings/settings_variable.hpp>
|
||||
#include <scwx/qt/types/text_types.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
|
@ -25,8 +26,15 @@ public:
|
|||
TextSettings(TextSettings&&) noexcept;
|
||||
TextSettings& operator=(TextSettings&&) noexcept;
|
||||
|
||||
SettingsVariable<std::string>&
|
||||
font_family(types::FontCategory fontCategory) const;
|
||||
SettingsVariable<std::string>&
|
||||
font_style(types::FontCategory fontCategory) const;
|
||||
SettingsVariable<double>&
|
||||
font_point_size(types::FontCategory fontCategory) const;
|
||||
|
||||
SettingsVariable<std::int64_t>& hover_text_wrap() const;
|
||||
SettingsVariable<std::string>& tooltip_method() const;
|
||||
SettingsVariable<std::string>& tooltip_method() const;
|
||||
|
||||
static TextSettings& Instance();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue