Several minor changes
This commit is contained in:
@@ -103,7 +103,7 @@ namespace JUI
|
||||
protected:
|
||||
std::string content = "Sample Text";
|
||||
Color4 text_color = {255,255,255,255};
|
||||
float text_outline;
|
||||
float text_outline = 1.f;
|
||||
Color4 outline_color = {255,255,255,255};
|
||||
bool word_wrap = false;
|
||||
TextAlign::H h_align = TextAlign::H::Left;
|
||||
|
@@ -252,6 +252,8 @@ namespace JUI
|
||||
/// Only this method represents the full bounding box of the widget.
|
||||
[[nodiscard]] virtual AABB2D GetActualRenderBounds() const;
|
||||
|
||||
void SetViewportSize(const Vector2& vps);
|
||||
|
||||
public:
|
||||
/// 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.
|
||||
@@ -269,18 +271,20 @@ namespace JUI
|
||||
/// The user should call this on their Scene instances only. JUI will handle the rest.
|
||||
/// See ReWindowIntegrationDemo for an example.
|
||||
virtual void ObserveMouseInput(MouseButton btn, bool pressed);
|
||||
|
||||
//virtual void ObserveKeyInput()
|
||||
protected:
|
||||
void DrawChildWidgets();
|
||||
void UpdateChildWidgets(float delta);
|
||||
protected:
|
||||
MouseButton mbtn;
|
||||
bool mb_state;
|
||||
bool prev_mb_state;
|
||||
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;
|
||||
UDim2 position;
|
||||
UDim2 size;
|
||||
Vector2 last_known_mouse_pos = {0,0};
|
||||
UDim2 position = {0_px, 0_px};
|
||||
UDim2 size = {50_px, 50_px};
|
||||
Widget* parent = nullptr;
|
||||
std::vector<Widget*> children;
|
||||
float rotation = 0;
|
||||
@@ -298,7 +302,11 @@ namespace JUI
|
||||
bool visible = true;
|
||||
Widget* next = nullptr;
|
||||
Widget* prev = nullptr;
|
||||
int zindex;
|
||||
int zindex = 0;
|
||||
|
||||
Vector2 viewport_size{0,0};
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
@@ -103,15 +103,15 @@ namespace JUI
|
||||
void OnHover(const J3ML::LinearAlgebra::Vector2 &MousePos) override;
|
||||
void OnExit(const J3ML::LinearAlgebra::Vector2 &MousePos) override;
|
||||
protected:
|
||||
bool disabled;
|
||||
Color4 hover_bg;
|
||||
Color4 hover_border;
|
||||
Color4 pressed_bg;
|
||||
Color4 pressed_border;
|
||||
Color4 disabled_bg;
|
||||
Color4 disabled_border;
|
||||
Color4 base_bg;
|
||||
Color4 base_border;
|
||||
bool disabled = false;
|
||||
Color4 hover_bg = Colors::Blues::SkyBlue;
|
||||
Color4 hover_border = Colors::Blues::DarkSlateBlue;
|
||||
Color4 pressed_bg = Colors::Blues::DarkSlateBlue;
|
||||
Color4 pressed_border = Colors::Blues::SkyBlue;;
|
||||
Color4 disabled_bg = Colors::Gray;
|
||||
Color4 disabled_border = Colors::Gray;
|
||||
Color4 base_bg = Colors::White;
|
||||
Color4 base_border = Colors::Black;
|
||||
};
|
||||
|
||||
|
||||
|
@@ -28,7 +28,6 @@ namespace JUI {
|
||||
|
||||
~Rect() override {}
|
||||
|
||||
bool IsMouseInside() const;
|
||||
|
||||
AABB2D GetActualRenderBounds() const override;
|
||||
|
||||
@@ -37,5 +36,10 @@ namespace JUI {
|
||||
void Draw() override;
|
||||
void Update(float delta) override;
|
||||
|
||||
|
||||
protected:
|
||||
void SetupScissor();
|
||||
void ResetScissor();
|
||||
virtual void DrawInScissor();
|
||||
};
|
||||
}
|
@@ -20,7 +20,6 @@ namespace JUI
|
||||
Scene();
|
||||
~Scene() override {}
|
||||
void Draw() override;
|
||||
void SetViewportSize(int w, int h);
|
||||
|
||||
Event<Vector2> MouseMoved;
|
||||
|
||||
@@ -31,7 +30,5 @@ namespace JUI
|
||||
[[nodiscard]] Vector2 GetAbsoluteSize() const override;
|
||||
|
||||
protected:
|
||||
int viewport_w;
|
||||
int viewport_h;
|
||||
};
|
||||
}
|
||||
|
@@ -19,8 +19,37 @@ namespace JUI
|
||||
class ScrollingRect : public Rect
|
||||
{
|
||||
public:
|
||||
ScrollingRect();
|
||||
explicit ScrollingRect(Widget* parent);
|
||||
|
||||
Rect* GetContentPanel() { return contents; }
|
||||
|
||||
Vector2 CanvasSize() const;
|
||||
void CanvasSize(const Vector2& canvas);
|
||||
|
||||
Vector2 CanvasPosition() const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
float ScrollPos() const;
|
||||
void ScrollPos(float pos) const;
|
||||
|
||||
void Draw() override
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DrawInScissor() override
|
||||
{
|
||||
Rect::DrawInScissor();
|
||||
}
|
||||
protected:
|
||||
bool scrollbar_visible;
|
||||
float scrollbar_width;
|
||||
Color4 scrollbar_color;
|
||||
Vector2 canvas_size;
|
||||
Rect* contents;
|
||||
private:
|
||||
};
|
||||
}
|
@@ -12,7 +12,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "TextRect.hpp"
|
||||
|
||||
namespace JUI
|
||||
{
|
||||
class TextInputForm : public TextRect
|
||||
{
|
||||
|
||||
};
|
||||
}
|
@@ -14,6 +14,7 @@ namespace JUI {
|
||||
[[nodiscard]] bool FitText() const { return fit_text; }
|
||||
void FitText(bool on) { fit_text = on; }
|
||||
protected:
|
||||
void DrawInScissor() override;
|
||||
bool fit_text = false;
|
||||
};
|
||||
}
|
28
main.cpp
28
main.cpp
@@ -20,6 +20,7 @@
|
||||
#include <JUI/Widgets/TextRect.hpp>
|
||||
#include <JUI/Widgets/Image.hpp>
|
||||
#include <JUI/Widgets/Slider.hpp>
|
||||
#include <JUI/Widgets/ScrollingRect.hpp>
|
||||
#include <rewindow/types/window.h>
|
||||
|
||||
JGL::Font FreeSans;
|
||||
@@ -31,7 +32,13 @@ JUI::Scene* CreateScene() {
|
||||
|
||||
Scene *root = new Scene();
|
||||
|
||||
|
||||
auto* btn = new TextButton(root);
|
||||
|
||||
|
||||
/*
|
||||
auto* JUI = new TextRect(root);
|
||||
JUI->SetClipsDescendants(true);
|
||||
JUI->SetFont(FreeSans);
|
||||
JUI->SetTextSize(48);
|
||||
JUI->SetTextColor({32, 48, 192});
|
||||
@@ -63,6 +70,9 @@ JUI::Scene* CreateScene() {
|
||||
Redacted->BorderColor({64, 64, 64});
|
||||
|
||||
|
||||
//auto* scrollRect = new ScrollingRect(root);
|
||||
|
||||
|
||||
// Rect //
|
||||
Rect *rect_element = new Rect(root);
|
||||
rect_element->Name("JimBob");
|
||||
@@ -188,11 +198,11 @@ JUI::Scene* CreateScene() {
|
||||
text->SetContent("YO MAMA");
|
||||
text->SetFont(FreeSans);
|
||||
text->SetTextSize(48);
|
||||
text->SetTextColor({255, 0, 0});
|
||||
text->SetTextColor({255, 0, 0});*/
|
||||
|
||||
|
||||
|
||||
root->SetViewportSize(800, 600);
|
||||
root->SetViewportSize({800, 600});
|
||||
|
||||
|
||||
|
||||
@@ -228,7 +238,7 @@ public:
|
||||
void OnRefresh(float elapsed) override {
|
||||
Update();
|
||||
JGL::Update(getSize());
|
||||
scene->SetViewportSize(getSize().x, getSize().y);
|
||||
scene->SetViewportSize(getSize());
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
@@ -259,6 +269,12 @@ public:
|
||||
|
||||
}
|
||||
|
||||
|
||||
void OnKeyDown(const ReWindow::WindowEvents::KeyDownEvent &) override
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//bool OnResizeRequest(const ReWindow::WindowResizeRequestEvent &e) override {}
|
||||
JUIDevelopmentTestWindow() : ReWindow::RWindow() {}
|
||||
};
|
||||
@@ -288,9 +304,13 @@ int main()
|
||||
sample_texture = new JGL::Texture("assets/ld.png");
|
||||
scene = CreateScene();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
window->OnResizeRequestEvent += [&] (ReWindow::WindowResizeRequestEvent e){
|
||||
Vector2 size = e.Size;//window->getLastKnownResize();
|
||||
scene->SetViewportSize(size.x, size.y);
|
||||
scene->SetViewportSize(size);
|
||||
std::cout << size.x << "," << size.y << std::endl;
|
||||
JGL::Update(size);
|
||||
};
|
||||
|
@@ -341,4 +341,13 @@ namespace JUI {
|
||||
return {GetAbsolutePosition(), GetAbsoluteSize()};
|
||||
}
|
||||
|
||||
void Widget::SetViewportSize(const Vector2 &vps) {
|
||||
viewport_size = vps;
|
||||
|
||||
for(auto& child : children)
|
||||
{
|
||||
child->SetViewportSize(viewport_size);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -9,6 +9,19 @@ namespace JUI {
|
||||
this->Parent(parent);
|
||||
}
|
||||
|
||||
void Rect::SetupScissor() { }
|
||||
|
||||
void Rect::ResetScissor() { }
|
||||
|
||||
|
||||
void Rect::DrawInScissor()
|
||||
{
|
||||
RectBase::Draw(GetAbsolutePosition(), GetAbsoluteSize());
|
||||
|
||||
// Draw Child Elements with scissor clipping still active
|
||||
Widget::Draw();
|
||||
}
|
||||
|
||||
void Rect::Draw() {
|
||||
if (!visible)
|
||||
return;
|
||||
@@ -19,29 +32,25 @@ namespace JUI {
|
||||
|
||||
auto root_size = GetFamilyTreeRoot()->GetAbsoluteSize();
|
||||
|
||||
GLint *old_scissor_bounds;
|
||||
GLint old_scissor_bounds[4];
|
||||
bool clip_was_enabled;
|
||||
// TODO: Re-enable clipping
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
RectBase::Draw(abs_pos, abs_size);
|
||||
|
||||
// Draw Child Elements with scissor clipping still active
|
||||
Widget::Draw();
|
||||
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]);
|
||||
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);
|
||||
@@ -68,20 +77,6 @@ namespace JUI {
|
||||
Widget::Update(delta);
|
||||
}
|
||||
|
||||
bool Rect::IsMouseInside() const {
|
||||
float x = last_known_mouse_pos.x;
|
||||
float y = last_known_mouse_pos.y;
|
||||
auto pos = GetAbsolutePosition();
|
||||
auto size = GetAbsoluteSize();
|
||||
|
||||
//DEBUG(std::format("X {} {} Y {} {}", x,pos.x, y,pos.y));
|
||||
|
||||
if (x > pos.x && y > pos.y && x < pos.x + size.x && y < pos.y + size.y){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
AABB2D Rect::GetActualRenderBounds() const {
|
||||
|
||||
Vector2 border = {border_width, border_width};
|
||||
|
@@ -5,17 +5,12 @@ namespace JUI {
|
||||
|
||||
Vector2 Scene::GetAbsolutePosition() const { return {0,0};}
|
||||
|
||||
Vector2 Scene::GetAbsoluteSize() const { return {(float)viewport_w,(float)viewport_h};}
|
||||
Vector2 Scene::GetAbsoluteSize() const { return viewport_size;}
|
||||
|
||||
void Scene::Draw() {
|
||||
Widget::Draw();
|
||||
}
|
||||
|
||||
void Scene::SetViewportSize(int w, int h) {
|
||||
viewport_w = w;
|
||||
viewport_h = h;
|
||||
}
|
||||
|
||||
void Scene::Update(float delta) {
|
||||
Widget::Update(delta);
|
||||
}
|
||||
|
@@ -4,4 +4,10 @@
|
||||
namespace JUI
|
||||
{
|
||||
|
||||
ScrollingRect::ScrollingRect() : Rect() {}
|
||||
|
||||
ScrollingRect::ScrollingRect(Widget *parent) : ScrollingRect()
|
||||
{
|
||||
this->Parent(parent);
|
||||
}
|
||||
}
|
2
src/JUI/Widgets/TextInputForm.cpp
Normal file
2
src/JUI/Widgets/TextInputForm.cpp
Normal file
@@ -0,0 +1,2 @@
|
||||
#include <JUI/Widgets/TextInputForm.hpp>
|
||||
|
@@ -39,11 +39,9 @@ namespace JUI {
|
||||
}
|
||||
|
||||
|
||||
|
||||
void TextRect::Draw() {
|
||||
Rect::Draw();
|
||||
|
||||
|
||||
void TextRect::DrawInScissor()
|
||||
{
|
||||
Rect::DrawInScissor();
|
||||
Vector2 abs_pos = this->GetAbsolutePosition();
|
||||
Vector2 abs_size = this->GetAbsoluteSize();
|
||||
|
||||
@@ -60,6 +58,13 @@ namespace JUI {
|
||||
TextBase::Draw(abs_pos + pad_shifts_pos_by, abs_size - pad_shrinks_size_by*2);
|
||||
}
|
||||
|
||||
void TextRect::Draw() {
|
||||
Rect::Draw();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user