mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 21:47:40 -05:00
ux: Added custom font and font size setting to settings menu, improve rebooting behaviour
This commit is contained in:
@@ -19,6 +19,9 @@ namespace hex::plugin::builtin {
|
||||
|
||||
[[nodiscard]] ImVec2 getMinSize() const override { return { 500, 300 }; }
|
||||
[[nodiscard]] ImVec2 getMaxSize() const override { return { 500, 300 }; }
|
||||
|
||||
private:
|
||||
bool m_restartRequested = false;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -57,27 +57,29 @@ namespace hex::plugin::builtin {
|
||||
return false;
|
||||
});
|
||||
|
||||
ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.scaling", 0, [](auto name, nlohmann::json &setting) {
|
||||
static int selection = static_cast<int>(setting);
|
||||
ContentRegistry::Settings::add(
|
||||
"hex.builtin.setting.interface", "hex.builtin.setting.interface.scaling", 0, [](auto name, nlohmann::json &setting) {
|
||||
static int selection = static_cast<int>(setting);
|
||||
|
||||
const char *scaling[] = {
|
||||
"hex.builtin.setting.interface.scaling.native"_lang,
|
||||
"hex.builtin.setting.interface.scaling.x0_5"_lang,
|
||||
"hex.builtin.setting.interface.scaling.x1_0"_lang,
|
||||
"hex.builtin.setting.interface.scaling.x1_5"_lang,
|
||||
"hex.builtin.setting.interface.scaling.x2_0"_lang,
|
||||
};
|
||||
const char *scaling[] = {
|
||||
"hex.builtin.setting.interface.scaling.native"_lang,
|
||||
"hex.builtin.setting.interface.scaling.x0_5"_lang,
|
||||
"hex.builtin.setting.interface.scaling.x1_0"_lang,
|
||||
"hex.builtin.setting.interface.scaling.x1_5"_lang,
|
||||
"hex.builtin.setting.interface.scaling.x2_0"_lang,
|
||||
};
|
||||
|
||||
if (ImGui::Combo(name.data(), &selection, scaling, IM_ARRAYSIZE(scaling))) {
|
||||
setting = selection;
|
||||
if (ImGui::Combo(name.data(), &selection, scaling, IM_ARRAYSIZE(scaling))) {
|
||||
setting = selection;
|
||||
|
||||
ImHexApi::Common::restartImHex();
|
||||
ImHexApi::Common::restartImHex();
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
return false;
|
||||
},
|
||||
true);
|
||||
|
||||
ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.language", "en-US", [](auto name, nlohmann::json &setting) {
|
||||
auto &languages = LangEntry::getSupportedLanguages();
|
||||
@@ -222,9 +224,58 @@ namespace hex::plugin::builtin {
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
static std::string fontPath;
|
||||
ContentRegistry::Settings::add(
|
||||
"hex.builtin.setting.font", "hex.builtin.setting.font.font_path", "", [](auto name, nlohmann::json &setting) {
|
||||
fontPath = static_cast<std::string>(setting);
|
||||
|
||||
if (ImGui::InputText("##font_path", fontPath.data(), fontPath.capacity(), ImGuiInputTextFlags_CallbackResize, ImGui::UpdateStringSizeCallback, &fontPath)) {
|
||||
setting = fontPath;
|
||||
return true;
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
if (ImGui::IconButton(ICON_VS_FOLDER_OPENED, ImGui::GetStyleColorVec4(ImGuiCol_Text))) {
|
||||
return hex::openFileBrowser("hex.builtin.setting.font.font_path", DialogMode::Open, {
|
||||
{"TTF Font", "ttf"}
|
||||
},
|
||||
[&](const fs::path &path) {
|
||||
fontPath = path.string();
|
||||
setting = fontPath;
|
||||
});
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::TextFormatted("{}", name);
|
||||
|
||||
return false;
|
||||
},
|
||||
true);
|
||||
|
||||
ContentRegistry::Settings::add(
|
||||
"hex.builtin.setting.font", "hex.builtin.setting.font.font_size", 13, [](auto name, nlohmann::json &setting) {
|
||||
static int fontSize = static_cast<int>(setting);
|
||||
|
||||
ImGui::BeginDisabled(fontPath.empty());
|
||||
|
||||
if (ImGui::SliderInt(name.data(), &fontSize, 0, 100, "%d", ImGuiSliderFlags_NoInput)) {
|
||||
setting = fontSize;
|
||||
return true;
|
||||
}
|
||||
|
||||
ImGui::EndDisabled();
|
||||
|
||||
return false;
|
||||
},
|
||||
true);
|
||||
|
||||
|
||||
static const std::string dirsSetting { "hex.builtin.setting.folders" };
|
||||
|
||||
ContentRegistry::Settings::addCategoryDescrition(dirsSetting, "hex.builtin.setting.folders.description");
|
||||
ContentRegistry::Settings::addCategoryDescription(dirsSetting, "hex.builtin.setting.folders.description");
|
||||
|
||||
ContentRegistry::Settings::add(dirsSetting, dirsSetting, std::vector<std::string> {}, [](auto name, nlohmann::json &setting) {
|
||||
static std::vector<std::string> folders = setting;
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include <hex/api/content_registry.hpp>
|
||||
|
||||
#include <hex/helpers/logger.hpp>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
@@ -45,15 +47,20 @@ namespace hex::plugin::builtin {
|
||||
const auto &descriptions = ContentRegistry::Settings::getCategoryDescriptions();
|
||||
|
||||
for (auto &it : sortedCategories) {
|
||||
auto &[category, entries] = *it;
|
||||
auto &[category, settings] = *it;
|
||||
if (ImGui::BeginTabItem(LangEntry(category))) {
|
||||
const std::string &categoryDesc = descriptions.count(category) ? descriptions.at(category) : category.name;
|
||||
ImGui::TextUnformatted(LangEntry(categoryDesc));
|
||||
ImGui::Separator();
|
||||
|
||||
for (auto &[name, callback] : entries) {
|
||||
if (callback(LangEntry(name), ContentRegistry::Settings::getSettingsData()[category.name][name]))
|
||||
for (auto &[name, requiresRestart, callback] : settings) {
|
||||
if (callback(LangEntry(name), ContentRegistry::Settings::getSettingsData()[category.name][name])) {
|
||||
log::info("Setting [{}]: {} was changed", category.name, name);
|
||||
EventManager::post<EventSettingsChanged>();
|
||||
|
||||
if (requiresRestart)
|
||||
this->m_restartRequested = true;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::EndTabItem();
|
||||
@@ -65,6 +72,10 @@ namespace hex::plugin::builtin {
|
||||
ImGui::EndPopup();
|
||||
} else
|
||||
this->getWindowOpenState() = false;
|
||||
|
||||
if (this->getWindowOpenState() == false && this->m_restartRequested) {
|
||||
View::showYesNoQuestionPopup("hex.builtin.view.settings.restart_question"_lang, ImHexApi::Common::restartImHex, [] {});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.common.info", "Information" },
|
||||
{ "hex.builtin.common.error", "Fehler" },
|
||||
{ "hex.builtin.common.fatal", "Fataler Fehler" },
|
||||
{ "hex.builtin.common.question", "Frage" },
|
||||
{ "hex.builtin.common.address", "Adresse" },
|
||||
{ "hex.builtin.common.size", "Länge" },
|
||||
{ "hex.builtin.common.region", "Region" },
|
||||
@@ -330,6 +331,7 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.view.pattern_data.value", "Wert" },
|
||||
|
||||
{ "hex.builtin.view.settings.name", "Einstellungen" },
|
||||
{ "hex.builtin.view.settings.restart_question", "Eine Änderung die du gemacht hast benötigt einen neustart von ImHex. Möchtest du ImHex jetzt neu starten?" },
|
||||
|
||||
{ "hex.builtin.view.strings.name", "Strings" },
|
||||
{ "hex.builtin.view.strings.copy", "String kopieren" },
|
||||
@@ -672,6 +674,11 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.setting.hex_editor.grey_zeros", "Nullen ausgrauen" },
|
||||
{ "hex.builtin.setting.hex_editor.uppercase_hex", "Hex Zeichen als Grossbuchstaben" },
|
||||
{ "hex.builtin.setting.hex_editor.extra_info", "Extra informationen anzeigen" },
|
||||
{ "hex.builtin.setting.folders", "Ordner" },
|
||||
{ "hex.builtin.setting.folders.description", "Gib zusätzliche Orderpfade an in welchen Pattern, Scripts, Yara Rules und anderes gesucht wird" },
|
||||
{ "hex.builtin.setting.font", "Schriftart" },
|
||||
{ "hex.builtin.setting.font.font_path", "Eigene Schriftart" },
|
||||
{ "hex.builtin.setting.font.font_size", "Schriftgrösse" },
|
||||
|
||||
{ "hex.builtin.provider.file.path", "Dateipfad" },
|
||||
{ "hex.builtin.provider.file.size", "Größe" },
|
||||
|
||||
@@ -60,6 +60,7 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.common.info", "Information" },
|
||||
{ "hex.builtin.common.error", "Error" },
|
||||
{ "hex.builtin.common.fatal", "Fatal Error" },
|
||||
{ "hex.builtin.common.question", "Question" },
|
||||
{ "hex.builtin.common.address", "Address" },
|
||||
{ "hex.builtin.common.size", "Size" },
|
||||
{ "hex.builtin.common.region", "Region" },
|
||||
@@ -334,6 +335,7 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.view.pattern_data.value", "Value" },
|
||||
|
||||
{ "hex.builtin.view.settings.name", "Settings" },
|
||||
{ "hex.builtin.view.settings.restart_question", "A change you made requires a restart of ImHex to take effect. Would you like to restart it now?" },
|
||||
|
||||
{ "hex.builtin.view.strings.name", "Strings" },
|
||||
{ "hex.builtin.view.strings.copy", "Copy string" },
|
||||
@@ -677,7 +679,10 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.setting.hex_editor.uppercase_hex", "Upper case Hex characters" },
|
||||
{ "hex.builtin.setting.hex_editor.extra_info", "Display extra information" },
|
||||
{ "hex.builtin.setting.folders", "Folders" },
|
||||
{ "hex.builtin.setting.folders.description", "Specify additional search paths for patterns, scripts, rules and more" },
|
||||
{ "hex.builtin.setting.folders.description", "Specify additional search paths for patterns, scripts, Yara rules and more" },
|
||||
{ "hex.builtin.setting.font", "Font" },
|
||||
{ "hex.builtin.setting.font.font_path", "Custom Font Path" },
|
||||
{ "hex.builtin.setting.font.font_size", "Font Size" },
|
||||
|
||||
{ "hex.builtin.provider.file.path", "File path" },
|
||||
{ "hex.builtin.provider.file.size", "Size" },
|
||||
|
||||
@@ -58,6 +58,7 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.common.info", "Informazioni" },
|
||||
{ "hex.builtin.common.error", "Errore" },
|
||||
{ "hex.builtin.common.fatal", "Errore Fatale" },
|
||||
//{ "hex.builtin.common.question", "Question" },
|
||||
{ "hex.builtin.common.address", "Indirizzo" },
|
||||
{ "hex.builtin.common.size", "Dimensione" },
|
||||
{ "hex.builtin.common.region", "Regione" },
|
||||
@@ -329,6 +330,7 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.view.pattern_data.value", "Valore" },
|
||||
|
||||
{ "hex.builtin.view.settings.name", "Impostazioni" },
|
||||
//{ "hex.builtin.view.settings.restart_question", "A change you made requires a restart of ImHex to take effect. Would you like to restart it now?" },
|
||||
|
||||
{ "hex.builtin.view.strings.name", "Stringhe" },
|
||||
{ "hex.builtin.view.strings.copy", "Copia stringa" },
|
||||
@@ -673,6 +675,11 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.setting.hex_editor.grey_zeros", "Taglia fuori gli zeri" },
|
||||
{ "hex.builtin.setting.hex_editor.uppercase_hex", "Caratteri esadecimali maiuscoli" },
|
||||
{ "hex.builtin.setting.hex_editor.extra_info", "Mostra informazioni extra" },
|
||||
//{ "hex.builtin.setting.folders", "Folders" },
|
||||
//{ "hex.builtin.setting.folders.description", "Specify additional search paths for patterns, scripts, rules and more" },
|
||||
//{ "hex.builtin.setting.font", "Font" },
|
||||
//{ "hex.builtin.setting.font.font_path", "Custom Font Path" },
|
||||
//{ "hex.builtin.setting.font.font_size", "Font Size" },
|
||||
|
||||
{ "hex.builtin.provider.file.path", "Percorso del File" },
|
||||
{ "hex.builtin.provider.file.size", "Dimensione" },
|
||||
|
||||
@@ -59,6 +59,7 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.common.info", "情報" },
|
||||
{ "hex.builtin.common.error", "エラー" },
|
||||
{ "hex.builtin.common.fatal", "深刻なエラー" },
|
||||
//{ "hex.builtin.common.question", "Question" },
|
||||
{ "hex.builtin.common.address", "アドレス" },
|
||||
{ "hex.builtin.common.size", "サイズ" },
|
||||
{ "hex.builtin.common.region", "住所" },
|
||||
@@ -333,6 +334,7 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.view.pattern_data.value", "値" },
|
||||
|
||||
{ "hex.builtin.view.settings.name", "設定" },
|
||||
//{ "hex.builtin.view.settings.restart_question", "A change you made requires a restart of ImHex to take effect. Would you like to restart it now?" },
|
||||
|
||||
{ "hex.builtin.view.strings.name", "文字列" },
|
||||
{ "hex.builtin.view.strings.copy", "文字列をコピー" },
|
||||
@@ -674,6 +676,11 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.setting.hex_editor.grey_zeros", "ゼロをグレーアウト" },
|
||||
{ "hex.builtin.setting.hex_editor.uppercase_hex", "16進数を大文字表記" },
|
||||
{ "hex.builtin.setting.hex_editor.extra_info", "追加情報を表示" },
|
||||
//{ "hex.builtin.setting.folders", "Folders" },
|
||||
//{ "hex.builtin.setting.folders.description", "Specify additional search paths for patterns, scripts, rules and more" },
|
||||
//{ "hex.builtin.setting.font", "Font" },
|
||||
//{ "hex.builtin.setting.font.font_path", "Custom Font Path" },
|
||||
//{ "hex.builtin.setting.font.font_size", "Font Size" },
|
||||
|
||||
{ "hex.builtin.provider.file.path", "ファイルパス" },
|
||||
{ "hex.builtin.provider.file.size", "サイズ" },
|
||||
|
||||
@@ -59,6 +59,7 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.common.info", "信息" },
|
||||
{ "hex.builtin.common.error", "错误" },
|
||||
{ "hex.builtin.common.fatal", "致命错误" },
|
||||
// { "hex.builtin.common.question", "Question" },
|
||||
{ "hex.builtin.common.address", "地址" },
|
||||
{ "hex.builtin.common.size", "大小" },
|
||||
{ "hex.builtin.common.region", "区域" },
|
||||
@@ -329,6 +330,7 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.view.pattern_data.value", "值" },
|
||||
|
||||
{ "hex.builtin.view.settings.name", "设置" },
|
||||
//{ "hex.builtin.view.settings.restart_question", "A change you made requires a restart of ImHex to take effect. Would you like to restart it now?" },
|
||||
|
||||
{ "hex.builtin.view.strings.name", "字符串" },
|
||||
{ "hex.builtin.view.strings.copy", "复制字符串" },
|
||||
@@ -668,6 +670,11 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.setting.hex_editor.grey_zeros", "显示零字节为灰色" },
|
||||
{ "hex.builtin.setting.hex_editor.uppercase_hex", "大写Hex字符" },
|
||||
{ "hex.builtin.setting.hex_editor.extra_info", "显示额外信息" },
|
||||
//{ "hex.builtin.setting.folders", "Folders" },
|
||||
//{ "hex.builtin.setting.folders.description", "Specify additional search paths for patterns, scripts, rules and more" },
|
||||
//{ "hex.builtin.setting.font", "Font" },
|
||||
//{ "hex.builtin.setting.font.font_path", "Custom Font Path" },
|
||||
//{ "hex.builtin.setting.font.font_size", "Font Size" },
|
||||
|
||||
{ "hex.builtin.provider.file.path", "路径" },
|
||||
{ "hex.builtin.provider.file.size", "大小" },
|
||||
|
||||
Reference in New Issue
Block a user