1
1
#include < pch.h>
2
+ #include < Helpers/MemoryOperations.h>
2
3
#include < LogUIComponent.h>
3
4
#include < imgui.h>
5
+ #include < algorithm>
4
6
5
7
using namespace ZEngine ::Logging;
8
+ using namespace ZEngine ::Helpers;
6
9
7
10
namespace Tetragrama ::Components
8
11
{
@@ -28,36 +31,69 @@ namespace Tetragrama::Components
28
31
{
29
32
ImGui::Begin (Name.c_str (), (CanBeClosed ? &CanBeClosed : NULL ), ImGuiWindowFlags_NoCollapse);
30
33
31
- ImGui::SameLine () ;
32
- m_is_clear_button_pressed = ImGui::Button ( " Clear " ) ;
34
+ static const char * items[] = { " All " , " info " , " error " , " warn " , " critical " , " trace " } ;
35
+ static int current_item = 0 ;
33
36
34
37
ImGui::SameLine ();
35
- m_is_copy_button_pressed = ImGui::Button (" Copy" );
38
+ ImGui::SetNextItemWidth (70 );
39
+ if (ImGui::BeginCombo (" ##Dropdown" , items[current_item]))
40
+ {
41
+ for (int n = 0 ; n < IM_ARRAYSIZE (items); n++)
42
+ {
43
+ if (ImGui::Selectable (items[n], current_item == n))
44
+ {
45
+ current_item = n;
46
+ ImGui::SetItemDefaultFocus ();
47
+ }
48
+ }
49
+ ImGui::EndCombo ();
50
+ }
36
51
37
- ImGui::Separator ();
52
+ ImGui::SameLine ();
53
+ if (ImGui::Button (" Clear" ))
54
+ {
55
+ ClearLog ();
56
+ m_search_buffer[0 ] = ' \0 ' ;
57
+ }
38
58
39
- if (m_is_copy_button_pressed)
59
+ ImGui::SameLine ();
60
+ if (m_is_copy_button_pressed = ImGui::Button (" Copy" ))
40
61
{
41
62
ImGui::LogToClipboard ();
42
63
}
43
64
44
- if (m_is_clear_button_pressed)
65
+ ImGui::SameLine ();
66
+ ImGui::InputTextWithHint (" ##Search" , " Search logs..." , m_search_buffer, IM_ARRAYSIZE (m_search_buffer));
67
+ ImGui::Separator ();
68
+
69
+ std::string search_term;
70
+ if (secure_strlen (m_search_buffer) > 0 )
45
71
{
46
- ClearLog ();
72
+ search_term = m_search_buffer;
73
+ std::transform (search_term.begin (), search_term.end (), search_term.begin (), ::tolower);
47
74
}
48
75
49
76
ImGui::PushStyleVar (ImGuiStyleVar_ItemSpacing, ImVec2 (0 , 0 ));
50
-
51
77
if (ImGui::BeginTable (" log_table" , 1 , ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY))
52
78
{
53
79
std::lock_guard<std::mutex> lock (m_mutex);
80
+ for (const auto & message : m_log_queue)
54
81
{
55
- for (const ZEngine::Logging::LogMessage& message : m_log_queue)
82
+ if (current_item != 0 )
83
+ {
84
+ if (GetMessageType (message) != items[current_item])
85
+ continue ;
86
+ }
87
+ if (secure_strlen (m_search_buffer) > 0 )
56
88
{
57
- ImGui::TableNextRow ();
58
- ImGui::TableSetColumnIndex (0 );
59
- ImGui::TextColored ({message.Color [0 ], message.Color [1 ], message.Color [2 ], message.Color [3 ]}, message.Message .data ());
89
+ std::string message_lower = message.Message ;
90
+ std::transform (message_lower.begin (), message_lower.end (), message_lower.begin (), ::tolower);
91
+ if (message_lower.find (search_term) == std::string::npos)
92
+ continue ;
60
93
}
94
+ ImGui::TableNextRow ();
95
+ ImGui::TableSetColumnIndex (0 );
96
+ ImGui::TextColored ({message.Color [0 ], message.Color [1 ], message.Color [2 ], message.Color [3 ]}, message.Message .data ());
61
97
}
62
98
ImGui::EndTable ();
63
99
}
@@ -92,4 +128,17 @@ namespace Tetragrama::Components
92
128
m_currentCount++;
93
129
}
94
130
}
131
+
132
+ std::string LogUIComponent::GetMessageType (const ZEngine::Logging::LogMessage& message)
133
+ {
134
+ if (message.Color [0 ] == 0 .0f && message.Color [1 ] == 1 .0f && message.Color [2 ] == 0 .0f && message.Color [3 ] == 1 .0f )
135
+ return " info" ;
136
+ if (message.Color [0 ] == 1 .0f && message.Color [1 ] == 0 .5f && message.Color [2 ] == 0 .0f && message.Color [3 ] == 1 .0f )
137
+ return " warn" ;
138
+ if (message.Color [0 ] == 1 .0f && message.Color [1 ] == 0 .0f && message.Color [2 ] == 0 .0f && message.Color [3 ] == 1 .0f )
139
+ return " error" ;
140
+ if (message.Color [0 ] == 1 .0f && message.Color [1 ] == 0 .0f && message.Color [2 ] == 1 .0f && message.Color [3 ] == 0 .0f )
141
+ return " critical" ;
142
+ return " trace" ;
143
+ }
95
144
} // namespace Tetragrama::Components
0 commit comments