Adding new widgets
This commit is contained in:
@@ -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.
|
||||
|
@@ -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:
|
||||
|
10
include/JUI/Widgets/CheckboxLabel.hpp
Normal file
10
include/JUI/Widgets/CheckboxLabel.hpp
Normal 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
|
||||
{
|
||||
|
||||
};
|
||||
}
|
87
include/JUI/Widgets/CommandLine.hpp
Normal file
87
include/JUI/Widgets/CommandLine.hpp
Normal 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:
|
||||
};
|
||||
}
|
@@ -31,6 +31,8 @@
|
||||
& &
|
||||
*/
|
||||
|
||||
// TODO: Simpler "One-liner" Rich text, which is a horizontal sequence of textlabels automatically generated from a format.
|
||||
|
||||
namespace RichTextFormat
|
||||
{
|
||||
|
||||
|
@@ -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;
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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;
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user