impr: Simplified custom font selection
This commit is contained in:
parent
2ba7db184b
commit
3129d6e8fd
@ -753,7 +753,6 @@ namespace hex {
|
||||
|
||||
const std::vector<Font>& getFonts();
|
||||
|
||||
void setCustomFontPath(const std::fs::path &path);
|
||||
void setFontSize(float size);
|
||||
void setFontAtlas(ImFontAtlas *fontAtlas);
|
||||
|
||||
@ -773,12 +772,6 @@ namespace hex {
|
||||
ImFont* Bold();
|
||||
ImFont* Italic();
|
||||
|
||||
/**
|
||||
* @brief Gets the current custom font path
|
||||
* @return The current custom font path
|
||||
*/
|
||||
const std::filesystem::path& getCustomFontPath();
|
||||
|
||||
/**
|
||||
* @brief Gets the current font size
|
||||
* @return The current font size
|
||||
|
@ -993,11 +993,6 @@ namespace hex {
|
||||
return *s_fonts;
|
||||
}
|
||||
|
||||
static AutoReset<std::fs::path> s_customFontPath;
|
||||
void setCustomFontPath(const std::fs::path &path) {
|
||||
s_customFontPath = path;
|
||||
}
|
||||
|
||||
static float s_fontSize = DefaultFontSize;
|
||||
void setFontSize(float size) {
|
||||
s_fontSize = size;
|
||||
@ -1079,10 +1074,6 @@ namespace hex {
|
||||
});
|
||||
}
|
||||
|
||||
const std::fs::path& getCustomFontPath() {
|
||||
return impl::s_customFontPath;
|
||||
}
|
||||
|
||||
float getFontSize() {
|
||||
return impl::s_fontSize;
|
||||
}
|
||||
|
@ -450,7 +450,6 @@
|
||||
"hex.builtin.setting.folders.remove_folder": "Ausgewählter Ordner von Liste entfernen",
|
||||
"hex.builtin.setting.font": "Schriftart",
|
||||
"hex.builtin.setting.font.custom_font": "Schriftart",
|
||||
"hex.builtin.setting.font.custom_font_enable": "Benutzerdefinierte Schriftart aktivieren",
|
||||
"hex.builtin.setting.font.custom_font_info": "Die folgenden Einstellungen sind nur verfügbar wenn eine benutzerdefinierte Schriftart ausgewählt ist.",
|
||||
"hex.builtin.setting.font.font_antialias": "Schrift Anti-Aliasing",
|
||||
"hex.builtin.setting.font.font_bold": "Fett",
|
||||
|
@ -463,7 +463,6 @@
|
||||
"hex.builtin.setting.font": "Font",
|
||||
"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",
|
||||
|
@ -449,7 +449,6 @@
|
||||
"hex.builtin.setting.folders.remove_folder": "Eliminar la carpeta seleccionada de la lista",
|
||||
"hex.builtin.setting.font": "Fuente",
|
||||
"hex.builtin.setting.font.custom_font": "",
|
||||
"hex.builtin.setting.font.custom_font_enable": "",
|
||||
"hex.builtin.setting.font.custom_font_info": "",
|
||||
"hex.builtin.setting.font.font_antialias": "",
|
||||
"hex.builtin.setting.font.font_bold": "",
|
||||
|
@ -443,7 +443,6 @@
|
||||
"hex.builtin.setting.font": "Betűtípus",
|
||||
"hex.builtin.setting.font.glyphs": "Szimbólumok",
|
||||
"hex.builtin.setting.font.custom_font": "Saját betűtípus",
|
||||
"hex.builtin.setting.font.custom_font_enable": "Saját betűtípus használata",
|
||||
"hex.builtin.setting.font.custom_font_info": "Az alábbi beállítások csak egyéni betűtípusok esetén érhetők el.",
|
||||
"hex.builtin.setting.font.font_bold": "Félkövér",
|
||||
"hex.builtin.setting.font.font_italic": "Dőlt",
|
||||
|
@ -449,7 +449,6 @@
|
||||
"hex.builtin.setting.folders.remove_folder": "",
|
||||
"hex.builtin.setting.font": "",
|
||||
"hex.builtin.setting.font.custom_font": "",
|
||||
"hex.builtin.setting.font.custom_font_enable": "",
|
||||
"hex.builtin.setting.font.custom_font_info": "",
|
||||
"hex.builtin.setting.font.font_antialias": "",
|
||||
"hex.builtin.setting.font.font_bold": "",
|
||||
|
@ -449,7 +449,6 @@
|
||||
"hex.builtin.setting.folders.remove_folder": "選択中のフォルダをリストから消去",
|
||||
"hex.builtin.setting.font": "フォント",
|
||||
"hex.builtin.setting.font.custom_font": "",
|
||||
"hex.builtin.setting.font.custom_font_enable": "",
|
||||
"hex.builtin.setting.font.custom_font_info": "",
|
||||
"hex.builtin.setting.font.font_antialias": "",
|
||||
"hex.builtin.setting.font.font_bold": "",
|
||||
|
@ -449,7 +449,6 @@
|
||||
"hex.builtin.setting.folders.remove_folder": "목록에서 현재 선택된 폴더 제거",
|
||||
"hex.builtin.setting.font": "글꼴",
|
||||
"hex.builtin.setting.font.custom_font": "사용자 정의 글꼴",
|
||||
"hex.builtin.setting.font.custom_font_enable": "사용자 정의 글꼴",
|
||||
"hex.builtin.setting.font.custom_font_info": "",
|
||||
"hex.builtin.setting.font.font_antialias": "안티에일리어싱",
|
||||
"hex.builtin.setting.font.font_bold": "굵게",
|
||||
|
@ -449,7 +449,6 @@
|
||||
"hex.builtin.setting.folders.remove_folder": "Remover a pasta atualmente selecionada da lista",
|
||||
"hex.builtin.setting.font": "Fonte",
|
||||
"hex.builtin.setting.font.custom_font": "",
|
||||
"hex.builtin.setting.font.custom_font_enable": "",
|
||||
"hex.builtin.setting.font.custom_font_info": "",
|
||||
"hex.builtin.setting.font.font_antialias": "",
|
||||
"hex.builtin.setting.font.font_bold": "",
|
||||
|
@ -502,7 +502,6 @@
|
||||
"hex.builtin.setting.folders.remove_folder": "从列表中移除当前目录",
|
||||
"hex.builtin.setting.font": "字体",
|
||||
"hex.builtin.setting.font.custom_font": "自定义字体",
|
||||
"hex.builtin.setting.font.custom_font_enable": "使用自定义字体",
|
||||
"hex.builtin.setting.font.custom_font_info": "仅当选择自定义字体时,以下设置才可用。",
|
||||
"hex.builtin.setting.font.font_antialias": "抗锯齿",
|
||||
"hex.builtin.setting.font.font_bold": "粗体",
|
||||
|
@ -449,7 +449,6 @@
|
||||
"hex.builtin.setting.folders.remove_folder": "從列表中移除目前選擇的資料夾",
|
||||
"hex.builtin.setting.font": "字體",
|
||||
"hex.builtin.setting.font.custom_font": "",
|
||||
"hex.builtin.setting.font.custom_font_enable": "",
|
||||
"hex.builtin.setting.font.custom_font_info": "",
|
||||
"hex.builtin.setting.font.font_antialias": "",
|
||||
"hex.builtin.setting.font.font_bold": "",
|
||||
|
@ -691,10 +691,11 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
|
||||
for (const auto &[path, fontName] : fonts) {
|
||||
if (ImGui::Selectable(fontName.c_str(), m_path == path)) {
|
||||
if (ImGui::Selectable(limitStringLength(fontName, 50).c_str(), m_path == path)) {
|
||||
m_path = path;
|
||||
changed = true;
|
||||
}
|
||||
ImGui::SetItemTooltip("%s", fontName.c_str());
|
||||
}
|
||||
|
||||
ImGui::EndCombo();
|
||||
@ -921,22 +922,13 @@ namespace hex::plugin::builtin {
|
||||
/* Fonts */
|
||||
{
|
||||
const auto scaleWarningHandler = [](auto&) {
|
||||
s_showScalingWarning = ImHexApi::Fonts::getCustomFontPath().empty() &&
|
||||
ContentRegistry::Settings::read<bool>("hex.builtin.setting.font", "hex.builtin.setting.font.pixel_perfect_default_font", true);
|
||||
s_showScalingWarning = ContentRegistry::Settings::read<bool>("hex.builtin.setting.font", "hex.builtin.setting.font.pixel_perfect_default_font", true);
|
||||
};
|
||||
ContentRegistry::Settings::onChange("hex.builtin.setting.font", "hex.builtin.setting.font.pixel_perfect_default_font", scaleWarningHandler);
|
||||
|
||||
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.font", "hex.builtin.setting.font.glyphs", "hex.builtin.setting.font.load_all_unicode_chars", false)
|
||||
.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();
|
||||
|
||||
const auto customFontsEnabled = [customFontEnabledSetting] {
|
||||
auto &customFontsEnabled = static_cast<Widgets::Checkbox &>(customFontEnabledSetting.getWidget());
|
||||
|
||||
return customFontsEnabled.isChecked();
|
||||
};
|
||||
|
||||
auto customFontPathSetting = ContentRegistry::Settings::add<FontFilePicker>("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.font_path")
|
||||
.requiresRestart()
|
||||
.setChangedCallback([scaleWarningHandler](Widgets::Widget &widget) {
|
||||
@ -944,32 +936,28 @@ namespace hex::plugin::builtin {
|
||||
|
||||
auto &fontPicker = static_cast<FontFilePicker&>(widget);
|
||||
ContentRegistry::Settings::write<bool>("hex.builtin.setting.font", "hex.builtin.setting.font.pixel_perfect_default_font", fontPicker.isPixelPerfectFontSelected());
|
||||
})
|
||||
.setEnabledCallback(customFontsEnabled);
|
||||
});
|
||||
|
||||
const auto customFontSettingsEnabled = [customFontEnabledSetting, customFontPathSetting] {
|
||||
auto &customFontsEnabled = static_cast<Widgets::Checkbox &>(customFontEnabledSetting.getWidget());
|
||||
const bool pixelPerfectFont = ContentRegistry::Settings::read<bool>("hex.builtin.setting.font", "hex.builtin.setting.font.pixel_perfect_default_font", true);
|
||||
const auto fontCustomizationEnabled = [customFontPathSetting ] {
|
||||
auto &fontPicker = static_cast<FontFilePicker&>(customFontPathSetting.getWidget());
|
||||
|
||||
return customFontsEnabled.isChecked() && !pixelPerfectFont;
|
||||
return !fontPicker.isPixelPerfectFontSelected();
|
||||
};
|
||||
|
||||
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::Label>("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.custom_font_info");
|
||||
|
||||
ContentRegistry::Settings::add<SliderPoints>("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.font_size", 16, 2, 100)
|
||||
.requiresRestart()
|
||||
.setEnabledCallback(customFontSettingsEnabled);
|
||||
.setEnabledCallback(fontCustomizationEnabled);
|
||||
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.font_bold", false)
|
||||
.requiresRestart()
|
||||
.setEnabledCallback(customFontSettingsEnabled);
|
||||
.setEnabledCallback(fontCustomizationEnabled);
|
||||
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.font_italic", false)
|
||||
.requiresRestart()
|
||||
.setEnabledCallback(customFontSettingsEnabled);
|
||||
.setEnabledCallback(fontCustomizationEnabled);
|
||||
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.font_antialias", true)
|
||||
.requiresRestart()
|
||||
.setEnabledCallback(customFontSettingsEnabled);
|
||||
.setEnabledCallback(fontCustomizationEnabled);
|
||||
}
|
||||
|
||||
/* Folders */
|
||||
|
@ -288,19 +288,20 @@ namespace hex::fonts {
|
||||
|
||||
fontAtlas.enableUnicodeCharacters(shouldLoadUnicode);
|
||||
|
||||
auto pixelPerfectFont = ContentRegistry::Settings::read<bool>("hex.builtin.setting.font", "hex.builtin.setting.font.pixel_perfect_default_font", true);
|
||||
|
||||
std::fs::path customFontPath;
|
||||
// If a custom font is set in the settings, load the rest of the settings as well
|
||||
if (ContentRegistry::Settings::read<bool>("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font_enable", false)) {
|
||||
if (!pixelPerfectFont) {
|
||||
fontAtlas.setBold(ContentRegistry::Settings::read<bool>("hex.builtin.setting.font", "hex.builtin.setting.font.font_bold", false));
|
||||
fontAtlas.setItalic(ContentRegistry::Settings::read<bool>("hex.builtin.setting.font", "hex.builtin.setting.font.font_italic", false));
|
||||
fontAtlas.setAntiAliasing(ContentRegistry::Settings::read<bool>("hex.builtin.setting.font", "hex.builtin.setting.font.font_antialias", true));
|
||||
|
||||
ImHexApi::Fonts::impl::setCustomFontPath(findCustomFontPath());
|
||||
customFontPath = findCustomFontPath();
|
||||
}
|
||||
ImHexApi::Fonts::impl::setFontSize(getFontSize());
|
||||
|
||||
|
||||
const auto fontSize = ImHexApi::Fonts::getFontSize();
|
||||
const auto &customFontPath = ImHexApi::Fonts::getCustomFontPath();
|
||||
|
||||
// Try to load the custom font if one was set
|
||||
std::optional<Font> defaultFont;
|
||||
@ -314,8 +315,6 @@ namespace hex::fonts {
|
||||
|
||||
// If there's no custom font set, or it failed to load, fall back to the default font
|
||||
if (!defaultFont.has_value()) {
|
||||
auto pixelPerfectFont = ContentRegistry::Settings::read<bool>("hex.builtin.setting.font", "hex.builtin.setting.font.pixel_perfect_default_font", true);
|
||||
|
||||
if (pixelPerfectFont)
|
||||
defaultFont = fontAtlas.addDefaultFont();
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user