impr: Code style improvements

This commit is contained in:
WerWolv
2023-12-27 16:33:49 +01:00
parent ec45d1f564
commit 74b5c93caf
64 changed files with 267 additions and 277 deletions

View File

@@ -53,14 +53,14 @@ namespace hex::plugin::builtin {
// Determine achievement fill color based on unlock state
const auto fillColor = [&] {
if (achievement.isUnlocked())
if (achievement.isUnlocked()) {
return ImGui::GetColorU32(ImGuiCol_FrameBg, 1.0F) | 0xFF000000;
else if (node->isUnlockable()) {
} else if (node->isUnlockable()) {
auto cycleProgress = sinf(float(ImGui::GetTime()) * 6.0F) * 0.5F + 0.5F;
return (u32(ImColor(ImLerp(ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled), ImGui::GetStyleColorVec4(ImGuiCol_Text), cycleProgress))) & 0x00FFFFFF) | 0x80000000;
}
else
} else {
return ImGui::GetColorU32(ImGuiCol_TextDisabled, 0.5F);
}
}();
// Draw achievement background

View File

@@ -141,7 +141,7 @@ namespace hex::plugin::builtin {
ProjectFile::registerPerProviderHandler({
.basePath = "bookmarks.json",
.required = false,
.load = [this](prv::Provider *provider, const std::fs::path &basePath, Tar &tar) -> bool {
.load = [this](prv::Provider *provider, const std::fs::path &basePath, const Tar &tar) -> bool {
auto fileContent = tar.readString(basePath);
if (fileContent.empty())
return true;
@@ -150,7 +150,7 @@ namespace hex::plugin::builtin {
m_bookmarks.get(provider).clear();
return this->importBookmarks(provider, data);
},
.store = [this](prv::Provider *provider, const std::fs::path &basePath, Tar &tar) -> bool {
.store = [this](prv::Provider *provider, const std::fs::path &basePath, const Tar &tar) -> bool {
nlohmann::json data;
bool result = this->exportBookmarks(provider, data);
@@ -194,7 +194,7 @@ namespace hex::plugin::builtin {
static void drawColorPopup(ImColor &color) {
// Generate color picker palette
static auto Palette = [] {
const static auto Palette = [] {
constexpr static auto ColorCount = 36;
std::array<ImColor, ColorCount> result = { 0 };
@@ -212,7 +212,7 @@ namespace hex::plugin::builtin {
bool colorChanged = false;
// Draw default color picker
if (ImGui::ColorPicker4("##picker", (float*)&color, ImGuiColorEditFlags_NoSidePreview | ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoOptions | ImGuiColorEditFlags_NoSmallPreview))
if (ImGui::ColorPicker4("##picker", &color.Value.x, ImGuiColorEditFlags_NoSidePreview | ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoOptions | ImGuiColorEditFlags_NoSmallPreview))
colorChanged = true;
ImGui::Separator();
@@ -343,9 +343,9 @@ namespace hex::plugin::builtin {
ImGui::SameLine();
// Draw bookmark name if the bookmark is locked or an input text box if it's unlocked
if (locked)
if (locked) {
ImGui::TextUnformatted(name.data());
else {
} else {
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x);
ImGui::InputText("##nameInput", name);
ImGui::PopItemWidth();

View File

@@ -164,9 +164,9 @@ namespace hex::plugin::builtin {
// These commands are used by entering a single symbol and then any input
if (auto [match, value] = MatchCommand(input, command); match != MatchType::NoMatch) {
if (match != MatchType::PerfectMatch)
if (match != MatchType::PerfectMatch) {
results.push_back({ command + " (" + Lang(unlocalizedDescription) + ")", "", AutoComplete });
else {
} else {
auto matchedCommand = wolv::util::trim(input.substr(command.length()));
results.push_back({ displayCallback(matchedCommand), matchedCommand, executeCallback });
}
@@ -176,9 +176,9 @@ namespace hex::plugin::builtin {
// These commands are used by entering a keyword followed by a space and then any input
if (auto [match, value] = MatchCommand(input, command + " "); match != MatchType::NoMatch) {
if (match != MatchType::PerfectMatch)
if (match != MatchType::PerfectMatch) {
results.push_back({ command + " (" + Lang(unlocalizedDescription) + ")", "", AutoComplete });
else {
} else {
auto matchedCommand = wolv::util::trim(input.substr(command.length() + 1));
results.push_back({ displayCallback(matchedCommand), matchedCommand, executeCallback });
}

View File

@@ -213,9 +213,10 @@ namespace hex::plugin::builtin {
// Find the index of an attribute by its id
auto indexFromId = [this](u32 id) -> std::optional<u32> {
const auto &attributes = this->getAttributes();
for (u32 i = 0; i < attributes.size(); i++)
for (u32 i = 0; i < attributes.size(); i++) {
if (u32(attributes[i].getId()) == id)
return i;
}
return std::nullopt;
};
@@ -355,7 +356,7 @@ namespace hex::plugin::builtin {
ProjectFile::registerPerProviderHandler({
.basePath = "data_processor.json",
.required = false,
.load = [this](prv::Provider *provider, const std::fs::path &basePath, Tar &tar) {
.load = [this](prv::Provider *provider, const std::fs::path &basePath, const Tar &tar) {
std::string save = tar.readString(basePath);
ViewDataProcessor::loadNodes(m_mainWorkspace.get(provider), nlohmann::json::parse(save));
@@ -363,7 +364,7 @@ namespace hex::plugin::builtin {
return true;
},
.store = [this](prv::Provider *provider, const std::fs::path &basePath, Tar &tar) {
.store = [this](prv::Provider *provider, const std::fs::path &basePath, const Tar &tar) {
tar.writeString(basePath, ViewDataProcessor::saveNodes(m_mainWorkspace.get(provider)).dump(4));
return true;
@@ -599,11 +600,11 @@ namespace hex::plugin::builtin {
// Show a different context menu depending on if a node, a link
// or the background was right-clicked
if (ImNodes::IsNodeHovered(&m_rightClickedId))
if (ImNodes::IsNodeHovered(&m_rightClickedId)) {
ImGui::OpenPopup("Node Menu");
else if (ImNodes::IsLinkHovered(&m_rightClickedId))
} else if (ImNodes::IsLinkHovered(&m_rightClickedId)) {
ImGui::OpenPopup("Link Menu");
else {
} else {
ImGui::OpenPopup("Context Menu");
this->reloadCustomNodes();
}

View File

@@ -264,7 +264,7 @@ namespace hex::plugin::builtin {
return { };
std::vector<u8> bytes;
Occurrence::DecodeType decodeType = Occurrence::DecodeType::Binary;
auto decodeType = Occurrence::DecodeType::Binary;
std::endian endian;
switch (settings.type) {
default:
@@ -494,11 +494,11 @@ namespace hex::plugin::builtin {
void ViewFind::runSearch() {
Region searchRegion = m_searchSettings.region;
if (m_searchSettings.mode == SearchSettings::Mode::Strings)
if (m_searchSettings.mode == SearchSettings::Mode::Strings) {
AchievementManager::unlockAchievement("hex.builtin.achievement.find", "hex.builtin.achievement.find.find_strings.name");
else if (m_searchSettings.mode == SearchSettings::Mode::Sequence)
} else if (m_searchSettings.mode == SearchSettings::Mode::Sequence) {
AchievementManager::unlockAchievement("hex.builtin.achievement.find", "hex.builtin.achievement.find.find_specific_string.name");
else if (m_searchSettings.mode == SearchSettings::Mode::Value) {
} else if (m_searchSettings.mode == SearchSettings::Mode::Value) {
if (m_searchSettings.value.inputMin == "250" && m_searchSettings.value.inputMax == "1000")
AchievementManager::unlockAchievement("hex.builtin.achievement.find", "hex.builtin.achievement.find.find_numeric.name");
}

View File

@@ -1013,7 +1013,7 @@ namespace hex::plugin::builtin {
ProjectFile::registerPerProviderHandler({
.basePath = "custom_encoding.tbl",
.required = false,
.load = [this](prv::Provider *, const std::fs::path &basePath, Tar &tar) {
.load = [this](prv::Provider *, const std::fs::path &basePath, const Tar &tar) {
if (!tar.contains(basePath))
return true;
@@ -1023,7 +1023,7 @@ namespace hex::plugin::builtin {
return true;
},
.store = [this](prv::Provider *, const std::fs::path &basePath, Tar &tar) {
.store = [this](prv::Provider *, const std::fs::path &basePath, const Tar &tar) {
if (const auto &encoding = m_hexEditor.getCustomEncoding(); encoding.has_value()) {
auto content = encoding->getTableContent();

View File

@@ -115,7 +115,7 @@ namespace hex::plugin::builtin {
ProjectFile::registerPerProviderHandler({
.basePath = "highlight_rules.json",
.required = false,
.load = [this](prv::Provider *provider, const std::fs::path &basePath, Tar &tar) -> bool {
.load = [this](prv::Provider *provider, const std::fs::path &basePath, const Tar &tar) -> bool {
const auto json = nlohmann::json::parse(tar.readString(basePath));
auto &rules = m_rules.get(provider);
@@ -138,7 +138,7 @@ namespace hex::plugin::builtin {
return true;
},
.store = [this](prv::Provider *provider, const std::fs::path &basePath, Tar &tar) -> bool {
.store = [this](prv::Provider *provider, const std::fs::path &basePath, const Tar &tar) -> bool {
nlohmann::json result = nlohmann::json::array();
for (const auto &rule : m_rules.get(provider)) {
nlohmann::json content;

View File

@@ -292,9 +292,9 @@ namespace hex::plugin::builtin {
ImGui::TableNextColumn();
ImGuiExt::TextFormatted("{}", "hex.builtin.view.information.file_entropy"_lang);
ImGui::TableNextColumn();
if (m_averageEntropy < 0)
if (m_averageEntropy < 0) {
ImGui::TextUnformatted("???");
else {
} else {
auto entropy = std::abs(m_averageEntropy);
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.1F);
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImGui::GetColorU32(ImGuiCol_TableRowBgAlt));
@@ -333,9 +333,9 @@ namespace hex::plugin::builtin {
ImGui::TableNextColumn();
ImGuiExt::TextFormatted("{}", "hex.builtin.view.information.plain_text_percentage"_lang);
ImGui::TableNextColumn();
if (m_plainTextCharacterPercentage < 0)
if (m_plainTextCharacterPercentage < 0) {
ImGui::TextUnformatted("???");
else {
} else {
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.1F);
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImGui::GetColorU32(ImGuiCol_TableRowBgAlt));
ImGui::PushStyleColor(ImGuiCol_PlotHistogram, ImColor::HSV(0.3F * (m_plainTextCharacterPercentage / 100.0F), 0.8F, 0.6F, 1.0F).Value);

View File

@@ -21,7 +21,7 @@ namespace hex::plugin::builtin {
ProjectFile::registerPerProviderHandler({
.basePath = "patches.json",
.required = false,
.load = [](prv::Provider *provider, const std::fs::path &basePath, Tar &tar) {
.load = [](prv::Provider *provider, const std::fs::path &basePath, const Tar &tar) {
auto json = nlohmann::json::parse(tar.readString(basePath));
auto patches = json.at("patches").get<std::map<u64, u8>>();

View File

@@ -1,7 +1,6 @@
#include <content/views/view_pattern_data.hpp>
#include <hex/api/content_registry.hpp>
#include <hex/providers/provider.hpp>
#include <pl/patterns/pattern.hpp>
#include <wolv/utils/lock.hpp>

View File

@@ -68,12 +68,13 @@ namespace hex::plugin::builtin {
paletteIndex = TextEditor::PaletteIndex::Default;
} else if (TokenizeCStyleIdentifier(inBegin, inEnd, outBegin, outEnd)) {
paletteIndex = TextEditor::PaletteIndex::Identifier;
} else if (TokenizeCStyleNumber(inBegin, inEnd, outBegin, outEnd))
} else if (TokenizeCStyleNumber(inBegin, inEnd, outBegin, outEnd)) {
paletteIndex = TextEditor::PaletteIndex::Number;
else if (TokenizeCStyleCharacterLiteral(inBegin, inEnd, outBegin, outEnd))
} else if (TokenizeCStyleCharacterLiteral(inBegin, inEnd, outBegin, outEnd)) {
paletteIndex = TextEditor::PaletteIndex::CharLiteral;
else if (TokenizeCStyleString(inBegin, inEnd, outBegin, outEnd))
} else if (TokenizeCStyleString(inBegin, inEnd, outBegin, outEnd)) {
paletteIndex = TextEditor::PaletteIndex::String;
}
return paletteIndex != TextEditor::PaletteIndex::Max;
};
@@ -625,9 +626,9 @@ namespace hex::plugin::builtin {
});
const auto &patterns = [&, this] -> const auto& {
if (patternProvider->isReadable() && *m_executionDone)
if (patternProvider->isReadable() && *m_executionDone) {
return runtime.getPatterns(id);
else {
} else {
static const std::vector<std::shared_ptr<pl::ptrn::Pattern>> empty;
return empty;
}
@@ -1150,9 +1151,9 @@ namespace hex::plugin::builtin {
if (newProvider != nullptr) {
m_consoleEditor.SetTextLines(m_console.get(newProvider));
m_textEditor.SetText(wolv::util::trim(m_sourceCode.get(newProvider)));
}
else
} else {
m_textEditor.SetText("");
}
} else {
m_hasUnevaluatedChanges = true;
}
@@ -1252,16 +1253,18 @@ namespace hex::plugin::builtin {
[&, this] {
if (ImGui::BeginMenu("hex.builtin.view.pattern_editor.menu.edit.place_pattern.builtin"_lang)) {
if (ImGui::BeginMenu("hex.builtin.view.pattern_editor.menu.edit.place_pattern.builtin.single"_lang)) {
for (const auto &[type, size] : Types)
for (const auto &[type, size] : Types) {
if (ImGui::MenuItem(type))
appendVariable(type);
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("hex.builtin.view.pattern_editor.menu.edit.place_pattern.builtin.array"_lang)) {
for (const auto &[type, size] : Types)
for (const auto &[type, size] : Types) {
if (ImGui::MenuItem(type))
appendArray(type, size);
}
ImGui::EndMenu();
}
@@ -1366,7 +1369,7 @@ namespace hex::plugin::builtin {
ProjectFile::registerPerProviderHandler({
.basePath = "pattern_source_code.hexpat",
.required = false,
.load = [this](prv::Provider *provider, const std::fs::path &basePath, Tar &tar) {
.load = [this](prv::Provider *provider, const std::fs::path &basePath, const Tar &tar) {
std::string sourceCode = tar.readString(basePath);
if (!m_syncPatternSourceCode)
@@ -1377,7 +1380,7 @@ namespace hex::plugin::builtin {
return true;
},
.store = [this](prv::Provider *provider, const std::fs::path &basePath, Tar &tar) {
.store = [this](prv::Provider *provider, const std::fs::path &basePath, const Tar &tar) {
std::string sourceCode;
if (provider == ImHexApi::Provider::get())

View File

@@ -359,8 +359,9 @@ namespace hex::plugin::builtin {
}
category.downloadCallback();
} else
} else {
log::error("Download failed! HTTP Code {}", response.getStatusCode());
}
m_download = {};