Editor Refactor
This refactor of the editor code makes the code more maintainable. All widget objects have now moved away from RAII and are now just allocated object that live for the entirety of the applications lifetime. This feels better as I am used to this style plus constantly pushing and popping objects from the stack seems a little wasteful (although I as of right now have no way to prove that it is ).
This commit is contained in:
38
Editor/src/Console.cpp
Normal file
38
Editor/src/Console.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include "Console.h"
|
||||
#include <stdio.h>
|
||||
|
||||
Console::Console()
|
||||
: EditorWindow("Console"), Items(ImVector<char*>()), AutoScroll(false), ScrollToBottom(false)
|
||||
{
|
||||
AddLog("Hello Editor console!");
|
||||
}
|
||||
|
||||
Console::~Console() {
|
||||
|
||||
}
|
||||
|
||||
void Console::Show() {
|
||||
Draw();
|
||||
}
|
||||
|
||||
void Console::Draw() {
|
||||
ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver);
|
||||
|
||||
|
||||
for (int i = 0; i < Items.Size; i++)
|
||||
{
|
||||
const char* item = Items[i];
|
||||
ImGui::TextUnformatted(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Console::AddLog(const char* fmt, ...) {
|
||||
char buf[1024];
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args);
|
||||
buf[IM_ARRAYSIZE(buf) - 1] = 0;
|
||||
va_end(args);
|
||||
Items.push_back(strdup(buf));
|
||||
}
|
Reference in New Issue
Block a user