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