Skip to content

Commit

Permalink
Change error window to modal
Browse files Browse the repository at this point in the history
  • Loading branch information
dvsku committed Apr 25, 2024
1 parent babd4d5 commit 32a7e11
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 41 deletions.
22 changes: 0 additions & 22 deletions source/src/gui/dt_comp_errors.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion source/src/gui/dt_gui_mngr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ using namespace dvsku_toolkit;
// PUBLIC

dt_gui_mngr::dt_gui_mngr(dt_app& app)
: root(app), pack(app), unpack(app), errors(app) {}
: root(app), pack(app), unpack(app), modal_errors(app) {}
5 changes: 3 additions & 2 deletions source/src/gui/dt_gui_mngr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "gui/dt_comp_root.hpp"
#include "gui/dt_comp_pack.hpp"
#include "gui/dt_comp_unpack.hpp"
#include "gui/dt_comp_errors.hpp"
#include "gui/dt_modal_errors.hpp"

namespace dvsku_toolkit {
class dt_app;
Expand All @@ -13,7 +13,8 @@ namespace dvsku_toolkit {
dt_comp_root root;
dt_comp_pack pack;
dt_comp_unpack unpack;
dt_comp_errors errors;

dt_modal_errors modal_errors;

public:
dt_gui_mngr() = delete;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "gui/dt_comp_errors.hpp"
#include "gui/dt_modal_errors.hpp"
#include "dt_app.hpp"

#include <dv_gui_opengl\fonts\dv_font_fontawesome_solid.hpp>
Expand All @@ -9,25 +9,33 @@ using namespace dvsku;
///////////////////////////////////////////////////////////////////////////////
// PUBLIC

dt_comp_errors::dt_comp_errors(dt_app& app)
dt_modal_errors::dt_modal_errors(dt_app& app)
: dt_gui_base(app) {}

dv_command_state dt_comp_errors::render() {
dv_command_state dt_modal_errors::render() {
dv_command_state state = dv_command_state::repeat;

ImGui::OpenPopup("Errors##Modal");

ImGuiWindowFlags flags = 0;
flags |= ImGuiWindowFlags_NoNav;
flags |= ImGuiWindowFlags_NoSavedSettings;
flags |= ImGuiWindowFlags_NoDocking;
flags |= ImGuiWindowFlags_HorizontalScrollbar;
flags |= ImGuiWindowFlags_NoResize;
flags |= ImGuiWindowFlags_NoMove;
flags |= ImGuiWindowFlags_NoCollapse;

ImGui::SetNextWindowSize({350.0f, 400.0f}, ImGuiCond_Appearing);
ImVec2 pos = ImGui::GetMainViewport()->GetCenter();
ImVec2 size = {
ImGui::GetMainViewport()->Size.x * 0.9f,
ImGui::GetMainViewport()->Size.y * 0.9f
};

ImGui::SetNextWindowPos(pos, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGui::SetNextWindowSize(size, ImGuiCond_Always);

ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, { 6.0f, 4.0f });

bool* visible = &m_app.get_systems().command.is_set_to_execute(dt_commands::flag_show_error_window);
if (ImGui::Begin("Errors##Component", visible, flags)) {
if (ImGui::BeginPopupModal("Errors##Modal", visible, flags)) {
ImGui::PushStyleColor(ImGuiCol_Button, 0x00FFFFFF);
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, 0xFF3D3D3D);
ImGui::PushStyleColor(ImGuiCol_ButtonActive, 0xFF3D3D3D);
Expand All @@ -54,10 +62,10 @@ dv_command_state dt_comp_errors::render() {
ImGui::TextWrapped(m_app.get_systems().core.errors.c_str());
}
ImGui::EndChild();
}
ImGui::End();

ImGui::PopStyleVar(2);
ImGui::EndPopup();
}
ImGui::PopStyleVar(1);

return state;
}
22 changes: 22 additions & 0 deletions source/src/gui/dt_modal_errors.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include "gui/dt_gui_base.hpp"

#include <dv_gui_opengl/models/dv_command.hpp>

namespace dvsku_toolkit {
class dt_modal_errors : public dt_gui_base {
public:
dt_modal_errors() = delete;
dt_modal_errors(const dt_modal_errors&) = delete;
dt_modal_errors(dt_modal_errors&&) = delete;

dt_modal_errors(dt_app& app);

dt_modal_errors& operator=(const dt_modal_errors&) = delete;
dt_modal_errors& operator=(dt_modal_errors&&) = delete;

public:
dvsku::dv_command_state render();
};
}
2 changes: 1 addition & 1 deletion source/src/systems/dt_sys_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using namespace dvsku;

void dt_sys_command::prepare() {
set_command(dt_commands::flag_show_error_window, dv_command([this]() {
return m_app.get_gui().errors.render();
return m_app.get_gui().modal_errors.render();
}));
}

Expand Down
6 changes: 3 additions & 3 deletions source/src/systems/dt_sys_command.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ namespace dvsku_toolkit {

class dt_sys_command : public dt_system_base, public dvsku::dv_sys_command<dt_commands> {
public:
dt_sys_command() = delete;
dt_sys_command() = delete;
dt_sys_command(const dt_sys_command&) = delete;
dt_sys_command(dt_sys_command&&) = delete;
dt_sys_command(dt_sys_command&&) = delete;

dt_sys_command& operator=(const dt_sys_command&) = delete;
dt_sys_command& operator=(dt_sys_command&&) = delete;
dt_sys_command& operator=(dt_sys_command&&) = delete;

dt_sys_command(dt_app& app)
: dt_system_base(app), dv_sys_command<dt_commands>() {};
Expand Down

0 comments on commit 32a7e11

Please sign in to comment.