Various fixes and improvements

This commit is contained in:
WerWolv
2021-02-17 14:47:25 +01:00
parent df06dd49c5
commit 460d5a9386
6 changed files with 36 additions and 35 deletions

View File

@@ -122,21 +122,21 @@ namespace hex {
}
std::string toEngineeringString(double value) {
constexpr std::array prefixes = { "a", "f", "p", "n", "u", "m", "", "k", "M", "G", "T", "P", "E" };
constexpr std::array Suffixes = { "a", "f", "p", "n", "u", "m", "", "k", "M", "G", "T", "P", "E" };
int8_t prefixIndex = 6;
int8_t suffixIndex = 6;
while (prefixIndex != 0 && prefixIndex != 12 && (value >= 1000 || value < 1) && value != 0) {
while (suffixIndex != 0 && suffixIndex != 12 && (value >= 1000 || value < 1) && value != 0) {
if (value >= 1000) {
value /= 1000;
prefixIndex++;
suffixIndex++;
} else if (value < 1) {
value *= 1000;
prefixIndex--;
suffixIndex--;
}
}
return std::to_string(value).substr(0, 5) + prefixes[prefixIndex];
return std::to_string(value).substr(0, 5) + Suffixes[suffixIndex];
}
std::vector<u8> readFile(std::string_view path) {

View File

@@ -40,7 +40,6 @@ namespace hex {
}
void View::drawCommonInterfaces() {
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(20, 10));
if (ImGui::BeginPopupModal("Error", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::Text("%s", SharedData::errorPopupMessage.c_str());
ImGui::NewLine();
@@ -50,7 +49,6 @@ namespace hex {
ImGui::EndPopup();
}
ImGui::PopStyleVar();
if (SharedData::fileBrowser.showFileDialog(SharedData::fileBrowserTitle, SharedData::fileBrowserDialogMode, ImVec2(0, 0), SharedData::fileBrowserValidExtensions)) {
SharedData::fileBrowserCallback(SharedData::fileBrowser.selected_path);
@@ -61,7 +59,7 @@ namespace hex {
void View::showErrorPopup(std::string_view errorMessage) {
SharedData::errorPopupMessage = errorMessage;
ImGui::OpenPopup("Error");
View::doLater([] { ImGui::OpenPopup("Error"); });
}
bool View::hasViewMenuItemEntry() {