1
0
mirror of synced 2025-01-18 00:56:49 +01:00

impr: Better UI for the settings view

This commit is contained in:
WerWolv 2023-11-15 22:22:57 +01:00
parent e32def409a
commit a51f9fd90c
4 changed files with 27 additions and 10 deletions

View File

@ -269,6 +269,9 @@ namespace ImGui {
bool BeginBox();
void EndBox();
void BeginSubWindow(const char *label, ImVec2 size = ImVec2(0, 0));
void EndSubWindow();
template<typename T>
constexpr ImGuiDataType getImGuiDataType() {
if constexpr (std::same_as<T, u8>) return ImGuiDataType_U8;

View File

@ -834,4 +834,21 @@ namespace ImGui {
ImGui::PopStyleVar();
}
void BeginSubWindow(const char *label, ImVec2 size) {
const bool hasMenuBar = !std::string_view(label).empty();
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 5.0f);
if (ImGui::BeginChild(label, size, ImGuiChildFlags_Border | ImGuiChildFlags_AutoResizeY, hasMenuBar ? ImGuiWindowFlags_MenuBar : ImGuiWindowFlags_None)) {
if (hasMenuBar && ImGui::BeginMenuBar()) {
ImGui::TextUnformatted(label);
ImGui::EndMenuBar();
}
}
}
void EndSubWindow() {
ImGui::EndChild();
ImGui::PopStyleVar();
}
}

View File

@ -4,6 +4,7 @@
#include <hex/api/theme_manager.hpp>
#include <hex/helpers/http_requests.hpp>
#include <hex/helpers/utils.hpp>
#include <imgui.h>
#include <hex/ui/imgui_imhex_extensions.h>
@ -86,7 +87,7 @@ namespace hex::plugin::builtin {
bool draw(const std::string &) override {
bool result = false;
if (!ImGui::BeginListBox("", ImVec2(-38, -10))) {
if (!ImGui::BeginListBox("", ImVec2(-40_scaled, 280_scaled))) {
return false;
} else {
for (size_t n = 0; n < this->m_paths.size(); n++) {

View File

@ -53,8 +53,6 @@ namespace hex::plugin::builtin {
ImGui::NewLine();
}
bool firstSubCategory = true;
// Draw all settings of that category
for (auto &subCategory : category.subCategories) {
@ -62,15 +60,13 @@ namespace hex::plugin::builtin {
if (subCategory.entries.empty())
continue;
if (!subCategory.unlocalizedName.empty())
ImGui::Header(LangEntry(subCategory.unlocalizedName), firstSubCategory);
firstSubCategory = false;
if (ImGui::BeginBox()) {
ImGui::BeginSubWindow(LangEntry(subCategory.unlocalizedName));
{
for (auto &setting : subCategory.entries) {
ImGui::BeginDisabled(!setting.widget->isEnabled());
ImGui::PushItemWidth(-200_scaled);
bool settingChanged = setting.widget->draw(LangEntry(setting.unlocalizedName));
ImGui::PopItemWidth();
ImGui::EndDisabled();
if (auto tooltip = setting.widget->getTooltip(); tooltip.has_value() && ImGui::IsItemHovered())
@ -98,8 +94,8 @@ namespace hex::plugin::builtin {
}
}
ImGui::EndBox();
}
ImGui::EndSubWindow();
}