diff --git a/public/raid/components/task_list.hpp b/public/raid/components/task_list.hpp new file mode 100644 index 0000000..b107046 --- /dev/null +++ b/public/raid/components/task_list.hpp @@ -0,0 +1,78 @@ + +#pragma once + +#if !defined(RAID_PUBLIC_RAID_COMPONENTS_TASK_LIST_HPP_INCLUDED) +#define RAID_PUBLIC_RAID_COMPONENTS_TASK_LIST_HPP_INCLUDED 1 + +#include +#include "../imraid.hpp" +#include "../imutil.hpp" +#include "../raid.hpp" + +#include +#include + +namespace ImRaid +{ +template typename TAllocator, typename TPrintFunc> +void RenderTaskList(const char* strID, mijin::BaseSimpleTaskLoop& loop, TPrintFunc printFunc) +{ + if (!ImGui::BeginTable(strID, 3)) { + return; + } + ImGui::TableSetupColumn("Name"); + ImGui::TableSetupColumn("State"); + + ImGui::TableHeadersRow(); + + for (const mijin::TaskHandle& handle : loop.getAllTasks()) + { + if (!handle.isValid()) { + continue; + } + IDScope scope(handle.getState()); + + ImGui::TableNextRow(); + const mijin::Optional location = handle.getLocation(); + location.then( + /* success = */ [](std::source_location loc) { + ImGui::Text("%s [%s:%" PRIuLEAST32 "]", loc.function_name(), loc.file_name(), loc.line()); + }, + /* error = */ []() { + ImGui::TextUnformatted("???"); + } + ); + ImGui::TableNextColumn(); + ImGui::TextUnformatted("TBD"); + + ImGui::TableNextColumn(); + if (ImGui::SmallButton(ICON_FA_LIST)) + { + mijin::Optional> stackOpt = handle.getLocationStack(); + stackOpt.then( + /* success = */ [&](const std::vector& stack) { + for (std::source_location loc : stack) { + std::invoke(printFunc, raid::formatTemp("{} [{}:{}]", loc.function_name(), loc.file_name(), loc.line())); + } + }, + /* error = */ [&]() { + std::invoke(printFunc, "Could not capture stack."); + } + ); + } + ImGui::SetItemTooltip("Dump callstack"); + } + ImGui::EndTable(); +} + +template typename TAllocator, typename TPrintFunc> +void ShowTaskListWindow(const char* name, bool* open, mijin::BaseSimpleTaskLoop& loop, TPrintFunc printFunc) +{ + if (ImGui::Begin(name, open)) { + RenderTaskList("##tasks", loop, std::move(printFunc)); + } + ImGui::End(); +} +} // namespace ImRaid + +#endif // !defined(RAID_PUBLIC_RAID_COMPONENTS_TASK_LIST_HPP_INCLUDED)