# Changes 0.2.4-1

- Add GIT_BRANCH (for development and stable)
- Write  Documentation of
  - pd-core (exept of vec.hpp)
  - pd-app
  - pd-drivers
  - pd-lib3ds
  - pd-image
  - pd-image
  - pd-ui7
This commit is contained in:
2025-03-02 21:11:58 +01:00
parent af3d3e0b5b
commit 7d3f619169
56 changed files with 2481 additions and 536 deletions

View File

@ -27,8 +27,21 @@ SOFTWARE.
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 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, vec2 pos, LI::Renderer::Ref lr) {
this->screen = lr->CurrentScreen();
this->label = label;
@ -37,17 +50,27 @@ class Button : public Container {
color = UI7Color_Button;
this->SetSize(tdim + vec2(8, 4));
}
~Button() {}
~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
* @param inp Reference to the Input Handler
*/
void HandleInput(Hid::Ref inp) override;
/**
* Override for the Rendering Handler
* @note This function is usally called by Menu::Update
* */
void Draw() override;
private:
vec2 tdim;
UI7Color color;
std::string label;
bool pressed = false;
vec2 tdim; ///< Text size
UI7Color color; ///< current button color
std::string label; ///< Label of the Button
bool pressed = false; ///< ispressed value
};
} // namespace UI7
} // namespace PD

View File

@ -27,8 +27,21 @@ SOFTWARE.
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 Checkbox : public Container {
public:
/**
* Constructor for Checkbox Object
* @param label Label of the Checkbox
* @param pos Base Position
* @param usr_ref Reference to the bool value to update
* @param lr Reference to the renderer (for text size calculation)
*/
Checkbox(const std::string& label, vec2 pos, bool& usr_ref,
LI::Renderer::Ref lr)
: usr_ref(usr_ref) {
@ -39,17 +52,25 @@ class Checkbox : public Container {
color = UI7Color_FrameBackground;
this->SetSize(cbs + vec2(tdim.x() + 5, 0));
}
~Checkbox() {}
~Checkbox() = default;
/**
* Override for the Input Handler
* @note This function is usally called by Menu::Update
* @param inp Reference to the Input Handler
*/
void HandleInput(Hid::Ref inp) override;
/**
* Override for the Rendering Handler
* @note This function is usally called by Menu::Update
* */
void Draw() override;
private:
vec2 tdim;
vec2 cbs = vec2(18);
UI7Color color;
std::string label;
bool& usr_ref;
vec2 tdim; ///< Text Size
vec2 cbs = vec2(18); ///< Checkbox size
UI7Color color; ///< Checkbox background Color
std::string label; ///< Checkbox Label
bool& usr_ref; ///< User bool reference
};
} // namespace UI7
} // namespace PD

View File

@ -25,59 +25,128 @@ SOFTWARE.
#include <pd/core/common.hpp>
#include <pd/core/strings.hpp>
#include <pd/drivers/hid.hpp>
#include <pd/core/vec.hpp>
#include <pd/drivers/hid.hpp>
#include <pd/ui7/drawlist.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 Container : public SmartCtor<Container> {
public:
Container() {}
Container() = default;
/**
* Constructor with pos and Size
* @param pos Container Position
* @param size Container Size
*/
Container(const vec2& pos, const vec2& size) : pos(pos), size(size) {}
Container(const vec4& box) : pos(box.xy()), size(box.zw()) {}
~Container() {}
/**
* Constructor by a vec4 box
* @param box Box containing top left and bottom right coords
*/
Container(const vec4& box) : pos(box.xy()), size(box.zw() - box.xy()) {}
~Container() = default;
/**
* Init Function Required by every Object that uses
* Render or Input functions
* @param r Renderer Reference
* @param l DrawList Reference
* @param lt Theme Reference
*/
void Init(LI::Renderer::Ref r, UI7::DrawList::Ref l, UI7::Theme::Ref lt) {
list = l;
theme = lt;
ren = r;
}
/** Setter for Position */
void SetPos(const vec2& pos) { this->pos = pos; }
/** Setter for Size */
void SetSize(const vec2& size) { this->size = size; }
/** Getter for Position */
vec2 GetPos() { return pos; }
/** Getter for Size */
vec2 GetSize() { return size; }
/**
* Get the Containers Final Position
* for Rendering and Input (if it has a parent Object)
*/
vec2 FinalPos() {
vec2 res = pos;
if (parent) {
/// Probably should use parant->FinalPos here
res += parent->GetPos();
}
return res;
}
/** Setter for Parent Container */
void SetParent(Container::Ref v) { parent = v; }
/** Getter for Parent Container */
Container::Ref 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(vec2 scrolling, vec4 viewport);
/** Template function for Input Handling */
virtual void HandleInput(Hid::Ref inp) {}
/** Tamplate function for Object rendering */
virtual void Draw() {}
/**
* 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; }
protected:
/// used to skip Input/Render preocessing ot not
/** 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*/
vec2 pos;
/** Container Size*/
vec2 size;
/** Reference to the Drawlist to Draw to*/
UI7::DrawList::Ref list;
/** Reference to the theme to use*/
UI7::Theme::Ref theme;
/** Reference to the Renderer*/
LI::Renderer::Ref ren;
/** Reference to the parent container*/
Container::Ref parent;
/** Object ID (0 if unused)*/
u32 id = 0;
};
} // namespace UI7

View File

@ -27,8 +27,18 @@ SOFTWARE.
namespace PD {
namespace UI7 {
/**
* Image Object
*/
class Image : public Container {
public:
/**
* Constructor for the Image Object
* @param img Image Texture Reference
* @param pos Base Position
* @param lr Renderer Reference [to determinate screen]
* @param size Custom Size of the Image
*/
Image(Texture::Ref img, vec2 pos, LI::Renderer::Ref lr, vec2 size = 0.f) {
this->screen = lr->CurrentScreen();
this->img = img;
@ -39,12 +49,16 @@ class Image : public Container {
this->SetSize(img->GetSize());
}
}
~Image() {}
~Image() = default;
/**
* Override for the Rendering Handler
* @note This function is usally called by Menu::Update
* */
void Draw() override;
private:
Texture::Ref img;
Texture::Ref img; ///< Texture reference to the Image
};
} // namespace UI7
} // namespace PD

View File

@ -27,8 +27,17 @@ SOFTWARE.
namespace PD {
namespace UI7 {
/**
* Label [Text] Object
*/
class Label : public Container {
public:
/**
* Constructor for Label Object
* @param label Label [Text] to Draw
* @param pos Base Position
* @param lr Renderer Reference
*/
Label(const std::string& label, vec2 pos, LI::Renderer::Ref lr) {
this->screen = lr->CurrentScreen();
this->label = label;
@ -37,14 +46,18 @@ class Label : public Container {
color = UI7Color_Text;
this->SetSize(tdim);
}
~Label() {}
~Label() = default;
/**
* Override for the Rendering Handler
* @note This function is usally called by Menu::Update
* */
void Draw() override;
private:
vec2 tdim;
UI7Color color;
std::string label;
vec2 tdim; ///< Text Size
UI7Color color; ///< Color
std::string label; ///< Text to Render
};
} // namespace UI7
} // namespace PD

View File

@ -29,39 +29,75 @@ SOFTWARE.
namespace PD {
namespace UI7 {
/** DrawList class */
class DrawList : public SmartCtor<DrawList> {
public:
/**
* Constructor for a new Drawlist
* @param r Renderer reference
*/
DrawList(LI::Renderer::Ref r) { ren = r; }
~DrawList() = default;
/**
* Render a Rectangle
* @param pos Position
* @param szs Size
* @param clr Color
*/
void AddRectangle(vec2 pos, vec2 szs, const UI7Color& clr);
/**
* Render a Triangle
* @param pos0 Position a
* @param pos1 Position b
* @param pos2 Position c
* @param clr Color
*/
void AddTriangle(vec2 pos0, vec2 pos1, vec2 pos2, const UI7Color& clr);
/**
* 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(vec2 pos, const std::string& text, const UI7Color& clr,
LITextFlags flags = 0, vec2 box = vec2());
/**
* Render an Image
* @param pos Position
* @param img Image Texture Reference
* @param size Optional Size of the Image
*/
void AddImage(vec2 pos, Texture::Ref img, vec2 size = 0.f);
/** Clear the Drawlist */
void Clear();
/** Process [Render] the Drawlist */
void Process();
/** Getter for the Layer */
int Layer() const { return layer; }
/** Setter fot the Layer */
void Layer(int v) { layer = v; }
private:
/// @brief Base Layer offset (Internal Used)
/** Base Layer offset (Internal Used) */
int BaseLayer() const { return base; }
/// @brief Base Layer offset (Internal Used)
/** Base Layer offset (Internal Used) */
void BaseLayer(int v) { base = v; }
/// @brief Exopose Renderer here for Menus [DONT KNOW IF THIUS GETS REMOVED]
LI::Renderer::Ref GetRenderer() { return ren; }
// Set friendclass here to not expose private functions as public
friend class Menu;
friend class Context;
int layer;
int base;
LI::Renderer::Ref ren;
int layer; ///< Current Layer
int base; ///< Base Layer
LI::Renderer::Ref ren; ///< Renderer Reference
// Map for Auto Static Text
std::unordered_map<u32, LI::StaticText::Ref> static_text;
// List of Drawcommands generated
std::vector<std::pair<bool, LI::Command::Ref>> commands;
};
} // namespace UI7

View File

@ -23,26 +23,31 @@ 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;
/** Menu Flags */
enum UI7MenuFlags_ {
UI7MenuFlags_None = 0,
UI7MenuFlags_NoTitlebar = 1 << 0,
UI7MenuFlags_CenterTitle = 1 << 1,
UI7MenuFlags_HzScrolling = 1 << 2,
UI7MenuFlags_VtScrolling = 1 << 3,
UI7MenuFlags_NoBackground = 1 << 4,
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
// Enable Horizontal and Vertical Scrolling
UI7MenuFlags_Scrolling = UI7MenuFlags_HzScrolling | UI7MenuFlags_VtScrolling,
};
/// @brief Probably need to update this
/** Probably need to update this */
enum UI7Align_ {
UI7Align_Left = 1 << 0,
UI7Align_Center = 1 << 1,
UI7Align_Right = 1 << 2,
UI7Align_Top = 1 << 3,
UI7Align_Mid = 1 << 4,
UI7Align_Bottom = 1 << 5,
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,
};

View File

@ -28,25 +28,39 @@ SOFTWARE.
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;
}
~ID() {}
~ID() = default;
/** Get The ID Initial Name */
std::string GetName() const { return name; }
/** Return the ID when casting to u32 */
operator u32() const { return id; }
private:
u32 id;
std::string name;
u32 id; ///< Hash of the name
std::string name; ///< Name
};
} // namespace UI7
} // namespace PD

View File

@ -23,8 +23,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/drivers/hid.hpp>
#include <pd/core/tween.hpp>
#include <pd/drivers/hid.hpp>
#include <pd/ui7/containers.hpp>
#include <pd/ui7/drawlist.hpp>
#include <pd/ui7/flags.hpp>
@ -32,200 +32,292 @@ SOFTWARE.
namespace PD {
namespace UI7 {
/** Menu Class for UI7 */
class Menu : public SmartCtor<Menu> {
public:
/**
* Menu COnstructor (Unly used by UI7::Context)
* @param id ID of the Menu
* @param tl Theme Reference
* @param h Input Driver Reference
*/
Menu(ID id, Theme::Ref tl, Hid::Ref h) {
/// Setup the Input Data
theme = tl;
this->inp = h;
this->id = id;
this->name = id.GetName();
/// Set Default Values here
scrolling[0] = false;
scrolling[1] = false;
scrollbar[0] = false;
scrollbar[1] = false;
scroll_allowed[0] = false;
scroll_allowed[1] = false;
};
~Menu() {}
}
~Menu() = default;
/// Objects ///
// Objects
/// @brief Render a Simple Label
/// @param label The text to draw
/**
* Render a Simple Label
* @param label The text to draw
*/
void Label(const std::string& label);
/// @brief Render a Button
/// @param label The buttons text
/// @return if the button was pressed
/**
* Render a Button
* @param label The buttons text
* @return if the button was pressed
*/
bool Button(const std::string& label);
/// @brief Render a Checkbox
/// @param label Label of the Checkbox
/// @param v A value to update
/**
* Render a Checkbox
* @param label Label of the Checkbox
* @param v A value to update
*/
void Checkbox(const std::string& label, bool& v);
/// @brief Render an Image
/// @param img Texture reference of the image
/// @param size a Custom Size if needed
/**
* Render an Image
* @param img Texture reference of the image
* @param size a Custom Size if needed
*/
void Image(Texture::Ref img, vec2 size = 0.f);
/// Basic API ///
// Basic API
/// @brief Add the Next object to the same line
/** Add the Next Objext to the same line */
void SameLine();
/// @brief Add a Separator Line
/** Add a Separator Line */
void Separator();
/// @brief Render a Separator Line with a Text
/// @todo determinate text position by current alignment
/// @param label The Text to show
/**
* 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);
/// @brief Put the last Added Object into the Joinlist
/** Put the last Added Object into the Joinlist */
void Join();
/// @brief Add the Last element to the join list
/// and perform an alignment operation
/// @param a Alignment Oeration(s)
/**
* Add the Last element to the join list
* and perform an alignment operation
* @param a Alignment Oeration(s)
*/
void JoinAlign(UI7Align a);
/// @brief Align the Last Object
/// @param a Alignment Operation
/**
* Align the Last Object
* @param a Alignment Operation
*/
void AfterAlign(UI7Align a);
/// @brief Set a Temp alignment op for the next Object
/// @param a Alignment Operation
/**
* Set a Temp alignment op for the next Object
* @param a Alignment Operation
*/
void NextAlign(UI7Align a) { tmpalign = a; }
/// @brief Align Every Single Object by this operationset
/// @param a Alignment
/**
* Align Every Single Object by this operationset
* @param a Alignment
*/
void PushAlignment(UI7Align a) { alignment = a; }
/// @brief Use default alignment
/** Use default alignment */
void PopAlignment() { alignment = UI7Align_Default; }
/// @brief Get a New Position depending on the Alignment
/// @param pos Current Position
/// @param size Object size
/// @param view Viewport [position and size]
/// @param a Alignment Operations
/// @return new position based on the alignment
/**
* Get a New Position depending on the Alignment
* @param pos Current Position
* @param size Object size
* @param view Viewport [position and size]
* @param a Alignment Operations
* @return new position based on the alignment
*/
static vec2 AlignPos(vec2 pos, vec2 size, vec4 view, UI7Align a);
/// @brief Returns a Reference to the theme
/// @return Reference to the base Theme of the context
/**
* Returns a Reference to the theme
* @return Reference to the base Theme of the context
*/
Theme::Ref GetTheme() { return theme; }
/// @brief Directly return a Color by using the
/// m->ThemeColor(UI7Color_Text) for example
/// @param clr The Input UI7 Color
/// @return The 32bit color value
/**
* 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 theme->Get(clr); }
/// API for Custom Objects
// API for Custom Objects
/// @brief Handles the Position of Objects in Scrolling Menu
/// @note As Containers have their own FUnc to handle this, this
/// function is only useful to Render Live Objects whicch cannot be aligned
/// by the internal Alignment Api
/// @param pos position reference to write the new position to
/// @param size size of the Object
/// @return if the object can be skipped in rendering
/**
* Handles the Position of Objects in Scrolling Menu
* @note As Containers have their own FUnc to handle this, this
* function is only useful to Render Live Objects whicch cannot be aligned
* by the internal Alignment Api
* @param pos position reference to write the new position to
* @param size size of the Object
* @return if the object can be skipped in rendering
*/
bool HandleScrolling(vec2& pos, const vec2& size);
/// @brief Get the Cursor Position
/// @return Cursor Pos
/**
* Get the Cursor Position
* @return Cursor Pos
*/
vec2 Cursor() const { return cursor; }
/// @brief Set the Cursor position
/// @note The old Position can be restored with RestoreCursor
/// @param v New Position
/**
* Set the Cursor position
* @note The old Position can be restored with RestoreCursor
* @param v New Position
*/
void Cursor(const vec2& v) {
bcursor = cursor;
cursor = v;
}
/// @brief Restore to the last cursor Position
/** Restore to the last cursor Position */
void RestoreCursor() {
cursor = bcursor;
bcursor = vec2();
}
/// @brief Return if a Vertical Scrollbar exists
/** Return if a Vertical Scrollbar exists */
bool HasVerticalScrollbar() { return scrollbar[1]; }
/// @brief Return if a Horizontal Scrollbar exists
/** Return if a Horizontal Scrollbar exists */
bool HasHorizontalScrollbar() { return scrollbar[0]; }
/// @brief Get the Titlebar height
/** Get the Titlebar height */
float TitleBarHeight() { return tbh; }
/// @brief Set a Custom Titlebar heigt
/// @note Could destroy some basic functionality
/**
* Set a Custom Titlebar heigt
* @note Could destroy some basic functionality
*/
void TitleBarHeight(float v) { tbh = v; }
/// @brief Init the Cursor
/// @note Useful when using with a Custom TitlebarHeight
/**
* Init the Cursor
* @note Useful when using with a Custom TitlebarHeight
*/
void CursorInit() { Cursor(vec2(5, tbh + 5)); }
/// @brief Move the Cursor for new Object
/// @param szs Size of the current Object
/**
* Move the Cursor for new Object
* @param szs Size of the current Object
*/
void CursorMove(const vec2& szs);
/// @brief Get the ViewArea of the Menu
/** Get the ViewArea of the Menu */
vec4 ViewArea() const { return view_area; }
/// @brief Get the Main Area of the Menu
/// (only relevant for input)
/**
* Get the Main Area of the Menu
* (only relevant for input)
*/
vec4 MainArea() const { return main_area; }
/// @brief Set a MainArea for input
/// @param v Area where Objects can receive inputs
/**
* Set a MainArea for input
* @param v Area where Objects can receive inputs
*/
void MainArea(const vec4& v) { main_area = v; }
/// @brief Get The Scrolling offset
/** Get The Scrolling offset */
vec2 ScrollOffset() const { return scrolling_off; }
/// @brief Set a Scrolling offset
/// @param v Custom Scrolling offset
/**
* Set a Scrolling offset
* @param v Custom Scrolling offset
*/
void ScrollOffset(const vec2& v) { scrolling_off = v; }
/// @brief Get the Current Scrollmodification value
/** Get the Current Scrollmodification value */
vec2 ScrollMod() const { return scroll_mod; }
/// @brief Animated Scroll to Position
/// @param pos Destination Position
/**
* Animated Scroll to Position
* @param pos Destination Position
*/
void ScrollTo(vec2 pos) {
scroll_anim.From(scrolling_off)
.To(pos)
.In(1.f)
.As(scroll_anim.EaseInOutSine);
}
/// @brief Check if Still in ScrollAnimation
/** Check if Still in ScrollAnimation */
bool IsAnimatedScroll() { return !scroll_anim.IsFinished(); }
/// Objects API ///
// Objects API
/// @brief Push an object to the current ListHandler
/// @param obj Object reference to use
/// @return Reference to the Object (from a time
/// where ObjectPush(Container::New()) was used)
/**
* Push an object to the current ListHandler
* @param obj Object reference to use
* @return Reference to the Object (from a time
* where ObjectPush(Container::New()) was used)
*/
Container::Ref ObjectPush(Container::Ref obj);
/// @brief Search for an Object by an id
/// @param id 32 Bit hash/id
/// @return the found Object or nullptr
/**
* Search for an Object by an id
* @param id 32 Bit hash/id
* @return the found Object or nullptr
*/
Container::Ref FindIDObj(u32 id);
/**
* 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 Lists ///
// Draw Lists
/// @brief Background Layer Drawlist
/** Background Layer Drawlist */
DrawList::Ref BackList() { return back; }
/// @brief Setter for Background Layer Drawlist
/** Setter for Background Layer Drawlist */
void BackList(DrawList::Ref v) { back = v; }
/// @brief Main Layer Drawlist
/** Main Layer Drawlist */
DrawList::Ref MainList() { return main; }
/// @brief Setter for Main Layer Drawlist
/** Setter for Main Layer Drawlist */
void MainList(DrawList::Ref v) { main = v; }
/// @brief Foreground Layer Drawlist
/** Foreground Layer Drawlist */
DrawList::Ref FrontList() { return front; }
/// @brief Setter for Foreground Layer Drawlist
/** Setter for Foreground Layer Drawlist */
void FrontList(DrawList::Ref v) { front = v; }
/// Advanced ///
// Advanced
/// @brief Display Debug Labels of the Menu
/** Display Debug Labels of the Menu */
void DebugLabels();
/// Uneditable Stuff ///
// Uneditable Stuff
/// @brief Menu Name
/** Menu Name */
std::string GetName() const { return name; }
/// @brief Menu ID [Hash of the Name]
/** Menu ID [Hash of the Name] */
u32 GetID() const { return id; }
private:
/// Advanced Handlers
// Advanced Handlers
/**
* Setup for the Menu
* @param flags Menu Flags
*/
void PreHandler(UI7MenuFlags flags);
/** Handle things like scrolling */
void PostHandler();
/// Basic Settings
// Basic Settings
/**
* Set Backup Cursor
* @param v Position
*/
void BackupCursor(const vec2& v) { bcursor = v; }
/** Get Sameline Cursor */
vec2 SameLineCursor() const { return slcursor; }
/**
* Set Sameline Cursor
* @param v Position
*/
void SameLineCursor(const vec2& v) { slcursor = v; }
/**
* Set View Area
* @param v vec4 containing pos and size
*/
void ViewArea(const vec4& v) { view_area = v; }
/**
* Set Scroll Modification
* @param v Mod
*/
void ScrollMod(const vec2& v) { scroll_mod = v; }
/** Get the Alignment for Current State */
UI7Align GetAlignment() {
/// if temp alignment is used then return it and
/// reset tmpalign
if (tmpalign) {
auto t = tmpalign;
tmpalign = 0;
@ -234,49 +326,53 @@ class Menu : public SmartCtor<Menu> {
return alignment;
}
/// Internal Processing
/** Internal Processing */
void Update(float delta);
/// This ability is crazy useful
// This ability is crazy useful
friend class Context;
/// Data
// Data
// Default Alignment for all Objects
UI7Align alignment = UI7Align_Default;
UI7Align tmpalign = 0;
UI7MenuFlags flags = 0;
u32 id;
std::string name;
vec2 cursor;
vec2 bcursor;
vec2 slcursor;
vec4 view_area;
vec4 main_area;
vec2 scrolling_off;
bool scrolling[2];
vec2 scroll_mod;
float tbh;
bool scrollbar[2];
bool scroll_allowed[2];
bool has_touch;
UI7Align tmpalign = 0; ///< Temp Alignment [only used once]
UI7MenuFlags flags = 0; ///< Menu Flags
u32 id; ///< Menu ID
std::string name; ///< Menu Name
vec2 cursor; ///< Current Cursor Position
vec2 bcursor; ///< Backup Cursor
vec2 slcursor; ///< Sameline Cursor
vec4 view_area; ///< view Area
vec4 main_area; ///< Main Area [Input related]
vec2 scrolling_off; ///< Scrolling Position
bool scrolling[2]; ///< Is Hz or Vt Scrolling Enabled
vec2 scroll_mod; ///< Scroll Modificator
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)
Container::Ref tmp_parent;
Container::Ref tmp_parent; ///< Parent Container (for better alignment etc)
/// Objects API
std::vector<Container::Ref> objects;
std::vector<Container::Ref> idobjs;
std::vector<Container*> join;
int count_btn = 0;
int count_cbx = 0;
// Objects API
std::vector<Container::Ref> objects; ///< Current frame Objects
std::vector<Container::Ref> idobjs; ///< Objects using an ID
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
// DrawLists
DrawList::Ref back;
DrawList::Ref main;
DrawList::Ref front;
vec2 max;
vec2 mouse;
vec2 bslpos;
vec2 last_size;
DrawList::Ref back; ///< Background Drawlist
DrawList::Ref main; ///< Main Drawlist
DrawList::Ref front; ///< Foreground Drawlist
vec2 max; ///< Max Position
vec2 mouse; ///< Mouse/Touch Position
vec2 bslpos; ///< Before Sameline Position
vec2 last_size; ///< Last Object Size
// Theme
Theme::Ref theme;
@ -285,7 +381,8 @@ class Menu : public SmartCtor<Menu> {
Hid::Ref inp;
// Animations System
Tween<vec2> scroll_anim;
Tween<vec2> scroll_anim; ///< for Scroll to Animation
};
} // namespace UI7
} // namespace PD

View File

@ -25,40 +25,51 @@ SOFTWARE.
#include <pd/core/common.hpp>
/**
* Using this to support 32bit color values as well as
* values from UI7Color_
*/
using UI7Color = PD::u32;
/** Theme Color */
enum UI7Color_ {
UI7Color_Background,
UI7Color_Button,
UI7Color_ButtonDead,
UI7Color_ButtonActive,
UI7Color_ButtonHovered,
UI7Color_Text,
UI7Color_TextDead,
UI7Color_Header,
UI7Color_Selector,
UI7Color_Checkmark,
UI7Color_FrameBackground,
UI7Color_FrameBackgroundHovered,
UI7Color_Progressbar,
UI7Color_ListEven,
UI7Color_ListOdd,
UI7Color_Background, ///< UI7 Menu Background
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_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 {
/// @brief Theme Class
/** Theme Class */
class Theme : public SmartCtor<Theme> {
public:
public:
/**
* Default Constructor Setting up the Default theme
* @note if using SmartCtor Reference you probably need to do
* Theme::Default(*theme.get());
*/
Theme() { Default(*this); }
~Theme() {}
~Theme() = default;
/// @brief Simple static Loader for the Default Theme
/// @param theme Theme Reference
/**
* Simple static Loader for the Default Theme
* @param theme Theme Reference
*/
static void Default(Theme& theme);
/// @brief Revert the last Color Change
/** Revert the last Color Change */
Theme& Pop() {
theme[changes[changes.size() - 1].first] =
changes[changes.size() - 1].second;
@ -66,8 +77,10 @@ class Theme : public SmartCtor<Theme> {
return *this;
}
/// @brief Revert the last color Change done for a specific color
/// @param c Color to revert change from
/**
* 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 = changes.size() - 1; i > 0; i--) {
if (changes[i].first == c) {
@ -79,9 +92,11 @@ class Theme : public SmartCtor<Theme> {
return *this;
}
/// @brief Change a Color
/// @param tc Color Identifier
/// @param color Color to change to
/**
* Change a Color
* @param tc Color Identifier
* @param color Color to change to
*/
Theme& Change(UI7Color tc, u32 color) {
if (theme.find(tc) == theme.end()) {
return *this;
@ -91,8 +106,10 @@ class Theme : public SmartCtor<Theme> {
return *this;
}
/// @brief Get the Color of a Color ReferenceID
/// @param c ReferenceID
/**
* Get the Color of a Color ReferenceID
* @param c ReferenceID
*/
u32 Get(UI7Color c) const {
auto e = theme.find(c);
if (e == theme.end()) {
@ -101,18 +118,22 @@ class Theme : public SmartCtor<Theme> {
return e->second;
}
/// @brief Operator wrapper for get
/// @param c Color ReferenceID
/**
* Operator wrapper for get
* @param c Color ReferenceID
*/
u32 operator[](UI7Color c) const { return Get(c); }
/// @brief 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
/**
* 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) { theme[tc] = clr; }
private:
std::unordered_map<u32, u32> theme;
std::vector<std::pair<UI7Color, u32>> changes;
std::unordered_map<u32, u32> theme; ///< Theme Data
std::vector<std::pair<UI7Color, u32>> changes; ///< List of Changes
};
} // namespace UI7
} // namespace PD

View File

@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/drivers/hid.hpp> //// WOW A NON UI/ Header
#include <pd/drivers/hid.hpp>
#include <pd/ui7/drawlist.hpp>
#include <pd/ui7/flags.hpp>
#include <pd/ui7/id.hpp>
@ -32,67 +32,113 @@ SOFTWARE.
namespace PD {
namespace UI7 {
/** Base Context for UI7 */
class 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
this->ren = ren;
this->inp = hid;
/// Init Theme and Front / Back Drawlists
theme = Theme::New();
back = DrawList::New(ren);
front = DrawList::New(ren);
}
~Context() {}
~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);
/**
* 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)
*/
void EndMenu();
/// @brief Get Theme reference
/// @return Reference to the base Theme of the context
/**
* Get Theme reference
* @return Reference to the base Theme of the context
*/
Theme::Ref GetTheme() { return theme; }
/// @brief Directly return a Color by using the
/// ctx->ThemeColor(UI7Color_Text) for example
/// @param clr The Input UI7 Color
/// @return The 32bit color value
/**
*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 theme->Get(clr); }
/// @brief Update Context (Render menus)
/// @param delta deltatime
/**
* Update Context (Render menus)
* @param delta deltatime
*/
void Update(float delta);
/// Expose DrawLists
// Expose DrawLists
/** Background DrawList Reference */
DrawList::Ref BackList() { return back; }
/** Foreground DrawList Reference */
DrawList::Ref FrontList() { return 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; }
private:
// Used in Overlays
int root_layer = 0;
// Linked Renderer / Hid
// Linked Renderer
LI::Renderer::Ref ren;
// Input Driver Reference
Hid::Ref inp;
// Timing
// Delta time
float delta;
// Context Run Time
float time;
/// @brief Last Time [unused ?]
float last;
// Context
// In Menu [unused ?]
bool in_menu;
// Debug
// Is Debugging [unused ?]
bool debugging;
// Menu Handlers
// Map of The Menus by ID
std::unordered_map<u32, Menu::Ref> menus;
std::vector<u32> amenus; // Active ones
Menu::Ref current;
// Context DrawList
std::vector<u32> amenus; ///< Active ones
Menu::Ref current; ///< Current Menu
// Debug Drawlist
DrawList::Ref debug;
// Foreground Drawlist
DrawList::Ref front;
// Background Drawlist
DrawList::Ref back;
// Theme
// Active Theme
Theme::Ref theme;
// Promt Handler
};
} // namespace UI7
} // namespace PD