This commit is contained in:
2025-02-17 22:35:08 -05:00
parent f772369686
commit f105053fb2
27 changed files with 82 additions and 52 deletions

View File

@@ -51,7 +51,7 @@ namespace JUI
void SetClipsDescendants(bool clipping);
void BGColor(const Color4& col);
void BorderColor(const Color4& col);
void SetBorderWidth(float w);
void BorderWidth(float w);
[[nodiscard]] Color4 BGColor() const;

View File

@@ -65,8 +65,6 @@ namespace JUI {
Tween* TweenPosition(const UDim2& goal, TweenInfo params = {});
Tween* TweenSize(const UDim2& goal, TweenInfo params = {});
/// Adds a given widget to this widget's list of children.
/// @return The widget in question.
Widget* Add(Widget* newChild);
@@ -324,8 +322,6 @@ namespace JUI {
MouseButton mbtn;
bool mb_state = false;
bool prev_mb_state = false;
//int last_known_mouse_button;
//bool last_known_mouse_button_state;
Vector2 last_known_mouse_pos = {0,0};
UDim2 position = {0_px, 0_px};
UDim2 size = {50_px, 50_px};
@@ -349,10 +345,8 @@ namespace JUI {
Widget* prev = nullptr;
int zindex = 0;
int layout_order = 0;
Vector2 viewport_size{0,0};
/// Returns the amount of pixels this widget will be padded by from the top-left.
/// Generally, the widget will be shrunk and moved over by this amount, relative to the parent.
Vector2 GetAbsolutePaddingTopLeft() const;
@@ -360,13 +354,8 @@ namespace JUI {
/// Returns the amount of pixels this widget will be padded by from bottom-right.
/// Generally, the widget will be shrunk by twice this amount, relative to the parent.
Vector2 GetAbsolutePaddingBottomRight() const;
Vector2 GetAbsoluteMarginTopLeft();
Vector2 GetAbsoluteMarginBottomRight();
void UpdateTweens(float elapsed);
};
}

View File

@@ -22,7 +22,7 @@ namespace JUI
{
public:
GridLayout() : LayoutContainer() {
Name("GridLayout");
}
explicit GridLayout(Widget* parent) : GridLayout()
{

View File

@@ -11,7 +11,7 @@ namespace JUI {
public:
Separator() : Widget()
{
Name("Separator");
}
explicit Separator(Widget* parent)

View File

@@ -31,7 +31,7 @@ namespace JUI
public:
Event<float> ValueChanged;
Slider() = default;
Slider();
explicit Slider(JUI::Widget* parent);
[[nodiscard]] float Minimum() const;

View File

@@ -9,9 +9,8 @@ namespace JUI
class Tooltip : public TextRect
{
public:
Tooltip() : TextRect()
{
Tooltip() : TextRect() {
Name("Tooltip");
}
explicit Tooltip(Widget* parent) : Tooltip()
{

View File

@@ -6,6 +6,7 @@ namespace JUI
class ContextMenu : public Rect {
public:
ContextMenu() : Rect() {
Name("ContextMenu");
this->BGColor(Colors::White);
this->Margin(2_px);
this->Size({200, 200, 0, 0});
@@ -59,7 +60,7 @@ namespace JUI
this->Position({0,0,0,0});
this->BGColor(Colors::White);
this->BorderColor(Colors::Blues::CornflowerBlue);
this->SetBorderWidth(2);
this->BorderWidth(2);
this->Margin(2_px);
this->BorderMode(BorderMode::Outline);
layout = new HorizontalListLayout(this);
@@ -90,7 +91,7 @@ namespace JUI
btn->SetTextSize(14);
btn->SetTextColor(Colors::Black);
btn->Size({static_cast<int>(str_width.x)+16, 0, 0, 1});
btn->SetBorderWidth(0.f);
btn->BorderWidth(0.f);
btn->SetContent(name);
return btn;
}

View File

@@ -41,6 +41,7 @@ JUI::Scene* CreateScene() {
auto *root = new Scene();
auto* nineslice_demo_window = new JUI::Window(root);
nineslice_demo_window->Name("NineSlice Demo Window");
nineslice_demo_window->CornerRounding(10);
nineslice_demo_window->Size({50_percent, 50_percent});
nineslice_demo_window->SetTitle("9-Slice Demo");
@@ -158,6 +159,7 @@ JUI::Scene* CreateScene() {
auto* label = new TextRect(checkbox_horiz);
label->SetContent("Checkboxes");
label->BorderWidth(0);
label->AutoFitSizeToText(true);
auto* check1 = new Checkbox(checkbox_horiz);
@@ -326,21 +328,28 @@ public:
}
void OnKeyDown(const ReWindow::KeyDownEvent &) override
{
void OnKeyDown(const ReWindow::KeyDownEvent &) override {
}
void OnMouseWheel(const ReWindow::MouseWheelEvent &w) override
{
void OnMouseWheel(const ReWindow::MouseWheelEvent &w) override {
scale += w.WheelMovement * 0.125f;
scene->GlobalUIScale({scale, scale});
}
//bool OnResizeRequest(const ReWindow::WindowResizeRequestEvent &e) override {}
//JUIDevelopmentTestWindow() : ReWindow::OpenGLWindow() {}
};
void inspect_widget(JUI::Widget* w, int depth = 1) {
std::cout << std::setw(depth*4);
std::cout << w->Name() << std::endl;
std::cout << std::setw(0);
depth++;
for (auto* child : w->GetChildren())
{
inspect_widget(child, depth);
}
}
int main()
{
@@ -368,6 +377,8 @@ int main()
slicer = new JGL::Texture("assets/9slice.png");
scene = CreateScene();
inspect_widget(scene);
window->OnResizeRequestEvent += [&] (ReWindow::WindowResizeRequestEvent e){
Vector2i size = Vector2i(e.Size.x, e.Size.y);//window->getLastKnownResize();

View File

@@ -14,7 +14,7 @@ namespace JUI {
void RectBase::BorderColor(const Color4 &col) { border_color = col; }
void RectBase::SetBorderWidth(float w) {border_width = w; }
void RectBase::BorderWidth(float w) { border_width = w; }
float RectBase::GetBorderWidth() const { return border_width; }
@@ -24,7 +24,7 @@ namespace JUI {
void RectBase::SetBorderStyling(const Color4 &color, float width) {
BorderColor(color);
SetBorderWidth(width);
BorderWidth(width);
}

View File

@@ -268,7 +268,6 @@ void Widget::Draw() {
PreDraw();
InnerDraw();
PostDraw();
DrawChildWidgets();
}

View File

@@ -4,6 +4,7 @@
namespace JUI {
Button::Button(): Rect(), Clickable() {
Name("Button");
BGColor(BaseBGColor());
BorderColor(BaseBorderColor());
}

View File

@@ -2,11 +2,13 @@
namespace JUI {
Collapsible::Collapsible() : Rect() {
Name("Collapsible");
header = new TextButton(this);
header->Size({100_percent, header_height});
header->SetContent("Collapsible");
header->BaseBGColor(Colors::Gray);
header->BGColor(Colors::Gray);
header->BaseBGColor(Colors::DarkGray);
header->BGColor(Colors::DarkGray);
header->Center();
//header->
header->OnClickEvent += [this] (auto a, auto b) {
@@ -20,11 +22,12 @@ namespace JUI {
lil_arrow->Size({header_height, header_height});
lil_arrow->BGColor(Colors::Transparent);
lil_arrow->SetContent("/\\");
lil_arrow->BorderWidth(0);
content_box = new Rect(this);
content_box->BGColor(Colors::Transparent);
content_box->BorderColor(Colors::Transparent);
content_box->SetBorderWidth(0);
content_box->BorderWidth(0);
content_box->Position({0_px, header_height});
content_box->Size({100_percent, 100_percent - header_height});

View File

@@ -2,9 +2,8 @@
namespace JUI
{
Image::Image() : Widget(), ImageBase()
{
Image::Image() : Widget(), ImageBase() {
Name("Image");
}
Image::Image(Widget* parent) : Image()

View File

@@ -10,7 +10,9 @@ void JUI::ImageButton::Draw() {
ImageBase::Draw(GetAbsolutePosition()+GetAbsolutePaddingTopLeft(), GetAbsoluteSize()-GetAbsolutePaddingBottomRight());
}
JUI::ImageButton::ImageButton() : ImageBase(), Button() {}
JUI::ImageButton::ImageButton() : ImageBase(), Button() {
Name("ImageButton");
}
JUI::ImageButton::ImageButton(JUI::Widget *parent) : ImageButton() { Parent(parent); }

View File

@@ -1,6 +1,8 @@
#include <JUI/Widgets/ImageRect.hpp>
JUI::ImageRect::ImageRect() : Rect(), ImageBase() {}
JUI::ImageRect::ImageRect() : Rect(), ImageBase() {
Name("ImageRect");
}
JUI::ImageRect::ImageRect(JUI::Widget *parent) : ImageRect() {
Parent(parent);

View File

@@ -2,7 +2,9 @@
namespace JUI
{
ListLayout::ListLayout() : LayoutContainer() {}
ListLayout::ListLayout() : LayoutContainer() {
Name("ListLayout");
}
ListLayout::ListLayout(Widget* parent) : ListLayout() {}
VerticalListLayout::VerticalListLayout() : ListLayout() {}

View File

@@ -97,7 +97,9 @@ namespace JUI {
JGL::J2D::DrawPartialSprite(texture, c_computed_pos, c_quad.minPoint, c_quad.maxPoint, 0, {0,0}, c_scaling);
}
NineSliceRect::NineSliceRect() : Rect(), ImageBase() {}
NineSliceRect::NineSliceRect() : Rect(), ImageBase() {
Name("NineSliceRect");
}
NineSliceRect::NineSliceRect(Widget *parent) : Rect(parent), ImageBase() {}

View File

@@ -2,7 +2,9 @@
#include <JUI/Widgets/RadioButton.hpp>
namespace JUI {
RadioButton::RadioButton() : Button(), Toggleable() {}
RadioButton::RadioButton() : Button(), Toggleable() {
Name("RadioButton");
}
RadioButton::RadioButton(Widget* parent) : RadioButton() {
this->Parent(parent);
}

View File

@@ -3,7 +3,9 @@
#include <jlog/Logger.hpp>
namespace JUI {
Rect::Rect(): Widget(), RectBase() {}
Rect::Rect(): Widget(), RectBase() {
Name("Rect");
}
Rect::Rect(Widget *parent): Rect() {
this->Parent(parent);

View File

@@ -1,7 +1,9 @@
#include "JUI/Widgets/Scene.hpp"
namespace JUI {
Scene::Scene(): Widget() {}
Scene::Scene(): Widget() {
Name("Scene");
}
Vector2 Scene::GetAbsolutePosition() const { return {0,0};}

View File

@@ -68,6 +68,7 @@ const Vector2i default_initialize_canvas_size {1024, 4096};
ScrollingRect::~ScrollingRect() { delete canvas; }
ScrollingRect::ScrollingRect() : canvas(new RenderTarget(default_initialize_canvas_size)) {
Name("ScrollingRect");
bool success = canvas->SetMSAAEnabled(JGL::MSAA_SAMPLE_RATE::MSAA_8X);
}

View File

@@ -4,7 +4,7 @@
namespace JUI
{
Slider::Slider(JUI::Widget *parent)
Slider::Slider(JUI::Widget *parent) : Slider()
{
this->Parent(parent);
}
@@ -115,4 +115,8 @@ namespace JUI
void Slider::ScrubberColor(const Color4 &color) { scrubber_color = color;}
void Slider::ScrubberWidth(float width) { scrubber_width = width;}
Slider::Slider() {
Name("Slider");
}
}

View File

@@ -2,7 +2,9 @@
namespace JUI {
Text::Text() : Widget(), TextBase() {}
Text::Text() : Widget(), TextBase() {
Name("Text");
}
Text::Text(Widget* parent) : Text()
{

View File

@@ -2,7 +2,9 @@
namespace JUI
{
TextButton::TextButton() : Button(), TextBase() {}
TextButton::TextButton() : Button(), TextBase() {
Name("TextButton");
}
TextButton::TextButton(Widget* parent) : TextButton() {
this->Parent(parent);
}

View File

@@ -2,7 +2,9 @@
#include <ReWindow/InputService.h>
namespace JUI {
TextInputForm::TextInputForm() : TextRect(), Clickable() { }
TextInputForm::TextInputForm() : TextRect(), Clickable() {
Name("TextInputForm");
}
TextInputForm::TextInputForm(Widget* parent) : TextInputForm() {
this->Parent(parent);
}

View File

@@ -1,7 +1,9 @@
#include "JUI/Widgets/TextRect.hpp"
namespace JUI {
TextRect::TextRect() : Rect(), TextBase() {}
TextRect::TextRect() : Rect(), TextBase() {
Name("TextRect");
}
TextRect::TextRect(Widget* parent) : TextRect() {
this->Parent(parent);
}

View File

@@ -5,12 +5,13 @@
namespace JUI {
Window::Window() : Widget(), Clickable(), Hoverable(), RectBase(), Draggable(), Resizable(), Dockable() {
Name("Window");
this->Position({200, 200, 0, 0});
this->Size({400, 200, 0, 0});
min_size = {400, 200};
this->BGColor({92,92,192, 255});
this->BorderColor({92,92,192});
this->SetBorderWidth(2);
this->BorderWidth(2);
this->BorderMode(BorderMode::Middle);
@@ -28,7 +29,7 @@ namespace JUI {
Viewport->Position({0, titlebar_height, 0, 0});
// TODO: Viewport->AnchorPoint({0.f, 0.f});
Viewport->BorderColor({128, 128, 128, 255});
Viewport->SetBorderWidth(0);
Viewport->BorderWidth(0);
//Viewport->Padding(1_px);
// TODO: Viewport->SetBorderRadius(0);
@@ -39,7 +40,7 @@ namespace JUI {
//Topbar->BGColor({92,92,192, 255});
Topbar->BGColor(Colors::Transparent);
Topbar->BorderColor({128, 128, 128, 0});
Topbar->SetBorderWidth(0);
Topbar->BorderWidth(0);
TitleLabel = new Text(Topbar);
TitleLabel->Center();
@@ -83,7 +84,7 @@ namespace JUI {
exit_btn->BGColor(Colors::Transparent);
exit_btn->BGColors(Colors::Transparent, Colors::Transparent, Colors::Transparent, Colors::Transparent);
exit_btn->SetBorderWidth(0.f);
exit_btn->BorderWidth(0.f);
exit_btn->BaseImageColor(Colors::Reds::LightCoral);
exit_btn->HoveredImageColor(Colors::Red);
exit_btn->PressedImageColor(Colors::Reds::DarkRed);