@@ -85,11 +85,12 @@ const static ImColor LEGEND_COLOR = {100, 100, 100};
8585const static float GRID_SZ = 64 .0f ;
8686const static float ARROW_THICKNESS = 3 .f;
8787const static float NODE_BORDER_THICKNESS = 4 .f;
88- const static float LEGEND_FONT_SIZE = 12 ;
89- const static float LEGEND_INTERLINE_SIZE = 2 ;
90- const static ImVec2 LEGEND_PADDING = {20 , 8 };
91- const static ImVec2 LEGEND_BOX_PADDING = {2 , 2 };
92- const static ImVec2 LEGEND_BOX_SIZE = {10 , 12 };
88+ const static ImVec4 LEGEND_BACKGROUND_COLOR = {0.125 , 0.180 , 0.196 , 1 };
89+
90+ const static ImColor SLOT_EMPTY_COLOR = {70 , 70 , 70 , 255 };
91+ const static ImColor SLOT_PENDING_COLOR = PaletteHelpers::RED;
92+ const static ImColor SLOT_DISPATCHED_COLOR = PaletteHelpers::YELLOW;
93+ const static ImColor SLOT_DONE_COLOR = PaletteHelpers::GREEN;
9394
9495// / Displays a grid
9596void displayGrid (bool show_grid, ImVec2 offset, ImDrawList* draw_list)
@@ -112,30 +113,33 @@ void displayLegend(bool show_legend, ImVec2 offset, ImDrawList* draw_list)
112113 if (show_legend == false ) {
113114 return ;
114115 }
115- ImVec2 win_pos = ImGui::GetCursorScreenPos ();
116- ImVec2 canvas_sz = ImGui::GetWindowSize ();
117- ImVec2 legend_top_left = canvas_sz;
118- legend_top_left.x *= 0.7 ;
119- legend_top_left.y *= 0.1 ;
120- ImVec2 legend_bottom_right = canvas_sz;
121- legend_bottom_right.x *= 0.95 ;
122- legend_bottom_right.y *= 0.3 ;
123- ImVec2 canvas_offset = {200 , 20 };
124-
125- ImColor (70 , 70 , 70 , 255 );
126- draw_list->AddRectFilled (canvas_offset + legend_top_left, canvas_offset + legend_bottom_right, LEGEND_COLOR);
127- draw_list->AddRectFilled (canvas_offset + legend_top_left + LEGEND_BOX_PADDING + ImVec2{0 , (LEGEND_FONT_SIZE + LEGEND_INTERLINE_SIZE) * 0 },
128- canvas_offset + legend_top_left - LEGEND_BOX_PADDING + ImVec2{0 , (LEGEND_FONT_SIZE + LEGEND_INTERLINE_SIZE) * 1 } + LEGEND_BOX_SIZE, ImColor (70 , 70 , 70 , 255 ));
129- draw_list->AddRectFilled (canvas_offset + legend_top_left + LEGEND_BOX_PADDING + ImVec2{0 , (LEGEND_FONT_SIZE + LEGEND_INTERLINE_SIZE) * 1 },
130- canvas_offset + legend_top_left - LEGEND_BOX_PADDING + ImVec2{0 , (LEGEND_FONT_SIZE + LEGEND_INTERLINE_SIZE) * 2 } + LEGEND_BOX_SIZE, ImColor (PaletteHelpers::RED));
131- draw_list->AddRectFilled (canvas_offset + legend_top_left + LEGEND_BOX_PADDING + ImVec2{0 , (LEGEND_FONT_SIZE + LEGEND_INTERLINE_SIZE) * 2 },
132- canvas_offset + legend_top_left - LEGEND_BOX_PADDING + ImVec2{0 , (LEGEND_FONT_SIZE + LEGEND_INTERLINE_SIZE) * 3 } + LEGEND_BOX_SIZE, ImColor (PaletteHelpers::YELLOW));
133- draw_list->AddRectFilled (canvas_offset + legend_top_left + LEGEND_BOX_PADDING + ImVec2{0 , (LEGEND_FONT_SIZE + LEGEND_INTERLINE_SIZE) * 3 },
134- canvas_offset + legend_top_left - LEGEND_BOX_PADDING + ImVec2{0 , (LEGEND_FONT_SIZE + LEGEND_INTERLINE_SIZE) * 4 } + LEGEND_BOX_SIZE, ImColor (PaletteHelpers::GREEN));
135- draw_list->AddText (canvas_offset + LEGEND_PADDING + ImVec2{0 , (LEGEND_FONT_SIZE + LEGEND_INTERLINE_SIZE) * 0 } + legend_top_left, ImColor (PaletteHelpers::BLACK), " Slot empty" );
136- draw_list->AddText (canvas_offset + LEGEND_PADDING + ImVec2{0 , (LEGEND_FONT_SIZE + LEGEND_INTERLINE_SIZE) * 1 } + legend_top_left, ImColor (PaletteHelpers::RED), " Slot pending" );
137- draw_list->AddText (canvas_offset + LEGEND_PADDING + ImVec2{0 , (LEGEND_FONT_SIZE + LEGEND_INTERLINE_SIZE) * 2 } + legend_top_left, ImColor (PaletteHelpers::YELLOW), " Timeslice dispatched" );
138- draw_list->AddText (canvas_offset + LEGEND_PADDING + ImVec2{0 , (LEGEND_FONT_SIZE + LEGEND_INTERLINE_SIZE) * 3 } + legend_top_left, ImColor (PaletteHelpers::GREEN), " Timeslice done" );
116+ struct LegendItem {
117+ std::string label;
118+ ImVec4 color;
119+ };
120+ static auto legend = {
121+ LegendItem{" Slot empty" , SLOT_EMPTY_COLOR},
122+ LegendItem{" Slot pending" , SLOT_PENDING_COLOR},
123+ LegendItem{" Slot dispatched" , SLOT_DISPATCHED_COLOR},
124+ LegendItem{" Slot done" , SLOT_DONE_COLOR},
125+ };
126+ ImGui::PushStyleColor (ImGuiCol_WindowBg, LEGEND_BACKGROUND_COLOR);
127+ ImGui::PushStyleColor (ImGuiCol_TitleBg, LEGEND_BACKGROUND_COLOR);
128+ ImGui::PushStyleColor (ImGuiCol_ResizeGrip, 0 );
129+
130+ ImGui::Begin (" Legend" );
131+ ImGui::Dummy (ImVec2 (0 .0f , 10 .0f ));
132+ for (auto [label, color] : legend) {
133+ ImVec2 vMin = ImGui::GetWindowPos () + ImGui::GetCursorPos () + ImVec2 (9 , 0 );
134+ ImVec2 vMax = vMin + ImGui::CalcTextSize (" " );
135+ ImGui::PushStyleColor (ImGuiCol_ChildBg, color);
136+ ImGui::GetWindowDrawList ()->AddRectFilled (vMin, vMax, ImColor (color));
137+ ImGui::GetWindowDrawList ()->AddRect (vMin, vMax, GRID_COLOR);
138+ ImGui::Text (" %s" , label.data ());
139+ ImGui::PopStyleColor ();
140+ }
141+ ImGui::End ();
142+ ImGui::PopStyleColor (3 );
139143}
140144
141145#define MAX_GROUP_NAME_SIZE 128
0 commit comments