-
Notifications
You must be signed in to change notification settings - Fork 0
/
WindowConsole.cpp
43 lines (35 loc) · 917 Bytes
/
WindowConsole.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "WindowConsole.h"
#include "Leaks.h"
WindowConsole::WindowConsole(std::string name, int windowID) : Window(name, windowID) {
autoScroll = true;
buffer.clear();
}
WindowConsole::~WindowConsole() {
buffer.clear();
}
void WindowConsole::AddLog(const char* fmt, ...) IM_FMTARGS(2) {
int old_size = buffer.size();
va_list args;
va_start(args, fmt);
buffer.appendfv(fmt, args);
va_end(args);
autoScroll = true;
}
void WindowConsole::Draw() {
if (!active) return;
if (!ImGui::Begin(name.c_str(), &active)) {
ImGui::End();
return;
}
ImGui::BeginChild("ScrollingRegion", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar);
if (ImGui::BeginPopupContextWindow()) {
if (ImGui::Selectable("Clear")) buffer.clear();
ImGui::EndPopup();
}
ImGui::TextUnformatted(buffer.begin());
if (autoScroll)
ImGui::SetScrollHere(1.0f);
autoScroll = false;
ImGui::EndChild();
ImGui::End();
}