feat: Added option to randomize window title
This commit is contained in:
parent
02b5df03ab
commit
e8b391c0f6
@ -505,6 +505,7 @@
|
||||
"hex.builtin.setting.interface.fps.native": "Native",
|
||||
"hex.builtin.setting.interface.language": "Language",
|
||||
"hex.builtin.setting.interface.multi_windows": "Enable Multi Window support",
|
||||
"hex.builtin.setting.interface.randomize_window_title": "Use a randomized Window Title",
|
||||
"hex.builtin.setting.interface.scaling_factor": "Scaling",
|
||||
"hex.builtin.setting.interface.scaling.native": "Native",
|
||||
"hex.builtin.setting.interface.scaling.fractional_warning": "The default font does not support fractional scaling. For better results, select a custom font in the 'Font' tab.",
|
||||
|
@ -809,6 +809,8 @@ namespace hex::plugin::builtin {
|
||||
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.interface", "hex.builtin.setting.interface.window", "hex.builtin.setting.interface.use_native_menu_bar", true);
|
||||
#endif
|
||||
|
||||
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.interface", "hex.builtin.setting.interface.window", "hex.builtin.setting.interface.randomize_window_title", false);
|
||||
|
||||
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.interface", "hex.builtin.setting.interface.window", "hex.builtin.setting.interface.restore_window_pos", false);
|
||||
|
||||
ContentRegistry::Settings::add<Widgets::ColorPicker>("hex.builtin.setting.hex_editor", "", "hex.builtin.setting.hex_editor.highlight_color", ImColor(0x80, 0x80, 0xC0, 0x60));
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
#include <random>
|
||||
#include <hex/ui/imgui_imhex_extensions.h>
|
||||
#include <ui/menu_items.hpp>
|
||||
|
||||
@ -94,7 +95,7 @@ namespace hex::plugin::builtin {
|
||||
void drawSidebar(ImVec2 dockSpaceSize, ImVec2 sidebarPos, float sidebarWidth) {
|
||||
static i32 openWindow = -1;
|
||||
u32 index = 0;
|
||||
u32 drawIndex = 0;
|
||||
u32 drawIndex = 1;
|
||||
ImGui::PushID("SideBarWindows");
|
||||
for (const auto &[icon, callback, enabledCallback] : ContentRegistry::Interface::impl::getSidebarItems()) {
|
||||
ImGui::SetCursorPosY(sidebarPos.y + sidebarWidth * drawIndex);
|
||||
@ -589,15 +590,15 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
});
|
||||
|
||||
constexpr static auto DefaultImHexTitle = "ImHex";
|
||||
static std::string s_applicationName = DefaultImHexTitle;
|
||||
|
||||
constexpr static auto ImHexTitle = "ImHex";
|
||||
|
||||
s_windowTitle = ImHexTitle;
|
||||
s_windowTitle = DefaultImHexTitle;
|
||||
|
||||
// Handle updating the window title
|
||||
RequestUpdateWindowTitle::subscribe([] {
|
||||
std::string prefix, postfix;
|
||||
std::string title = ImHexTitle;
|
||||
std::string title = DefaultImHexTitle;
|
||||
|
||||
if (ProjectFile::hasPath()) {
|
||||
// If a project is open, show the project name instead of the file name
|
||||
@ -626,8 +627,10 @@ namespace hex::plugin::builtin {
|
||||
|
||||
auto window = ImHexApi::System::getMainWindowHandle();
|
||||
if (window != nullptr) {
|
||||
if (title != ImHexTitle)
|
||||
title = std::string(ImHexTitle) + " - " + title;
|
||||
if (title != DefaultImHexTitle)
|
||||
title = std::string(DefaultImHexTitle) + " - " + title;
|
||||
|
||||
title = wolv::util::replaceStrings(title, DefaultImHexTitle, s_applicationName);
|
||||
|
||||
glfwSetWindowTitle(window, title.c_str());
|
||||
}
|
||||
@ -644,6 +647,20 @@ namespace hex::plugin::builtin {
|
||||
ContentRegistry::Settings::onChange("hex.builtin.setting.interface", "hex.builtin.setting.interface.use_native_menu_bar", [](const ContentRegistry::Settings::SettingsValue &value) {
|
||||
s_useNativeMenuBar = value.get<bool>(true);
|
||||
});
|
||||
|
||||
ContentRegistry::Settings::onChange("hex.builtin.setting.interface", "hex.builtin.setting.interface.randomize_window_title", [](const ContentRegistry::Settings::SettingsValue &value) {
|
||||
const bool randomTitle = value.get<bool>(false);
|
||||
if (randomTitle) {
|
||||
s_applicationName.clear();
|
||||
std::mt19937_64 rng(std::random_device{}());
|
||||
for (u32 i = 0; i < 24; i += 1) {
|
||||
s_applicationName += char(rng() % ('Z' - 'A' + 1)) + 'A';
|
||||
}
|
||||
} else {
|
||||
s_applicationName = DefaultImHexTitle;
|
||||
}
|
||||
RequestUpdateWindowTitle::post();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user