Skip to content

Commit

Permalink
impr: Move custom font setting behind a enable checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
WerWolv committed Nov 23, 2023
1 parent 71df45a commit 59b363d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions main/gui/source/init/tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ namespace hex::init {
static bool loadFontsImpl(bool loadUnicode) {
const float defaultFontSize = ImHexApi::System::DefaultFontSize * std::round(ImHexApi::System::getGlobalScale());

// Load font related settings
{
// Load custom font related settings
if (ContentRegistry::Settings::read("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font_enable", false)) {
std::fs::path fontFile = ContentRegistry::Settings::read("hex.builtin.setting.font", "hex.builtin.setting.font.font_path", "").get<std::string>();
if (!fontFile.empty()) {
if (!wolv::io::fs::exists(fontFile) || !wolv::io::fs::isRegularFile(fontFile)) {
Expand Down
17 changes: 13 additions & 4 deletions plugins/builtin/source/content/settings_entries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,13 +386,22 @@ namespace hex::plugin::builtin {
/* Fonts */

ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.font", "hex.builtin.setting.font.glyphs", "hex.builtin.setting.font.load_all_unicode_chars", false);
auto fontPathSetting = ContentRegistry::Settings::add<Widgets::FilePicker>("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.font_path").requiresRestart();

auto customFontEnabledSetting = ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.custom_font_enable", false).requiresRestart();

ContentRegistry::Settings::add<Widgets::FilePicker>("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.font_path")
.requiresRestart()
.setEnabledCallback([customFontEnabledSetting]{
auto &checkBox = static_cast<Widgets::Checkbox &>(customFontEnabledSetting.getWidget());

return checkBox.isChecked();
});
ContentRegistry::Settings::add<Widgets::SliderInteger>("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.font_size", 13, 0, 100)
.requiresRestart()
.setEnabledCallback([fontPathSetting]{
auto &filePicker = static_cast<Widgets::FilePicker &>(fontPathSetting.getWidget());
.setEnabledCallback([customFontEnabledSetting]{
auto &checkBox = static_cast<Widgets::Checkbox &>(customFontEnabledSetting.getWidget());

return !filePicker.getPath().empty();
return checkBox.isChecked();
});


Expand Down

0 comments on commit 59b363d

Please sign in to comment.