# Rewrite 5

- Move Libraries Source into pd directory and give them all their own CMakeLists.txt
- Partial rewrite core (color, autogenerated vec), lithium (now uses UNIQUE PTR for Commands), UI7
- Use MenuV2 as new standart in UI7
- Implementz ViewPort Pre alpha to UI7
- Add Line Drawing to DrawList (not Working)
- Implement a Complete new drievrs API (static Drivers)
- NO SUPPORT FOR SHARED LIBRARY BUILDS IN VERSION 5 YET
- Add Tools to Autogenerate Headers and Stuff
This commit is contained in:
2025-06-22 21:05:09 +02:00
parent 963fa72e41
commit 57634cbf4b
184 changed files with 13967 additions and 18453 deletions

1
include/pd/ui7/container/button.hpp Normal file → Executable file
View File

@ -48,6 +48,7 @@ class PD_UI7_API Button : public Container {
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
}
~Button() = default;
PD_SHARED(Button);
/** Return true if butten is pressed*/
bool IsPressed() { return pressed; }

1
include/pd/ui7/container/checkbox.hpp Normal file → Executable file
View File

@ -47,6 +47,7 @@ class PD_UI7_API Checkbox : public Container {
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
}
~Checkbox() = default;
PD_SHARED(Checkbox);
/**
* Override for the Input Handler
* @note This function is usally called by Menu::Update

5
include/pd/ui7/container/coloredit.hpp Normal file → Executable file
View File

@ -41,13 +41,14 @@ class PD_UI7_API ColorEdit : public Container {
* @param lr Reference to the Renderer
*/
ColorEdit(const std::string& label, u32* color, UI7::IO::Ref io) {
// PD::Assert(color != nullptr, "Input Color Address is null!");
// PD::Assert(color != nullptr, "Input Color Address is null!");
this->label = label;
this->color_ref = color;
this->initial_color = *color;
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
}
~ColorEdit() = default;
PD_SHARED(ColorEdit);
/**
* Override for the Input Handler
@ -64,7 +65,7 @@ class PD_UI7_API ColorEdit : public Container {
void Update() override;
private:
fvec2 tdim; ///< Text size
fvec2 tdim; ///< Text size
u32* color_ref = nullptr; ///< Color Reference
u32 initial_color; ///< Initial Color
std::string label; ///< Label of the Button

8
include/pd/ui7/container/container.hpp Normal file → Executable file
View File

@ -24,7 +24,6 @@ SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/ui7/drawlist.hpp>
#include <pd/ui7/io.hpp>
#include <pd/ui7/pd_p_api.hpp>
@ -34,7 +33,7 @@ namespace UI7 {
* Container base class all Objects are based on
* @note this class can be used to create custom Objects as well
*/
class PD_UI7_API Container : public SmartCtor<Container> {
class PD_UI7_API Container {
public:
Container() = default;
/**
@ -51,13 +50,14 @@ class PD_UI7_API Container : public SmartCtor<Container> {
: pos(fvec2(box.x, box.y)), size(fvec2(box.z - box.x, box.w - box.y)) {}
~Container() = default;
PD_SHARED(Container);
/**
* Init Function Required by every Object that uses
* Render or Input functions
* @param io IO Reference
* @param l DrawList Reference
*/
void Init(UI7::IO::Ref io, UI7::DrawList::Ref l) {
void Init(UI7::IO::Ref io, Li::DrawList::Ref l) {
list = l;
this->io = io;
// this->screen = io->Ren->CurrentScreen();
@ -146,7 +146,7 @@ class PD_UI7_API Container : public SmartCtor<Container> {
/** Container Size*/
fvec2 size;
/** Reference to the Drawlist to Draw to*/
UI7::DrawList::Ref list;
Li::DrawList::Ref list;
/** IO Reference for Renderer and Theme */
UI7::IO::Ref io;
/** Reference to the parent container*/

2
include/pd/ui7/container/dragdata.hpp Normal file → Executable file
View File

@ -62,6 +62,8 @@ class PD_UI7_API DragData : public Container {
}
~DragData() = default;
/** Als ob das funktioniert... */
PD_SHARED(DragData<T>);
/**
* Override for the Input Handler
* @note This function is usally called by Menu::Update

6
include/pd/ui7/container/dynobj.hpp Normal file → Executable file
View File

@ -44,12 +44,14 @@ class PD_UI7_API DynObj : public Container {
* @param pos Base Position
* @param lr Reference to the Renderer
*/
DynObj(std::function<void(UI7::IO::Ref, UI7::DrawList::Ref, Container*)>
DynObj(std::function<void(UI7::IO::Ref, Li::DrawList::Ref, Container*)>
RenderFunc) {
pRenFun = RenderFunc;
}
~DynObj() = default;
PD_SHARED(DynObj);
/** Return true if butten is pressed*/
bool IsPressed() { return pressed; }
/**
@ -69,7 +71,7 @@ class PD_UI7_API DynObj : public Container {
private:
UI7Color color = UI7Color_Button; ///< current button color
bool pressed = false; ///< ispressed value
std::function<void(UI7::IO::Ref, UI7::DrawList::Ref, Container*)> pRenFun;
std::function<void(UI7::IO::Ref, Li::DrawList::Ref, Container*)> pRenFun;
};
} // namespace UI7
} // namespace PD

128
include/pd/ui7/container/image.hpp Normal file → Executable file
View File

@ -1,64 +1,66 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/ui7/container/container.hpp>
namespace PD {
namespace UI7 {
/**
* Image Object
*/
class PD_UI7_API Image : public Container {
public:
/**
* Constructor for the Image Object
* @param img Image Texture Reference
* @param size Custom Size of the Image
*/
Image(LI::Texture::Ref img, fvec2 size = 0.f, LI::Rect uv = vec4(0.f)) {
this->img = img;
this->newsize = size;
this->cuv = uv;
if (size.x != 0 || size.y != 0) {
this->SetSize(size);
} else {
this->SetSize(fvec2(img->GetSize().x, img->GetSize().y));
}
}
~Image() = default;
/**
* Override for the Rendering Handler
* @note This function is usally called by Menu::Update
* */
void Draw() override;
private:
LI::Texture::Ref img; ///< Texture reference to the Image
fvec2 newsize = 0.f; ///< New Size
LI::Rect cuv; ///< Custom UV
};
} // namespace UI7
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/ui7/container/container.hpp>
namespace PD {
namespace UI7 {
/**
* Image Object
*/
class PD_UI7_API Image : public Container {
public:
/**
* Constructor for the Image Object
* @param img Image Texture Reference
* @param size Custom Size of the Image
*/
Image(Li::Texture::Ref img, fvec2 size = 0.f, Li::Rect uv = fvec4(0.f)) {
this->img = img;
this->newsize = size;
this->cuv = uv;
if (size.x != 0 || size.y != 0) {
this->SetSize(size);
} else {
this->SetSize(fvec2(img->GetSize().x, img->GetSize().y));
}
}
~Image() = default;
PD_SHARED(Image);
/**
* Override for the Rendering Handler
* @note This function is usally called by Menu::Update
* */
void Draw() override;
private:
Li::Texture::Ref img; ///< Texture reference to the Image
fvec2 newsize = 0.f; ///< New Size
Li::Rect cuv; ///< Custom UV
};
} // namespace UI7
} // namespace PD

118
include/pd/ui7/container/label.hpp Normal file → Executable file
View File

@ -1,59 +1,61 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/ui7/container/container.hpp>
namespace PD {
namespace UI7 {
/**
* Label [Text] Object
*/
class PD_UI7_API Label : public Container {
public:
/**
* Constructor for Label Object
* @param label Label [Text] to Draw
* @param lr Renderer Reference
*/
Label(const std::string& label, IO::Ref io) {
this->label = label;
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
this->SetSize(tdim);
}
~Label() = default;
/**
* Override for the Rendering Handler
* @note This function is usally called by Menu::Update
* */
void Draw() override;
private:
fvec2 tdim; ///< Text Size
UI7Color color = UI7Color_Text; ///< Color
std::string label; ///< Text to Render
};
} // namespace UI7
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/ui7/container/container.hpp>
namespace PD {
namespace UI7 {
/**
* Label [Text] Object
*/
class PD_UI7_API Label : public Container {
public:
/**
* Constructor for Label Object
* @param label Label [Text] to Draw
* @param lr Renderer Reference
*/
Label(const std::string& label, IO::Ref io) {
this->label = label;
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
this->SetSize(tdim);
}
~Label() = default;
PD_SHARED(Label);
/**
* Override for the Rendering Handler
* @note This function is usally called by Menu::Update
* */
void Draw() override;
private:
fvec2 tdim; ///< Text Size
UI7Color color = UI7Color_Text; ///< Color
std::string label; ///< Text to Render
};
} // namespace UI7
} // namespace PD

0
include/pd/ui7/containers.hpp Normal file → Executable file
View File

View File

@ -1,236 +0,0 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/lithium/renderer.hpp>
#include <pd/ui7/flags.hpp>
#include <pd/ui7/pd_p_api.hpp>
#include <pd/ui7/theme.hpp>
namespace PD {
namespace UI7 {
class IO;
/** DrawList class */
class PD_UI7_API DrawList : public SmartCtor<DrawList> {
public:
/**
* Constructor for a new Drawlist
* @param r Renderer reference
*/
DrawList(UI7::IO* io_ref) { pIO = io_ref; }
~DrawList() = default;
/**
* Draw a Rectangle (LINED)
* @param pos position of the rect
* @param size Size of the rect
* @param clr Color of the rect
* @param thickness Thickness of the lines
*/
void AddRect(const fvec2& pos, const fvec2& size, const UI7Color& clr,
int thickness = 1);
/**
* Render a Rectangle
* @param pos Position
* @param szs Size
* @param clr Color
*/
void AddRectangle(fvec2 pos, fvec2 szs, const UI7Color& clr);
/**
* Render a Triangle
* @param a Position a
* @param b Position b
* @param c Position c
* @param clr Color
* @param thickness Thickness of the lines
*/
void AddTriangle(const fvec2& a, const fvec2& b, const fvec2& c,
const UI7Color& clr, int thickness = 1);
/**
* Render a Filled Triangle
* @param a Position a
* @param b Position b
* @param c Position c
* @param clr Color
*/
void AddTriangleFilled(const fvec2& a, const fvec2& b, const fvec2& c,
const UI7Color& clr);
/**
* Add a Lined Circle
* @param pos Center position
* @param rad radius of the circle
* @param col Color of the Circle
* @param num_segments Number of Segments (0 = auto)
* @param thickness thickness of the line
*/
void AddCircle(const fvec2& pos, float rad, UI7Color col,
int num_segments = 0, int thickness = 1);
/**
* Add a Circle
* @param pos Center position
* @param rad radius of the circle
* @param col Color of the Circle
* @param num_segments Number of Segments (0 = auto)
*/
void AddCircleFilled(const fvec2& pos, float rad, UI7Color col,
int num_segments = 0);
/**
* Render a Text
* @param pos Position
* @param text Text
* @param clr Color
* @param flags Flags
* @param box Aditional Text Box limit (for specific flags)
*/
void AddText(fvec2 pos, const std::string& text, const UI7Color& clr,
u32 flags = 0, fvec2 box = fvec2());
/**
* Render an Image
* @param pos Position
* @param img Image Texture Reference
* @param size Optional Size of the Image
* @param uv Custom UV coords
*/
void AddImage(fvec2 pos, LI::Texture::Ref img, fvec2 size = 0.f,
LI::Rect uv = fvec4(0.f));
/**
* Render a Line from Position A to Position B
* @param a Pos a
* @param b Pos b
* @param clr Color
* @param t Thcikness
*/
void AddLine(const fvec2& a, const fvec2& b, const UI7Color& clr, int t = 1);
/**
* Take list of points and display it as a line on screen
* @param points List of Positions
* @param clr Color of the Line
* @param flags Additional Flags (Close for go back to starting point)
* @param thickness Thickness of the Line
*/
void AddPolyLine(const Vec<fvec2>& points, const UI7Color& clr,
UI7DrawFlags flags = 0, int thickness = 1);
/**
* Take a List ofpoints and display it as Filled Shape
* @note Keep in mind to setup the list of points clockwise
* @param points List of Points
* @param clr Color of the shape
*/
void AddConvexPolyFilled(const Vec<fvec2>& points, const UI7Color& clr);
/** Clear the Drawlist */
void Clear();
/** Process [Render] the Drawlist */
void Process(LI::DrawList::Ref d);
/** Push a Clip Rect */
void PushClipRect(const fvec4& v) { pClipRects.Push(v); }
/** Revert Last Clip Rect */
void PopClipRect() { pClipRects.Pop(); }
/** Path API */
/**
* Function to reserve Memory to prevent overhead on
* pusing a lot of points with PathNext
* @param num_points Number of Positions you want to add
*/
void PathReserve(size_t num_points) {
Path.Reserve(Path.Size() + num_points);
}
/**
* Clear current Path
* @note PathStroke and PathFill will automatically clear
*/
void PathClear() { Path.Clear(); }
/**
* Add a Point to the Path
* @note Keep in mind that this function is used for
* setting the starting point
* @param v Position to add
*/
void PathNext(const fvec2& v) { Path.Add(v); }
/**
* Path Stroke Create Line from point to point
* @note For Primitives like Rect or Triangle mak sure to use
* UI7DrawFlags_Close to add a line back to the starting point
* @param clr Color od the line
* @param thickness Thickness of the line
* @param flags Additional Drawflags
*/
void PathStroke(const UI7Color& clr, int thickness = 1,
UI7DrawFlags flags = 0) {
AddPolyLine(Path, clr, flags, thickness);
Path.Clear();
}
/**
* Fill a Path with a Color
* @note **IMPORTANT: ** Paths need to be setup clockwise
* to be rendered correctly
* @param clr Fill Color
*/
void PathFill(const UI7Color& clr) {
AddConvexPolyFilled(Path, clr);
Path.Clear();
}
void PathArcToN(const fvec2& c, float radius, float a_min, float a_max,
int segments);
/// @brief Create a Path Rect (uses to Positions instead of Pos/Size)
/// @param a Top Left Position
/// @param b Bottom Right Position
/// @param rounding rounding
/// @param flags DrawFlags (for special rounding rules)
void PathRect(fvec2 a, fvec2 b, float rounding = 0.f, UI7DrawFlags flags = 0);
int Layer; ///< Layer
int Base; ///< Base Layer
Stack<fvec4> pClipRects; ///< ClipRects
u32 NumVertices; ///< Num vertices
u32 NumIndices; ///< Num Indices
UI7::IO* pIO; ///< IO Reference
LI::Texture::Ref CurrentTex; ///< Current Texture
private:
/**
* One liner to setup command cliprect
*/
void ClipCmd(LI::Command::Ref cmd);
// Set friendclass here to not expose private functions as public
friend class Menu;
friend class Context;
Vec<fvec2> Path;
// Map for Auto Static Text
// std::unordered_map<u32, LI::StaticText::Ref> static_text;
// List of Drawcommands generated
Vec<LI::Command::Ref> Commands;
};
} // namespace UI7
} // namespace PD

0
include/pd/ui7/flags.hpp Normal file → Executable file
View File

141
include/pd/ui7/id.hpp Normal file → Executable file
View File

@ -1,72 +1,71 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/core.hpp>
namespace PD {
namespace UI7 {
/**
* ID Class (Generating an ID by String)
*/
class ID {
public:
/**
* Constructor to Generate ID by input string
* @param text Input String
*/
ID(const std::string& text) {
id = PD::Strings::FastHash(text);
name = text;
}
/**
* Constructor used for const char* which is automatically
* used when directly placing a string istead of using ID("")
* @param text Input String
*/
ID(const char* text) {
id = PD::Strings::FastHash(text);
name = text;
}
/**
* Use an ID as Input
*/
ID(u32 id) { this->id = id; }
~ID() = default;
/** Get The ID Initial Name */
const std::string& GetName() const { return name; }
/** Getter for the raw 32bit int id */
const u32& RawID() const { return id; }
/** Return the ID when casting to u32 */
operator u32() const { return id; }
private:
u32 id; ///< Hash of the name
std::string name; ///< Name
};
} // namespace UI7
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/core.hpp>
namespace PD {
namespace UI7 {
/**
* ID Class (Generating an ID by String)
*/
class ID {
public:
/**
* Constructor to Generate ID by input string
* @param text Input String
*/
ID(const std::string& text) {
pID = PD::Strings::FastHash(text);
pName = text;
}
/**
* Constructor used for const char* which is automatically
* used when directly placing a string istead of using ID("")
* @param text Input String
*/
ID(const char* text) {
pID = PD::Strings::FastHash(text);
pName = text;
}
/**
* Use an ID as Input
*/
ID(u32 id) { pID = id; }
~ID() = default;
/** Get The ID Initial Name */
const std::string& GetName() const { return pName; }
/** Getter for the raw 32bit int id */
const u32& RawID() const { return pID; }
/** Return the ID when casting to u32 */
operator u32() const { return pID; }
u32 pID; ///< Hash of the name
std::string pName; ///< Name
};
} // namespace UI7
} // namespace PD

34
include/pd/ui7/input_api.hpp Normal file → Executable file
View File

@ -2,7 +2,8 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -24,19 +25,19 @@ SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/lithium/renderer.hpp>
#include <pd/lithium/lithium.hpp>
#include <pd/ui7/id.hpp>
#include <pd/ui7/pd_p_api.hpp>
namespace PD {
namespace UI7 {
class InputHandler : public SmartCtor<InputHandler> {
class InputHandler {
public:
InputHandler(Hid::Ref inp_drv) {
DragTime = Timer::New(false);
Inp = inp_drv;
}
InputHandler() { DragTime = Timer::New(false); }
~InputHandler() = default;
PD_SHARED(InputHandler);
/**
* Function to Check if current Object is dragged
* or set it dragged
@ -55,9 +56,9 @@ class InputHandler : public SmartCtor<InputHandler> {
}
}
// Get a Short define for touch pos
vec2 p = Inp->TouchPos();
fvec2 p = Hid::MousePos();
// Check if Drag starts in the area position
if (Inp->IsDown(Inp->Touch) && LI::Renderer::InBox(p, area)) {
if (Hid::IsDown(Hid::Key::Touch) && Li::Renderer::InBox(p, area)) {
// Set ID and iniatial Positions
DraggedObject = id;
DragSourcePos = p;
@ -68,22 +69,22 @@ class InputHandler : public SmartCtor<InputHandler> {
DragTime->Reset();
DragTime->Rseume();
return false; // To make sure the Object is "Dragged"
} else if (Inp->IsHeld(Inp->Touch) && IsObjectDragged()) {
} else if (Hid::IsHeld(Hid::Key::Touch) && IsObjectDragged()) {
// Update DragLast and DragPoisition
DragLastPosition = DragPosition;
DragPosition = p;
} else if (Inp->IsUp(Inp->Touch) && IsObjectDragged()) {
} else if (Hid::IsUp(Hid::Key::Touch) && IsObjectDragged()) {
// Released... Everything gets reset
DraggedObject = 0;
DragPosition = 0;
DragSourcePos = 0;
DragLastPosition = 0;
DragDestination = 0;
DragDestination = fvec4(0);
// Set Drag released to true (only one frame)
// and Only if still in Box
DragReleased = LI::Renderer::InBox(Inp->TouchPosLast(), area);
DragReleased = Li::Renderer::InBox(Hid::MousePosLast(), area);
DragReleasedAW = true; // Advanced
u64 d_rel = Sys::GetTime();
u64 d_rel = PD::OS::GetTime();
if (d_rel - DragLastReleased < DoubleClickTime) {
DragDoubleRelease = true;
DragLastReleased = 0; // Set 0 to prevent double exec
@ -115,7 +116,8 @@ class InputHandler : public SmartCtor<InputHandler> {
fvec2 DragSourcePos = 0;
fvec2 DragPosition = 0;
fvec2 DragLastPosition = 0;
fvec4 DragDestination = 0;
/** Fvec4 has an constructor problem currently */
fvec4 DragDestination = fvec4(0);
Timer::Ref DragTime;
u64 DragLastReleased = 0;
bool DragReleased = false; ///< Drag Releaded in Box
@ -123,8 +125,6 @@ class InputHandler : public SmartCtor<InputHandler> {
bool DragDoubleRelease = false; ///< Double Click
/** Check if an object is Dragged already */
bool IsObjectDragged() const { return DraggedObject != 0; }
Hid::Ref Inp;
};
} // namespace UI7
} // namespace PD

64
include/pd/ui7/io.hpp Normal file → Executable file
View File

@ -2,7 +2,8 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -24,53 +25,43 @@ SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/ui7/drawlist.hpp>
#include <pd/ui7/flags.hpp>
#include <pd/ui7/id.hpp>
#include <pd/ui7/input_api.hpp>
#include <pd/ui7/pd_p_api.hpp>
#include <pd/ui7/theme.hpp>
#include <pd/ui7/viewport.hpp>
namespace PD {
namespace UI7 {
/**
* Shared Configuration and Runtime Data for a UI7 Context
*/
class PD_UI7_API IO : public SmartCtor<IO> {
class PD_UI7_API IO {
public:
/**
* IO Constructor setting UP References
*/
IO(Hid::Ref input_driver, LI::Renderer::Ref ren) {
IO() {
Time = Timer::New();
InputHandler = UI7::InputHandler::New(input_driver);
InputHandler = InputHandler::New();
Theme = UI7::Theme::New();
Inp = input_driver;
Ren = ren;
Back = UI7::DrawList::New(this);
Front = UI7::DrawList::New(this);
pRDL = LI::DrawList::New(Ren->WhitePixel);
DrawListRegestry.PushFront(
Pair<UI7::ID, DrawList::Ref>("CtxBackList", Back));
// RegisterDrawList("CtxBackList", Back);
Back = Li::DrawList::New();
Front = Li::DrawList::New();
DeltaStats = TimeStats::New(60);
};
~IO() = default;
/** Probably not the best solution i guess */
CurrentViewPort.z = PD::Li::Gfx::pGfx->ViewPort.x;
CurrentViewPort.w = PD::Li::Gfx::pGfx->ViewPort.y;
}
~IO() {}
PD_SHARED(IO);
/**
* IO Update Internal Variables
*/
void Update();
ivec4 CurrentViewPort = ivec4(0, 0, 0, 0);
std::unordered_map<u32, ViewPort::Ref> ViewPorts;
float Framerate = 0.f;
float Delta = 0.f;
u64 LastTime = 0;
TimeStats::Ref DeltaStats;
Timer::Ref Time;
Hid::Ref Inp;
LI::Renderer::Ref Ren;
LI::DrawList::Ref pRDL;
LI::Font::Ref Font;
Li::Font::Ref Font;
float FontScale = 0.7f;
UI7::Theme::Ref Theme;
fvec2 MenuPadding = 5.f;
@ -81,21 +72,28 @@ class PD_UI7_API IO : public SmartCtor<IO> {
bool ShowFrameBorder = false; // not implemented yet
float OverScrollMod = 0.15f;
u64 DoubleClickTime = 500; // Milliseconds
PD::List<Pair<UI7::ID, DrawList::Ref>> DrawListRegestry;
PD::List<Pair<UI7::ID, Li::DrawList::Ref>> DrawListRegestry;
// Short define for DrawKistRegestryLast
PD::List<Pair<UI7::ID, DrawList::Ref>> pDLRL;
// std::vector<std::pair<UI7::ID, DrawList::Ref>> DrawListRegestry;
DrawList::Ref Back;
DrawList::Ref Front;
PD::List<Pair<UI7::ID, Li::DrawList::Ref>> pDLRL;
// std::vector<std::pair<UI7::ID, Li::DrawList::Ref>> DrawListRegestry;
Li::DrawList::Ref Back;
Li::DrawList::Ref Front;
u32 NumVertices = 0; ///< Debug Vertices Num
u32 NumIndices = 0; ///< Debug Indices Num
Vec<u32> MenuOrder;
// DrawListApi
void RegisterDrawList(const UI7::ID& id, DrawList::Ref v) {
void RegisterDrawList(const UI7::ID& id, Li::DrawList::Ref v) {
DrawListRegestry.PushBack(Pair(id, v));
}
void AddViewPort(const ID& id, const ivec4& size) {
if (ViewPorts.count(id)) {
return;
}
ViewPorts[id] = ViewPort::New(id, size);
}
UI7::InputHandler::Ref InputHandler;
};
} // namespace UI7

20
include/pd/ui7/layout.hpp Normal file → Executable file
View File

@ -2,7 +2,8 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -25,27 +26,30 @@ SOFTWARE.
#include <pd/core/core.hpp>
#include <pd/ui7/container/container.hpp>
#include <pd/ui7/drawlist.hpp>
#include <pd/ui7/flags.hpp>
#include <pd/ui7/io.hpp>
#include <pd/ui7/input_api.hpp>
#include <pd/ui7/pd_p_api.hpp>
#include <pd/ui7/theme.hpp>
namespace PD {
namespace UI7 {
class PD_UI7_API Layout : public PD::SmartCtor<Layout> {
class PD_UI7_API Layout {
public:
Layout(const ID& id, IO::Ref io) : ID(id) {
this->IO = io;
DrawList = UI7::DrawList::New(io.get());
DrawList = Li::DrawList::New();
DrawList->SetFont(IO->Font);
Scrolling[0] = false;
Scrolling[1] = false;
CursorInit();
Pos = fvec2(0, 0);
Size = fvec2(320, 240);
Size = fvec2(io->CurrentViewPort.z, io->CurrentViewPort.w);
WorkRect = fvec4(IO->MenuPadding, Size - (fvec2(2) * IO->MenuPadding));
}
~Layout() = default;
PD_SHARED(Layout);
const std::string& GetName() const { return ID.GetName(); }
const UI7::ID& GetID() const { return this->ID; }
@ -54,7 +58,7 @@ class PD_UI7_API Layout : public PD::SmartCtor<Layout> {
const fvec2& GetSize() const { return Size; }
void SetSize(const fvec2& v) { Size = v; }
UI7::DrawList::Ref GetDrawList() { return DrawList; }
Li::DrawList::Ref GetDrawList() { return DrawList; }
void CursorInit();
void SameLine();
@ -104,7 +108,7 @@ class PD_UI7_API Layout : public PD::SmartCtor<Layout> {
// Base Components
UI7::ID ID;
UI7::IO::Ref IO;
UI7::DrawList::Ref DrawList;
Li::DrawList::Ref DrawList;
// Positioning
fvec2 Pos;

275
include/pd/ui7/menu.hpp Normal file → Executable file
View File

@ -2,7 +2,8 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -23,278 +24,90 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "pd/ui7/container/dragdata.hpp"
#include <pd/core/core.hpp>
#include <pd/ui7/containers.hpp>
#include <pd/ui7/drawlist.hpp>
#include <pd/ui7/flags.hpp>
#include <pd/ui7/id.hpp>
#include <pd/ui7/io.hpp>
#include <pd/ui7/layout.hpp>
#include <pd/ui7/pd_p_api.hpp>
namespace PD {
namespace UI7 {
/** Menu Class for UI7 */
class PD_UI7_API Menu : public SmartCtor<Menu> {
public:
/**
* Menu COnstructor (Unly used by UI7::Context)
* @param id ID of the Menu
* @param io IO Config Reference
*/
Menu(ID id, UI7::IO::Ref io) {
/// Setup the Input Data
this->io = io;
this->id = id;
this->name = id.GetName();
/// Set Default Values here
scrollbar[0] = false;
scrollbar[1] = false;
scroll_allowed[0] = false;
scroll_allowed[1] = false;
Layout = UI7::Layout::New(id, io);
}
~Menu() = default;
class PD_UI7_API Menu {
public:
Menu(const UI7::ID &id, UI7::IO::Ref pIO);
~Menu() {}
// Objects
PD_SHARED(Menu);
/**
* Render a Simple Label
* @param label The text to draw
*/
void Label(const std::string& label);
void Label(const std::string &label);
/**
* Render a Button
* @param label The buttons text
* @return if the button was pressed
*/
bool Button(const std::string& label);
bool Button(const std::string &label);
/**
* Render a Checkbox
* @param label Label of the Checkbox
* @param v A value to update
*/
void Checkbox(const std::string& label, bool& v);
void Checkbox(const std::string &label, bool &v);
/**
* Render an Image
* @param img Texture reference of the image
* @param size a Custom Size if needed
*/
void Image(LI::Texture::Ref img, fvec2 size = 0.f, LI::Rect uv = fvec4(0));
void Image(Li::Texture::Ref img, fvec2 size = 0.f, Li::Rect uv = fvec4(0));
/**
* Color Edit Object that opens a popup editor if clicked
* @param label Name of the Edit field
* @param color Color reference to edit
* Render a Drag Object witth any supported type:
* [`int`, `float`, `double`, `u8`, `u16`, `u32`]
* @param label Name of the Drag
* @param data Reference to Data Object (can be multiple as well)
* @param num_elements Defien the number of Elements in the Data addr
* @param precission Difine the Format string len for float/double
*/
void ColorEdit(const std::string& label, u32* color);
void DragFloat(const std::string& label, float* data, size_t num_elms);
template <typename T>
void DragData(const std::string& label, T* data, size_t num_elms = 1,
void DragData(const std::string &label, T *data, size_t num_elms = 1,
T min = std::numeric_limits<T>::min(),
T max = std::numeric_limits<T>::max(), T step = 1,
int precision = 1) {
u32 id = Strings::FastHash("drd" + label + std::to_string((uintptr_t)data));
Container::Ref r = Layout->FindObject(id);
Container::Ref r = pLayout->FindObject(id);
if (!r) {
r = PD::New<UI7::DragData<T>>(label, data, num_elms, io, min, max, step,
precision);
r = UI7::DragData<T>::New(label, data, num_elms, pIO, min, max, step,
precision);
// Isnt This exactly the same line???
// r = UI7::DragData<T>::New(label, data, num_elms, pIO, min, max, step,
// precision);
r->SetID(id);
}
Layout->AddObject(r);
pLayout->AddObject(r);
}
// Basic API
/**
* Create a Tree Node
* @param id String ID of the Node
* @return node open or not
*/
bool BeginTreeNode(const UI7::ID& id);
/**
* End a Tree Node
*/
void EndTreeNode();
/** Add the Next Objext to the same line */
void SameLine() { Layout->SameLine(); }
/** Add a Separator Line */
void Sameline() { pLayout->SameLine(); }
void Separator();
/**
* Render a Separator Line with a Text
* @todo determinate text position by current alignment
* @param label The Text to show
*/
void SeparatorText(const std::string& label);
/** Put the last Added Object into the Joinlist */
void Join();
/**
* Add the Last element to the join list
* and perform an alignment operation
* @param a Alignment Oeration(s)
*/
void JoinAlign(UI7Align a);
/**
* Align the Last Object
* @param a Alignment Operation
*/
void AfterAlign(UI7Align a);
/**
* Set a Temp alignment op for the next Object
* @param a Alignment Operation
*/
void NextAlign(UI7Align a) { Layout->NextAlign(a); }
/**
* Align Every Single Object by this operationset
* @param a Alignment
*/
void PushAlignment(UI7Align a) { Layout->SetAlign(a); }
/** Use default alignment */
void PopAlignment() { Layout->Alignment = UI7Align_Default; }
/**
* Returns a Reference to the theme
* @return Reference to the base Theme of the context
*/
Theme::Ref GetTheme() { return io->Theme; }
/**
* Directly return a Color by using the
* m->ThemeColor(UI7Color_Text) for example
* @param clr The Input UI7 Color
* @return The 32bit color value
*/
u32 ThemeColor(UI7Color clr) const { return io->Theme->Get(clr); }
void SeparatorText(const std::string &label);
/**
* Get IO Reference
* @return io Reference
*/
UI7::IO::Ref GetIO() { return io; }
void HandleFocus();
void HandleScrolling();
void HandleTitlebarActions();
void DrawBaseLayout();
// API for Custom Objects
void Update();
/** Return if a Vertical Scrollbar exists */
bool HasVerticalScrollbar() { return scrollbar[1]; }
/** Return if a Horizontal Scrollbar exists */
bool HasHorizontalScrollbar() { return scrollbar[0]; }
/** Get the Titlebar height */
float TitleBarHeight() { return tbh; }
/**
* Set a Custom Titlebar heigt
* @note Could destroy some basic functionality
*/
void TitleBarHeight(float v) { tbh = v; }
/** Data Section */
/**
* Animated Scroll to Position
* @param pos Destination Position
*/
void ScrollTo(fvec2 pos) {
scroll_anim.From(Layout->ScrollOffset)
.To(pos)
.In(1.f)
.As(scroll_anim.EaseInOutSine);
}
/** Check if Still in ScrollAnimation */
bool IsAnimatedScroll() { return !scroll_anim.IsFinished(); }
UI7MenuFlags Flags = 0;
Layout::Ref pLayout;
IO::Ref pIO;
ID pID;
bool *pIsShown = nullptr;
bool pIsOpen = true;
// Objects API
/**
* Create a Parent Container to move and edit all sub
* instances at once
*/
void CreateParent();
/** Destory the parent container (if one active) */
void DestroyParent() { tmp_parent = nullptr; }
// Draw List
/** Get DrawList */
DrawList::Ref GetDrawList() { return Layout->DrawList; }
UI7::Layout::Ref GetLayout() { return Layout; }
// Advanced
/**
* Display Debug Labels of a Menu
* @param m Menu to display Data from
* @param t Target to Write the Labels into
*/
static void DebugLabels(Menu::Ref m, Menu::Ref t = nullptr);
// Uneditable Stuff
/** Menu Name */
std::string GetName() const { return name; }
/** Menu ID [Hash of the Name] */
u32 GetID() const { return id; }
private:
// Advanced Handlers
/**
* Setup for the Menu
* @param flags Menu Flags
*/
void PreHandler(UI7MenuFlags flags);
/** Handle things like scrolling */
void PostHandler();
/** Internal Processing */
void Update(float delta);
// Put some Buttons and functionality into its own functions
/** Handler of the Close Button (if exists) */
void CloseButtonHandler();
/** Handler of the Resize Dragging (lower right corner) */
void ResizeHandler();
/** Logic of the Titlebar Movement */
void MoveHandler();
/** Menu Collapse Button Handler */
void CollapseHandler();
/** Scroll Handler (Includes Slider Drag) */
void PostScrollHandler();
/** Handler to Set menu focused or not */
void MenuFocusHandler();
// This ability is crazy useful
friend class Context;
// Data
UI7MenuFlags flags = 0; ///< Menu Flags
u32 id; ///< Menu ID
std::string name; ///< Menu Name
float tbh; ///< Titlebar height
bool scrollbar[2]; ///< Is Hz or Vt Scrollbar rendered
bool scroll_allowed[2]; ///< Is Hz or Vt Scrolling Alowed
bool has_touch; ///< Menu has touch (depends on screen)
bool is_open = true; ///< For Collapse Event
bool* is_shown = nullptr; ///< For Close Button
Container::Ref tmp_parent; ///< Parent Container (for better alignment etc)
// Objects API
std::vector<Container*> join; ///< List of Combined Objects
int count_btn = 0; ///< Count for Button ID Prefix
int count_cbx = 0; ///< Cound for Checkbox ID Prefix
UI7::IO::Ref io; ///< IO Reference
std::map<u32, bool> tree_nodes; ///< Map of Tree nodes
// Animations System
Tween<fvec2> scroll_anim; ///< for Scroll to Animation
// Layout API
PD::UI7::Layout::Ref Layout;
UI7Color clr_close_btn = UI7Color_FrameBackground;
UI7Color clr_collapse_tri = UI7Color_FrameBackground;
UI7Color header = UI7Color_HeaderDead;
float TitleBarHeight = 0.f;
};
} // namespace UI7
} // namespace PD
} // namespace UI7
} // namespace PD

9
include/pd/ui7/pd_p_api.hpp Normal file → Executable file
View File

@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -22,9 +21,9 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
*/
#pragma once
/** Generated with ppam */
#ifdef _WIN32 // Windows (MSVC Tested)
#ifdef PD_UI7_BUILD_SHARED
@ -49,4 +48,4 @@ SOFTWARE.
#define PD_UI7_API
#else
#define PD_UI7_API
#endif
#endif

View File

@ -1,107 +0,0 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/ui7/layout.hpp>
namespace PD {
namespace UI7 {
/**
* ReMenu (Should get something like MenuBase or so)
* to define basic functionality and extend it by using this as a
* template class
*/
class PD_UI7_API ReMenu {
public:
ReMenu(const UI7::ID& id, UI7::IO::Ref io) : pID(id) {
pLayout = UI7::Layout::New(id, io);
pIO = io;
TitleBarHeight = io->FontScale * 30.f;
pLayout->WorkRect.y += TitleBarHeight;
pLayout->CursorInit();
}
~ReMenu() = default;
/** Using the Legacy version here */
PD_SMART_CTOR(ReMenu)
/**
* Render a Simple Label
* @param label The text to draw
*/
void Label(const std::string& label);
/**
* Render a Button
* @param label The buttons text
* @return if the button was pressed
*/
bool Button(const std::string& label);
/**
* Render a Checkbox
* @param label Label of the Checkbox
* @param v A value to update
*/
void Checkbox(const std::string& label, bool& v);
/**
* Render an Image
* @param img Texture reference of the image
* @param size a Custom Size if needed
*/
void Image(LI::Texture::Ref img, fvec2 size = 0.f, LI::Rect uv = fvec4(0));
template <typename T>
void DragData(const std::string& label, T* data, size_t num_elms = 1,
T min = std::numeric_limits<T>::min(),
T max = std::numeric_limits<T>::max(), T step = 1,
int precision = 1) {
u32 id = Strings::FastHash("drd" + label + std::to_string((uintptr_t)data));
Container::Ref r = pLayout->FindObject(id);
if (!r) {
r = PD::New<UI7::DragData<T>>(label, data, num_elms, pIO, min, max, step,
precision);
r->SetID(id);
}
pLayout->AddObject(r);
}
void Sameline() { pLayout->SameLine(); }
void Separator();
void SeparatorText(const std::string& label);
void HandleFocus();
void HandleScrolling();
void HandleTitlebarActions();
void DrawBaseLayout();
void Update();
UI7MenuFlags Flags = 0;
UI7::Layout::Ref pLayout;
UI7::IO::Ref pIO;
UI7::ID pID;
bool* pIsShown = nullptr;
bool pIsOpen = true;
float TitleBarHeight = 0.f;
};
} // namespace UI7
} // namespace PD

43
include/pd/ui7/theme.hpp Normal file → Executable file
View File

@ -55,16 +55,16 @@ enum UI7Color_ {
namespace PD {
namespace UI7 {
/** Theme Class */
class PD_UI7_API Theme : public SmartCtor<Theme> {
class PD_UI7_API Theme {
public:
/**
* Default Constructor Setting up the Default theme
* @note if using SmartCtor Reference you probably need to do
* @note if using Shared Reference you probably need to do
* Theme::Default(*theme.get());
*/
Theme() { Default(*this); }
~Theme() = default;
~Theme() {}
PD_SHARED(Theme);
/**
* Simple static Loader for the Default Theme
@ -79,9 +79,9 @@ class PD_UI7_API Theme : public SmartCtor<Theme> {
/** Revert the last Color Change */
Theme& Pop() {
theme[changes[changes.size() - 1].first] =
changes[changes.size() - 1].second;
changes.pop_back();
pTheme[pChanges[pChanges.size() - 1].first] =
pChanges[pChanges.size() - 1].second;
pChanges.pop_back();
return *this;
}
@ -90,10 +90,10 @@ class PD_UI7_API Theme : public SmartCtor<Theme> {
* @param c Color to revert change from
*/
Theme& Pop(UI7Color c) {
for (size_t i = changes.size() - 1; i > 0; i--) {
if (changes[i].first == c) {
theme[c] = changes[i].second;
changes.erase(changes.begin() + i);
for (size_t i = pChanges.size() - 1; i > 0; i--) {
if (pChanges[i].first == c) {
pTheme[c] = pChanges[i].second;
pChanges.erase(pChanges.begin() + i);
break;
}
}
@ -106,11 +106,11 @@ class PD_UI7_API Theme : public SmartCtor<Theme> {
* @param color Color to change to
*/
Theme& Change(UI7Color tc, u32 color) {
if (theme.find(tc) == theme.end()) {
if (pTheme.find(tc) == pTheme.end()) {
return *this;
}
changes.push_back(std::make_pair(tc, theme[tc]));
theme[tc] = color;
pChanges.push_back(std::make_pair(tc, pTheme[tc]));
pTheme[tc] = color;
return *this;
}
@ -119,8 +119,8 @@ class PD_UI7_API Theme : public SmartCtor<Theme> {
* @param c ReferenceID
*/
u32 Get(UI7Color c) const {
auto e = theme.find(c);
if (e == theme.end()) {
auto e = pTheme.find(c);
if (e == pTheme.end()) {
return 0x00000000;
}
return e->second;
@ -132,8 +132,8 @@ class PD_UI7_API Theme : public SmartCtor<Theme> {
* @param c ReferenceID
*/
u32& GetRef(UI7Color c) {
auto e = theme.find(c);
if (e == theme.end()) {
auto e = pTheme.find(c);
if (e == pTheme.end()) {
static u32 noclr = 0x00000000;
return noclr;
}
@ -151,11 +151,10 @@ class PD_UI7_API Theme : public SmartCtor<Theme> {
* @param tc Color ID (Can be self creeated ones as well)
* @param clr Color it should be set to
*/
void Set(UI7Color tc, u32 clr) { theme[tc] = clr; }
void Set(UI7Color tc, u32 clr) { pTheme[tc] = clr; }
private:
std::unordered_map<u32, u32> theme; ///< Theme Data
std::vector<std::pair<UI7Color, u32>> changes; ///< List of Changes
std::unordered_map<u32, u32> pTheme; ///< Theme Data
std::vector<std::pair<UI7Color, u32>> pChanges; ///< List of Changes
};
} // namespace UI7
} // namespace PD

135
include/pd/ui7/ui7.hpp Normal file → Executable file
View File

@ -2,7 +2,8 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -23,130 +24,56 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "pd/ui7/flags.hpp"
#include <pd/core/core.hpp>
#include <pd/ui7/drawlist.hpp>
#include <pd/ui7/flags.hpp>
#include <pd/ui7/id.hpp>
#include <pd/ui7/io.hpp>
#include <pd/ui7/menu.hpp>
#include <pd/ui7/remenu.hpp>
#include <pd/ui7/theme.hpp>
#include <pd/ui7/pd_p_api.hpp>
/**
* Declare UI7 Version
* Format: 00 00 00 00
* Major Minor Patch Build
* 0x01010000 -> 1.1.0-0
*/
#define UI7_VERSION 0x00040000
#define UI7_VERSION 0x00050000
namespace PD {
namespace UI7 {
/**
* Get UI7 Version String
* @param show_build Ahow build num (mostly unused)
* @param show_build Show build num (mostly unused)
* @return Version String (1.0.0-1 for example)
*/
PD_UI7_API std::string GetVersion(bool show_build = false);
/** Base Context for UI7 */
class PD_UI7_API Context : public SmartCtor<Context> {
public:
/**
* Constructor for UI7 Context
* @param ren Renderer Reference
* @param hid Input Driver Reference
*/
Context(LI::Renderer::Ref ren, Hid::Ref hid) {
/// Set the Internal References
io = IO::New(hid, ren);
}
class PD_UI7_API Context {
public:
Context() { pIO = IO::New(); }
~Context() = default;
/**
* Begin a New Menu
* @param id Menu ID / Name shown in Titlebar
* @param flags Optional flags to change stuff
* @return If the Menu was Created
* (useless as false results in an error screen)
*/
bool BeginMenu(const ID& id, UI7MenuFlags flags = 0, bool* show = nullptr);
bool DoMenuEx(const ID& id, UI7MenuFlags flags,
std::function<void(ReMenu::Ref m)> f);
/**
* Get the Current Menu
* for example for auto m = ctx->GetCurrentMenu
*/
Menu::Ref GetCurrentMenu();
/**
* Find a Menu by its ID to edit things outside of
* the place between Begin and EndMenu
* @param id ID (Menu Name) to search for
*/
Menu::Ref FindMenu(const ID& id);
/**
* Ends the Current Menu
* (to be able to create another one)
*/
PD_SHARED(Context);
void AddViewPort(const ID &id, const ivec4 &vp);
void UseViewPort(const ID &id);
void Update();
bool BeginMenu(const ID &id, UI7MenuFlags flags, bool *pShow = nullptr);
void EndMenu();
/**
* Get Theme reference
* @return Reference to the base Theme of the context
*/
Theme::Ref GetTheme() { return io->Theme; }
/**
*Directly return a Color by using the
* ctx->ThemeColor(UI7Color_Text) for example
* @param clr The Input UI7 Color
* @return The 32bit color value
*/
u32 ThemeColor(UI7Color clr) const { return io->Theme->Get(clr); }
Menu::Ref pGetOrCreateMenu(const ID &id) {
auto menu = pMenus.find(id);
if (menu == pMenus.end()) {
pMenus[id] = Menu::New(id, pIO);
menu = pMenus.find(id);
}
return menu->second;
}
/**
* Update Context (Render menus)
* @param delta deltatime
*/
void Update(float delta);
// Expose DrawLists
/** Background DrawList Reference */
DrawList::Ref BackList() { return io->Back; }
/** Foreground DrawList Reference */
DrawList::Ref FrontList() { return io->Front; }
/**
* Set the Root Layer of the Menu
* @param l Layer
*/
void RootLayer(int l) { root_layer = l; }
/** Get the Root Layer of the Menu */
int RootLayer() const { return root_layer; }
/** Get IO Reference */
IO::Ref GetIO() { return io; }
// Debugging / Demo / About
/** About Menu */
void AboutMenu(bool* show = nullptr);
/** Metrics */
void MetricsMenu(bool* show = nullptr);
/** Style Editor Menu (Includes Theme Editor) */
void StyleEditor(bool* show = nullptr);
private:
// Used in Overlays
int root_layer = 0;
// Map of The Menus by ID
std::unordered_map<u32, Menu::Ref> menus;
std::vector<u32> amenus; ///< Active ones
std::vector<u32> aml; ///< Copy of Active Menus
Menu::Ref current; ///< Current Menu
ReMenu::Ref Current;
// IO
IO::Ref io;
IO::Ref pIO;
/** Current Menu */
Menu::Ref pCurrent = nullptr;
std::vector<u32> pCurrentMenus;
std::unordered_map<u32, Menu::Ref> pMenus;
};
} // namespace UI7
} // namespace PD
} // namespace UI7
} // namespace PD

46
include/pd/ui7/viewport.hpp Executable file
View File

@ -0,0 +1,46 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/ui7/id.hpp>
namespace PD {
namespace UI7 {
class ViewPort {
public:
ViewPort(const ID& id, const ivec4& size) : pID(id), pSize(size) {}
~ViewPort() {}
PD_SHARED(ViewPort);
ID GetID() const { return pID; }
ivec4& GetSize() { return pSize; }
ID pID;
ivec4 pSize;
};
} // namespace UI7
} // namespace PD