Add CommandLine window widget.

This commit is contained in:
2025-04-02 15:25:41 -05:00
parent b3f65b3396
commit fffcc7f12d
2 changed files with 47 additions and 27 deletions

View File

@@ -8,44 +8,31 @@
namespace JUI
{
/// A generic "Game Console", which provides a log history, and input box for user-defined commands.
// 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:
Event<std::string> OnInput;
Event<> OnOpen;
Event<> OnClose;
explicit CommandLine(Widget* parent) : JUI::Window(parent)
{
this->SetTitle("Console");
message_log_box = new JUI::ScrollingRect(this->ViewportInstance());
message_log_box->Size(JUI::UDim2(0, -input_form_height, 1, 1));
message_log_list = new JUI::VerticalListLayout(message_log_box);
message_log_list->LayoutOrder(JUI::LayoutOrder::V::BOTTOM);
input_box = new JUI::TextInputForm(this->ViewportInstance());
input_box->SetAutoCompleteText(">Type Commands Here");
input_box->Size(JUI::UDim2(0, 20, 1, 0));
input_box->Position(JUI::UDim2(0, -20, 0, 1));
input_box->BGColor(Colors::Grays::DarkSlateGray);
input_box->SetTextSize(16);
input_box->SetTextColor(Colors::White);
input_box->SetAutocompleteTextColor(Colors::Gray);
input_box->OnReturn += [this] (const std::string& msg) {
OnInputBoxSend(msg);
};
}
/// 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.
explicit CommandLine(Widget* parent);
void Log(const std::string& message, const Color4& color = Colors::White)
{
@@ -84,4 +71,5 @@ namespace JUI
std::vector<std::string> msg_history;
private:
};
}
}

View File

@@ -0,0 +1,32 @@
#include <JUI/Widgets/CommandLine.hpp>
namespace JUI
{
CommandLine::CommandLine() {
this->SetTitle("Console");
message_log_box = new JUI::ScrollingRect(this->ViewportInstance());
message_log_box->Size(JUI::UDim2(0, -input_form_height, 1, 1));
message_log_list = new JUI::VerticalListLayout(message_log_box);
message_log_list->LayoutOrder(JUI::LayoutOrder::V::BOTTOM);
input_box = new JUI::TextInputForm(this->ViewportInstance());
input_box->SetAutoCompleteText(">Type Commands Here");
input_box->Size(JUI::UDim2(0, 20, 1, 0));
input_box->Position(JUI::UDim2(0, -20, 0, 1));
input_box->BGColor(Colors::Grays::DarkSlateGray);
input_box->SetTextSize(16);
input_box->SetTextColor(Colors::White);
input_box->SetAutocompleteTextColor(Colors::Gray);
input_box->OnReturn += [this] (const std::string& msg) {
OnInputBoxSend(msg);
};
}
CommandLine::CommandLine(Widget *parent): CommandLine() {
this->Parent(parent);
}
}