Merge remote-tracking branch 'origin/master'

This commit is contained in:
2024-08-05 22:13:37 -04:00
14 changed files with 214 additions and 30 deletions

View File

@@ -48,12 +48,12 @@ CPMAddPackage(
CPMAddPackage(
NAME ReWindow
URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-8.zip
URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-9.zip
)
CPMAddPackage(
NAME JGL
URL https://git.redacted.cc/josh/JGL/archive/Prerelease-29.zip
URL https://git.redacted.cc/josh/JGL/archive/Prerelease-30.zip
)
target_include_directories(JUI PUBLIC ${Event_SOURCE_DIR}/include)

56
README.md Normal file
View File

@@ -0,0 +1,56 @@
# Josh User Interface
![Static Badge](https://img.shields.io/badge/Lit-Based-%20)
Fourth Time's The Charm! (tm)
JUI is a C++20 Library for building interactive menus in OpenGL / Redacted3D.
It is expressly built with our Redacted3D engine in mind, but steps have been taken to support OpenGL generally.
## Abstract
JUI provides a set of objects that we term Widgets. Widgets can be styled and laid out on-screen in relation to each other. Each widget has a single parent, and a list of child elements. Your root widget should be a Scene object.
Provided widgets include Scene, Rect, Text, TextRect, Button, TextButton, TextInputForms, Slider, Image, ImageRect, RadioButton
## Features
### Why use this instead of imgui?
## Usage
## Examples
![JUI First Showcase](showcase.png)
Browse the src/Demos directories for examples of building and interacting with things in JUI.
## Documentation
Documentation is automatically generated from latest commit and is hosted at https://doc.redacted.cc/jui .
## Contributing
Contributions to JUI are welcome! Feel free to file bug reports or feature requests by creating an Issue. Pull requests are also very welcome!
## History
JUI started out as my menu toolkit for the LOVE2D framework many years ago. Between then and now I had re-implemented it twice, once for MonoGame Framework, and again in C++ for SDL2. Legacy versions are listed below.
JUI v1 - LOVE2D / Lua
JUI v2 - MonoGame / C#
JUI v3 - SDL2 / C++
## License
JUI is expressly released without a license, under no restrictions. We dedicate all of our works to the public domain for the (hopeful) betterment of humanity.
## Acknowledgements
JUI is developed and maintained by Joshua O'Leary from Redacted Software Group, and all the wonderful contributors.

BIN
assets/ld.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

View File

@@ -15,7 +15,6 @@
#include <J3ML/LinearAlgebra/Vector2.h>
#include "JGL/Texture.h"
using J3ML::LinearAlgebra::Vector2;
namespace JUI
@@ -23,13 +22,25 @@ namespace JUI
class ImageBase
{
public:
ImageBase();
ImageBase(JGL::Texture* texture);
public:
[[nodiscard]] JGL::Texture* Content() const { return texture;}
[[nodiscard]] Color4 Color() const { return image_color;}
[[nodiscard]] Vector2 Scale() const { return scale;}
[[nodiscard]] Vector2 Origin() const { return origin;}
void SetContent(JGL::Texture* content);
void Color(const Color4& newColor);
void Scale(const Vector2& newScale);
void Origin(const Vector2& newOrigin);
public:
void Draw(const Vector2& pos, const Vector2& size);
protected:
JGL::Texture texture;
Color4 image_color;
Vector2 scale;
Vector2 origin;
JGL::Texture* texture;
Color4 image_color = Color4(255,255,255);
Vector2 scale = Vector2(1,1);
Vector2 origin = Vector2(0,0);
private:
};
}

View File

@@ -0,0 +1,8 @@
//
// Created by dawsh on 8/5/24.
//
#ifndef JUI_CHECKBOX_HPP
#define JUI_CHECKBOX_HPP
#endif //JUI_CHECKBOX_HPP

View File

@@ -6,9 +6,8 @@
/// This work is dedicated to the public domain.
/// @file GridLayout.hpp
/// @desc Clickable Button widget.
/// @edit 2024-08-02
/// @desc Lays out child elements in a grid-matrix.
/// @edit 2024-08-05
#pragma once
@@ -16,21 +15,9 @@
namespace JUI
{
class ListLayout : public LayoutContainer
class GridLayout : public LayoutContainer
{
public:
};
class VerticalListLayout : public ListLayout
{
public:
};
class HorizontalListLayout : public ListLayout
{
};
}

View File

@@ -11,3 +11,31 @@
#pragma once
#include <JUI/Base/Widget.hpp>
#include <JUI/Base/ImageBase.hpp>
namespace JUI
{
class Image : public Widget, public ImageBase
{
public:
Image();
explicit Image(Widget* parent);
explicit Image(Widget* parent, JGL::Texture* tex);
~Image() override {}
public:
Vector2 GetAbsoluteSize() const override;
Vector2 GetAbsolutePosition() const override;
void Draw() override;
void Update(float delta) override;
bool FitImageToParent() const;
void FitImageToParent(bool on);
protected:
bool fit_image_to_parent;
};
}

View File

@@ -1,7 +1,6 @@
#pragma once
#include <JUI/Base/Widget.hpp>
namespace JUI
{
// TODO: SceneSizingBehavior - FillToWindow, CustomSized
@@ -12,12 +11,8 @@ namespace JUI
void Draw() override;
void SetViewportSize(int w, int h);
// TODO: Interface for passing input to JUI in a relatively
// independent way
Event<Vector2> MouseMoved;
void Update(float delta) override;
[[nodiscard]] Vector2 GetAbsolutePosition() const override;

View File

@@ -18,11 +18,13 @@
#include <JUI/Widgets/Text.hpp>
#include <JUI/Widgets/ListLayout.hpp>
#include <JUI/Widgets/TextRect.hpp>
#include <JUI/Widgets/Image.hpp>
#include <rewindow/types/window.h>
#include <jlog/jlog.hpp>
JGL::Font FreeSans;
JUI::Scene* scene;
JGL::Texture* sample_texture;
JUI::Scene* CreateScene() {
using namespace JUI;
@@ -130,6 +132,7 @@ JUI::Scene* CreateScene() {
//win_element->SetPadding(1_px);
// End Window //
auto list = new VerticalListLayout(win_element->GetViewportInstance());
list->SetPadding(10_px);
@@ -172,6 +175,9 @@ JUI::Scene* CreateScene() {
text->SetTextSize(48);
text->SetTextColor({255, 0, 0});
auto darkie = new Image(win_element->GetViewportInstance(), sample_texture);
darkie->FitImageToParent(true);
darkie->Color({255,255,255,128});
root->SetViewportSize(800, 600);
@@ -205,6 +211,7 @@ public:
void OnRefresh(float elapsed) override {
Update();
JGL::Update(getSize());
scene->SetViewportSize(getSize().x, getSize().y);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
@@ -228,7 +235,7 @@ public:
int main()
{
using namespace ReWindow;
//LOGLEVEL(jlog::severity::none)
LOGLEVEL(jlog::severity::none)
auto* window = new JUIDevelopmentTestWindow("Test Window", 800, 600);
window->setRenderer(RenderingAPI::OPENGL);
@@ -242,6 +249,7 @@ int main()
FreeSans = JGL::Font("assets/fonts/FreeSans.ttf");
sample_texture = new JGL::Texture("assets/ld.png");
scene = CreateScene();
window->OnResizeRequestEvent += [&] (ReWindow::WindowResizeRequestEvent e){

BIN
showcase.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

View File

@@ -0,0 +1,34 @@
#include <JUI/Base/ImageBase.hpp>
#include <JGL/JGL.h>
using namespace JGL;
namespace JUI
{
void ImageBase::Draw(const Vector2 &pos, const Vector2 &size) {
J2D::Begin();
J2D::DrawSprite(*texture, pos, origin, scale, image_color);
J2D::End();
}
ImageBase::ImageBase()
{
}
ImageBase::ImageBase(JGL::Texture* tex) : ImageBase()
{
this->texture = tex;
}
void ImageBase::SetContent(JGL::Texture *content) {
this->texture = content;
}
void ImageBase::Color(const Color4 &newColor) { this->image_color = newColor;}
void ImageBase::Scale(const Vector2 &newScale) { scale = newScale;}
void ImageBase::Origin(const Vector2 &newOrigin) { origin = newOrigin; }
}

View File

@@ -149,7 +149,7 @@ namespace JUI {
void Widget::SetSize(const UDim2& s) { size = s; }
float Widget::GetAbsoluteRotation() const {
// TODO: implement correctly!!
// TODO: implement rotation correctly!!
return rotation;
}

View File

@@ -0,0 +1,7 @@
#include <JUI/Widgets/GridLayout.hpp>
namespace JUI
{
}

View File

@@ -1,2 +1,52 @@
#include <JUI/Widgets/Image.hpp>
namespace JUI
{
Image::Image() : Widget(), ImageBase()
{
}
Image::Image(Widget* parent) : Image()
{
SetParent(parent);
}
Image::Image(Widget *parent, JGL::Texture *tex) : Widget(), ImageBase(tex)
{
this->SetParent(parent);
}
Vector2 Image::GetAbsoluteSize() const {
return parent->GetAbsoluteSize();
}
Vector2 Image::GetAbsolutePosition() const {
return parent->GetAbsolutePosition();
}
void Image::Draw() {
// TODO: Factor in margin?
if (fit_image_to_parent)
{
auto old_scale = scale;
scale = GetAbsoluteSize() / texture->GetDimensions();
ImageBase::Draw(GetAbsolutePosition(), GetAbsoluteSize());
scale = old_scale;
} else
{
ImageBase::Draw(GetAbsolutePosition(), GetAbsoluteSize());
}
Widget::Draw();
}
void Image::Update(float delta) {
Widget::Update(delta);
}
bool Image::FitImageToParent() const { return fit_image_to_parent; }
void Image::FitImageToParent(bool on) { fit_image_to_parent = on; }
}