mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-28 07:47:03 -05:00
impr: Remove hex::format, improve format and logging type safety
This commit is contained in:
@@ -41,7 +41,7 @@ namespace hex::plugin::visualizers {
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, ImVec2(0, 0.5F));
|
||||
|
||||
if (ImGui::Button(hex::format(" {} {}", ICON_VS_PLAY, pattern.getFormattedValue()).c_str(), ImVec2(ImGui::GetColumnWidth(), ImGui::GetTextLineHeight()))) {
|
||||
if (ImGui::Button(fmt::format(" {} {}", ICON_VS_PLAY, pattern.getFormattedValue()).c_str(), ImVec2(ImGui::GetColumnWidth(), ImGui::GetTextLineHeight()))) {
|
||||
auto *evaluator = pattern.getEvaluator();
|
||||
const auto functionName = arguments[0].toString(false);
|
||||
const auto &function = evaluator->findFunction(functionName);
|
||||
|
||||
@@ -346,16 +346,16 @@ namespace hex::plugin::visualizers {
|
||||
bool validateVector(const std::vector<float> &vector, u32 vertexCount, u32 divisor, const std::string &name, std::string &errorMessage) {
|
||||
if (!vector.empty()) {
|
||||
if (vector.size() % divisor != 0) {
|
||||
errorMessage = hex::format("hex.visualizers.pl_visualizer.3d.error_message_count"_lang, name , std::to_string(divisor));
|
||||
errorMessage = fmt::format("hex.visualizers.pl_visualizer.3d.error_message_count"_lang, name , std::to_string(divisor));
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
errorMessage = hex::format("hex.visualizers.pl_visualizer.3d.error_message_not_empty"_lang, name);
|
||||
errorMessage = fmt::format("hex.visualizers.pl_visualizer.3d.error_message_not_empty"_lang, name);
|
||||
return false;
|
||||
}
|
||||
auto vectorCount = vector.size()/divisor;
|
||||
if (vectorCount != vertexCount) {
|
||||
errorMessage = hex::format("hex.visualizers.pl_visualizer.3d.error_message_expected"_lang, std::to_string(vertexCount), std::to_string(vectorCount));
|
||||
errorMessage = fmt::format("hex.visualizers.pl_visualizer.3d.error_message_expected"_lang, std::to_string(vertexCount), std::to_string(vectorCount));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -502,7 +502,7 @@ namespace hex::plugin::visualizers {
|
||||
drawList->AddText(
|
||||
screenPos + scaled({ 5, 5 }),
|
||||
ImGui::GetColorU32(ImGuiCol_Text),
|
||||
hex::format("X: {:.5}\nY: {:.5}", mousePos.x, mousePos.y).c_str());
|
||||
fmt::format("X: {:.5}\nY: {:.5}", mousePos.x, mousePos.y).c_str());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -669,7 +669,7 @@ namespace hex::plugin::visualizers {
|
||||
errorMessage += std::to_string(badIndex) + ", ";
|
||||
errorMessage.pop_back();
|
||||
errorMessage.pop_back();
|
||||
errorMessage += hex::format("hex.visualizers.pl_visualizer.3d.error_message_for_vertex_count"_lang.get(), s_vertexCount);
|
||||
errorMessage += fmt::format("hex.visualizers.pl_visualizer.3d.error_message_for_vertex_count"_lang, s_vertexCount);
|
||||
throw std::runtime_error(errorMessage);
|
||||
}
|
||||
}
|
||||
@@ -706,7 +706,7 @@ namespace hex::plugin::visualizers {
|
||||
errorMessage += std::to_string(badIndex) + ", ";
|
||||
errorMessage.pop_back();
|
||||
errorMessage.pop_back();
|
||||
errorMessage += hex::format("hex.visualizers.pl_visualizer.3d.error_message_for_vertex_count"_lang.get(), s_vertexCount);
|
||||
errorMessage += fmt::format("hex.visualizers.pl_visualizer.3d.error_message_for_vertex_count"_lang, s_vertexCount);
|
||||
throw std::runtime_error(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace hex::plugin::visualizers {
|
||||
addressTask = TaskManager::createBackgroundTask("hex.visualizers.pl_visualizer.coordinates.querying", [lat = latitude, lon = longitude](auto &) {
|
||||
constexpr static auto ApiURL = "https://geocode.maps.co/reverse?lat={}&lon={}&format=jsonv2";
|
||||
|
||||
HttpRequest request("GET", hex::format(ApiURL, lat, lon));
|
||||
HttpRequest request("GET", fmt::format(ApiURL, lat, lon));
|
||||
auto response = request.execute().get();
|
||||
|
||||
if (!response.isSuccess())
|
||||
@@ -76,13 +76,13 @@ namespace hex::plugin::visualizers {
|
||||
|
||||
std::scoped_lock lock(addressMutex);
|
||||
if (jsonAddr.contains("village")) {
|
||||
address = hex::format("{} {}, {} {}",
|
||||
address = fmt::format("{} {}, {} {}",
|
||||
jsonAddr["village"].get<std::string>(),
|
||||
jsonAddr["county"].get<std::string>(),
|
||||
jsonAddr["state"].get<std::string>(),
|
||||
jsonAddr["country"].get<std::string>());
|
||||
} else if (jsonAddr.contains("city")) {
|
||||
address = hex::format("{}, {} {}, {} {}",
|
||||
address = fmt::format("{}, {} {}, {} {}",
|
||||
jsonAddr["road"].get<std::string>(),
|
||||
jsonAddr["quarter"].get<std::string>(),
|
||||
jsonAddr["city"].get<std::string>(),
|
||||
|
||||
@@ -28,9 +28,9 @@ namespace hex::plugin::visualizers {
|
||||
static TaskHolder resetTask;
|
||||
|
||||
if (sampleRate == 0)
|
||||
throw std::logic_error(hex::format("Invalid sample rate: {}", sampleRate));
|
||||
throw std::logic_error(fmt::format("Invalid sample rate: {}", sampleRate));
|
||||
else if (channels == 0)
|
||||
throw std::logic_error(hex::format("Invalid channel count: {}", channels));
|
||||
throw std::logic_error(fmt::format("Invalid channel count: {}", channels));
|
||||
u64 sampledIndex;
|
||||
if (shouldReset) {
|
||||
waveData.clear();
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace hex::plugin::visualizers {
|
||||
}
|
||||
|
||||
if (width >= IMGUI_TABLE_MAX_COLUMNS)
|
||||
throw std::logic_error(hex::format("Table visualizer cannot have more than {} columns.", IMGUI_TABLE_MAX_COLUMNS));
|
||||
throw std::logic_error(fmt::format("Table visualizer cannot have more than {} columns.", IMGUI_TABLE_MAX_COLUMNS));
|
||||
|
||||
if (ImGui::BeginTable("##visualizer_table", width, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg)) {
|
||||
for (u64 i = 0; i < height; i += 1) {
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace hex::plugin::visualizers {
|
||||
|
||||
// Draw clock sections and numbers
|
||||
for (u8 i = 0; i < 12; ++i) {
|
||||
auto text = hex::format("{}", (((i + 2) % 12) + 1));
|
||||
auto text = fmt::format("{}", (((i + 2) % 12) + 1));
|
||||
drawList->AddLine(center + sectionPos(i) * size / 2.2F, center + sectionPos(i) * size / 2, ImGui::GetColorU32(ImGuiCol_TextDisabled), 1_scaled);
|
||||
drawList->AddText(center + sectionPos(i) * size / 3.0F - ImGui::CalcTextSize(text.c_str()) / 2, ImGui::GetColorU32(ImGuiCol_Text), text.c_str());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user