Adding new widgets

This commit is contained in:
2025-04-02 13:19:06 -04:00
parent 4193a2a693
commit b3f65b3396
10 changed files with 106 additions and 8 deletions

View File

@@ -17,8 +17,7 @@
using J3ML::LinearAlgebra::Vector2;
namespace JUI
{
namespace JUI {
/// The ImageBase class is an object that handles managing and rendering a texture reference.
/// This class is used as a mixin on widgets that must render images. i.e. Image class.
/// This object is complex, stateful, and manages resources. Do not use this as a general-purpose texture data type.

View File

@@ -332,7 +332,7 @@ namespace JUI {
/// This is designed in such a way that the end-user can plug this into their existing code.
/// The user should call this on their Scene instances only. JUI will handle the rest.
/// See ReWindowIntegrationDemo for an example.
virtual void ObserveKeyInput(Key key, bool pressed);
virtual bool ObserveKeyInput(Key key, bool pressed);
protected:

View File

@@ -0,0 +1,10 @@
#pragma once
namespace JUI
{
/// A composite class which combines a Checkbox and TextLabel into one element.
class CheckboxLabel : public Rect
{
};
}

View File

@@ -0,0 +1,87 @@
#pragma once
#include <JUI/Widgets/Window.hpp>
#include <JUI/Widgets/TextInputForm.hpp>
#include <JUI/Widgets/ScrollingRect.hpp>
#include <JUI/Widgets/ListLayout.hpp>
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.
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);
};
}
void Log(const std::string& message, const Color4& color = Colors::White)
{
const Color4 light {60, 60, 60};
const Color4 dark {80, 80, 80};
auto* entry = new JUI::TextRect(message_log_list);
entry->Size({100_percent, UDim(message_height, 0)});
entry->SetContent(message);
}
[[nodiscard]] bool Opened() const;
[[nodiscard]] bool Closed() const;
void Open(bool open = true);
void Close(bool open = false);
bool ObserveKeyInput(Key key, bool pressed) override;
virtual void OnInputBoxSend(const std::string message)
{
OnInput.Invoke(message);
input_box->SetContent("");
input_box->SetAutoCompleteText("");
}
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;
bool open = false;
std::vector<std::string> msg_history;
private:
};
}

View File

@@ -31,6 +31,8 @@
& &amp;
*/
// TODO: Simpler "One-liner" Rich text, which is a horizontal sequence of textlabels automatically generated from a format.
namespace RichTextFormat
{

View File

@@ -52,7 +52,7 @@ public:
void Draw() override;
void Update(float delta) override;
void ObserveKeyInput(Key key, bool pressed) override;
bool ObserveKeyInput(Key key, bool pressed) override;
public:
~ScrollingRect() override;

View File

@@ -63,7 +63,7 @@ namespace JUI {
void PushKeyToCurrentPlaceInInputBuffer(const Key &key);
void ObserveKeyInput(Key key, bool pressed) override;
bool ObserveKeyInput(Key key, bool pressed) override;
bool ObserveMouseInput(MouseButton btn, bool pressed) override;
bool ObserveMouseMovement(const Vector2 &latest_known_pos) override;
[[nodiscard]] std::string GetAutocompleteText() const;

View File

@@ -339,7 +339,7 @@ bool Widget::ObserveMouseMovement(const Vector2 &latest_known_pos) {
return false;
}
void Widget::ObserveKeyInput(Key key, bool pressed) {
bool Widget::ObserveKeyInput(Key key, bool pressed) {
for (Widget* child : children)
child->ObserveKeyInput(key, pressed);
}

View File

@@ -86,7 +86,7 @@ void ScrollingRect::Update(float delta) {
Rect::Update(delta);
}
void ScrollingRect::ObserveKeyInput(Key key, bool pressed) {
bool ScrollingRect::ObserveKeyInput(Key key, bool pressed) {
if (key == Keys::UpArrow && pressed)
{
scroll -= 10;

View File

@@ -184,7 +184,7 @@ namespace JUI {
PushStringToCurrentPlaceInInputBuffer(insertion);
}
void TextInputForm::ObserveKeyInput(Key key, bool pressed) {
bool TextInputForm::ObserveKeyInput(Key key, bool pressed) {
Widget::ObserveKeyInput(key, pressed);
if (!pressed || !focused) return;
if (key == Keys::Return || key == Keys::NumPadReturn)