-
-
Notifications
You must be signed in to change notification settings - Fork 49
/
LogWidget.cpp
54 lines (48 loc) · 1.27 KB
/
LogWidget.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
44
45
46
47
48
49
50
51
52
53
54
#include "LogWidget.h"
LogWidget::LogWidget(Hosting& hosting)
: _commandLog(hosting.getCommandLog()), _messageCount(0)
{
}
bool LogWidget::render()
{
AppStyle::pushTitle();
ImGui::SetNextWindowSizeConstraints(ImVec2(300, 200), ImVec2(800, 900));
ImGui::Begin("Log", (bool*)0);
AppStyle::pushInput();
ImVec2 size = ImGui::GetContentRegionAvail();
static vector<string>::iterator it;
it = _commandLog.begin();
ImGui::BeginChild("Log text", ImVec2(size.x, size.y));
for (; it != _commandLog.end(); ++it)
{
if ((*it)[0] == '@')
{
AppStyle::pushPositive();
ImGui::TextWrapped((*it).c_str());
AppStyle::pop();
}
else if ((*it)[0] == '!')
{
AppStyle::pushNegative();
ImGui::TextWrapped((*it).c_str());
AppStyle::pop();
}
else
{
ImGui::TextWrapped((*it).c_str());
}
}
if (_messageCount != _commandLog.size())
{
if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY() - 10)
{
ImGui::SetScrollHereY(1.0f);
}
_messageCount = _commandLog.size();
}
ImGui::EndChild();
AppStyle::pop();
ImGui::End();
AppStyle::pop();
return true;
}