Files
ReJUI/include/JUI/Widgets/CommandLine.hpp

64 lines
2.3 KiB
C++

#pragma once
#include <JUI/Widgets/Window.hpp>
#include <JUI/Widgets/TextInputForm.hpp>
#include <JUI/Widgets/ScrollingRect.hpp>
#include <JUI/Widgets/ListLayout.hpp>
namespace JUI {
// TODO: Implement "Rich Text" message support.
// TODO: Implement command autocomplete helper API.
// TODO: Implement API for user-projects to bind commands.
// TODO: Implement API for user-projects to bind loggers.
// TODO: Implement message history.
// TODO: As of now, the API user is in charge of parsing and executing commands.
// TODO: A fairly-generic CommandInterpreter which suits our purposes.
// TODO: <command> <arg1> <arg2> <arg3>
// TODO: Tight JSON integration for specifying complex metadata in commands.
/// A generic "Game Console", which provides a log history, and input box for user-defined commands.
class CommandLine : public Window {
public:
/// This event is invoked when the user has sent a message to the command line.
Event<std::string> OnInput;
/// The default constructor initializes the layout and events of child elements.
/// This constructor is a delegate called by the explicit constructor with parent parameter.
CommandLine();
/// Constructs a command line by specifying the widget it should be parented to.
/// @param parent
explicit CommandLine(Widget* parent);
/// Adds a message to the CommandLine message history.
/// @param message
/// @param color
void Log(const std::string& message, const Color4& color = Colors::White);
/// Sets the "open"-ness of the window widget. The widget will be invisible and ignore input if it is not open.
void SetOpen(bool openVal) override;
/// Passes input events down the widget hierarchy.
/// @return True if this widget will "consume" the input.
bool ObserveKeyInput(Key key, bool pressed) override;
/// Invoked when a message is sent to the command line.
virtual void OnInputBoxSend(const std::string& message);
protected:
TextInputForm* input_box;
ScrollingRect* message_log_box;
VerticalListLayout* message_log_list;
protected:
int index = 0;
int input_form_height = 20;
int message_height = 16;
std::vector<std::string> msg_history;
private:
};
}