From a66fec489c6d038640120a02cfe3c8716b1429f7 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Mon, 24 Jan 2022 00:46:19 +0100 Subject: [PATCH] ui: Added some hint text for in/out variable tab, improved centered hints --- .../include/hex/ui/imgui_imhex_extensions.h | 14 ++++++++++++++ plugins/builtin/source/content/layouts.cpp | 2 -- .../source/content/views/view_bookmarks.cpp | 7 +------ plugins/builtin/source/lang/de_DE.cpp | 1 + plugins/builtin/source/lang/en_US.cpp | 1 + plugins/builtin/source/lang/it_IT.cpp | 1 + plugins/builtin/source/lang/zh_CN.cpp | 1 + 7 files changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h b/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h index 7ccf04e80..ea37b0003 100644 --- a/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h +++ b/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h @@ -2,7 +2,9 @@ #include +#define IMGUI_DEFINE_MATH_OPERATORS #include +#include #include @@ -105,4 +107,16 @@ namespace ImGui { void TextFormattedWrapped(const std::string &fmt, auto&& ... args) { ImGui::TextWrapped("%s", hex::format(fmt, std::forward(args)...).c_str()); } + + void TextFormattedCentered(const std::string &fmt, auto&& ... args) { + auto text = hex::format(fmt); + auto availableSpace = ImGui::GetContentRegionAvail(); + auto textSize = ImGui::CalcTextSize(text.c_str(), nullptr, false, availableSpace.x * 0.75F); + + ImGui::SetCursorPos(((availableSpace - textSize) / 2.0F)); + + ImGui::PushTextWrapPos(availableSpace.x * 0.75F); + ImGui::TextFormattedWrapped("{}", text); + ImGui::PopTextWrapPos(); + } } \ No newline at end of file diff --git a/plugins/builtin/source/content/layouts.cpp b/plugins/builtin/source/content/layouts.cpp index b4553d17b..a29d6b28e 100644 --- a/plugins/builtin/source/content/layouts.cpp +++ b/plugins/builtin/source/content/layouts.cpp @@ -1,7 +1,5 @@ #include -#include -#include #include namespace hex::plugin::builtin { diff --git a/plugins/builtin/source/content/views/view_bookmarks.cpp b/plugins/builtin/source/content/views/view_bookmarks.cpp index b2e0d7360..e25f2c9bd 100644 --- a/plugins/builtin/source/content/views/view_bookmarks.cpp +++ b/plugins/builtin/source/content/views/view_bookmarks.cpp @@ -57,12 +57,7 @@ namespace hex::plugin::builtin { auto &bookmarks = ImHexApi::Bookmarks::getEntries(); if (bookmarks.empty()) { - std::string text = "hex.builtin.view.bookmarks.no_bookmarks"_lang; - auto textSize = ImGui::CalcTextSize(text.c_str()); - auto availableSpace = ImGui::GetContentRegionAvail(); - - ImGui::SetCursorPos((availableSpace - textSize) / 2.0F); - ImGui::TextUnformatted(text.c_str()); + ImGui::TextFormattedCentered("hex.builtin.view.bookmarks.no_bookmarks"_lang); } u32 id = 1; diff --git a/plugins/builtin/source/lang/de_DE.cpp b/plugins/builtin/source/lang/de_DE.cpp index 7f8872cd2..b4091b276 100644 --- a/plugins/builtin/source/lang/de_DE.cpp +++ b/plugins/builtin/source/lang/de_DE.cpp @@ -290,6 +290,7 @@ namespace hex::plugin::builtin { { "hex.builtin.view.pattern_editor.settings", "Einstellungen" }, { "hex.builtin.view.pattern_editor.dangerous_function.name", "Gefährliche funktion erlauben?" }, { "hex.builtin.view.pattern_editor.dangerous_function.desc", "Dieses Pattern hat versucht eine gefährliche Funktion aufzurufen.\nBist du sicher, dass du diesem Pattern vertraust?" }, + { "hex.builtin.view.pattern_editor.no_in_out_vars", "Definiere einige globale Variablen mit dem 'in' oder 'out' specifier damit diese hier auftauchen." }, { "hex.builtin.view.pattern_data.name", "Pattern Daten" }, { "hex.builtin.view.pattern_data.var_name", "Name" }, diff --git a/plugins/builtin/source/lang/en_US.cpp b/plugins/builtin/source/lang/en_US.cpp index 18f932423..006cac2c6 100644 --- a/plugins/builtin/source/lang/en_US.cpp +++ b/plugins/builtin/source/lang/en_US.cpp @@ -293,6 +293,7 @@ namespace hex::plugin::builtin { { "hex.builtin.view.pattern_editor.settings", "Settings" }, { "hex.builtin.view.pattern_editor.dangerous_function.name", "Allow dangerous function?" }, { "hex.builtin.view.pattern_editor.dangerous_function.desc", "This pattern tried to call a dangerous function.\nAre you sure you want to trust this pattern?" }, + { "hex.builtin.view.pattern_editor.no_in_out_vars", "Define some global variables with the 'in' or 'out' specifier for them to appear here." }, { "hex.builtin.view.pattern_data.name", "Pattern Data" }, { "hex.builtin.view.pattern_data.var_name", "Name" }, diff --git a/plugins/builtin/source/lang/it_IT.cpp b/plugins/builtin/source/lang/it_IT.cpp index 1d12aaa1b..080d62792 100644 --- a/plugins/builtin/source/lang/it_IT.cpp +++ b/plugins/builtin/source/lang/it_IT.cpp @@ -290,6 +290,7 @@ namespace hex::plugin::builtin { //{ "hex.builtin.view.pattern_editor.settings", "Settings" }, //{ "hex.builtin.view.pattern_editor.dangerous_function.name", "Allow dangerous function?" }, //{ "hex.builtin.view.pattern_editor.dangerous_function.desc", "This pattern tried to call a dangerous function.\nAre you sure you want to trust this pattern?" }, + //{ "hex.builtin.view.pattern_editor.no_in_out_vars", "Define some global variables with the 'in' or 'out' specifier for them to appear here." }, { "hex.builtin.view.pattern_data.name", "Dati dei Pattern" }, { "hex.builtin.view.pattern_data.var_name", "Nome" }, diff --git a/plugins/builtin/source/lang/zh_CN.cpp b/plugins/builtin/source/lang/zh_CN.cpp index 74dd4adb1..eed07aa59 100644 --- a/plugins/builtin/source/lang/zh_CN.cpp +++ b/plugins/builtin/source/lang/zh_CN.cpp @@ -289,6 +289,7 @@ namespace hex::plugin::builtin { //{ "hex.builtin.view.pattern_editor.settings", "Settings" }, //{ "hex.builtin.view.pattern_editor.dangerous_function.name", "Allow dangerous function?" }, //{ "hex.builtin.view.pattern_editor.dangerous_function.desc", "This pattern tried to call a dangerous function.\nAre you sure you want to trust this pattern?" }, + //{ "hex.builtin.view.pattern_editor.no_in_out_vars", "Define some global variables with the 'in' or 'out' specifier for them to appear here." }, { "hex.builtin.view.pattern_data.name", "模式数据" }, { "hex.builtin.view.pattern_data.var_name", "名称" },