Add flags to collapsing headers in zeml

This commit is contained in:
scawful
2024-04-19 16:40:53 -04:00
parent e8fe8a6c79
commit b9212732a3
2 changed files with 34 additions and 4 deletions

View File

@@ -41,7 +41,7 @@ class Emulator : public SharedRom {
TableNextColumn, TableNextColumn,
BeginChild id="##" size="0,0" flags="NoMove|NoScrollbar" { BeginChild id="##" size="0,0" flags="NoMove|NoScrollbar" {
CollapsingHeader id="cpuState" title="Register Values" open=true { CollapsingHeader id="cpuState" title="Register Values" flags="DefaultOpen" {
Columns id="registersColumns" count="2" { Columns id="registersColumns" count="2" {
Text text="A: 0x%04X" data="cpu.A", Text text="A: 0x%04X" data="cpu.A",
Text text="D: 0x%04X" data="cpu.D", Text text="D: 0x%04X" data="cpu.D",

View File

@@ -193,6 +193,32 @@ void ParseFlags(const WidgetType& type, const std::string& flags,
attributes.flags = new ImGuiWindowFlags(windowFlags); attributes.flags = new ImGuiWindowFlags(windowFlags);
break; break;
} }
case WidgetType::CollapsingHeader: {
// Create a flag map using the tree node flags
static std::map<std::string, ImGuiTreeNodeFlags> flagMap = {
{"None", ImGuiTreeNodeFlags_None},
{"Selected", ImGuiTreeNodeFlags_Selected},
{"Framed", ImGuiTreeNodeFlags_Framed},
{"AllowItemOverlap", ImGuiTreeNodeFlags_AllowItemOverlap},
{"NoTreePushOnOpen", ImGuiTreeNodeFlags_NoTreePushOnOpen},
{"NoAutoOpenOnLog", ImGuiTreeNodeFlags_NoAutoOpenOnLog},
{"DefaultOpen", ImGuiTreeNodeFlags_DefaultOpen},
{"OpenOnDoubleClick", ImGuiTreeNodeFlags_OpenOnDoubleClick},
{"OpenOnArrow", ImGuiTreeNodeFlags_OpenOnArrow},
{"Leaf", ImGuiTreeNodeFlags_Leaf},
{"Bullet", ImGuiTreeNodeFlags_Bullet},
{"FramePadding", ImGuiTreeNodeFlags_FramePadding},
{"NavLeftJumpsBackHere", ImGuiTreeNodeFlags_NavLeftJumpsBackHere},
{"CollapsingHeader", ImGuiTreeNodeFlags_CollapsingHeader}};
ImGuiTreeNodeFlags treeFlags = ImGuiTreeNodeFlags_None;
for (const auto& flag : flag_tokens) {
if (flagMap.find(flag) != flagMap.end()) {
treeFlags |= flagMap[flag];
}
}
attributes.flags = new ImGuiTreeNodeFlags(treeFlags);
break;
}
case WidgetType::Table: { case WidgetType::Table: {
// Create a flag map // Create a flag map
static std::map<std::string, ImGuiTableFlags> flagMap = { static std::map<std::string, ImGuiTableFlags> flagMap = {
@@ -377,13 +403,17 @@ void Render(Node& node) {
} }
} }
break; break;
case WidgetType::CollapsingHeader: case WidgetType::CollapsingHeader: {
if (ImGui::CollapsingHeader(node.attributes.title.c_str())) { ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_None;
if (node.attributes.flags) {
flags = *(ImGuiTreeNodeFlags*)node.attributes.flags;
}
if (ImGui::CollapsingHeader(node.attributes.title.c_str(), flags)) {
for (auto& child : node.children) { for (auto& child : node.children) {
Render(child); Render(child);
} }
} }
break; } break;
case WidgetType::Columns: case WidgetType::Columns:
ImGui::Columns(node.attributes.count, node.attributes.title.c_str()); ImGui::Columns(node.attributes.count, node.attributes.title.c_str());
ImGui::Separator(); ImGui::Separator();