Voltray Engine Docs
Loading...
Searching...
No Matches
Console.h
Go to the documentation of this file.
1#pragma once
2#include "../UI/Panel.h"
3#include <vector>
4#include <string>
5#include <chrono>
6#include <sstream>
7#include <iostream>
8#include <memory>
9#include <imgui.h>
10
16namespace Editor::Components
17{
22 enum class MessageType
23 {
24 Info,
25 Warning,
26 Error,
27 Debug,
29 };
30
36 {
37 std::string text;
39 std::chrono::steady_clock::time_point timestamp;
40
41 ConsoleMessage(const std::string &msg, MessageType msgType)
42 : text(msg), type(msgType), timestamp(std::chrono::steady_clock::now()) {}
43 };
44
50 class Console : public Panel
51 {
52 public:
56 Console();
57
62
67 void Draw() override;
68
74 void AddMessage(const std::string &message, MessageType type = MessageType::Info);
75
79 void Clear();
80
85 static Console &GetInstance();
86
87 // Static convenience functions for easy debug printing
88 static void Print(const std::string &message);
89 static void PrintWarning(const std::string &message);
90 static void PrintError(const std::string &message);
91 static void PrintDebug(const std::string &message);
92 static void PrintSuccess(const std::string &message);
93
94 private:
95 std::vector<ConsoleMessage> m_messages;
96 bool m_autoScroll = true;
97 bool m_showTimestamps = true;
98
99 // Filter options
100 bool m_showInfo = true;
101 bool m_showWarning = true;
102 bool m_showError = true;
103 bool m_showDebug = true;
104 bool m_showSuccess = true;
105
106 // Static instance for singleton pattern
107 static std::unique_ptr<Console> s_instance;
108
114 ImVec4 GetMessageColor(MessageType type) const;
115
121 const char *GetMessagePrefix(MessageType type) const;
122
128 std::string FormatTimestamp(const std::chrono::steady_clock::time_point &timestamp) const;
129 };
130
131 // Global convenience functions (can be used from anywhere)
132 void DebugPrint(const std::string &message);
133 void DebugPrintWarning(const std::string &message);
134 void DebugPrintError(const std::string &message);
135 void DebugPrintDebug(const std::string &message);
136 void DebugPrintSuccess(const std::string &message);
137}
A panel component that provides console functionality in the editor.
Definition Console.h:51
static void Print(const std::string &message)
Definition Console.cpp:184
static Console & GetInstance()
Gets the singleton instance of the console.
Definition Console.cpp:21
static void PrintSuccess(const std::string &message)
Definition Console.cpp:204
void AddMessage(const std::string &message, MessageType type=MessageType::Info)
Adds a message to the console.
Definition Console.cpp:117
~Console()
Destructor that cleans up console resources.
static void PrintError(const std::string &message)
Definition Console.cpp:194
void Draw() override
Renders the console panel interface. @override Implements the abstract method from the Panel base cla...
Definition Console.cpp:30
void Clear()
Clears all messages from the console.
Definition Console.cpp:127
static void PrintDebug(const std::string &message)
Definition Console.cpp:199
static void PrintWarning(const std::string &message)
Definition Console.cpp:189
Console()
Constructor that sets up the console.
Definition Console.cpp:11
Base class for all UI panels in the editor.
Definition Panel.h:19
Represents the Inspector panel component in the Editor.
Definition Console.cpp:7
void DebugPrintWarning(const std::string &message)
Definition Console.cpp:215
void DebugPrintError(const std::string &message)
Definition Console.cpp:220
void DebugPrint(const std::string &message)
Definition Console.cpp:210
void DebugPrintDebug(const std::string &message)
Definition Console.cpp:225
MessageType
Defines different types of console messages.
Definition Console.h:23
void DebugPrintSuccess(const std::string &message)
Definition Console.cpp:230
Represents a single message in the console.
Definition Console.h:36
std::string text
Definition Console.h:37
ConsoleMessage(const std::string &msg, MessageType msgType)
Definition Console.h:41
std::chrono::steady_clock::time_point timestamp
Definition Console.h:39
MessageType type
Definition Console.h:38