Cogs.Core
ShowLicensesCommand.cpp
1#include "imgui.h"
2#include "markdown/imgui_markdown.h"
3
4#include "ShowLicensesCommand.h"
5#include "Bridge/Bridge.h"
6#include "Commands/EditorCommand.h"
7#include "Foundation/Logging/Logger.h"
8
9namespace
10{
11 const Cogs::Logging::Log logger = Cogs::Logging::getLogger("ShowLicensesCommand");
12}
13
14Cogs::Core::ShowLicensesCommand::ShowLicensesCommand(EditorState* state) : ModalEditorCommand(state)
15{
16 licensesText = ::getLicenseText(context);
17 if (!licensesText) {
18 LOG_ERROR(logger, "Cannot open the License.md file from Resources.");
19 }
20}
21
23{
24 modal = true;
25}
26
28{
29 assert(modal);
30
31 ImGui::SetNextWindowSizeConstraints(ImVec2(300, 200), ImVec2(FLT_MAX, FLT_MAX));
32 ImGui::OpenPopup("Show Licenses");
33 // Passing modal as p_open parameter would convenietly perform modal = false if window was closed on X button.
34 if (ImGui::BeginPopupModal("Show Licenses", &modal, ImGuiWindowFlags_None)) {
35 if (licensesText) {
36 ImGui::BeginChild("Markdown", ImVec2(ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y - 30), false, ImGuiWindowFlags_None);
37 ImGui::Markdown(licensesText, std::strlen(licensesText), config);
38 ImGui::EndChild();
39 }
40
41 ImGui::Separator();
42
43 if (ImGui::Button("OK", ImVec2(120, 20))) {
44 modal = false;
45 ImGui::CloseCurrentPopup();
46 }
47
48 ImGui::EndPopup();
49 }
50
51}
52
54{
55 return modal;
56}
Log implementation class.
Definition: LogManager.h:139
constexpr Log getLogger(const char(&name)[LEN]) noexcept
Definition: LogManager.h:180
void beginModal() override
Called when the command is initiated.
void showGui() override
Display custom ImGUI.
bool continueModal() override
Shall return true while the GUI should still be shown. False when.