Partially Completed Edits xddd
This commit is contained in:
@@ -65,8 +65,10 @@ namespace JUI
|
||||
void SetBorderStyling(const Color4& color, float width);
|
||||
|
||||
void Draw(const Vector2& pos, const Vector2& size);
|
||||
void Draw(const Color4& bgColor, const Color4& fgColor, const Vector2& pos, const Vector2& size);
|
||||
|
||||
protected:
|
||||
|
||||
enum BorderMode border_mode = BorderMode::Middle;
|
||||
bool mouse_press_debounce;
|
||||
bool mouse_inside_debounce;
|
||||
|
@@ -1,3 +1,14 @@
|
||||
/// Josh's User Interface Library
|
||||
/// A C++20 Library for creating, styling, and rendering of a UI/UX widgets.
|
||||
/// Developed and Maintained by Josh O'Leary @ Redacted Software.
|
||||
/// Special Thanks to William Tomasine II and Maxine Hayes.
|
||||
/// (c) 2024 Redacted Software
|
||||
/// This work is dedicated to the public domain.
|
||||
|
||||
/// @file TextBase.hpp
|
||||
/// @desc Demo Program Entry Point
|
||||
/// @edit 2024-11-16
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <J3ML/LinearAlgebra.hpp>
|
||||
|
@@ -293,6 +293,14 @@ namespace JUI
|
||||
void SetViewportSize(const Vector2& vps);
|
||||
|
||||
public:
|
||||
|
||||
// TODO: Consider calling J2D::Begin here.
|
||||
virtual void PreDraw() {}
|
||||
virtual void PostDraw() {}
|
||||
|
||||
// TODO: Consider calling J2D::End here.
|
||||
virtual void InnerDraw() {}
|
||||
|
||||
/// Renders the widget to the current OpenGL Context using JGL.
|
||||
/// The user should call this on their Scene instances only. JUI will handle the rest.
|
||||
virtual void Draw();
|
||||
|
@@ -1,3 +1,14 @@
|
||||
/// Josh's User Interface Library
|
||||
/// A C++20 Library for creating, styling, and rendering of a UI/UX widgets.
|
||||
/// Developed and Maintained by Josh O'Leary @ Redacted Software.
|
||||
/// Special Thanks to William Tomasine II and Maxine Hayes.
|
||||
/// (c) 2024 Redacted Software
|
||||
/// This work is dedicated to the public domain.
|
||||
|
||||
/// @file Toggleable.hpp
|
||||
/// @desc Toggleable Mixin Helper Class - Added to widgets that should have special behavior when hovered by the mouse.
|
||||
/// @edit 2024-10-11
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Event.h>
|
||||
|
@@ -29,7 +29,7 @@ namespace JUI
|
||||
|
||||
/// The Button class is a basic rect widget that accepts mouse inputs, and provides event hooks.
|
||||
/// The button also provides built-in automatic coloring based on it's current state, which are listed above.
|
||||
class Button : public Widget, public RectBase, public Clickable, public Hoverable
|
||||
class Button : public Rect, public Clickable, public Hoverable
|
||||
{
|
||||
public:
|
||||
Event<> OnEnabled;
|
||||
@@ -99,7 +99,6 @@ namespace JUI
|
||||
/// Enables this button. @see Disable, SetEnabled
|
||||
void Enable();
|
||||
|
||||
void Draw() override;
|
||||
void Update(float delta) override;
|
||||
|
||||
void OnClick(const Vector2& mouse_pos, const MouseButton& btn) override;
|
||||
|
@@ -1,8 +1,24 @@
|
||||
//
|
||||
// Created by dawsh on 8/1/24.
|
||||
//
|
||||
/// Josh's User Interface Library
|
||||
/// A C++20 Library for creating, styling, and rendering of a UI/UX widgets.
|
||||
/// Developed and Maintained by Josh O'Leary @ Redacted Software.
|
||||
/// Special Thanks to William Tomasine II and Maxine Hayes.
|
||||
/// (c) 2024 Redacted Software
|
||||
/// This work is dedicated to the public domain.
|
||||
|
||||
#ifndef JUI_CANVAS_HPP
|
||||
#define JUI_CANVAS_HPP
|
||||
/// @file Canvas.hpp
|
||||
/// @desc A 2D drawable canvas widget.
|
||||
/// @edit 2024-11-27
|
||||
|
||||
#endif //JUI_CANVAS_HPP
|
||||
#pragma once
|
||||
|
||||
#include <JUI/Widgets/Rect.hpp>
|
||||
|
||||
namespace JUI
|
||||
{
|
||||
class Canvas : public Rect
|
||||
{
|
||||
public:
|
||||
protected:
|
||||
private:
|
||||
};
|
||||
}
|
@@ -20,11 +20,16 @@
|
||||
|
||||
namespace JUI
|
||||
{
|
||||
class Checkbox : public Button
|
||||
{
|
||||
class Checkbox : public Button {
|
||||
public:
|
||||
Checkbox();
|
||||
explicit Checkbox(Widget* parent);
|
||||
Checkbox() : Button() {
|
||||
|
||||
}
|
||||
|
||||
explicit Checkbox(Widget *parent) : Checkbox()
|
||||
{
|
||||
this->Parent(parent);
|
||||
}
|
||||
|
||||
void Update(float delta) override
|
||||
{
|
||||
@@ -35,27 +40,67 @@ namespace JUI
|
||||
void OnRelease(const J3ML::LinearAlgebra::Vector2 &mouse_pos, const JUI::MouseButton &bnt, bool still_hovering) override
|
||||
{
|
||||
Button::OnRelease(mouse_pos, bnt, still_hovering);
|
||||
|
||||
checked = !checked;
|
||||
}
|
||||
|
||||
void Draw() override
|
||||
void InnerDraw() override
|
||||
{
|
||||
Button::Draw();
|
||||
|
||||
Rect::InnerDraw();
|
||||
if (checked)
|
||||
{
|
||||
J2D::Begin();
|
||||
//J2D::DrawLine(check_color, );
|
||||
Vector2 check_padding = {2, 2};
|
||||
RectBase::Draw(check_color, check_color, GetAbsolutePosition()+check_padding, GetAbsoluteSize()-(check_padding*2));
|
||||
J2D::End();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Draw() override
|
||||
{
|
||||
if (!visible)
|
||||
return;
|
||||
|
||||
J2D::Begin();
|
||||
Vector2 abs_pos = GetAbsolutePosition();
|
||||
Vector2 abs_size = GetAbsoluteSize();
|
||||
|
||||
auto root_size = GetFamilyTreeRoot()->GetAbsoluteSize();
|
||||
|
||||
GLint *old_scissor_bounds;
|
||||
bool clip_was_enabled;
|
||||
|
||||
if (clips_descendants) {
|
||||
clip_was_enabled = glIsEnabled(GL_SCISSOR_TEST);
|
||||
if (clip_was_enabled)
|
||||
glGetIntegerv(GL_SCISSOR_BOX, old_scissor_bounds);
|
||||
|
||||
float presumed_screen_height = 600;
|
||||
glScissor(abs_pos.x, presumed_screen_height-abs_size.y-abs_pos.y, abs_size.x, abs_size.y);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
RectBase::Draw(abs_pos, abs_size);
|
||||
|
||||
// Draw Child Elements with scissor clipping still active
|
||||
Widget::Draw();
|
||||
|
||||
// Returns clip to previous state
|
||||
if (clips_descendants)
|
||||
{
|
||||
//glScissor(old_scissor_bounds[0], old_scissor_bounds[1], old_scissor_bounds[2], old_scissor_bounds[3]);
|
||||
|
||||
if (!clip_was_enabled) {}
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
|
||||
}
|
||||
|
||||
J2D::End();
|
||||
}
|
||||
protected:
|
||||
bool checked;
|
||||
Color4 check_color;
|
||||
Color4 check_color = Colors::Red;
|
||||
private:
|
||||
};
|
||||
}
|
@@ -33,13 +33,13 @@ namespace JUI {
|
||||
|
||||
|
||||
public:
|
||||
void PreDraw() override;
|
||||
void InnerDraw() override;
|
||||
void PostDraw() override;
|
||||
void Draw() override;
|
||||
void Update(float delta) override;
|
||||
|
||||
|
||||
protected:
|
||||
void SetupScissor();
|
||||
void ResetScissor();
|
||||
virtual void DrawInScissor();
|
||||
GLint old_scissor_bounds[4];
|
||||
bool clip_was_enabled;
|
||||
};
|
||||
}
|
@@ -48,46 +48,14 @@ namespace JUI
|
||||
|
||||
void RecomputeRenderTarget()
|
||||
{
|
||||
if (!visible)
|
||||
return;
|
||||
|
||||
J2D::Begin(canvas);
|
||||
Vector2 abs_pos = GetAbsolutePosition();
|
||||
Vector2 abs_size = GetAbsoluteSize();
|
||||
|
||||
auto root_size = GetFamilyTreeRoot()->GetAbsoluteSize();
|
||||
|
||||
GLint old_scissor_bounds[4];
|
||||
bool clip_was_enabled;
|
||||
|
||||
/*if (clips_descendants) {
|
||||
clip_was_enabled = glIsEnabled(GL_SCISSOR_TEST);
|
||||
if (clip_was_enabled)
|
||||
glGetIntegerv(GL_SCISSOR_BOX, old_scissor_bounds);
|
||||
|
||||
float presumed_screen_height = viewport_size.y;
|
||||
glScissor(abs_pos.x, presumed_screen_height-abs_size.y-abs_pos.y, abs_size.x, abs_size.y);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
}*/
|
||||
|
||||
DrawInScissor();
|
||||
|
||||
// Returns clip to previous state
|
||||
/* if (clips_descendants)
|
||||
{
|
||||
glScissor(old_scissor_bounds[0], old_scissor_bounds[1], old_scissor_bounds[2], old_scissor_bounds[3]);
|
||||
|
||||
if (!clip_was_enabled) {}
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
|
||||
}*/
|
||||
|
||||
J2D::End();
|
||||
Rect::PreDraw();
|
||||
InnerDraw();
|
||||
Rect::PostDraw();
|
||||
}
|
||||
|
||||
void DrawInScissor() override
|
||||
void InnerDraw() override
|
||||
{
|
||||
Rect::DrawInScissor();
|
||||
Rect::InnerDraw();
|
||||
}
|
||||
protected:
|
||||
bool scrollbar_visible = true;
|
||||
|
@@ -18,8 +18,9 @@ namespace JUI {
|
||||
|
||||
bool TextWrap() const;
|
||||
void TextWrap(bool enable) const;
|
||||
void InnerDraw() override;
|
||||
protected:
|
||||
void DrawInScissor() override;
|
||||
|
||||
bool fit_size_to_text = false;
|
||||
bool wrap_text = false;
|
||||
};
|
||||
|
9
main.cpp
9
main.cpp
@@ -22,6 +22,7 @@
|
||||
#include <JUI/Widgets/Slider.hpp>
|
||||
#include <JUI/Widgets/ScrollingRect.hpp>
|
||||
#include <JUI/Widgets/UtilityBar.hpp>
|
||||
#include <JUI/Widgets/Checkbox.hpp>
|
||||
#include <rewindow/types/window.h>
|
||||
|
||||
JGL::Font FreeSans;
|
||||
@@ -99,6 +100,14 @@ JUI::Scene* CreateScene() {
|
||||
button3->SetContent("Button");
|
||||
button3->AlignRight();
|
||||
|
||||
auto* checkbox_container = new Rect(s1_vert);
|
||||
checkbox_container->Size({0, 35, 1, 0});
|
||||
|
||||
|
||||
auto* checkbox_horiz = new HorizontalListLayout(checkbox_container);
|
||||
|
||||
auto* check1 = new Checkbox(checkbox_horiz);
|
||||
|
||||
|
||||
//auto* main_wnd = new Window(root);
|
||||
//auto* left = new HorizontalListLayout();
|
||||
|
@@ -27,15 +27,21 @@ namespace JUI {
|
||||
SetBorderWidth(width);
|
||||
}
|
||||
|
||||
void RectBase::Draw(const Vector2 &abs_pos, const Vector2 &abs_size) {
|
||||
|
||||
void RectBase::Draw(const Vector2& abs_pos, const Vector2& abs_size)
|
||||
{
|
||||
Draw(bg_color, border_color, abs_pos, abs_size);
|
||||
}
|
||||
|
||||
void RectBase::Draw(const Color4& bgColor, const Color4& borderColor, const Vector2 &abs_pos, const Vector2 &abs_size) {
|
||||
|
||||
J2D::Begin();
|
||||
|
||||
// Background rect
|
||||
if (corner_rounding_radius > 0)
|
||||
J2D::FillRoundedRect(bg_color, abs_pos, abs_size, corner_rounding_radius);
|
||||
J2D::FillRoundedRect(bgColor, abs_pos, abs_size, corner_rounding_radius);
|
||||
else
|
||||
J2D::FillRect(bg_color, abs_pos, abs_size);
|
||||
J2D::FillRect(bgColor, abs_pos, abs_size);
|
||||
|
||||
// Outline rect - compute the size change to fit the border accurately.
|
||||
Vector2 border_offset = {0, 0};
|
||||
@@ -51,9 +57,9 @@ namespace JUI {
|
||||
if (border_width > 0)
|
||||
{
|
||||
if (corner_rounding_radius > 0)
|
||||
J2D::OutlineRoundedRect(border_color, abs_pos - border_offset, abs_size + (border_offset*2), corner_rounding_radius, border_width);
|
||||
J2D::OutlineRoundedRect(borderColor, abs_pos - border_offset, abs_size + (border_offset*2), corner_rounding_radius, border_width);
|
||||
else
|
||||
J2D::OutlineRect(border_color, abs_pos - border_offset, abs_size + (border_offset*2), border_width);
|
||||
J2D::OutlineRect(borderColor, abs_pos - border_offset, abs_size + (border_offset*2), border_width);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -313,6 +313,10 @@ namespace JUI {
|
||||
if (!visible)
|
||||
return;
|
||||
|
||||
PreDraw();
|
||||
InnerDraw();
|
||||
PostDraw();
|
||||
|
||||
DrawChildWidgets();
|
||||
}
|
||||
|
||||
|
@@ -4,7 +4,7 @@
|
||||
|
||||
namespace JUI
|
||||
{
|
||||
Button::Button(): Widget(), Clickable() {
|
||||
Button::Button(): Rect(), Clickable() {
|
||||
BGColor(BaseBGColor());
|
||||
BorderColor(BaseBorderColor());
|
||||
}
|
||||
@@ -13,48 +13,6 @@ namespace JUI
|
||||
this->Parent(parent);
|
||||
};
|
||||
|
||||
void Button::Draw() {
|
||||
if (!visible)
|
||||
return;
|
||||
|
||||
J2D::Begin();
|
||||
Vector2 abs_pos = GetAbsolutePosition();
|
||||
Vector2 abs_size = GetAbsoluteSize();
|
||||
|
||||
auto root_size = GetFamilyTreeRoot()->GetAbsoluteSize();
|
||||
|
||||
GLint *old_scissor_bounds;
|
||||
bool clip_was_enabled;
|
||||
|
||||
if (clips_descendants) {
|
||||
clip_was_enabled = glIsEnabled(GL_SCISSOR_TEST);
|
||||
if (clip_was_enabled)
|
||||
glGetIntegerv(GL_SCISSOR_BOX, old_scissor_bounds);
|
||||
|
||||
float presumed_screen_height = 600;
|
||||
glScissor(abs_pos.x, presumed_screen_height-abs_size.y-abs_pos.y, abs_size.x, abs_size.y);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
RectBase::Draw(abs_pos, abs_size);
|
||||
|
||||
// Draw Child Elements with scissor clipping still active
|
||||
Widget::Draw();
|
||||
|
||||
// Returns clip to previous state
|
||||
if (clips_descendants)
|
||||
{
|
||||
//glScissor(old_scissor_bounds[0], old_scissor_bounds[1], old_scissor_bounds[2], old_scissor_bounds[3]);
|
||||
|
||||
if (!clip_was_enabled) {}
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
|
||||
}
|
||||
|
||||
J2D::End();
|
||||
}
|
||||
|
||||
|
||||
void Button::OnClick(const Vector2& mouse_pos, const MouseButton& btn)
|
||||
{
|
||||
if (disabled)
|
||||
|
2
src/JUI/Widgets/Canvas.cpp
Normal file
2
src/JUI/Widgets/Canvas.cpp
Normal file
@@ -0,0 +1,2 @@
|
||||
#include <JUI/Widgets/Canvas.hpp>
|
||||
|
@@ -1 +1,8 @@
|
||||
#include <JUI/Widgets/Checkbox.hpp>
|
||||
#include <JUI/Widgets/Checkbox.hpp>
|
||||
|
||||
|
||||
namespace JUI
|
||||
{
|
||||
|
||||
|
||||
}
|
@@ -9,32 +9,15 @@ namespace JUI {
|
||||
this->Parent(parent);
|
||||
}
|
||||
|
||||
void Rect::SetupScissor() { }
|
||||
|
||||
void Rect::ResetScissor() { }
|
||||
|
||||
|
||||
void Rect::DrawInScissor()
|
||||
void Rect::PreDraw()
|
||||
{
|
||||
RectBase::Draw(GetAbsolutePosition(), GetAbsoluteSize());
|
||||
|
||||
// Draw Child Elements with scissor clipping still active
|
||||
Widget::Draw();
|
||||
}
|
||||
|
||||
void Rect::Draw() {
|
||||
if (!visible)
|
||||
return;
|
||||
|
||||
J2D::Begin();
|
||||
Vector2 abs_pos = GetAbsolutePosition();
|
||||
Vector2 abs_size = GetAbsoluteSize();
|
||||
|
||||
auto root_size = GetFamilyTreeRoot()->GetAbsoluteSize();
|
||||
|
||||
GLint old_scissor_bounds[4];
|
||||
bool clip_was_enabled;
|
||||
|
||||
if (clips_descendants) {
|
||||
clip_was_enabled = glIsEnabled(GL_SCISSOR_TEST);
|
||||
if (clip_was_enabled)
|
||||
@@ -44,22 +27,30 @@ namespace JUI {
|
||||
glScissor(abs_pos.x, presumed_screen_height-abs_size.y-abs_pos.y, abs_size.x, abs_size.y);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
}
|
||||
}
|
||||
|
||||
DrawInScissor();
|
||||
|
||||
void Rect::PostDraw()
|
||||
{
|
||||
// Returns clip to previous state
|
||||
if (clips_descendants)
|
||||
{
|
||||
glScissor(old_scissor_bounds[0], old_scissor_bounds[1], old_scissor_bounds[2], old_scissor_bounds[3]);
|
||||
|
||||
if (!clip_was_enabled) {}
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
|
||||
}
|
||||
|
||||
J2D::End();
|
||||
}
|
||||
|
||||
void Rect::InnerDraw()
|
||||
{
|
||||
J2D::Begin();
|
||||
RectBase::Draw(GetAbsolutePosition(), GetAbsoluteSize());
|
||||
J2D::End();
|
||||
// Draw Child Elements with scissor clipping still active
|
||||
//Widget::DrawChildWidgets();
|
||||
|
||||
}
|
||||
|
||||
void Rect::Update(float delta) {
|
||||
if (IsMouseInside() && !mouse_inside_debounce)
|
||||
@@ -93,6 +84,10 @@ namespace JUI {
|
||||
return { GetAbsolutePosition(), GetAbsoluteSize()};
|
||||
}
|
||||
|
||||
void Rect::Draw() {
|
||||
Widget::Draw();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@@ -39,9 +39,9 @@ namespace JUI {
|
||||
}
|
||||
|
||||
|
||||
void TextRect::DrawInScissor()
|
||||
void TextRect::InnerDraw()
|
||||
{
|
||||
Rect::DrawInScissor();
|
||||
Rect::InnerDraw();
|
||||
Vector2 abs_pos = this->GetAbsolutePosition();
|
||||
Vector2 abs_size = this->GetAbsoluteSize();
|
||||
|
||||
@@ -61,8 +61,6 @@ namespace JUI {
|
||||
void TextRect::Draw() {
|
||||
Rect::Draw();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user