Added console concept
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
#include <functional>
|
||||
#include <sophia/frame_info.hpp>
|
||||
#include <sophia/ui/panel.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace sophia {
|
||||
|
||||
class ConsolePanel : public Panel {
|
||||
public:
|
||||
using CommandCallback =
|
||||
std::function<void(ConsolePanel&, const std::string&)>;
|
||||
|
||||
ConsolePanel() : Panel{"Console"} { registerDefaultCommands(); }
|
||||
|
||||
void onUpdate(const FrameInfo& frameInfo) override;
|
||||
|
||||
void log(const std::string& message);
|
||||
void clear();
|
||||
|
||||
void setCommandCallback(CommandCallback callback) {
|
||||
this->commandCallback = std::move(callback);
|
||||
}
|
||||
|
||||
private:
|
||||
struct Entry {
|
||||
std::string text;
|
||||
ImVec4 color;
|
||||
};
|
||||
|
||||
void registerDefaultCommands();
|
||||
void execute(const std::string& command);
|
||||
int textEditCallback(struct ImGuiInputTextCallbackData* data);
|
||||
|
||||
std::vector<Entry> entries;
|
||||
std::vector<std::string> history;
|
||||
int historyPos = -1;
|
||||
|
||||
char inputBuffer[256] = {};
|
||||
bool autoScroll = true;
|
||||
bool scrollToBottom = false;
|
||||
|
||||
CommandCallback commandCallback;
|
||||
};
|
||||
|
||||
} // namespace sophia
|
||||
Reference in New Issue
Block a user