diff --git a/lib/libimhex/include/hex/api/content_registry.hpp b/lib/libimhex/include/hex/api/content_registry.hpp index a0624732c..dd4e4ee03 100644 --- a/lib/libimhex/include/hex/api/content_registry.hpp +++ b/lib/libimhex/include/hex/api/content_registry.hpp @@ -130,7 +130,7 @@ namespace hex { Interface m_interface = Interface(this); }; - class Checkbox : public Widget { + class Checkbox : public Widget { public: explicit Checkbox(bool defaultValue) : m_value(defaultValue) { } @@ -144,6 +144,7 @@ namespace hex { private: bool m_value; }; + class SliderInteger : public Widget { public: SliderInteger(i32 defaultValue, i32 min, i32 max) : m_value(defaultValue), m_min(min), m_max(max) { } @@ -158,7 +159,8 @@ namespace hex { int m_value; i32 m_min, m_max; }; - class SliderFloat : public Widget { + + class SliderFloat : public Widget { public: SliderFloat(float defaultValue, float min, float max) : m_value(defaultValue), m_min(min), m_max(max) { } bool draw(const std::string &name) override; @@ -172,7 +174,8 @@ namespace hex { float m_value; float m_min, m_max; }; - class ColorPicker : public Widget { + + class ColorPicker : public Widget { public: explicit ColorPicker(ImColor defaultColor); @@ -186,7 +189,8 @@ namespace hex { private: std::array m_value{}; }; - class DropDown : public Widget { + + class DropDown : public Widget { public: explicit DropDown(const std::vector &items, const std::vector &settingsValues, const nlohmann::json &defaultItem) : m_items(items), m_settingsValues(settingsValues), m_defaultItem(defaultItem) { } @@ -205,7 +209,8 @@ namespace hex { int m_value = -1; }; - class TextBox : public Widget { + + class TextBox : public Widget { public: explicit TextBox(std::string defaultValue) : m_value(std::move(defaultValue)) { } @@ -220,20 +225,29 @@ namespace hex { private: std::string m_value; }; - class FilePicker : public Widget { + + class FilePicker : public Widget { public: bool draw(const std::string &name) override; void load(const nlohmann::json &data) override; nlohmann::json store() override; - [[nodiscard]] - std::fs::path getPath() const { return this->m_value; } + [[nodiscard]] std::fs::path getPath() const { + return this->m_value; + } private: std::string m_value; }; + class Label : public Widget { + public: + bool draw(const std::string &name) override; + + void load(const nlohmann::json &) override {} + nlohmann::json store() override { return {}; } + }; } diff --git a/lib/libimhex/source/api/content_registry.cpp b/lib/libimhex/source/api/content_registry.cpp index 7a3113c21..537590aaf 100644 --- a/lib/libimhex/source/api/content_registry.cpp +++ b/lib/libimhex/source/api/content_registry.cpp @@ -376,6 +376,14 @@ namespace hex { return this->m_value; } + bool Label::draw(const std::string& name) { + ImGui::NewLine(); + ImGui::TextUnformatted(name.c_str()); + + return false; + } + + } } diff --git a/plugins/builtin/romfs/lang/en_US.json b/plugins/builtin/romfs/lang/en_US.json index cea73b987..920dcc260 100644 --- a/plugins/builtin/romfs/lang/en_US.json +++ b/plugins/builtin/romfs/lang/en_US.json @@ -563,6 +563,7 @@ "hex.builtin.setting.font.glyphs": "Glyphs", "hex.builtin.setting.font.custom_font": "Custom Font", "hex.builtin.setting.font.custom_font_enable": "Use custom font", + "hex.builtin.setting.font.custom_font_info": "The following settings are only available when a custom font has been selected.", "hex.builtin.setting.font.font_bold": "Bold", "hex.builtin.setting.font.font_italic": "Italic", "hex.builtin.setting.font.font_antialias": "Antialiasing", diff --git a/plugins/builtin/source/content/settings_entries.cpp b/plugins/builtin/source/content/settings_entries.cpp index eb9850709..18a2646f4 100644 --- a/plugins/builtin/source/content/settings_entries.cpp +++ b/plugins/builtin/source/content/settings_entries.cpp @@ -406,28 +406,39 @@ namespace hex::plugin::builtin { auto customFontEnabledSetting = ContentRegistry::Settings::add("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.custom_font_enable", false).requiresRestart(); - const auto fontSettingsEnabled = [customFontEnabledSetting]{ - auto &checkBox = static_cast(customFontEnabledSetting.getWidget()); + const auto customFontsEnabled = [customFontEnabledSetting] { + auto &customFontsEnabled = static_cast(customFontEnabledSetting.getWidget()); - return checkBox.isChecked(); + return customFontsEnabled.isChecked(); }; - ContentRegistry::Settings::add("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.font_path") + auto customFontPathSetting = ContentRegistry::Settings::add("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.font_path") .requiresRestart() - .setEnabledCallback(fontSettingsEnabled); + .setEnabledCallback(customFontsEnabled); + + const auto customFontSettingsEnabled = [customFontEnabledSetting, customFontPathSetting] { + auto &customFontsEnabled = static_cast(customFontEnabledSetting.getWidget()); + auto &fontPath = static_cast(customFontPathSetting.getWidget()); + + return customFontsEnabled.isChecked() && !fontPath.getPath().empty(); + }; + + ContentRegistry::Settings::add("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.custom_font_info") + .setEnabledCallback(customFontsEnabled); + + ContentRegistry::Settings::add("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.font_size", 13, 0, 100) .requiresRestart() - .setEnabledCallback(fontSettingsEnabled); - + .setEnabledCallback(customFontSettingsEnabled); ContentRegistry::Settings::add("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.font_bold", false) .requiresRestart() - .setEnabledCallback(fontSettingsEnabled); + .setEnabledCallback(customFontSettingsEnabled); ContentRegistry::Settings::add("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.font_italic", false) .requiresRestart() - .setEnabledCallback(fontSettingsEnabled); + .setEnabledCallback(customFontSettingsEnabled); ContentRegistry::Settings::add("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.font_antialias", false) .requiresRestart() - .setEnabledCallback(fontSettingsEnabled); + .setEnabledCallback(customFontSettingsEnabled);