ui: Added functionality icons to most text input fields
This commit is contained in:
parent
f8b4d04713
commit
814c595c12
@ -139,6 +139,7 @@ namespace ImGui {
|
||||
}
|
||||
|
||||
bool InputText(const char* label, std::string &buffer, ImGuiInputTextFlags flags = ImGuiInputTextFlags_None);
|
||||
bool InputTextIcon(const char* label, const char *icon, std::string &buffer, ImGuiInputTextFlags flags = ImGuiInputTextFlags_None);
|
||||
bool InputText(const char *label, std::u8string &buffer, ImGuiInputTextFlags flags = ImGuiInputTextFlags_None);
|
||||
bool InputTextMultiline(const char* label, std::string &buffer, const ImVec2& size = ImVec2(0, 0), ImGuiInputTextFlags flags = ImGuiInputTextFlags_None);
|
||||
bool InputTextWithHint(const char *label, const char *hint, std::string &buffer, ImGuiInputTextFlags flags = ImGuiInputTextFlags_None);
|
||||
|
@ -563,6 +563,33 @@ namespace ImGui {
|
||||
return ImGui::InputText(label, buffer.data(), buffer.size() + 1, ImGuiInputTextFlags_CallbackResize | flags, ImGui::UpdateStringSizeCallback, &buffer);
|
||||
}
|
||||
|
||||
bool InputTextIcon(const char *label, const char *icon, std::string &buffer, ImGuiInputTextFlags flags) {
|
||||
auto window = ImGui::GetCurrentWindow();
|
||||
const ImGuiID id = window->GetID(label);
|
||||
const ImGuiStyle &style = GImGui->Style;
|
||||
|
||||
|
||||
const ImVec2 label_size = CalcTextSize(label, nullptr, true);
|
||||
const ImVec2 icon_frame_size = CalcTextSize(icon) + style.FramePadding * 2.0f;
|
||||
const ImVec2 frame_size = CalcItemSize(ImVec2(0, 0), icon_frame_size.x, label_size.y + style.FramePadding.y * 2.0f);
|
||||
const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + frame_size);
|
||||
|
||||
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + frame_size.x);
|
||||
|
||||
bool value_changed = ImGui::InputTextEx(label, nullptr, buffer.data(), buffer.size() + 1, ImVec2(CalcItemWidth() - frame_size.x, label_size.y + style.FramePadding.y * 2.0f), ImGuiInputTextFlags_CallbackResize | flags, ImGui::UpdateStringSizeCallback, &buffer);
|
||||
|
||||
if (value_changed)
|
||||
MarkItemEdited(GImGui->LastItemData.ID);
|
||||
|
||||
RenderNavHighlight(frame_bb, id);
|
||||
RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding);
|
||||
|
||||
RenderFrame(frame_bb.Min, frame_bb.Min + icon_frame_size, GetColorU32(ImGuiCol_TableBorderStrong), true, style.FrameRounding);
|
||||
RenderText(ImVec2(frame_bb.Min.x + style.FramePadding.x, frame_bb.Min.y + style.FramePadding.y * 2), icon);
|
||||
|
||||
return value_changed;
|
||||
}
|
||||
|
||||
bool InputTextWithHint(const char *label, const char *hint, std::string &buffer, ImGuiInputTextFlags flags) {
|
||||
return ImGui::InputTextWithHint(label, hint, buffer.data(), buffer.size() + 1, ImGuiInputTextFlags_CallbackResize | flags, ImGui::UpdateStringSizeCallback, &buffer);
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <imgui.h>
|
||||
#include <implot.h>
|
||||
#include <hex/ui/imgui_imhex_extensions.h>
|
||||
#include <fonts/codicons_font.h>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
@ -66,22 +67,17 @@ namespace hex::plugin::builtin {
|
||||
class NodeString : public dp::Node {
|
||||
public:
|
||||
NodeString() : Node("hex.builtin.nodes.constants.string.header", { dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "") }) {
|
||||
this->m_value.resize(0xFFF, 0x00);
|
||||
|
||||
}
|
||||
|
||||
void drawNode() override {
|
||||
ImGui::PushItemWidth(100);
|
||||
ImGui::InputText("##string", reinterpret_cast<char *>(this->m_value.data()), this->m_value.size() - 1);
|
||||
ImGui::InputTextIcon("##string", ICON_VS_SYMBOL_KEY, this->m_value);
|
||||
ImGui::PopItemWidth();
|
||||
}
|
||||
|
||||
void process() override {
|
||||
std::vector<u8> output(std::strlen(this->m_value.c_str()) + 1, 0x00);
|
||||
std::strcpy(reinterpret_cast<char *>(output.data()), this->m_value.c_str());
|
||||
|
||||
output.pop_back();
|
||||
|
||||
this->setBufferOnOutput(0, output);
|
||||
this->setBufferOnOutput(0, { this->m_value.begin(), this->m_value.end() });
|
||||
}
|
||||
|
||||
void store(nlohmann::json &j) override {
|
||||
|
@ -113,8 +113,8 @@ namespace hex::plugin::builtin {
|
||||
static auto replacePattern = [] { std::string s; s.reserve(0xFFF); return s; }();
|
||||
static auto regexOutput = [] { std::string s; s.reserve(0xFFF); return s; }();
|
||||
|
||||
bool changed1 = ImGui::InputText("hex.builtin.tools.regex_replacer.pattern"_lang, regexPattern);
|
||||
bool changed2 = ImGui::InputText("hex.builtin.tools.regex_replacer.replace"_lang, replacePattern);
|
||||
bool changed1 = ImGui::InputTextIcon("hex.builtin.tools.regex_replacer.pattern"_lang, ICON_VS_REGEX, regexPattern);
|
||||
bool changed2 = ImGui::InputTextIcon("hex.builtin.tools.regex_replacer.replace"_lang, ICON_VS_REGEX, replacePattern);
|
||||
bool changed3 = ImGui::InputTextMultiline("hex.builtin.tools.regex_replacer.input"_lang, regexInput, ImVec2(0, 0));
|
||||
|
||||
if (changed1 || changed2 || changed3) {
|
||||
@ -420,7 +420,7 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
|
||||
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x);
|
||||
if (ImGui::InputText("##input", mathInput, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll)) {
|
||||
if (ImGui::InputTextIcon("##input", ICON_VS_SYMBOL_OPERATOR, mathInput, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll)) {
|
||||
ImGui::SetKeyboardFocusHere();
|
||||
evaluate = true;
|
||||
}
|
||||
@ -448,75 +448,45 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
|
||||
void drawBaseConverter() {
|
||||
static char buffer[4][0x1000] = { { '0' }, { '0' }, { '0' }, { '0' } };
|
||||
|
||||
static auto CharFilter = [](ImGuiInputTextCallbackData *data) -> int {
|
||||
switch (*static_cast<u32 *>(data->UserData)) {
|
||||
case 16:
|
||||
return std::isxdigit(data->EventChar);
|
||||
case 10:
|
||||
return std::isdigit(data->EventChar);
|
||||
case 8:
|
||||
return std::isdigit(data->EventChar) && data->EventChar < '8';
|
||||
case 2:
|
||||
return data->EventChar == '0' || data->EventChar == '1';
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
};
|
||||
static std::array<std::string, 4> buffers;
|
||||
|
||||
static auto ConvertBases = [](u8 base) {
|
||||
u64 number;
|
||||
|
||||
errno = 0;
|
||||
switch (base) {
|
||||
case 16:
|
||||
number = std::strtoull(buffer[1], nullptr, base);
|
||||
number = std::strtoull(buffers[1].c_str(), nullptr, base);
|
||||
break;
|
||||
case 10:
|
||||
number = std::strtoull(buffer[0], nullptr, base);
|
||||
number = std::strtoull(buffers[0].c_str(), nullptr, base);
|
||||
break;
|
||||
case 8:
|
||||
number = std::strtoull(buffer[2], nullptr, base);
|
||||
number = std::strtoull(buffers[2].c_str(), nullptr, base);
|
||||
break;
|
||||
case 2:
|
||||
number = std::strtoull(buffer[3], nullptr, base);
|
||||
number = std::strtoull(buffers[3].c_str(), nullptr, base);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
auto base10String = std::to_string(number);
|
||||
auto base16String = hex::format("0x{0:X}", number);
|
||||
auto base8String = hex::format("{0:#o}", number);
|
||||
auto base2String = hex::toBinaryString(number);
|
||||
|
||||
std::strncpy(buffer[0], base10String.c_str(), sizeof(buffer[0]) - 1);
|
||||
std::strncpy(buffer[1], base16String.c_str(), sizeof(buffer[1]) - 1);
|
||||
std::strncpy(buffer[2], base8String.c_str(), sizeof(buffer[2]) - 1);
|
||||
std::strncpy(buffer[3], base2String.c_str(), sizeof(buffer[3]) - 1);
|
||||
|
||||
buffer[0][0xFFF] = '\x00';
|
||||
buffer[1][0xFFF] = '\x00';
|
||||
buffer[2][0xFFF] = '\x00';
|
||||
buffer[3][0xFFF] = '\x00';
|
||||
buffers[0] = std::to_string(number);
|
||||
buffers[1] = hex::format("0x{0:X}", number);
|
||||
buffers[2] = hex::format("{0:#o}", number);
|
||||
buffers[3] = hex::toBinaryString(number);
|
||||
};
|
||||
|
||||
u8 base = 10;
|
||||
if (ImGui::InputText("hex.builtin.tools.base_converter.dec"_lang, buffer[0], 20 + 1, ImGuiInputTextFlags_CallbackCharFilter, CharFilter, &base))
|
||||
ConvertBases(base);
|
||||
if (ImGui::InputTextIcon("hex.builtin.tools.base_converter.dec"_lang, ICON_VS_SYMBOL_NUMERIC, buffers[0]))
|
||||
ConvertBases(10);
|
||||
|
||||
base = 16;
|
||||
if (ImGui::InputText("hex.builtin.tools.base_converter.hex"_lang, buffer[1], 16 + 1, ImGuiInputTextFlags_CallbackCharFilter, CharFilter, &base))
|
||||
ConvertBases(base);
|
||||
if (ImGui::InputTextIcon("hex.builtin.tools.base_converter.hex"_lang, ICON_VS_SYMBOL_NUMERIC, buffers[1]))
|
||||
ConvertBases(16);
|
||||
|
||||
base = 8;
|
||||
if (ImGui::InputText("hex.builtin.tools.base_converter.oct"_lang, buffer[2], 22 + 1, ImGuiInputTextFlags_CallbackCharFilter, CharFilter, &base))
|
||||
ConvertBases(base);
|
||||
if (ImGui::InputTextIcon("hex.builtin.tools.base_converter.oct"_lang, ICON_VS_SYMBOL_NUMERIC, buffers[2]))
|
||||
ConvertBases(8);
|
||||
|
||||
base = 2;
|
||||
if (ImGui::InputText("hex.builtin.tools.base_converter.bin"_lang, buffer[3], 64 + 1, ImGuiInputTextFlags_CallbackCharFilter, CharFilter, &base))
|
||||
ConvertBases(base);
|
||||
if (ImGui::InputTextIcon("hex.builtin.tools.base_converter.bin"_lang, ICON_VS_SYMBOL_NUMERIC, buffers[3]))
|
||||
ConvertBases(2);
|
||||
}
|
||||
|
||||
void drawPermissionsCalculator() {
|
||||
@ -691,7 +661,7 @@ namespace hex::plugin::builtin {
|
||||
|
||||
bool startSearch;
|
||||
|
||||
startSearch = ImGui::InputText("##search", searchString, ImGuiInputTextFlags_EnterReturnsTrue);
|
||||
startSearch = ImGui::InputTextIcon("##search", ICON_VS_SYMBOL_KEY, searchString, ImGuiInputTextFlags_EnterReturnsTrue);
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::BeginDisabled((searchProcess.valid() && searchProcess.wait_for(0s) != std::future_status::ready) || searchString.empty());
|
||||
|
@ -602,7 +602,7 @@ namespace hex::plugin::builtin {
|
||||
|
||||
mode = SearchSettings::Mode::Sequence;
|
||||
|
||||
ImGui::InputText("hex.builtin.common.value"_lang, settings.sequence);
|
||||
ImGui::InputTextIcon("hex.builtin.common.value"_lang, ICON_VS_SYMBOL_KEY, settings.sequence);
|
||||
|
||||
this->m_settingsValid = !settings.sequence.empty() && !hex::decodeByteString(settings.sequence).empty();
|
||||
|
||||
@ -613,7 +613,7 @@ namespace hex::plugin::builtin {
|
||||
|
||||
mode = SearchSettings::Mode::Regex;
|
||||
|
||||
ImGui::InputText("hex.builtin.view.find.regex.pattern"_lang, settings.pattern);
|
||||
ImGui::InputTextIcon("hex.builtin.view.find.regex.pattern"_lang, ICON_VS_REGEX, settings.pattern);
|
||||
|
||||
try {
|
||||
std::regex regex(settings.pattern);
|
||||
@ -634,7 +634,7 @@ namespace hex::plugin::builtin {
|
||||
|
||||
mode = SearchSettings::Mode::BinaryPattern;
|
||||
|
||||
ImGui::InputText("hex.builtin.view.find.binary_pattern"_lang, settings.input);
|
||||
ImGui::InputTextIcon("hex.builtin.view.find.binary_pattern"_lang, ICON_VS_SYMBOL_NAMESPACE, settings.input);
|
||||
|
||||
settings.pattern = parseBinaryPatternString(settings.input);
|
||||
this->m_settingsValid = !settings.pattern.empty();
|
||||
@ -648,8 +648,8 @@ namespace hex::plugin::builtin {
|
||||
|
||||
bool edited = false;
|
||||
|
||||
if (ImGui::InputText("hex.builtin.view.find.value.min"_lang, settings.inputMin)) edited = true;
|
||||
if (ImGui::InputText("hex.builtin.view.find.value.max"_lang, settings.inputMax)) edited = true;
|
||||
if (ImGui::InputTextIcon("hex.builtin.view.find.value.min"_lang, ICON_VS_SYMBOL_NUMERIC, settings.inputMin)) edited = true;
|
||||
if (ImGui::InputTextIcon("hex.builtin.view.find.value.max"_lang, ICON_VS_SYMBOL_NUMERIC, settings.inputMax)) edited = true;
|
||||
|
||||
const std::array<std::string, 10> InputTypes = {
|
||||
"hex.builtin.common.type.u8"_lang,
|
||||
|
@ -100,7 +100,7 @@ namespace hex::plugin::builtin {
|
||||
|
||||
ImGui::NewLine();
|
||||
|
||||
ImGui::InputText("##Name", this->m_newHashName);
|
||||
ImGui::InputTextIcon("##hash_name", ICON_VS_SYMBOL_KEY, this->m_newHashName);
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::BeginDisabled(this->m_newHashName.empty() || this->m_selectedHash == nullptr);
|
||||
|
@ -44,7 +44,7 @@ namespace hex::plugin::builtin {
|
||||
|
||||
ImGui::SetKeyboardFocusHere();
|
||||
ImGui::SetNextFrameWantCaptureKeyboard(true);
|
||||
if (ImGui::InputText("##input", this->m_input, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll)) {
|
||||
if (ImGui::InputTextIcon("##input", ICON_VS_SYMBOL_OPERATOR, this->m_input, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll)) {
|
||||
if (auto result = this->m_evaluator.evaluate(this->m_input); result.has_value()) {
|
||||
const auto inputResult = result.value();
|
||||
u64 newAddress = 0x00;
|
||||
@ -160,7 +160,7 @@ namespace hex::plugin::builtin {
|
||||
ImGui::TextUnformatted("hex.builtin.view.hex_editor.menu.file.search"_lang);
|
||||
if (ImGui::BeginTabBar("##find_tabs")) {
|
||||
if (ImGui::BeginTabItem("hex.builtin.view.hex_editor.search.hex"_lang)) {
|
||||
if (ImGui::InputText("##input", this->m_input, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_CharsHexadecimal)) {
|
||||
if (ImGui::InputTextIcon("##input", ICON_VS_SYMBOL_NUMERIC, this->m_input, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_CharsHexadecimal)) {
|
||||
if (!this->m_input.empty()) {
|
||||
this->m_shouldSearch = true;
|
||||
this->m_backwards = false;
|
||||
@ -177,7 +177,7 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
|
||||
if (ImGui::BeginTabItem("hex.builtin.view.hex_editor.search.string"_lang)) {
|
||||
if (ImGui::InputText("##input", this->m_input, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll)) {
|
||||
if (ImGui::InputTextIcon("##input", ICON_VS_SYMBOL_KEY, this->m_input, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll)) {
|
||||
if (!this->m_input.empty()) {
|
||||
this->m_shouldSearch = true;
|
||||
this->m_backwards = false;
|
||||
|
Loading…
Reference in New Issue
Block a user