Added first version of the task list component.
This commit is contained in:
78
public/raid/components/task_list.hpp
Normal file
78
public/raid/components/task_list.hpp
Normal file
@@ -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 <cinttypes>
|
||||
#include "../imraid.hpp"
|
||||
#include "../imutil.hpp"
|
||||
#include "../raid.hpp"
|
||||
|
||||
#include <ifch/IconsFontAwesome6.h>
|
||||
#include <mijin/async/coroutine.hpp>
|
||||
|
||||
namespace ImRaid
|
||||
{
|
||||
template<template<typename> typename TAllocator, typename TPrintFunc>
|
||||
void RenderTaskList(const char* strID, mijin::BaseSimpleTaskLoop<TAllocator>& 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<std::source_location> 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<std::vector<std::source_location>> stackOpt = handle.getLocationStack();
|
||||
stackOpt.then(
|
||||
/* success = */ [&](const std::vector<std::source_location>& 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<template<typename> typename TAllocator, typename TPrintFunc>
|
||||
void ShowTaskListWindow(const char* name, bool* open, mijin::BaseSimpleTaskLoop<TAllocator>& 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)
|
||||
Reference in New Issue
Block a user