Refactor CommandLine to not naiively override Window::Open, Close()

This commit is contained in:
2025-06-27 15:28:06 -05:00
parent d935608e05
commit 944bd66b43
2 changed files with 4 additions and 25 deletions

View File

@@ -24,10 +24,6 @@ namespace JUI {
/// This event is invoked when the user has sent a message to the command line.
Event<std::string> OnInput;
/// This event is invoked when the CommandLine window is opened.
Event<> OnOpen;
/// This event is invoked when the CommandLine window is closed.
Event<> OnClose;
/// The default constructor initializes the layout and events of child elements.
/// This constructor is a delegate called by the explicit constructor with parent parameter.
@@ -42,18 +38,8 @@ namespace JUI {
/// @param color
void Log(const std::string& message, const Color4& color = Colors::White);
/// @return True if the window widget is currently open and visible. Input will be ignored if not.
[[nodiscard]] bool Opened() const;
/// @return True if the window widget is currently closed and invisible. Input will be ignored if so.
[[nodiscard]] bool Closed() const;
/// Opens the window widget.
void Open(bool openVal = true);
/// Closes the window widget.
void Close(bool openVal = false);
/// 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);
void SetOpen(bool openVal) override;
/// Passes input events down the widget hierarchy.
/// @return True if this widget will "consume" the input.
@@ -70,7 +56,6 @@ namespace JUI {
int index = 0;
int input_form_height = 20;
int message_height = 16;
bool open = false;
std::vector<std::string> msg_history;
private:
};

View File

@@ -35,6 +35,7 @@ namespace JUI
input_box->TextSize(16);
input_box->TextColor(Colors::White);
input_box->SetAutocompleteTextColor(Colors::Gray);
input_box->KeepInputHistory(true);
input_box->OnReturn += [this] (const std::string& msg) {
OnInputBoxSend(msg);
@@ -46,17 +47,10 @@ namespace JUI
this->Parent(parent);
}
bool CommandLine::Opened() const { return this->open == true;}
bool CommandLine::Closed() const { return this->open == false;}
void CommandLine::Open(bool openVal) { SetOpen(openVal); }
void CommandLine::Close(bool openVal) { SetOpen(openVal);}
void CommandLine::SetOpen(bool openVal) {
this->Visible(openVal);
this->open = openVal;
Window::SetOpen(openVal);
this->input_box->SetFocused(openVal);
}
void CommandLine::Log(const std::string &message, const Color4 &color) {