1
0
mirror of synced 2025-01-18 17:14:13 +01:00

impr: Added data size widget

This commit is contained in:
WerWolv 2024-05-19 10:21:54 +02:00
parent 1e48277566
commit d5eb6b5bbc
3 changed files with 32 additions and 11 deletions

View File

@ -150,6 +150,8 @@ namespace ImGuiExt {
bool InputHexadecimal(const char* label, u32 *value, ImGuiInputTextFlags flags = ImGuiInputTextFlags_None);
bool InputHexadecimal(const char* label, u64 *value, ImGuiInputTextFlags flags = ImGuiInputTextFlags_None);
bool SliderBytes(const char *label, u64 *value, u64 min, u64 max, ImGuiSliderFlags flags = ImGuiSliderFlags_None);
inline bool HasSecondPassed() {
return static_cast<ImU32>(ImGui::GetTime() * 100) % 100 <= static_cast<ImU32>(ImGui::GetIO().DeltaTime * 100);
}

View File

@ -828,15 +828,6 @@ namespace ImGuiExt {
char buf[64];
DataTypeFormatString(buf, IM_ARRAYSIZE(buf), type, value, format);
bool value_changed = false;
PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0);
if (InputTextEx(label, nullptr, buf, IM_ARRAYSIZE(buf), ImVec2(CalcItemWidth() - frame_size.x, label_size.y + style.FramePadding.y * 2.0F), flags))
value_changed = DataTypeApplyFromText(buf, type, value, format);
PopStyleVar();
if (value_changed)
MarkItemEdited(GImGui->LastItemData.ID);
RenderNavHighlight(frame_bb, id);
RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding);
@ -844,6 +835,19 @@ namespace ImGuiExt {
RenderText(ImVec2(frame_bb.Min.x + style.FramePadding.x, frame_bb.Min.y + style.FramePadding.y), prefix);
PopStyleVar();
bool value_changed = false;
PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0);
PushStyleColor(ImGuiCol_FrameBg, 0x00000000);
PushStyleColor(ImGuiCol_FrameBgHovered, 0x00000000);
PushStyleColor(ImGuiCol_FrameBgActive, 0x00000000);
if (InputTextEx(label, nullptr, buf, IM_ARRAYSIZE(buf), ImVec2(CalcItemWidth() - frame_size.x, label_size.y + style.FramePadding.y * 2.0F), flags))
value_changed = DataTypeApplyFromText(buf, type, value, format);
PopStyleColor(3);
PopStyleVar();
if (value_changed)
MarkItemEdited(GImGui->LastItemData.ID);
return value_changed;
}
@ -855,6 +859,21 @@ namespace ImGuiExt {
return InputIntegerPrefix(label, "0x", value, ImGuiDataType_U64, "%llX", flags | ImGuiInputTextFlags_CharsHexadecimal);
}
bool SliderBytes(const char *label, u64 *value, u64 min, u64 max, ImGuiSliderFlags flags) {
std::string format;
if (*value < 1024) {
format = hex::format("{} Bytes", *value);
} else if (*value < 1024 * 1024) {
format = hex::format("{:.2f} KB", *value / 1024.0);
} else if (*value < 1024 * 1024 * 1024) {
format = hex::format("{:.2f} MB", *value / (1024.0 * 1024.0));
} else {
format = hex::format("{:.2f} GB", *value / (1024.0 * 1024.0 * 1024.0));
}
return ImGui::SliderScalar(label, ImGuiDataType_U64, value, &min, &max, format.c_str(), flags | ImGuiSliderFlags_Logarithmic);
}
void SmallProgressBar(float fraction, float yOffset) {
ImGuiWindow *window = GetCurrentWindow();
if (window->SkipItems)

View File

@ -211,7 +211,7 @@ namespace hex::plugin::builtin {
}
void drawSettings() override {
ImGuiExt::InputHexadecimal("hex.builtin.information_section.info_analysis.block_size"_lang, &m_inputChunkSize);
ImGuiExt::SliderBytes("hex.builtin.information_section.info_analysis.block_size"_lang, &m_inputChunkSize, 0, 1_MiB);
ImGui::Checkbox("hex.builtin.information_section.info_analysis.show_annotations"_lang, &m_showAnnotations);
}
@ -351,7 +351,7 @@ namespace hex::plugin::builtin {
}
private:
u32 m_inputChunkSize = 0;
u64 m_inputChunkSize = 0;
u32 m_blockSize = 0;
double m_averageEntropy = -1.0;