Files
sophia/engine/src/ui/panels/console_panel.hpp
T
2026-09-15 02:36:23 -07:00

51 lines
1.0 KiB
C++

#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