diff --git a/lib/libimhex/include/hex/api/content_registry.hpp b/lib/libimhex/include/hex/api/content_registry.hpp index 81c07bec5..c66074080 100644 --- a/lib/libimhex/include/hex/api/content_registry.hpp +++ b/lib/libimhex/include/hex/api/content_registry.hpp @@ -633,6 +633,7 @@ namespace hex { struct SidebarItem { std::string icon; DrawCallback callback; + EnabledCallback enabledCallback; }; struct TitleBarButton { @@ -712,8 +713,9 @@ namespace hex { * @brief Adds a new sidebar item * @param icon The icon to use for the item * @param function The function to call to draw the item + * @param enabledCallback The function */ - void addSidebarItem(const std::string &icon, const impl::DrawCallback &function); + void addSidebarItem(const std::string &icon, const impl::DrawCallback &function, const impl::EnabledCallback &enabledCallback = []{ return true; }); /** * @brief Adds a new title bar button diff --git a/lib/libimhex/source/api/content_registry.cpp b/lib/libimhex/source/api/content_registry.cpp index fccf29504..40d9de1ce 100644 --- a/lib/libimhex/source/api/content_registry.cpp +++ b/lib/libimhex/source/api/content_registry.cpp @@ -748,8 +748,8 @@ namespace hex { impl::getToolbarItems().push_back(function); } - void addSidebarItem(const std::string &icon, const impl::DrawCallback &function) { - impl::getSidebarItems().push_back({ icon, function }); + void addSidebarItem(const std::string &icon, const impl::DrawCallback &function, const impl::EnabledCallback &enabledCallback) { + impl::getSidebarItems().push_back({ icon, function, enabledCallback }); } void addTitleBarButton(const std::string &icon, const std::string &unlocalizedTooltip, const impl::ClickCallback &function) { diff --git a/main/gui/source/window/window.cpp b/main/gui/source/window/window.cpp index 5ba91c60d..34c45e18c 100644 --- a/main/gui/source/window/window.cpp +++ b/main/gui/source/window/window.cpp @@ -423,14 +423,14 @@ namespace hex { static i32 openWindow = -1; u32 index = 0; ImGui::PushID("SideBarWindows"); - for (const auto &[icon, callback] : ContentRegistry::Interface::impl::getSidebarItems()) { + for (const auto &[icon, callback, enabledCallback] : ContentRegistry::Interface::impl::getSidebarItems()) { ImGui::SetCursorPosY(sidebarPos.y + sidebarWidth * index); ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetColorU32(ImGuiCol_MenuBarBg)); ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImGui::GetColorU32(ImGuiCol_ScrollbarGrabActive)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImGui::GetColorU32(ImGuiCol_ScrollbarGrabHovered)); - ImGui::BeginDisabled(!ImHexApi::Provider::isValid()); + ImGui::BeginDisabled(!(ImHexApi::Provider::isValid() && enabledCallback())); { if (ImGui::Button(icon.c_str(), ImVec2(sidebarWidth, sidebarWidth))) { if (static_cast(openWindow) == index) @@ -447,14 +447,48 @@ namespace hex { bool open = static_cast(openWindow) == index; if (open) { + static float width = 200_scaled; + ImGui::SetNextWindowPos(ImGui::GetWindowPos() + sidebarPos + ImVec2(sidebarWidth - 1_scaled, -1_scaled)); - ImGui::SetNextWindowSize(ImVec2(250_scaled, dockSpaceSize.y + 11_scaled - footerHeight)); + ImGui::SetNextWindowSize(ImVec2(width, dockSpaceSize.y + 11_scaled - footerHeight)); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1); - if (ImGui::Begin("SideBarWindow", &open, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar)) { - callback(); + if (ImGui::Begin("SideBarWindow", &open, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) { + if (ImGui::BeginTable("##Table", 2)) { + ImGui::TableSetupColumn("Main", ImGuiTableColumnFlags_WidthStretch, 1.0F); + ImGui::TableSetupColumn("Slider", ImGuiTableColumnFlags_WidthFixed, 1); - if (!ImGui::IsWindowFocused() && !sideBarFocused) { + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + + callback(); + + ImGui::TableNextColumn(); + + static bool dragging = false; + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0)); + ImGui::Button("##Resize", ImGui::GetContentRegionAvail()); + ImGui::PopStyleVar(); + + if (ImGui::IsMouseDragging(ImGuiMouseButton_Left, 0)) { + if (ImGui::IsItemHovered()) + dragging = true; + } else { + dragging = false; + } + if (ImGui::IsItemHovered()) { + ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeEW); + } + + if (dragging) { + width += ImGui::GetMouseDragDelta(ImGuiMouseButton_Left, 0).x; + ImGui::ResetMouseDragDelta(ImGuiMouseButton_Left); + } + + ImGui::EndTable(); + } + + if (!ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) && !sideBarFocused) { openWindow = -1; } }