1
0
mirror of synced 2025-01-11 05:42:15 +01:00

impr: Added better notes to the settings tabs in the pattern editor view

This commit is contained in:
WerWolv 2024-12-23 21:26:22 +01:00
parent a29b502a33
commit 7cc99c6fc9
5 changed files with 69 additions and 55 deletions

View File

@ -295,7 +295,7 @@ namespace ImGuiExt {
bool DimmedIconToggle(const char *icon, bool *v); bool DimmedIconToggle(const char *icon, bool *v);
bool DimmedIconToggle(const char *iconOn, const char *iconOff, bool *v); bool DimmedIconToggle(const char *iconOn, const char *iconOff, bool *v);
void TextOverlay(const char *text, ImVec2 pos); void TextOverlay(const char *text, ImVec2 pos, float maxWidth = -1);
bool BeginBox(); bool BeginBox();
void EndBox(); void EndBox();

View File

@ -1164,8 +1164,8 @@ namespace ImGuiExt {
return toggled; return toggled;
} }
void TextOverlay(const char *text, ImVec2 pos) { void TextOverlay(const char *text, ImVec2 pos, float maxWidth) {
const auto textSize = CalcTextSize(text); const auto textSize = CalcTextSize(text, nullptr, false, maxWidth);
const auto textPos = pos - textSize / 2; const auto textPos = pos - textSize / 2;
const auto margin = GetStyle().FramePadding * 2; const auto margin = GetStyle().FramePadding * 2;
const auto textRect = ImRect(textPos - margin, textPos + textSize + margin); const auto textRect = ImRect(textPos - margin, textPos + textSize + margin);
@ -1174,7 +1174,7 @@ namespace ImGuiExt {
drawList->AddRectFilled(textRect.Min, textRect.Max, GetColorU32(ImGuiCol_WindowBg) | 0xFF000000); drawList->AddRectFilled(textRect.Min, textRect.Max, GetColorU32(ImGuiCol_WindowBg) | 0xFF000000);
drawList->AddRect(textRect.Min, textRect.Max, GetColorU32(ImGuiCol_Border)); drawList->AddRect(textRect.Min, textRect.Max, GetColorU32(ImGuiCol_Border));
drawList->AddText(textPos, GetColorU32(ImGuiCol_Text), text); drawList->AddText(nullptr, 0.0F, textPos, GetColorU32(ImGuiCol_Text), text, nullptr, maxWidth);
} }
bool BeginBox() { bool BeginBox() {

View File

@ -961,6 +961,9 @@
"hex.builtin.view.pattern_editor.menu.replace_all": "Replace All", "hex.builtin.view.pattern_editor.menu.replace_all": "Replace All",
"hex.builtin.view.pattern_editor.name": "Pattern editor", "hex.builtin.view.pattern_editor.name": "Pattern editor",
"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_editor.no_in_out_vars": "Define some global variables with the 'in' or 'out' specifier for them to appear here.",
"hex.builtin.view.pattern_editor.no_sections": "Create additional output sections to display and decode processed data by using the std::mem::create_section function.",
"hex.builtin.view.pattern_editor.no_virtual_files": "Visualize regions of data as a virtual folder structure by adding them using the hex::core::add_virtual_file function.",
"hex.builtin.view.pattern_editor.no_env_vars": "The content of Environment Variables created here can be accessed from Pattern scripts using the std::env function.",
"hex.builtin.view.pattern_editor.no_results": "no results", "hex.builtin.view.pattern_editor.no_results": "no results",
"hex.builtin.view.pattern_editor.of": "of", "hex.builtin.view.pattern_editor.of": "of",
"hex.builtin.view.pattern_editor.open_pattern": "Open pattern", "hex.builtin.view.pattern_editor.open_pattern": "Open pattern",

View File

@ -1094,6 +1094,10 @@ namespace hex::plugin::builtin {
static u32 envVarCounter = 1; static u32 envVarCounter = 1;
if (ImGui::BeginChild("##env_vars", size, true, ImGuiWindowFlags_AlwaysVerticalScrollbar)) { if (ImGui::BeginChild("##env_vars", size, true, ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
if (envVars.size() <= 1) {
ImGuiExt::TextOverlay("hex.builtin.view.pattern_editor.no_env_vars"_lang, ImGui::GetWindowPos() + ImGui::GetWindowSize() / 2, ImGui::GetWindowWidth() * 0.7);
}
if (ImGui::BeginTable("##env_vars_table", 4, ImGuiTableFlags_SizingStretchProp | ImGuiTableFlags_BordersInnerH)) { if (ImGui::BeginTable("##env_vars_table", 4, ImGuiTableFlags_SizingStretchProp | ImGuiTableFlags_BordersInnerH)) {
ImGui::TableSetupColumn("Type", ImGuiTableColumnFlags_WidthStretch, 0.1F); ImGui::TableSetupColumn("Type", ImGuiTableColumnFlags_WidthStretch, 0.1F);
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthStretch, 0.4F); ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthStretch, 0.4F);
@ -1197,63 +1201,63 @@ namespace hex::plugin::builtin {
void ViewPatternEditor::drawVariableSettings(ImVec2 size, std::map<std::string, PatternVariable> &patternVariables) { void ViewPatternEditor::drawVariableSettings(ImVec2 size, std::map<std::string, PatternVariable> &patternVariables) {
if (ImGui::BeginChild("##settings", size, true, ImGuiWindowFlags_AlwaysVerticalScrollbar)) { if (ImGui::BeginChild("##settings", size, true, ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
if (patternVariables.empty()) { if (patternVariables.empty()) {
ImGuiExt::TextFormattedCentered("hex.builtin.view.pattern_editor.no_in_out_vars"_lang); ImGuiExt::TextOverlay("hex.builtin.view.pattern_editor.no_in_out_vars"_lang, ImGui::GetWindowPos() + ImGui::GetWindowSize() / 2, ImGui::GetWindowWidth() * 0.7);
} else { }
if (ImGui::BeginTable("##in_out_vars_table", 2, ImGuiTableFlags_SizingStretchProp | ImGuiTableFlags_BordersInnerH | ImGuiTableFlags_BordersOuterH | ImGuiTableFlags_RowBg)) {
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthStretch, 0.25F);
ImGui::TableSetupColumn("Value", ImGuiTableColumnFlags_WidthStretch, 0.75F);
for (auto &[name, variable] : patternVariables) { if (ImGui::BeginTable("##in_out_vars_table", 2, ImGuiTableFlags_SizingStretchProp | ImGuiTableFlags_BordersInnerH | ImGuiTableFlags_BordersOuterH | ImGuiTableFlags_RowBg)) {
ImGui::TableNextRow(); ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthStretch, 0.25F);
ImGui::TableNextColumn(); ImGui::TableSetupColumn("Value", ImGuiTableColumnFlags_WidthStretch, 0.75F);
ImGui::TextUnformatted(name.c_str()); for (auto &[name, variable] : patternVariables) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::TableNextColumn(); ImGui::TextUnformatted(name.c_str());
ImGui::PushItemWidth(-1); ImGui::TableNextColumn();
if (variable.outVariable) {
ImGuiExt::TextFormattedSelectable("{}", variable.value.toString(true).c_str());
} else if (variable.inVariable) {
const std::string label { "##" + name };
if (pl::core::Token::isSigned(variable.type)) { ImGui::PushItemWidth(-1);
i64 value = hex::get_or<i128>(variable.value, 0); if (variable.outVariable) {
if (ImGui::InputScalar(label.c_str(), ImGuiDataType_S64, &value)) ImGuiExt::TextFormattedSelectable("{}", variable.value.toString(true).c_str());
m_hasUnevaluatedChanges = true; } else if (variable.inVariable) {
variable.value = i128(value); const std::string label { "##" + name };
} else if (pl::core::Token::isUnsigned(variable.type)) {
u64 value = hex::get_or<u128>(variable.value, 0); if (pl::core::Token::isSigned(variable.type)) {
if (ImGui::InputScalar(label.c_str(), ImGuiDataType_U64, &value)) i64 value = hex::get_or<i128>(variable.value, 0);
m_hasUnevaluatedChanges = true; if (ImGui::InputScalar(label.c_str(), ImGuiDataType_S64, &value))
variable.value = u128(value); m_hasUnevaluatedChanges = true;
} else if (pl::core::Token::isFloatingPoint(variable.type)) { variable.value = i128(value);
auto value = hex::get_or<double>(variable.value, 0.0); } else if (pl::core::Token::isUnsigned(variable.type)) {
if (ImGui::InputScalar(label.c_str(), ImGuiDataType_Double, &value)) u64 value = hex::get_or<u128>(variable.value, 0);
m_hasUnevaluatedChanges = true; if (ImGui::InputScalar(label.c_str(), ImGuiDataType_U64, &value))
variable.value = value; m_hasUnevaluatedChanges = true;
} else if (variable.type == pl::core::Token::ValueType::Boolean) { variable.value = u128(value);
auto value = hex::get_or<bool>(variable.value, false); } else if (pl::core::Token::isFloatingPoint(variable.type)) {
if (ImGui::Checkbox(label.c_str(), &value)) auto value = hex::get_or<double>(variable.value, 0.0);
m_hasUnevaluatedChanges = true; if (ImGui::InputScalar(label.c_str(), ImGuiDataType_Double, &value))
variable.value = value; m_hasUnevaluatedChanges = true;
} else if (variable.type == pl::core::Token::ValueType::Character) { variable.value = value;
std::array<char, 2> buffer = { hex::get_or<char>(variable.value, '\x00') }; } else if (variable.type == pl::core::Token::ValueType::Boolean) {
if (ImGui::InputText(label.c_str(), buffer.data(), buffer.size())) auto value = hex::get_or<bool>(variable.value, false);
m_hasUnevaluatedChanges = true; if (ImGui::Checkbox(label.c_str(), &value))
variable.value = buffer[0]; m_hasUnevaluatedChanges = true;
} else if (variable.type == pl::core::Token::ValueType::String) { variable.value = value;
std::string buffer = hex::get_or<std::string>(variable.value, ""); } else if (variable.type == pl::core::Token::ValueType::Character) {
if (ImGui::InputText(label.c_str(), buffer)) std::array<char, 2> buffer = { hex::get_or<char>(variable.value, '\x00') };
m_hasUnevaluatedChanges = true; if (ImGui::InputText(label.c_str(), buffer.data(), buffer.size()))
variable.value = buffer; m_hasUnevaluatedChanges = true;
} variable.value = buffer[0];
} else if (variable.type == pl::core::Token::ValueType::String) {
std::string buffer = hex::get_or<std::string>(variable.value, "");
if (ImGui::InputText(label.c_str(), buffer))
m_hasUnevaluatedChanges = true;
variable.value = buffer;
} }
ImGui::PopItemWidth();
} }
ImGui::PopItemWidth();
ImGui::EndTable();
} }
ImGui::EndTable();
} }
} }
ImGui::EndChild(); ImGui::EndChild();
@ -1270,6 +1274,10 @@ namespace hex::plugin::builtin {
ImGui::TableHeadersRow(); ImGui::TableHeadersRow();
if (sections.empty()) {
ImGuiExt::TextOverlay("hex.builtin.view.pattern_editor.no_sections"_lang, ImGui::GetWindowPos() + ImGui::GetWindowSize() / 2, ImGui::GetWindowWidth() * 0.7);
}
if (TRY_LOCK(ContentRegistry::PatternLanguage::getRuntimeLock())) { if (TRY_LOCK(ContentRegistry::PatternLanguage::getRuntimeLock())) {
for (auto &[id, section] : sections) { for (auto &[id, section] : sections) {
if (section.name.empty()) if (section.name.empty())
@ -1364,6 +1372,10 @@ namespace hex::plugin::builtin {
virtualFilePointers.emplace_back(&file); virtualFilePointers.emplace_back(&file);
if (ImGui::BeginTable("Virtual File Tree", 1, ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersInnerH | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY, size)) { if (ImGui::BeginTable("Virtual File Tree", 1, ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersInnerH | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY, size)) {
if (virtualFiles.empty()) {
ImGuiExt::TextOverlay("hex.builtin.view.pattern_editor.no_virtual_files"_lang, ImGui::GetWindowPos() + ImGui::GetWindowSize() / 2, ImGui::GetWindowWidth() * 0.7);
}
ImGui::TableSetupColumn("##path", ImGuiTableColumnFlags_WidthStretch); ImGui::TableSetupColumn("##path", ImGuiTableColumnFlags_WidthStretch);
levelId = 1; levelId = 1;
drawVirtualFileTree(virtualFilePointers); drawVirtualFileTree(virtualFilePointers);
@ -1376,7 +1388,6 @@ namespace hex::plugin::builtin {
void ViewPatternEditor::drawDebugger(ImVec2 size) { void ViewPatternEditor::drawDebugger(ImVec2 size) {
const auto &runtime = ContentRegistry::PatternLanguage::getRuntime(); const auto &runtime = ContentRegistry::PatternLanguage::getRuntime();
if (ImGui::BeginChild("##debugger", size, true)) { if (ImGui::BeginChild("##debugger", size, true)) {
auto &evaluator = runtime.getInternals().evaluator; auto &evaluator = runtime.getInternals().evaluator;
m_breakpoints = m_textEditor.GetBreakpoints(); m_breakpoints = m_textEditor.GetBreakpoints();

View File

@ -1442,7 +1442,7 @@ namespace hex::ui {
m_jumpToPattern = nullptr; m_jumpToPattern = nullptr;
if (m_favoritesUpdateTask.isRunning()) { if (m_favoritesUpdateTask.isRunning()) {
ImGuiExt::TextOverlay("hex.ui.pattern_drawer.updating"_lang, ImGui::GetWindowPos() + ImGui::GetWindowSize() / 2); ImGuiExt::TextOverlay("hex.ui.pattern_drawer.updating"_lang, ImGui::GetWindowPos() + ImGui::GetWindowSize() / 2, ImGui::GetWindowWidth() * 0.5);
} }
} }