Skip to content

Commit

Permalink
[frontend] ErrorDialogList: Color-code entries
Browse files Browse the repository at this point in the history
  • Loading branch information
riidefi committed Jul 12, 2023
1 parent b35cec3 commit e1bbfae
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
18 changes: 10 additions & 8 deletions source/frontend/legacy_editor/EditorWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ void BRRESEditor::init() {

// We handle the Dockspace manually (disabling it in an error state)
BRRESEditor::BRRESEditor(std::string path)
: StudioWindow(getFileShort(path), DockSetting::None),
mDocument(nullptr), mPath(path) {}
: StudioWindow(getFileShort(path), DockSetting::None), mDocument(nullptr),
mPath(path) {}
BRRESEditor::BRRESEditor(std::span<const u8> span, const std::string& path)
: StudioWindow(getFileShort(path), DockSetting::None),
mDocument(nullptr), mPath(path) {
: StudioWindow(getFileShort(path), DockSetting::None), mDocument(nullptr),
mPath(path) {
auto out = std::make_unique<g3d::Collection>();
oishii::BinaryReader reader(span, path, std::endian::big);
kpi::LightIOTransaction trans;
Expand Down Expand Up @@ -95,6 +95,7 @@ void BRRESEditor::draw_() {
if (!mLoadErrorMessages.empty()) {
auto name = idIfyChild("Warnings");
bool open = true;
ImGui::SetNextWindowSize(ImVec2(900.0f, 500.0f), ImGuiCond_FirstUseEver);
if (ImGui::Begin(name.c_str(), &open)) {
mLoadErrors.Draw(mLoadErrorMessages);
if (ImGui::Button("OK")) {
Expand Down Expand Up @@ -150,11 +151,11 @@ void BRRESEditor::saveAsImpl(std::string path) {

// We handle the Dockspace manually (disabling it in an error state)
BMDEditor::BMDEditor(std::string path)
: StudioWindow(getFileShort(path), DockSetting::None),
mDocument(nullptr), mPath(path) {}
: StudioWindow(getFileShort(path), DockSetting::None), mDocument(nullptr),
mPath(path) {}
BMDEditor::BMDEditor(std::span<const u8> span, const std::string& path)
: StudioWindow(getFileShort(path), DockSetting::None),
mDocument(nullptr), mPath(path) {
: StudioWindow(getFileShort(path), DockSetting::None), mDocument(nullptr),
mPath(path) {
auto out = std::make_unique<j3d::Collection>();
oishii::BinaryReader reader(span, path, std::endian::big);
kpi::LightIOTransaction trans;
Expand Down Expand Up @@ -208,6 +209,7 @@ void BMDEditor::draw_() {
if (!mLoadErrorMessages.empty()) {
auto name = idIfyChild("Warnings");
bool open = true;
ImGui::SetNextWindowSize(ImVec2(900.0f, 500.0f), ImGuiCond_FirstUseEver);
if (ImGui::Begin(name.c_str(), &open)) {
mLoadErrors.Draw(mLoadErrorMessages);
if (ImGui::Button("OK")) {
Expand Down
17 changes: 17 additions & 0 deletions source/frontend/widgets/ErrorDialogList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ struct Message {
message_body(std::move(body)) {}
};
struct ErrorDialogList {
static constexpr ImVec4 WHITE = {1.0f, 1.0f, 1.0f, 1.0};
static constexpr ImVec4 YELLOW = {1.0f, 1.0f, 0.0f, 1.0};
static constexpr ImVec4 RED = {1.0f, 0.0f, 0.0f, 1.0};

void Draw(std::span<const Message> messages) {
const auto entry_flags =
ImGuiTableFlags_Borders | ImGuiTableFlags_Sortable |
Expand All @@ -30,6 +34,18 @@ struct ErrorDialogList {
for (auto& msg : messages) {
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::PushStyleColor(ImGuiCol_Text,
[](kpi::IOMessageClass mclass) -> ImVec4 {
switch (mclass) {
case kpi::IOMessageClass::None:
case kpi::IOMessageClass::Information:
return WHITE;
case kpi::IOMessageClass::Warning:
return YELLOW;
case kpi::IOMessageClass::Error:
return RED;
}
}(msg.message_class));
ImGui::TextUnformatted([](kpi::IOMessageClass mclass) -> const char* {
switch (mclass) {
case kpi::IOMessageClass::None:
Expand All @@ -46,6 +62,7 @@ struct ErrorDialogList {
ImGui::TextUnformatted(msg.domain.c_str());
ImGui::TableSetColumnIndex(2);
ImGui::TextWrapped("%s", msg.message_body.c_str());
ImGui::PopStyleColor();
}

ImGui::EndTable();
Expand Down

0 comments on commit e1bbfae

Please sign in to comment.