1
0
mirror of synced 2024-11-28 09:30:51 +01:00

impr: Add hint text about font size when no custom font is selected

This commit is contained in:
WerWolv 2023-12-09 12:14:45 +01:00
parent 350635d464
commit 09a148b8a5
4 changed files with 52 additions and 18 deletions

View File

@ -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<float, 4> m_value{};
};
class DropDown : public Widget {
class DropDown : public Widget {
public:
explicit DropDown(const std::vector<std::string> &items, const std::vector<nlohmann::json> &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 {}; }
};
}

View File

@ -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;
}
}
}

View File

@ -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",

View File

@ -406,28 +406,39 @@ namespace hex::plugin::builtin {
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();
const auto fontSettingsEnabled = [customFontEnabledSetting]{
auto &checkBox = static_cast<Widgets::Checkbox &>(customFontEnabledSetting.getWidget());
const auto customFontsEnabled = [customFontEnabledSetting] {
auto &customFontsEnabled = static_cast<Widgets::Checkbox &>(customFontEnabledSetting.getWidget());
return checkBox.isChecked();
return customFontsEnabled.isChecked();
};
ContentRegistry::Settings::add<Widgets::FilePicker>("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.font_path")
auto customFontPathSetting = ContentRegistry::Settings::add<Widgets::FilePicker>("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<Widgets::Checkbox &>(customFontEnabledSetting.getWidget());
auto &fontPath = static_cast<Widgets::FilePicker &>(customFontPathSetting.getWidget());
return customFontsEnabled.isChecked() && !fontPath.getPath().empty();
};
ContentRegistry::Settings::add<Widgets::Label>("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.custom_font_info")
.setEnabledCallback(customFontsEnabled);
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(fontSettingsEnabled);
.setEnabledCallback(customFontSettingsEnabled);
ContentRegistry::Settings::add<Widgets::Checkbox>("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<Widgets::Checkbox>("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<Widgets::Checkbox>("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.font_antialias", false)
.requiresRestart()
.setEnabledCallback(fontSettingsEnabled);
.setEnabledCallback(customFontSettingsEnabled);