yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
diagnostics_panel.cc
Go to the documentation of this file.
2
3#include <string>
4
7#include "imgui/imgui.h"
8
9namespace yaze {
10namespace editor {
11
12namespace {
13
15 const char* icon;
16 ImVec4 color;
17 const char* label;
18};
19
21 switch (severity) {
23 return {ICON_MD_WARNING, ImVec4(1.0f, 0.8f, 0.2f, 1.0f), "warning"};
25 return {ICON_MD_INFO, ImVec4(0.6f, 0.8f, 1.0f, 1.0f), "note"};
27 default:
28 return {ICON_MD_ERROR, ImVec4(1.0f, 0.4f, 0.4f, 1.0f), "error"};
29 }
30}
31
32} // namespace
33
34void DrawDiagnosticsPanel(std::span<const core::AssemblyDiagnostic> diagnostics,
35 const DiagnosticsPanelCallbacks& callbacks) {
36 if (diagnostics.empty()) {
37 ImGui::TextDisabled("No diagnostics");
38 return;
39 }
40
41 // Counts strip — quick read on the overall health.
42 int errors = 0, warnings = 0, notes = 0;
43 for (const auto& d : diagnostics) {
44 switch (d.severity) {
46 ++warnings;
47 break;
49 ++notes;
50 break;
52 default:
53 ++errors;
54 break;
55 }
56 }
57 if (notes > 0) {
58 ImGui::Text("%d error(s), %d warning(s), %d note(s)", errors, warnings,
59 notes);
60 } else {
61 ImGui::Text("%d error(s), %d warning(s)", errors, warnings);
62 }
63 ImGui::Separator();
64
65 if (ImGui::BeginTable("##diagnostics", 3,
66 ImGuiTableFlags_RowBg | ImGuiTableFlags_Resizable |
67 ImGuiTableFlags_ScrollY)) {
68 ImGui::TableSetupColumn("Severity", ImGuiTableColumnFlags_WidthFixed,
69 90.0f);
70 ImGui::TableSetupColumn("Location", ImGuiTableColumnFlags_WidthFixed,
71 220.0f);
72 ImGui::TableSetupColumn("Message", ImGuiTableColumnFlags_WidthStretch);
73 ImGui::TableHeadersRow();
74
75 for (std::size_t i = 0; i < diagnostics.size(); ++i) {
76 const auto& d = diagnostics[i];
77 const auto style = StyleFor(d.severity);
78
79 ImGui::PushID(static_cast<int>(i));
80 ImGui::TableNextRow();
81
82 ImGui::TableSetColumnIndex(0);
83 {
84 gui::StyleColorGuard guard(ImGuiCol_Text, style.color);
85 ImGui::Text("%s %s", style.icon, style.label);
86 }
87
88 ImGui::TableSetColumnIndex(1);
89 if (!d.file.empty()) {
90 std::string label = d.file + ":" + std::to_string(d.line);
91 if (d.column > 0)
92 label += ":" + std::to_string(d.column);
93 if (ImGui::Selectable(label.c_str(), false,
94 ImGuiSelectableFlags_SpanAllColumns)) {
95 if (callbacks.on_diagnostic_activated) {
96 callbacks.on_diagnostic_activated(d.file, d.line, d.column);
97 }
98 }
99 } else {
100 ImGui::TextDisabled("<unknown>");
101 }
102
103 ImGui::TableSetColumnIndex(2);
104 ImGui::TextWrapped("%s", d.message.c_str());
105
106 ImGui::PopID();
107 }
108 ImGui::EndTable();
109 }
110}
111
112} // namespace editor
113} // namespace yaze
RAII guard for ImGui style colors.
Definition style_guard.h:27
#define ICON_MD_INFO
Definition icons.h:993
#define ICON_MD_WARNING
Definition icons.h:2123
#define ICON_MD_ERROR
Definition icons.h:686
SeverityStyle StyleFor(core::AssemblyDiagnosticSeverity severity)
void DrawDiagnosticsPanel(std::span< const core::AssemblyDiagnostic > diagnostics, const DiagnosticsPanelCallbacks &callbacks)
std::function< void(const std::string &file, int line, int column) on_diagnostic_activated)