Refactoring and cleaning up sections.
This commit is contained in:
@@ -73,8 +73,7 @@ namespace JUI
|
||||
bool IsDescendantOf(Widget* ancestor) const;
|
||||
|
||||
/// Returns the first child widget that has the given symbolic name, Otherwise, a nullpointer is returned
|
||||
/// TODO: Use std::optional here and anywhere else a nullptr could be returned.
|
||||
Widget* FindFirstChild(const std::string& name);
|
||||
std::optional<Widget*> FindFirstChild(const std::string& name);
|
||||
|
||||
/// Returns a flat list of all nodes that are lower in the hierarchy list.
|
||||
std::vector<Widget*> GetDescendants();
|
||||
|
@@ -0,0 +1,17 @@
|
||||
/// 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 ScrollingRect.hpp
|
||||
/// @desc Scrolling Rectangle Widget
|
||||
/// @edit 2024-10-11
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace JUI
|
||||
{
|
||||
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
/// 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 ScrollingRect.hpp
|
||||
/// @desc Scrolling Rectangle Widget
|
||||
/// @edit 2024-10-11
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace JUI
|
||||
{
|
||||
/// A mixin helper class that enables a widget to be docked into a DockingStation.
|
||||
class Dockable {};
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
/// 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 ScrollingRect.hpp
|
||||
/// @desc Scrolling Rectangle Widget
|
||||
/// @edit 2024-10-11
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Event.h>
|
||||
#include <J3ML/LinearAlgebra/Vector2.hpp>
|
||||
|
||||
namespace JUI
|
||||
{
|
||||
/// A mixin helper class that enables a widget to be dragged around by the mouse.
|
||||
class Draggable {
|
||||
public:
|
||||
Event<> OnDragBegan;
|
||||
Event<> OnDragEnded;
|
||||
bool Dragging() const { return dragging;}
|
||||
virtual void SetDrag(bool b) {
|
||||
this->dragging = b;
|
||||
}
|
||||
virtual void StartDragging(const Vector2& point)
|
||||
{
|
||||
initial_drag_offset = point;
|
||||
}
|
||||
virtual void StopDragging() {}
|
||||
virtual void Update(float delta) {}
|
||||
protected:
|
||||
bool dragging = false;
|
||||
Vector2 initial_drag_offset = {0, 0};
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
@@ -0,0 +1,18 @@
|
||||
/// 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 ScrollingRect.hpp
|
||||
/// @desc Scrolling Rectangle Widget
|
||||
/// @edit 2024-10-11
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace JUI
|
||||
{
|
||||
|
||||
}
|
34
include/JUI/Mixins/Resizable.hpp
Normal file
34
include/JUI/Mixins/Resizable.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
/// 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 Resizable.hpp
|
||||
/// @desc Resizable Mixin Helper class
|
||||
/// @edit 2024-10-11
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Event.h>
|
||||
#include <J3ML/LinearAlgebra/Vector2.hpp>
|
||||
|
||||
namespace JUI
|
||||
{
|
||||
/// A mixin helper class that enables a widget to be resized by the mouse.
|
||||
class Resizable {
|
||||
public:
|
||||
Event<> OnDragBegan;
|
||||
Event<> OnDragEnded;
|
||||
[[nodiscard]] bool Resizing() const;
|
||||
virtual void SetResize(bool b);
|
||||
virtual void StartResizing(const Vector2& point);
|
||||
virtual void StopResizing();
|
||||
virtual void Update(float delta);
|
||||
protected:
|
||||
bool resizing = false;
|
||||
Vector2 initial_resize_offset = {0, 0};
|
||||
};
|
||||
}
|
||||
|
@@ -1,8 +1,26 @@
|
||||
//
|
||||
// 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_SCROLLINGRECT_HPP
|
||||
#define JUI_SCROLLINGRECT_HPP
|
||||
/// @file ScrollingRect.hpp
|
||||
/// @desc Scrolling Rectangle Widget
|
||||
/// @edit 2024-10-11
|
||||
|
||||
#endif //JUI_SCROLLINGRECT_HPP
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <JUI/Widgets/Rect.hpp>
|
||||
|
||||
namespace JUI
|
||||
{
|
||||
class ScrollingRect : public Rect
|
||||
{
|
||||
public:
|
||||
protected:
|
||||
Vector2 canvas_size;
|
||||
private:
|
||||
};
|
||||
}
|
@@ -7,4 +7,12 @@
|
||||
|
||||
/// @file Widget.hpp
|
||||
/// @desc Base Widget Class - All JUI widgets extend their behavior from this class.
|
||||
/// @edit 2024-07-31
|
||||
/// @edit 2024-07-31
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace JUI
|
||||
{
|
||||
|
||||
}
|
@@ -18,54 +18,14 @@
|
||||
#include <JUI/Widgets/Rect.hpp>
|
||||
#include <JUI/Widgets/Text.hpp>
|
||||
#include <JUI/Widgets/Button.hpp>
|
||||
#include "JUI/Mixins/Draggable.hpp"
|
||||
#include "JUI/Mixins/Resizable.hpp"
|
||||
#include "JUI/Mixins/Dockable.hpp"
|
||||
|
||||
namespace JUI
|
||||
{
|
||||
using J3ML::LinearAlgebra::Vector2;
|
||||
|
||||
/// A mixin helper class that enables a widget to be dragged around by the mouse.
|
||||
class Draggable {
|
||||
public:
|
||||
Event<> OnDragBegan;
|
||||
Event<> OnDragEnded;
|
||||
bool Dragging() const { return dragging;}
|
||||
virtual void SetDrag(bool b) {
|
||||
this->dragging = b;
|
||||
}
|
||||
virtual void StartDragging(const Vector2& point)
|
||||
{
|
||||
initial_drag_offset = point;
|
||||
}
|
||||
virtual void StopDragging() {}
|
||||
virtual void Update(float delta) {}
|
||||
protected:
|
||||
bool dragging = false;
|
||||
Vector2 initial_drag_offset = {0, 0};
|
||||
};
|
||||
|
||||
/// A mixin helper class that enables a widget to be resized by the mouse.
|
||||
class Resizable {
|
||||
public:
|
||||
Event<> OnDragBegan;
|
||||
Event<> OnDragEnded;
|
||||
bool Resizing() const { return resizing;}
|
||||
virtual void SetResize(bool b) {
|
||||
this->resizing = b;
|
||||
}
|
||||
virtual void StartResizing(const Vector2& point)
|
||||
{
|
||||
initial_resize_offset = point;
|
||||
}
|
||||
virtual void StopResizing() {}
|
||||
virtual void Update(float delta) {}
|
||||
protected:
|
||||
bool resizing = false;
|
||||
Vector2 initial_resize_offset = {0, 0};
|
||||
};
|
||||
|
||||
|
||||
/// A mixin helper class that enables a widget to be docked into a DockingStation.
|
||||
class Dockable {};
|
||||
|
||||
/// TODO: Scope out.
|
||||
class DockingStation {};
|
||||
@@ -79,30 +39,46 @@ namespace JUI
|
||||
Window();
|
||||
/// Construct a window widget by specifying it's parent.
|
||||
Window(Widget* parent);
|
||||
/// Returns the minimum size (in x,y pixels) that the Window widget is allowed to be.
|
||||
[[nodiscard]] Vector2 MinSize() const;
|
||||
/// Returns the maximum size (in x,y pixels) that the Window widget is allowed to be.
|
||||
[[nodiscard]] Vector2 MaxSize() const;
|
||||
|
||||
/// Returns the current size (in x,y pixels) of the Window widget.
|
||||
[[nodiscard]] Vector2 CurrentSize() const;
|
||||
|
||||
/// Returns the minimum size (in x,y pixels) that the Window widget is allowed to be.
|
||||
[[nodiscard]] Vector2 MinSize() const;
|
||||
/// Sets the minimum size (in x,y pixels) that the Window widget is allowed to be.
|
||||
void MinSize(const Vector2& constraint);
|
||||
/// Returns the maximum size (in x,y pixels) that the Window widget is allowed to be.
|
||||
[[nodiscard]] Vector2 MaxSize() const;
|
||||
/// Sets the maximum size (in x,y pixels) that the Window widget is allowed to be.
|
||||
void MaxSize(const Vector2& constraint);
|
||||
|
||||
|
||||
/// Returns the height (in pixels) of the Window's titlebar.
|
||||
// TODO: Decide if this will auto-scale with the titlebar's text height, or the other way around.
|
||||
int TitlebarHeight() const;
|
||||
|
||||
/// Returns the text displayed as the Window's title.
|
||||
[[nodiscard]] std::string Title() const;
|
||||
|
||||
|
||||
void SetTitle(const std::string& title);
|
||||
/// Returns whether dragging the window about with the mouse is enabled.
|
||||
/// @see class Draggable.
|
||||
bool IsDraggable() const;
|
||||
|
||||
|
||||
void SetDraggable(bool value);
|
||||
|
||||
/// Returns whether this Window is able to be 'Docked' into another widget.
|
||||
/// @see class Dockable.
|
||||
bool IsDockable() const;
|
||||
|
||||
void SetDockable(bool value);
|
||||
|
||||
/// Returns whether resizing the window via right-click is enabled.
|
||||
/// @see class Resizable
|
||||
bool IsResizable() const;
|
||||
|
||||
void SetResizable(bool value);
|
||||
|
||||
/// Returns a pointer to the Text Widget that is used to render the title bar's text.
|
||||
Text* GetTitleInstance();
|
||||
/// Returns a pointer to the Rect Widget that is used to layout the title bar contents.
|
||||
@@ -112,7 +88,11 @@ namespace JUI
|
||||
/// Returns a pointer to the Exit Button Widget.
|
||||
TextButton* GetExitButtonInstance();
|
||||
|
||||
/// Sets the font used by the title-bar text on this Window.
|
||||
void SetTitleFont(const Font& f);
|
||||
|
||||
|
||||
/// Toggles whether this window is actively being dragged by the mouse.
|
||||
/// @see class Draggable.
|
||||
void SetDrag(bool d) override;
|
||||
|
||||
|
@@ -223,13 +223,12 @@ namespace JUI {
|
||||
}
|
||||
|
||||
|
||||
// TODO: Consider std::optional
|
||||
Widget* Widget::FindFirstChild(const std::string& search_name) {
|
||||
std::optional<Widget*> Widget::FindFirstChild(const std::string& search_name) {
|
||||
for (auto& child : children) {
|
||||
if (child->GetName() == search_name)
|
||||
return child;
|
||||
}
|
||||
return nullptr;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
|
||||
|
2
src/JUI/Mixins/Clickable.cpp
Normal file
2
src/JUI/Mixins/Clickable.cpp
Normal file
@@ -0,0 +1,2 @@
|
||||
#include <JUI/Mixins/Clickable.hpp>
|
||||
|
1
src/JUI/Mixins/Dockable.cpp
Normal file
1
src/JUI/Mixins/Dockable.cpp
Normal file
@@ -0,0 +1 @@
|
||||
#include <JUI/Mixins/Dockable.hpp>
|
1
src/JUI/Mixins/Draggable.cpp
Normal file
1
src/JUI/Mixins/Draggable.cpp
Normal file
@@ -0,0 +1 @@
|
||||
#include <JUI/Mixins/Draggable.hpp>
|
1
src/JUI/Mixins/Hoverable.cpp
Normal file
1
src/JUI/Mixins/Hoverable.cpp
Normal file
@@ -0,0 +1 @@
|
||||
#include <JUI/Mixins/Hoverable.hpp>
|
15
src/JUI/Mixins/Resizable.cpp
Normal file
15
src/JUI/Mixins/Resizable.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <JUI/Mixins/Resizable.hpp>
|
||||
|
||||
void JUI::Resizable::SetResize(bool b) {
|
||||
this->resizing = b;
|
||||
}
|
||||
|
||||
void JUI::Resizable::StartResizing(const Vector2 &point) {
|
||||
initial_resize_offset = point;
|
||||
}
|
||||
|
||||
void JUI::Resizable::StopResizing() {}
|
||||
|
||||
void JUI::Resizable::Update(float delta) {}
|
||||
|
||||
bool JUI::Resizable::Resizing() const { return resizing; }
|
@@ -220,4 +220,24 @@ namespace JUI
|
||||
void Window::SetTitle(const std::string &title) {
|
||||
GetTitleInstance()->SetContent(title);
|
||||
}
|
||||
|
||||
void Window::MinSize(const Vector2 &constraint) {
|
||||
min_size = constraint;
|
||||
}
|
||||
|
||||
void Window::MaxSize(const Vector2 &constraint) {
|
||||
max_size = constraint;
|
||||
}
|
||||
|
||||
void Window::SetDraggable(bool value) {
|
||||
draggable = value;
|
||||
}
|
||||
|
||||
void Window::SetDockable(bool value) {
|
||||
dockable = value;
|
||||
}
|
||||
|
||||
void Window::SetResizable(bool value) {
|
||||
resizable = value;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user