UI7 is BACK!
took me about a full week to get something to render again withour shared_ptrs as of now this is very unstable, untested and lacking a lot of features due to lithium is lacking the base for that Added JetBrainsMono font as debug font for the metrics
This commit is contained in:
Executable
+75
@@ -0,0 +1,75 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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>
|
||||
#include <pd/ui7/io.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
/**
|
||||
* Button Object
|
||||
* @note Button Press is delayed by 1 frame
|
||||
* (but the visual reaction is done in the same frame)
|
||||
* This only means that InPressed is responding the info in
|
||||
* the next frame
|
||||
*/
|
||||
class PD_API Button : public Container {
|
||||
public:
|
||||
/**
|
||||
* Button Object constructor
|
||||
* @param label Label of the Button
|
||||
* @param pos Base Position
|
||||
* @param lr Reference to the Renderer
|
||||
*/
|
||||
Button(const std::string& label, UI7::IO& io) {
|
||||
this->label = label;
|
||||
this->tdim = io.Font->GetTextBounds(label.c_str(), io.FontScale);
|
||||
}
|
||||
~Button() = default;
|
||||
|
||||
/** Return true if butten is pressed*/
|
||||
bool IsPressed() { return pressed; }
|
||||
/**
|
||||
* Override for the Input Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
*/
|
||||
void HandleInput() override;
|
||||
/**
|
||||
* Override for the Rendering Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
* */
|
||||
void Draw() override;
|
||||
|
||||
/** Function to Update Size if framepadding changes */
|
||||
void Update() override;
|
||||
|
||||
private:
|
||||
fvec2 tdim; ///< Text size
|
||||
UI7Color color = UI7Color_Button; ///< current button color
|
||||
std::string label; ///< Label of the Button
|
||||
bool pressed = false; ///< ispressed value
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
Executable
+72
@@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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 {
|
||||
/**
|
||||
* Checkbox Object
|
||||
* @note The Updated input is available after
|
||||
* Context::Update while the visual update is done
|
||||
* during the Update
|
||||
*/
|
||||
class PD_API Checkbox : public Container {
|
||||
public:
|
||||
/**
|
||||
* Constructor for Checkbox Object
|
||||
* @param label Label of the Checkbox
|
||||
* @param usr_ref Reference to the bool value to update
|
||||
* @param io IO Reference
|
||||
*/
|
||||
Checkbox(const std::string& label, bool& usr_ref, UI7::IO& io)
|
||||
: usr_ref(usr_ref) {
|
||||
this->label = label;
|
||||
this->tdim = io.Font->GetTextBounds(label.c_str(), io.FontScale);
|
||||
}
|
||||
~Checkbox() = default;
|
||||
/**
|
||||
* Override for the Input Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
*/
|
||||
void HandleInput() override;
|
||||
/**
|
||||
* Override for the Rendering Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
* */
|
||||
void Draw() override;
|
||||
|
||||
/** Update Size if framepadding changed */
|
||||
void Update() override;
|
||||
|
||||
private:
|
||||
fvec2 tdim; ///< Text Size
|
||||
fvec2 cbs = fvec2(18); ///< Checkbox size
|
||||
UI7Color color = UI7Color_FrameBackground; ///< Checkbox background Color
|
||||
std::string label; ///< Checkbox Label
|
||||
bool& usr_ref; ///< User bool reference
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
Executable
+75
@@ -0,0 +1,75 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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>
|
||||
#include <pd/ui7/io.hpp>
|
||||
#include <pd/ui7/layout.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
/**
|
||||
* Color Editor (Creating a PopUP when clicking)
|
||||
*/
|
||||
class PD_API ColorEdit : public Container {
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
* @param label Label of the Button
|
||||
* @param pos Base Position
|
||||
* @param lr Reference to the Renderer
|
||||
*/
|
||||
ColorEdit(const std::string& label, u32* color, UI7::IO& io) {
|
||||
// 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.c_str(), io.FontScale);
|
||||
}
|
||||
~ColorEdit() = default;
|
||||
|
||||
/**
|
||||
* Override for the Input Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
*/
|
||||
void HandleInput() override;
|
||||
/**
|
||||
* Override for the Rendering Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
* */
|
||||
void Draw() override;
|
||||
|
||||
/** Function to Update Size if framepadding changes */
|
||||
void Update() override;
|
||||
|
||||
private:
|
||||
fvec2 tdim; ///< Text size
|
||||
u32* color_ref = nullptr; ///< Color Reference
|
||||
u32 initial_color; ///< Initial Color
|
||||
std::string label; ///< Label of the Button
|
||||
Layout* layout; ///< Layout to open
|
||||
bool is_shown = false; ///< AHow Layout Editor
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
@@ -0,0 +1,179 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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/pd_p_api.hpp>
|
||||
#include <pd/ui7/io.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
/**
|
||||
* Container base class all Objects are based on
|
||||
* @note this class can be used to create custom Objects as well
|
||||
*/
|
||||
class PD_API Container {
|
||||
public:
|
||||
Container() = default;
|
||||
/**
|
||||
* Constructor with pos and Size
|
||||
* @param pos Container Position
|
||||
* @param size Container Size
|
||||
*/
|
||||
Container(const fvec2& pos, const fvec2& size) : pos(pos), size(size) {}
|
||||
/**
|
||||
* Constructor by a vec4 box
|
||||
* @param box Box containing top left and bottom right coords
|
||||
*/
|
||||
Container(const fvec4& box)
|
||||
: pos(fvec2(box.x, box.y)), size(fvec2(box.z - box.x, box.w - box.y)) {}
|
||||
~Container() = default;
|
||||
|
||||
/**
|
||||
* Init Function Required by every Object that uses
|
||||
* Render or Input functions
|
||||
* @param io IO Reference
|
||||
* @param l Drawlist Reference
|
||||
*/
|
||||
void Init(UI7::IO* io, Li::Drawlist* l) {
|
||||
list = l;
|
||||
this->io = io;
|
||||
// this->screen = io->Ren->CurrentScreen();
|
||||
}
|
||||
|
||||
void SetClipRect(fvec4 clip) {
|
||||
pClipRect = clip;
|
||||
pCLipRectUsed = true;
|
||||
}
|
||||
|
||||
/** Setter for Position */
|
||||
void SetPos(const fvec2& pos) { this->pos = pos; }
|
||||
/** Setter for Size */
|
||||
void SetSize(const fvec2& size) { this->size = size; }
|
||||
/** Getter for Position */
|
||||
fvec2 GetPos() { return pos; }
|
||||
/** Getter for Size */
|
||||
fvec2 GetSize() { return size; }
|
||||
/**
|
||||
* Get the Containers Final Position
|
||||
* for Rendering and Input (if it has a parent Object)
|
||||
*/
|
||||
fvec2 FinalPos() {
|
||||
vec2 res = pos;
|
||||
if (parent) {
|
||||
/// Probably should use parant->FinalPos here
|
||||
res += parent->GetPos();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/** Setter for Parent Container */
|
||||
void SetParent(Container* v) { parent = v; }
|
||||
/** Getter for Parent Container */
|
||||
Container* GetParent() { return parent; }
|
||||
|
||||
/** Check if Rendering can be skipped */
|
||||
bool Skippable() const { return skippable; }
|
||||
/** Check if the Object got a timeout (ID OBJ Relevant) */
|
||||
bool Removable() const { return rem; }
|
||||
|
||||
/**
|
||||
* Handles Scrolling by scrolling pos as well as
|
||||
* Time for Remove for ID Objects
|
||||
* @param scrolling Scrolling Position
|
||||
* @param viewport Viewport to check if the Object is skippable
|
||||
*/
|
||||
void HandleScrolling(fvec2 scrolling, fvec4 viewport);
|
||||
/** Template function for Input Handling */
|
||||
virtual void HandleInput() {}
|
||||
/** Tamplate function for Object rendering */
|
||||
virtual void Draw() {}
|
||||
/** Template function to update internal data (if needed) */
|
||||
virtual void Update() {}
|
||||
|
||||
/** Internal function */
|
||||
void PreDraw();
|
||||
/** Internal function */
|
||||
void PostDraw();
|
||||
|
||||
/** Internal Input Handler */
|
||||
void HandleInternalInput();
|
||||
|
||||
/**
|
||||
* Function to unlock Input after Rendering is done in
|
||||
* Menu::Update
|
||||
* @note This is used if the Object got Input Handled directly after creation
|
||||
* to not check for Inputs twice
|
||||
*/
|
||||
void UnlockInput() { inp_done = false; }
|
||||
|
||||
/** Get the Objects ID (if it is an ID object)*/
|
||||
u32 GetID() const { return id; }
|
||||
/**
|
||||
* Set ID for ID Objects
|
||||
* @param id Object ID (hashed prefix+objname+prefixed_counter)
|
||||
*/
|
||||
void SetID(u32 id) { this->id = id; }
|
||||
|
||||
/** Get a reference to IO */
|
||||
UI7::IO* GetIO() { return io; }
|
||||
|
||||
protected:
|
||||
/** used to skip Input/Render preocessing ot not*/
|
||||
bool skippable = false;
|
||||
/** value to check if an ID Object goes out of lifetime*/
|
||||
bool rem = false;
|
||||
/** Time of the last use (set by HandleScrolling)*/
|
||||
u64 last_use = 0;
|
||||
/** Input done or not for current frame*/
|
||||
bool inp_done = false;
|
||||
/** Reference to the Screen to draw the Object on*/
|
||||
// Screen::Ref screen;
|
||||
/** Container Position*/
|
||||
fvec2 pos;
|
||||
/** Container Size*/
|
||||
fvec2 size;
|
||||
/** Reference to the Drawlist to Draw to*/
|
||||
Li::Drawlist* list;
|
||||
/** IO Reference for Renderer and Theme */
|
||||
UI7::IO* io;
|
||||
/** Reference to the parent container*/
|
||||
Container* parent;
|
||||
/** Object ID (0 if unused)*/
|
||||
u32 id = 0;
|
||||
/** Internal Flags */
|
||||
u32 pFlags = 0;
|
||||
/** Is Selected? */
|
||||
bool pSelected = false;
|
||||
/** Was Pressed */
|
||||
bool pPressed = false;
|
||||
/** Was Pressed Twice */
|
||||
bool pPressedTwice = false;
|
||||
/** ClipRect */
|
||||
fvec4 pClipRect;
|
||||
/** Clip Rect used */
|
||||
bool pCLipRectUsed = false;
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
Executable
+90
@@ -0,0 +1,90 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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>
|
||||
#include <pd/ui7/io.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
/**
|
||||
* DragData Object can take a datatype or a list
|
||||
* and modifys these by moving left or right when dragging
|
||||
*/
|
||||
template <typename T>
|
||||
class PD_API DragData : public Container {
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
* @param label Label of the Button
|
||||
* @param data Data reference (Supported types can be seen in dragdata.cpp)
|
||||
* @param num_elms Number of Array elements (for exaple with use ofvec4)
|
||||
* @param io IO Reference
|
||||
* @param min minimum number using Minimum limit
|
||||
* @param max Maximum number set by max limit by default
|
||||
* @param step To set the modifier for drag movement
|
||||
* @param precision for float and double to set precision
|
||||
*/
|
||||
DragData(const std::string& label, T* data, size_t num_elms, UI7::IO& io,
|
||||
T min = std::numeric_limits<T>::min(),
|
||||
T max = std::numeric_limits<T>::max(), T step = 1,
|
||||
int precision = 1) {
|
||||
// PD::Assert(data != nullptr, "Input Data Address is null!");
|
||||
this->label = label;
|
||||
this->data = data;
|
||||
this->elm_count = num_elms;
|
||||
this->min = min;
|
||||
this->max = max;
|
||||
this->step = step;
|
||||
this->precision = precision;
|
||||
this->tdim = io.Font->GetTextBounds(label.c_str(), io.FontScale);
|
||||
}
|
||||
~DragData() = default;
|
||||
|
||||
/**
|
||||
* Override for the Input Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
*/
|
||||
void HandleInput() override;
|
||||
/**
|
||||
* Override for the Rendering Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
* */
|
||||
void Draw() override;
|
||||
|
||||
/** Function to Update Size if framepadding changes */
|
||||
void Update() override;
|
||||
|
||||
private:
|
||||
fvec2 tdim; ///< Text size
|
||||
std::string label; ///< Label of the Button
|
||||
T* data;
|
||||
size_t elm_count = 0;
|
||||
T min;
|
||||
T max;
|
||||
T step;
|
||||
int precision = 1;
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
Executable
+79
@@ -0,0 +1,79 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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>
|
||||
#include <pd/ui7/io.hpp>
|
||||
#include <functional>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
/**
|
||||
* Button Object
|
||||
* @note Button Press is delayed by 1 frame
|
||||
* (but the visual reaction is done in the same frame)
|
||||
* This only means that InPressed is responding the info in
|
||||
* the next frame
|
||||
*/
|
||||
class PD_API DynObj : public Container {
|
||||
public:
|
||||
/**
|
||||
* Button Object constructor
|
||||
* @param label Label of the Button
|
||||
* @param pos Base Position
|
||||
* @param lr Reference to the Renderer
|
||||
*/
|
||||
DynObj(std::function<void(UI7::IO*, Li::Drawlist*, Container*)> RenderFunc) {
|
||||
pRenFun = RenderFunc;
|
||||
}
|
||||
~DynObj() = default;
|
||||
|
||||
void AddInputHandler(std::function<void(UI7::IO*, Container*)> inp) {
|
||||
pInp = inp;
|
||||
}
|
||||
|
||||
/** Return true if butten is pressed*/
|
||||
bool IsPressed() { return pressed; }
|
||||
/**
|
||||
* Override for the Input Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
*/
|
||||
void HandleInput() override;
|
||||
/**
|
||||
* Override for the Rendering Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
* */
|
||||
void Draw() override;
|
||||
|
||||
/** Function to Update Size if framepadding changes */
|
||||
void Update() override;
|
||||
|
||||
private:
|
||||
UI7Color color = UI7Color_Button; ///< current button color
|
||||
bool pressed = false; ///< ispressed value
|
||||
std::function<void(UI7::IO*, Li::Drawlist*, Container*)> pRenFun;
|
||||
std::function<void(UI7::IO*, Container*)> pInp;
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
Executable
+66
@@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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_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 img, fvec2 size = 0.f, Li::Rect uv = fvec4(0.f)) {
|
||||
this->img = img;
|
||||
if (size == fvec2(0.f)) {
|
||||
size = img.GetSize();
|
||||
}
|
||||
if (uv == Li::Rect(fvec4(0.f))) {
|
||||
uv = img.GetUV();
|
||||
}
|
||||
this->cuv = uv;
|
||||
this->newsize = size;
|
||||
SetSize(size);
|
||||
}
|
||||
~Image() = default;
|
||||
|
||||
/**
|
||||
* Override for the Rendering Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
* */
|
||||
void Draw() override;
|
||||
|
||||
private:
|
||||
Li::Texture img; ///< Texture
|
||||
fvec2 newsize = 0.f; ///< New Size
|
||||
Li::Rect cuv; ///< Custom UV
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
Executable
+63
@@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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_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& io) {
|
||||
this->label = label;
|
||||
this->tdim = io.Font->GetTextBounds(label.c_str(), io.FontScale);
|
||||
this->SetSize(tdim);
|
||||
}
|
||||
~Label() = default;
|
||||
|
||||
/**
|
||||
* Override for the Rendering Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
* */
|
||||
void Draw() override;
|
||||
/**
|
||||
* Override Update func to support Text modifications
|
||||
*/
|
||||
void Update() override;
|
||||
|
||||
private:
|
||||
fvec2 tdim; ///< Text Size
|
||||
UI7Color color = UI7Color_Text; ///< Color
|
||||
std::string label; ///< Text to Render
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
@@ -0,0 +1,89 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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>
|
||||
#include <pd/ui7/io.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
/**
|
||||
* Slider Object can take a datatype or a list
|
||||
* and modifys these by moving left or right when dragging
|
||||
*/
|
||||
template <typename T>
|
||||
class PD_API Slider : public Container {
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
* @param label Label of the Button
|
||||
* @param data Data reference (Supported types can be seen in Slider.cpp)
|
||||
* @param num_elms Number of Array elements (for exaple with use ofvec4)
|
||||
* @param io IO Reference
|
||||
* @param min minimum number using Minimum limit
|
||||
* @param max Maximum number set by max limit by default
|
||||
* @param step To set the modifier for drag movement
|
||||
* @param precision for float and double to set precision
|
||||
*/
|
||||
Slider(const std::string& label, T* data, UI7::IO& io,
|
||||
T min = std::numeric_limits<T>::min(),
|
||||
T max = std::numeric_limits<T>::max(), int precision = 1) {
|
||||
// PD::Assert(data != nullptr, "Input Data Address is null!");
|
||||
this->label = label;
|
||||
this->data = data;
|
||||
this->min = min;
|
||||
this->max = max;
|
||||
this->precision = precision;
|
||||
this->width = io.CurrentViewPort.pSize.z * 0.3f;
|
||||
this->tdim = io.Font->GetTextBounds(label.c_str(), io.FontScale);
|
||||
}
|
||||
~Slider() = default;
|
||||
|
||||
/**
|
||||
* Override for the Input Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
*/
|
||||
void HandleInput() override;
|
||||
/**
|
||||
* Override for the Rendering Handler
|
||||
* @note This function is usally called by Menu::Update
|
||||
* */
|
||||
void Draw() override;
|
||||
|
||||
/** Function to Update Size if framepadding changes */
|
||||
void Update() override;
|
||||
|
||||
private:
|
||||
fvec2 tdim; ///< Text size
|
||||
float width; ///< Size
|
||||
std::string label; ///< Label of the Button
|
||||
T* data;
|
||||
T min;
|
||||
T max;
|
||||
int precision = 1;
|
||||
float slw = 0.f; // silider drag width (calculated in update)
|
||||
float slp = 0.f; // silider drag pos (calculated in update)
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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/button.hpp>
|
||||
#include <pd/ui7/container/checkbox.hpp>
|
||||
#include <pd/ui7/container/coloredit.hpp>
|
||||
#include <pd/ui7/container/dragdata.hpp>
|
||||
#include <pd/ui7/container/dynobj.hpp>
|
||||
#include <pd/ui7/container/image.hpp>
|
||||
#include <pd/ui7/container/label.hpp>
|
||||
#include <pd/ui7/container/slider.hpp>
|
||||
@@ -0,0 +1,100 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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.
|
||||
*/
|
||||
|
||||
/** 32Bit Value to Stpre Menu Flags */
|
||||
using UI7MenuFlags = unsigned int;
|
||||
/** 32Bit Value to store Alignment Flags */
|
||||
using UI7Align = unsigned int;
|
||||
/** 32Bit Value to store Context (IO) flags */
|
||||
using UI7IOFlags = unsigned int;
|
||||
/** 32Bit Value for Layout Flags */
|
||||
using UI7LayoutFlags = unsigned int;
|
||||
|
||||
/** Menu Flags */
|
||||
enum UI7MenuFlags_ {
|
||||
UI7MenuFlags_None = 0, ///< No Flags (Default)
|
||||
UI7MenuFlags_NoTitlebar = 1 << 0, ///< Dont Show Titlebar
|
||||
UI7MenuFlags_CenterTitle = 1 << 1, ///< Center the Menu Title in Titlebar
|
||||
UI7MenuFlags_HzScrolling = 1 << 2, ///< Enable Horizontal Scrolling
|
||||
UI7MenuFlags_VtScrolling = 1 << 3, ///< Enable Vertical Scrolling
|
||||
UI7MenuFlags_NoBackground = 1 << 4, ///< Dont Render Menu Background
|
||||
UI7MenuFlags_NoClipRect = 1 << 5, ///< Disable clip render area of the Menu
|
||||
UI7MenuFlags_NoCollapse = 1 << 6, ///< Disable Menu Collapse
|
||||
UI7MenuFlags_NoMove = 1 << 7, ///< Disable Menu Movement
|
||||
UI7MenuFlags_NoResize = 1 << 8, ///< Disable Menu Resize
|
||||
UI7MenuFlags_NoClose = 1 << 9, ///< Disable Close Button
|
||||
UI7MenuFlags_NoScrollbar = 1 << 10, ///< Hide the Scrollbar
|
||||
// POC
|
||||
UI7MenuFlags_Maximize = 1 << 11, ///< Add a Maximize Button
|
||||
UI7MenuFlags_Minimize = 1 << 12, ///< Add a Minimize Button
|
||||
UI7MenuFlags_AlwaysAutoSize = 1 << 13, ///< Always Auto Resize Menu
|
||||
// Enable Horizontal and Vertical Scrolling
|
||||
UI7MenuFlags_Scrolling = UI7MenuFlags_HzScrolling | UI7MenuFlags_VtScrolling,
|
||||
};
|
||||
|
||||
/** UI7 Layout Flags */
|
||||
enum UI7LayoutFlags_ {
|
||||
UI7LayoutFlags_None = 0, ///< No Flags used
|
||||
UI7LayoutFlags_UseClipRect = 1 << 0, ///< Enable ClipRect
|
||||
};
|
||||
|
||||
/** UI7 Context Flags */
|
||||
enum UI7IOFlags_ {
|
||||
UI7IOFlags_None = 0, ///< No Additional Config available
|
||||
UI7IOFlags_HasTouch = 1 << 0, ///< Enable touch support [future]
|
||||
UI7IOFlags_HasMouseCursor = 1 << 1, ///< Enable Mouse support [future]
|
||||
};
|
||||
|
||||
/** Probably need to update this */
|
||||
enum UI7Align_ {
|
||||
UI7Align_Left = 1 << 0, ///< [Hz Op] Align Left (Default)
|
||||
UI7Align_Center = 1 << 1, ///< [Hz Op] Align Center
|
||||
UI7Align_Right = 1 << 2, ///< [Hz Op] Align Right
|
||||
UI7Align_Top = 1 << 3, ///< [Vt Op] Align Top (Default)
|
||||
UI7Align_Mid = 1 << 4, ///< [Vt Op] Align Mid
|
||||
UI7Align_Bottom = 1 << 5, ///< [Vt Op] Align Bottom
|
||||
// Default Horizontal and Vertical Alignment
|
||||
UI7Align_Default = UI7Align_Left | UI7Align_Top,
|
||||
};
|
||||
|
||||
/** Special flags for Layout::AddObjectEx */
|
||||
enum UI7LytAdd_ {
|
||||
UI7LytAdd_None = 0, ///< Also known as default or ->AddObject
|
||||
UI7LytAdd_NoCursorUpdate = 1 << 0, ///< Add without cursor alignment
|
||||
UI7LytAdd_NoScrollHandle = 1 << 1, ///< Skip HandleScrolling
|
||||
UI7LytAdd_Front = 1 << 2, ///< Add in front of the list
|
||||
};
|
||||
|
||||
/**
|
||||
* Todo: Look at this
|
||||
* Maybe proof of concept ???
|
||||
* Didnt remember that this exists
|
||||
*/
|
||||
enum UI7ContainerFlags_ {
|
||||
UI7ContainerFlags_None = 0,
|
||||
UI7ContainerFlags_EnableInternalInput = 1 << 0,
|
||||
UI7ContainerFlags_Selectable = 1 << 1,
|
||||
UI7ContainerFlags_OutlineSelected = 1 << 2,
|
||||
};
|
||||
@@ -0,0 +1,74 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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);
|
||||
// pStrName = 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
|
||||
*/
|
||||
constexpr ID(const char* text) {
|
||||
pID = PD::FNV1A32(text);
|
||||
pName = text;
|
||||
}
|
||||
/**
|
||||
* Use an ID as Input
|
||||
*/
|
||||
ID(u32 id) { pID = id; }
|
||||
~ID() = default;
|
||||
|
||||
/** Get The ID Initial Name */
|
||||
// constexpr const std::string_view& GetNameView() const { return pName; }
|
||||
const std::string GetName() const { return std::string(pName); }
|
||||
|
||||
/** Getter for the raw 32bit int id */
|
||||
constexpr const u32& RawID() const { return pID; }
|
||||
|
||||
/** Return the ID when casting to u32 */
|
||||
constexpr operator u32() const { return pID; }
|
||||
|
||||
u32 pID; ///< Hash of the name
|
||||
std::string pName; ///< Name
|
||||
// std::string pStrName; ///< Keep this stringview alive
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
@@ -0,0 +1,138 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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/drivers/drivers.hpp>
|
||||
#include <pd/lithium/lithium.hpp>
|
||||
#include <pd/pd_p_api.hpp>
|
||||
#include <pd/ui7/id.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
class InputHandler {
|
||||
public:
|
||||
InputHandler() {}
|
||||
~InputHandler() = default;
|
||||
|
||||
/**
|
||||
* Function to Check if current Object is dragged
|
||||
* or set it dragged
|
||||
* @param id ID to identify this specific Object
|
||||
* @param area Area where to start dragging
|
||||
* @return if inputs to this objects are alowed or not
|
||||
*/
|
||||
bool DragObject(const UI7::ID& id, fvec4 area) {
|
||||
if (CurrentMenu != FocusedMenu) {
|
||||
return false;
|
||||
}
|
||||
if (IsObjectDragged()) {
|
||||
// Only block if the Dragged Object has a difrent id
|
||||
if (DraggedObject != id) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Get a Short define for touch pos
|
||||
fvec2 p = PD::Hid::MousePos();
|
||||
// Check if Drag starts in the area position
|
||||
if ((PD::Hid::IsEvent(PD::Hid::Event::Down, PD::Hid::Gamepad::Touch) ||
|
||||
PD::Hid::IsEvent(PD::Hid::Event::Down,
|
||||
PD::Hid::Keyboard::MouseLeft)) &&
|
||||
Li::Math::InBounds(p, area)) {
|
||||
// Set ID and iniatial Positions
|
||||
DraggedObject = id;
|
||||
DragSourcePos = p;
|
||||
DragPosition = p;
|
||||
DragLastPosition = p;
|
||||
DragDestination = area;
|
||||
// Reset and Start DragTimer
|
||||
DragTime.Reset();
|
||||
DragTime.Rseume();
|
||||
return false; // To make sure the Object is "Dragged"
|
||||
} else if ((PD::Hid::IsEvent(PD::Hid::Event::Held,
|
||||
PD::Hid::Gamepad::Touch) ||
|
||||
PD::Hid::IsEvent(PD::Hid::Event::Held,
|
||||
PD::Hid::Keyboard::MouseLeft)) &&
|
||||
IsObjectDragged()) {
|
||||
// Update DragLast and DragPoisition
|
||||
DragLastPosition = DragPosition;
|
||||
DragPosition = p;
|
||||
} else if ((PD::Hid::IsEvent(PD::Hid::Event::Up, PD::Hid::Gamepad::Touch) ||
|
||||
PD::Hid::IsEvent(PD::Hid::Event::Up,
|
||||
PD::Hid::Keyboard::MouseLeft)) &&
|
||||
IsObjectDragged()) {
|
||||
// Released... Everything gets reset
|
||||
DraggedObject = 0;
|
||||
DragPosition = 0;
|
||||
DragSourcePos = 0;
|
||||
DragLastPosition = 0;
|
||||
DragDestination = fvec4(0);
|
||||
// Set Drag released to true (only one frame)
|
||||
// and Only if still in Box
|
||||
DragReleased = Li::Math::InBounds(PD::Hid::MousePosLast(), area);
|
||||
DragReleasedAW = true; // Advanced
|
||||
u64 d_rel = PD::Os::GetTime();
|
||||
if (d_rel - DragLastReleased < DoubleClickTime) {
|
||||
DragDoubleRelease = true;
|
||||
DragLastReleased = 0; // Set 0 to prevent double exec
|
||||
} else {
|
||||
DragLastReleased = d_rel;
|
||||
}
|
||||
// Ensure timer is paused
|
||||
DragTime.Pause();
|
||||
DragTime.Reset();
|
||||
// Still return The Object is Dragged to ensure
|
||||
// the DragReleased var can be used
|
||||
return true;
|
||||
}
|
||||
return IsObjectDragged();
|
||||
}
|
||||
|
||||
void Update() {
|
||||
DragTime.Update();
|
||||
DragReleased = false;
|
||||
DragReleasedAW = false;
|
||||
DragDoubleRelease = false;
|
||||
}
|
||||
|
||||
u64 DoubleClickTime = 500; // Milliseconds
|
||||
u32 FocusedMenu = 0;
|
||||
fvec4 FocusedMenuRect;
|
||||
u32 CurrentMenu = 0;
|
||||
u32 DraggedObject = 0;
|
||||
fvec2 DragSourcePos = 0;
|
||||
fvec2 DragPosition = 0;
|
||||
fvec2 DragLastPosition = 0;
|
||||
/** Fvec4 has an constructor problem currently */
|
||||
fvec4 DragDestination = fvec4(0);
|
||||
Timer DragTime;
|
||||
u64 DragLastReleased = 0;
|
||||
bool DragReleased = false; ///< Drag Releaded in Box
|
||||
bool DragReleasedAW = false; ///< Drag Released Anywhere
|
||||
bool DragDoubleRelease = false; ///< Double Click
|
||||
/** Check if an object is Dragged already */
|
||||
bool IsObjectDragged() const { return DraggedObject != 0; }
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
@@ -0,0 +1,110 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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 <list>
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/pd_p_api.hpp>
|
||||
#include <pd/ui7/input_api.hpp>
|
||||
#include <pd/ui7/theme.hpp>
|
||||
#include <pd/ui7/viewport.hpp>
|
||||
|
||||
namespace PD {
|
||||
class Context;
|
||||
namespace UI7 {
|
||||
class PD_API IO {
|
||||
public:
|
||||
IO() : DeltaStats(60), CurrentViewPort("", 0) {
|
||||
/** Probably not the best solution i guess */
|
||||
// CurrentViewPort =
|
||||
// ViewPort::New("Default", ivec4(ivec2(0, 0), pCtx.Gfx()->ViewPort));
|
||||
}
|
||||
~IO() {}
|
||||
|
||||
/**
|
||||
* IO Update Internal Variables
|
||||
*/
|
||||
void Update();
|
||||
|
||||
/**
|
||||
* Final Draw List for PD::Li::Gfx::RednerDrawData
|
||||
*
|
||||
* Possible thanks to the Drawlist::Merge Feature
|
||||
*/
|
||||
Li::Drawlist FDL;
|
||||
ViewPort CurrentViewPort;
|
||||
// ivec4 CurrentViewPort = ivec4(0, 0, 0, 0);
|
||||
std::unordered_map<u32, ViewPort> ViewPorts;
|
||||
float Framerate = 0.f;
|
||||
float Delta = 0.f;
|
||||
u64 LastTime = 0;
|
||||
TimeStats DeltaStats;
|
||||
Timer Time;
|
||||
Li::Font* Font = nullptr;
|
||||
float FontScale = 0.7f;
|
||||
UI7::Theme Theme;
|
||||
fvec2 MenuPadding = 5.f;
|
||||
fvec2 FramePadding = 5.f;
|
||||
float ItemRowHeight = 0.f;
|
||||
float FrameRounding = 0.f;
|
||||
fvec2 ItemSpace = fvec2(5.f, 2.f);
|
||||
fvec2 MinSliderDragSize = 10.f; // Min height (Vt) and Min Width (Hz)
|
||||
bool ShowMenuBorder = true;
|
||||
bool ShowFrameBorder = false; // not implemented yet
|
||||
bool WrapLabels = false; // Beta state
|
||||
float OverScrollMod = 0.15f;
|
||||
u64 DoubleClickTime = 500; // Milliseconds
|
||||
std::list<std::pair<UI7::ID, Li::Drawlist*>> DrawlistRegestry;
|
||||
// Short define for DrawKLstRegestryLast
|
||||
std::list<std::pair<UI7::ID, Li::Drawlist*>> pDLRL;
|
||||
Li::Drawlist Back;
|
||||
Li::Drawlist Front;
|
||||
u32 NumVertices = 0; ///< Debug Vertices Num
|
||||
u32 NumIndices = 0; ///< Debug Indices Num
|
||||
std::vector<u32> MenuOrder;
|
||||
|
||||
// DrawlistApi
|
||||
void RegisterDrawlist(const UI7::ID& id, Li::Drawlist* v) {
|
||||
DrawlistRegestry.push_back(std::make_pair(id, v));
|
||||
}
|
||||
|
||||
void AddViewPort(const ID& id, const ivec4& size) {
|
||||
if (ViewPorts.count(id.RawID())) {
|
||||
return;
|
||||
}
|
||||
ViewPorts[id.RawID()] = ViewPort(id, size);
|
||||
}
|
||||
|
||||
ViewPort& GetViewPort(const ID& id) {
|
||||
if (!ViewPorts.count(id.RawID())) {
|
||||
static ViewPort err;
|
||||
return err;
|
||||
}
|
||||
return ViewPorts[id.RawID()];
|
||||
}
|
||||
|
||||
UI7::InputHandler InputHandler;
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
@@ -0,0 +1,207 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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/pd_p_api.hpp>
|
||||
#include <pd/ui7/container/container.hpp>
|
||||
#include <pd/ui7/container/dragdata.hpp>
|
||||
#include <pd/ui7/container/slider.hpp>
|
||||
#include <pd/ui7/flags.hpp>
|
||||
#include <pd/ui7/input_api.hpp>
|
||||
#include <pd/ui7/theme.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
class Context;
|
||||
class PD_API Layout {
|
||||
public:
|
||||
Layout(const ID& id, IO& io) : ID(id), IO(io) {
|
||||
DrawList.SetFont(IO.Font);
|
||||
DrawList.SetFontscale(io.FontScale);
|
||||
Scrolling[0] = false;
|
||||
Scrolling[1] = false;
|
||||
CursorInit();
|
||||
Pos = fvec2(io.CurrentViewPort.pSize.x, io.CurrentViewPort.pSize.y);
|
||||
Size = 0;
|
||||
WorkRect = fvec4(IO.MenuPadding, Size - (fvec2(2) * IO.MenuPadding));
|
||||
}
|
||||
~Layout() = default;
|
||||
|
||||
/** SECTION CONTAINERS */
|
||||
/**
|
||||
* Render a Simple Label
|
||||
* @param label The text to draw
|
||||
*/
|
||||
void Label(const std::string& label);
|
||||
template <typename... Args>
|
||||
void Label(std::format_string<Args...> s, Args&&... args) {
|
||||
Label(std::format(s, std::forward<Args>(args)...));
|
||||
}
|
||||
/**
|
||||
* 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 img, fvec2 size = 0.f, Li::Rect uv = fvec4(0));
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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* r = FindObject(id);
|
||||
if (!r) {
|
||||
r = new UI7::DragData<T>(label, data, num_elms, this->IO, min, max, step,
|
||||
precision);
|
||||
r->SetID(id);
|
||||
}
|
||||
AddObject(r);
|
||||
}
|
||||
template <typename T>
|
||||
void Slider(const std::string& label, T* data,
|
||||
T min = std::numeric_limits<T>::min(),
|
||||
T max = std::numeric_limits<T>::max(), int precision = 1) {
|
||||
u32 id = Strings::FastHash("drd" + label + std::to_string((uintptr_t)data));
|
||||
Container* r = FindObject(id);
|
||||
if (!r) {
|
||||
r = new UI7::Slider<T>(label, data, this->IO, min, max, precision);
|
||||
r->SetID(id);
|
||||
}
|
||||
AddObject(r);
|
||||
}
|
||||
|
||||
/** SECTION OTHERSTUFF */
|
||||
|
||||
const std::string GetName() const { return ID.GetName(); }
|
||||
const UI7::ID& GetID() const { return this->ID; }
|
||||
|
||||
const fvec2& GetPosition() const { return Pos; }
|
||||
void SetPosition(const fvec2& v) { Pos = v; }
|
||||
const fvec2& GetSize() const { return Size; }
|
||||
void SetSize(const fvec2& v) { Size = v; }
|
||||
|
||||
Li::Drawlist& GetDrawList() { return DrawList; }
|
||||
|
||||
void CursorInit();
|
||||
void SameLine();
|
||||
void CursorMove(const fvec2& size);
|
||||
|
||||
bool ObjectWorkPos(fvec2& movpos);
|
||||
|
||||
/**
|
||||
* Extended Object Add Func to Add Object in Front or disable
|
||||
* Position by cursor as well as cursor update...
|
||||
* Should only be used in special cases as the
|
||||
* AddObject function is faster
|
||||
* Using Flags for its features cause dont want to have too much args
|
||||
*/
|
||||
void AddObjectEx(Container* obj, u32 Flags);
|
||||
/**
|
||||
* Fast Function to Add Object in Layout SPace like
|
||||
* button Label images etc
|
||||
*/
|
||||
void AddObject(Container* obj);
|
||||
Container* FindObject(u32 id);
|
||||
void ClearIDObjects() { IDObjects.clear(); }
|
||||
|
||||
fvec2 AlignPosition(fvec2 pos, fvec2 size, fvec4 area, UI7Align alignment);
|
||||
|
||||
/** Get the Alignment for Current State */
|
||||
UI7Align GetAlignment() {
|
||||
/// if temp alignment is used then return it and
|
||||
/// reset tmpalign
|
||||
if (TempAlign) {
|
||||
auto t = TempAlign;
|
||||
TempAlign = 0;
|
||||
return t;
|
||||
}
|
||||
return Alignment;
|
||||
}
|
||||
|
||||
void SetAlign(UI7Align a) { Alignment = a; }
|
||||
void NextAlign(UI7Align a) { TempAlign = a; }
|
||||
|
||||
void Update();
|
||||
|
||||
fvec2 DbgScrollOffset() { return ScrollOffset; }
|
||||
|
||||
private:
|
||||
friend class Menu;
|
||||
friend class PD::UI7::Context;
|
||||
friend class ReMenu;
|
||||
// Base Components
|
||||
UI7::ID ID;
|
||||
UI7::IO& IO;
|
||||
Li::Drawlist DrawList;
|
||||
UI7LayoutFlags Flags;
|
||||
|
||||
// Positioning
|
||||
fvec2 Pos;
|
||||
fvec2 Size;
|
||||
UI7Align Alignment = UI7Align_Default;
|
||||
UI7Align TempAlign;
|
||||
|
||||
// Cursor
|
||||
fvec2 Cursor;
|
||||
fvec2 InitialCursorOffset;
|
||||
fvec2 BackupCursor;
|
||||
fvec2 SamelineCursor;
|
||||
fvec2 BeforeSameLine;
|
||||
fvec2 LastObjSize;
|
||||
fvec2 MaxPosition;
|
||||
fvec4 WorkRect;
|
||||
|
||||
// Scrolling (Only theoretical)
|
||||
// Rendering must be done by the Objective that uses the Lyt
|
||||
fvec2 ScrollOffset;
|
||||
fvec2 ScrollStart;
|
||||
bool Scrolling[2];
|
||||
|
||||
// Objects
|
||||
std::list<Container*> Objects;
|
||||
std::vector<Container*> IDObjects;
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
@@ -0,0 +1,144 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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/pd_p_api.hpp>
|
||||
#include <pd/ui7/containers.hpp>
|
||||
#include <pd/ui7/io.hpp>
|
||||
#include <pd/ui7/layout.hpp>
|
||||
|
||||
#include "pd/ui7/container/dragdata.hpp"
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
class PD_API Menu {
|
||||
public:
|
||||
Menu(const UI7::ID& id, UI7::IO& pIO);
|
||||
~Menu() {}
|
||||
|
||||
/**
|
||||
* Render a Simple Label
|
||||
* @param label The text to draw
|
||||
*/
|
||||
void Label(const std::string& label);
|
||||
template <typename... Args>
|
||||
void Label(std::format_string<Args...> s, Args&&... args) {
|
||||
Label(std::format(s, std::forward<Args>(args)...));
|
||||
}
|
||||
/**
|
||||
* 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 img, fvec2 size = 0.f, Li::Rect uv = fvec4(0));
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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* r = pLayout.FindObject(id);
|
||||
if (!r) {
|
||||
r = new UI7::DragData<T>(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);
|
||||
}
|
||||
pLayout.AddObject(r);
|
||||
}
|
||||
template <typename T>
|
||||
void Slider(const std::string& label, T* data,
|
||||
T min = std::numeric_limits<T>::min(),
|
||||
T max = std::numeric_limits<T>::max(), int precision = 1) {
|
||||
u32 id = Strings::FastHash("drd" + label + std::to_string((uintptr_t)data));
|
||||
Container* r = pLayout.FindObject(id);
|
||||
if (!r) {
|
||||
r = new UI7::Slider<T>(label, data, pIO, min, max, precision);
|
||||
r->SetID(id);
|
||||
}
|
||||
pLayout.AddObject(r);
|
||||
}
|
||||
void ColorEdit(const std::string& label, u32& clr);
|
||||
void SameLine() { pLayout.SameLine(); }
|
||||
void Separator();
|
||||
void SeparatorText(const std::string& label);
|
||||
bool BeginTreeNode(const ID& id);
|
||||
void EndTreeNode();
|
||||
|
||||
void HandleFocus();
|
||||
void HandleScrolling();
|
||||
void HandleTitlebarActions();
|
||||
void DrawBaseLayout();
|
||||
|
||||
void AddObject(PD::UI7::Container* obj) { pLayout.AddObject(obj); }
|
||||
void AddObjectEx(PD::UI7::Container* obj, PD::u32 flags) {
|
||||
pLayout.AddObjectEx(obj, flags);
|
||||
}
|
||||
Container* FindObject(u32 id) { return pLayout.FindObject(id); }
|
||||
|
||||
void Update();
|
||||
|
||||
void SetSize(PD::fvec2 size) { pLayout.SetSize(size); }
|
||||
void SetPosition(PD::fvec2 pos) { pLayout.SetPosition(pos); }
|
||||
const PD::fvec2& GetSize() const { return pLayout.GetSize(); }
|
||||
const PD::fvec2& GetPosition() const { return pLayout.GetPosition(); }
|
||||
|
||||
/** Data Section */
|
||||
|
||||
UI7MenuFlags Flags = 0;
|
||||
Layout pLayout;
|
||||
IO& pIO;
|
||||
ID pID;
|
||||
bool* pIsShown = nullptr;
|
||||
bool pIsOpen = true;
|
||||
std::unordered_map<u32, bool> pTreeNodes;
|
||||
fvec2 TempScrollXY;
|
||||
|
||||
float TitleBarHeight = 0.f;
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
Executable
+159
@@ -0,0 +1,159 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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/pd_p_api.hpp>
|
||||
|
||||
/**
|
||||
* Using this to support 32bit color values as well as
|
||||
* values from UI7Color_
|
||||
*/
|
||||
using UI7Color = PD::u32;
|
||||
|
||||
/** Theme Color */
|
||||
enum UI7Color_ {
|
||||
UI7Color_Background, ///< UI7 Menu Background
|
||||
UI7Color_Border, ///< Menu/Frame Border Color
|
||||
UI7Color_Button, ///< UI7 Button Idle Color
|
||||
UI7Color_ButtonDead, ///< UI7 Disabled Button Color
|
||||
UI7Color_ButtonActive, ///< UI7 Pressed Button Color
|
||||
UI7Color_ButtonHovered, ///< UI7 Hovered Button Color
|
||||
UI7Color_Text, ///< UI7 Text Color
|
||||
UI7Color_TextDead, ///< UI7 Dead Text Color
|
||||
UI7Color_Header, ///< UI7 Menu Header Color
|
||||
UI7Color_HeaderDead, ///< Inactive Header
|
||||
UI7Color_Selector, ///< UI7 Selector Color
|
||||
UI7Color_Checkmark, ///< UI7 Checkmark Color
|
||||
UI7Color_FrameBackground, ///< UI7 Frame Background
|
||||
UI7Color_FrameBackgroundHovered, ///< UI7 Hovered Frame Background
|
||||
UI7Color_Progressbar, ///< UI7 Progressbar Background
|
||||
UI7Color_ListEven, ///< UI7 List (Even Entry) Background Color
|
||||
UI7Color_ListOdd, ///< UI7 List (Odd Entry) Background Color
|
||||
};
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
class PD_API Theme {
|
||||
public:
|
||||
/**
|
||||
* Default Constructor Setting up the Default theme
|
||||
* @note if using Shared Reference you probably need to do
|
||||
* Theme::Default(*theme.get());
|
||||
*/
|
||||
Theme() { Default(*this); }
|
||||
~Theme() {}
|
||||
|
||||
/**
|
||||
* Simple static Loader for the Default Theme
|
||||
* @param theme Theme Reference
|
||||
*/
|
||||
static void Default(Theme& theme);
|
||||
/**
|
||||
* White Mode Theme
|
||||
* @param Theme theme reference
|
||||
*/
|
||||
static void Flashbang(Theme& theme);
|
||||
|
||||
/** Revert the last Color Change */
|
||||
Theme& Pop() {
|
||||
pTheme[pChanges[pChanges.size() - 1].first] =
|
||||
pChanges[pChanges.size() - 1].second;
|
||||
pChanges.pop_back();
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Revert the last color Change done for a specific color
|
||||
* @param c Color to revert change from
|
||||
*/
|
||||
Theme& Pop(UI7Color c) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change a Color
|
||||
* @param tc Color Identifier
|
||||
* @param color Color to change to
|
||||
*/
|
||||
Theme& Change(UI7Color tc, u32 color) {
|
||||
if (pTheme.find(tc) == pTheme.end()) {
|
||||
return *this;
|
||||
}
|
||||
pChanges.push_back(std::make_pair(tc, pTheme[tc]));
|
||||
pTheme[tc] = color;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Color of a Color ReferenceID
|
||||
* @param c ReferenceID
|
||||
*/
|
||||
u32 Get(UI7Color c) const {
|
||||
auto e = pTheme.find(c);
|
||||
if (e == pTheme.end()) {
|
||||
return 0x00000000;
|
||||
}
|
||||
return e->second;
|
||||
}
|
||||
|
||||
/**
|
||||
* [UNSAFE] to use
|
||||
* Get the Color Ref of a Color ReferenceID
|
||||
* @param c ReferenceID
|
||||
*/
|
||||
u32& GetRef(UI7Color c) {
|
||||
auto e = pTheme.find(c);
|
||||
if (e == pTheme.end()) {
|
||||
static u32 noclr = 0x00000000;
|
||||
return noclr;
|
||||
}
|
||||
return e->second;
|
||||
}
|
||||
|
||||
/**
|
||||
* Operator wrapper for get
|
||||
* @param c Color ReferenceID
|
||||
*/
|
||||
u32 operator[](UI7Color c) const { return Get(c); }
|
||||
|
||||
/**
|
||||
* Change but just sets [can implement completly new ids]
|
||||
* @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) { pTheme[tc] = clr; }
|
||||
|
||||
std::unordered_map<u32, u32> pTheme; ///< Theme Data
|
||||
std::vector<std::pair<UI7Color, u32>> pChanges; ///< List of Changes
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
@@ -0,0 +1,86 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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/pd_p_api.hpp>
|
||||
#include <pd/ui7/io.hpp>
|
||||
#include <pd/ui7/menu.hpp>
|
||||
|
||||
#include "pd/ui7/flags.hpp"
|
||||
|
||||
/**
|
||||
* Declare UI7 Version
|
||||
* Format: 00 00 00 00
|
||||
* Major Minor Patch Build
|
||||
* 0x01010000 -> 1.1.0-0
|
||||
*/
|
||||
#define UI7_VERSION 0x00070000
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
/**
|
||||
* Get UI7 Version String
|
||||
* @param show_build Show build num (mostly unused)
|
||||
* @return Version String (1.0.0-1 for example)
|
||||
*/
|
||||
PD_API std::string GetVersion(bool show_build = false);
|
||||
/** Base Context for UI7 */
|
||||
class PD_API Context {
|
||||
public:
|
||||
Context() {}
|
||||
~Context() = default;
|
||||
|
||||
IO& GetIO() { return pIO; }
|
||||
void AddViewPort(const ID& id, const ivec4& vp);
|
||||
void UseViewPort(const ID& id);
|
||||
void Update();
|
||||
Menu* BeginMenu(const ID& id, UI7MenuFlags flags = 0,
|
||||
bool* pShow = nullptr);
|
||||
Menu* CurrentMenu() { return pCurrent; }
|
||||
void EndMenu();
|
||||
void AboutMenu(bool* show = nullptr);
|
||||
void MetricsMenu(bool* show = nullptr);
|
||||
void StyleEditor(bool* show = nullptr);
|
||||
|
||||
Li::Drawlist& GetDrawData() { return pIO.FDL; }
|
||||
|
||||
Menu* pGetOrCreateMenu(const ID& id) {
|
||||
auto menu = pMenus.find(id);
|
||||
if (menu == pMenus.end()) {
|
||||
pMenus[id] = new Menu(id, pIO);
|
||||
menu = pMenus.find(id);
|
||||
}
|
||||
return menu->second;
|
||||
}
|
||||
|
||||
IO pIO;
|
||||
/** Current Menu */
|
||||
Menu* pCurrent = nullptr;
|
||||
std::vector<u32> pCurrentMenus;
|
||||
std::vector<u32> pDFO; /** Debug Final Order */
|
||||
std::unordered_map<u32, Menu*> pMenus;
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 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/ui7/id.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
class ViewPort {
|
||||
public:
|
||||
ViewPort() : pID(""), pSize(0) {}
|
||||
ViewPort(const ID& id, const ivec4& size) : pID(id), pSize(size) {}
|
||||
~ViewPort() {}
|
||||
|
||||
ID GetID() const { return pID; }
|
||||
ivec4& GetSize() { return pSize; }
|
||||
|
||||
ID pID;
|
||||
ivec4 pSize;
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
||||
Reference in New Issue
Block a user