# Changes 0.2.8
- Fix Flickering problem in StaticText api - Fix Lagacy and Container HandleScrolling InBox checks - Add IO Flags define for future - Implement Single Object Dragging API by IO Context - Add TreeNodes - Use ioMenuPadding and ItemSpace - Add StyleEditorMenu - Rework ContainerApi to take functions from IO and add an Update function template for Updating internal values if required - Use new DragApi for MenuCollabse, MenuDragging, MenuResize, SliderDragging and TreeNodes Open/Close - Add Helper Defines for Metrics Menu [INTERNAL] - Add TimeTrace as Tree to Metrics as well as other new Data - Add GetRawObject to StaticText for custom rendering like ui7 - Add DrawlistRegestry to correctly render Menus in their own layer ranges
This commit is contained in:
@ -305,6 +305,9 @@ class StaticText : public SmartCtor<StaticText> {
|
||||
*/
|
||||
void Draw();
|
||||
|
||||
/** Get the Raw Object for Custom API's */
|
||||
StaticObject::Ref GetRawObject() { return text; }
|
||||
|
||||
/**
|
||||
* Set Font used by the static Text
|
||||
* @param fnt Font used
|
||||
|
@ -24,6 +24,7 @@ SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/ui7/container/container.hpp>
|
||||
#include <pd/ui7/io.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
@ -42,13 +43,9 @@ class Button : public Container {
|
||||
* @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();
|
||||
Button(const std::string& label, UI7::IO::Ref io) {
|
||||
this->label = label;
|
||||
this->SetPos(pos);
|
||||
this->tdim = lr->GetTextDimensions(label);
|
||||
color = UI7Color_Button;
|
||||
this->SetSize(tdim + vec2(8, 4));
|
||||
this->tdim = io->Ren->GetTextDimensions(label);
|
||||
}
|
||||
~Button() = default;
|
||||
|
||||
@ -66,11 +63,14 @@ class Button : public Container {
|
||||
* */
|
||||
void Draw() override;
|
||||
|
||||
/** Function to Update Size if framepadding changes */
|
||||
void Update() override;
|
||||
|
||||
private:
|
||||
vec2 tdim; ///< Text size
|
||||
UI7Color color; ///< current button color
|
||||
std::string label; ///< Label of the Button
|
||||
bool pressed = false; ///< ispressed value
|
||||
vec2 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
|
@ -38,19 +38,13 @@ class Checkbox : public Container {
|
||||
/**
|
||||
* 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)
|
||||
* @param io IO Reference
|
||||
*/
|
||||
Checkbox(const std::string& label, vec2 pos, bool& usr_ref,
|
||||
LI::Renderer::Ref lr)
|
||||
Checkbox(const std::string& label, bool& usr_ref, UI7::IO::Ref io)
|
||||
: usr_ref(usr_ref) {
|
||||
this->screen = lr->CurrentScreen();
|
||||
this->label = label;
|
||||
this->SetPos(pos);
|
||||
this->tdim = lr->GetTextDimensions(label);
|
||||
color = UI7Color_FrameBackground;
|
||||
this->SetSize(cbs + vec2(tdim.x() + 5, 0));
|
||||
this->tdim = io->Ren->GetTextDimensions(label);
|
||||
}
|
||||
~Checkbox() = default;
|
||||
/**
|
||||
@ -65,12 +59,15 @@ class Checkbox : public Container {
|
||||
* */
|
||||
void Draw() override;
|
||||
|
||||
/** Update Size if framepadding changed */
|
||||
void Update() override;
|
||||
|
||||
private:
|
||||
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
|
||||
vec2 tdim; ///< Text Size
|
||||
vec2 cbs = vec2(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
|
@ -28,6 +28,7 @@ SOFTWARE.
|
||||
#include <pd/core/vec.hpp>
|
||||
#include <pd/drivers/hid.hpp>
|
||||
#include <pd/ui7/drawlist.hpp>
|
||||
#include <pd/ui7/io.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
@ -54,14 +55,13 @@ class Container : public SmartCtor<Container> {
|
||||
/**
|
||||
* Init Function Required by every Object that uses
|
||||
* Render or Input functions
|
||||
* @param r Renderer Reference
|
||||
* @param io IO Reference
|
||||
* @param l DrawList Reference
|
||||
* @param lt Theme Reference
|
||||
*/
|
||||
void Init(LI::Renderer::Ref r, UI7::DrawList::Ref l, UI7::Theme::Ref lt) {
|
||||
void Init(UI7::IO::Ref io, UI7::DrawList::Ref l) {
|
||||
list = l;
|
||||
theme = lt;
|
||||
ren = r;
|
||||
this->io = io;
|
||||
this->screen = io->Ren->CurrentScreen();
|
||||
}
|
||||
|
||||
/** Setter for Position */
|
||||
@ -106,6 +106,8 @@ class Container : public SmartCtor<Container> {
|
||||
virtual void HandleInput(Hid::Ref inp) {}
|
||||
/** Tamplate function for Object rendering */
|
||||
virtual void Draw() {}
|
||||
/** Template function to update internal data (if needed) */
|
||||
virtual void Update() {}
|
||||
|
||||
/**
|
||||
* Function to unlock Input after Rendering is done in
|
||||
@ -140,10 +142,8 @@ class Container : public SmartCtor<Container> {
|
||||
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;
|
||||
/** IO Reference for Renderer and Theme */
|
||||
UI7::IO::Ref io;
|
||||
/** Reference to the parent container*/
|
||||
Container::Ref parent;
|
||||
/** Object ID (0 if unused)*/
|
||||
|
@ -35,14 +35,10 @@ class Image : public Container {
|
||||
/**
|
||||
* 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();
|
||||
Image(Texture::Ref img, vec2 size = 0.f) {
|
||||
this->img = img;
|
||||
this->SetPos(pos);
|
||||
this->newsize = size;
|
||||
if (size.x() != 0 || size.y() != 0) {
|
||||
this->SetSize(size);
|
||||
|
@ -35,15 +35,11 @@ class Label : public Container {
|
||||
/**
|
||||
* 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();
|
||||
Label(const std::string& label, LI::Renderer::Ref lr) {
|
||||
this->label = label;
|
||||
this->SetPos(pos);
|
||||
this->tdim = lr->GetTextDimensions(label);
|
||||
color = UI7Color_Text;
|
||||
this->SetSize(tdim);
|
||||
}
|
||||
~Label() = default;
|
||||
@ -55,9 +51,9 @@ class Label : public Container {
|
||||
void Draw() override;
|
||||
|
||||
private:
|
||||
vec2 tdim; ///< Text Size
|
||||
UI7Color color; ///< Color
|
||||
std::string label; ///< Text to Render
|
||||
vec2 tdim; ///< Text Size
|
||||
UI7Color color = UI7Color_Text; ///< Color
|
||||
std::string label; ///< Text to Render
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
@ -27,6 +27,8 @@ SOFTWARE.
|
||||
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;
|
||||
|
||||
/** Menu Flags */
|
||||
enum UI7MenuFlags_ {
|
||||
@ -44,6 +46,13 @@ enum UI7MenuFlags_ {
|
||||
UI7MenuFlags_Scrolling = UI7MenuFlags_HzScrolling | UI7MenuFlags_VtScrolling,
|
||||
};
|
||||
|
||||
/** 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)
|
||||
|
@ -25,9 +25,10 @@ SOFTWARE.
|
||||
|
||||
#include <pd/core/common.hpp>
|
||||
#include <pd/core/timer.hpp>
|
||||
#include <pd/drivers/hid.hpp>
|
||||
#include <pd/ui7/drawlist.hpp>
|
||||
#include <pd/ui7/flags.hpp>
|
||||
#include <pd/ui7/menu.hpp>
|
||||
#include <pd/ui7/id.hpp>
|
||||
#include <pd/ui7/theme.hpp>
|
||||
|
||||
namespace PD {
|
||||
@ -40,21 +41,111 @@ class IO : public SmartCtor<IO> {
|
||||
/**
|
||||
* IO Constructor setting UP References
|
||||
*/
|
||||
IO(Hid::Ref input_driver) {
|
||||
IO(Hid::Ref input_driver, LI::Renderer::Ref ren) {
|
||||
Time = Timer::New();
|
||||
DragTime = Timer::New(false);
|
||||
Theme = UI7::Theme::New();
|
||||
Inp = input_driver;
|
||||
Ren = ren;
|
||||
Back = UI7::DrawList::New(Ren);
|
||||
Front = UI7::DrawList::New(Ren);
|
||||
DrawListRegestry["CtxBackList"] = Back;
|
||||
DrawListRegestry["CtxFrontList"] = Front;
|
||||
DeltaStats = TimeStats::New(60);
|
||||
};
|
||||
~IO() = default;
|
||||
|
||||
/**
|
||||
* IO Update Internal Variables
|
||||
*/
|
||||
void Update();
|
||||
|
||||
float Framerate = 0.f;
|
||||
float Delta = 0.f;
|
||||
TimeStats::Ref DeltaStats;
|
||||
Timer::Ref Time;
|
||||
Hid::Ref Inp;
|
||||
LI::Renderer::Ref Ren;
|
||||
UI7::Theme::Ref Theme;
|
||||
float MenuPadding = 5.f;
|
||||
vec2 MenuPadding = 5.f;
|
||||
vec2 FramePadding = 5.f;
|
||||
vec2 ItemSpace = vec2(5.f, 2.f);
|
||||
std::map<UI7::ID, DrawList::Ref> DrawListRegestry;
|
||||
DrawList::Ref Back;
|
||||
DrawList::Ref Front;
|
||||
|
||||
// Layer Rules
|
||||
int ContextBackLayer = 10;
|
||||
int MenuBackLayer = 20;
|
||||
int MenuMainLayer = 30;
|
||||
int MenuFrontLayer = 40;
|
||||
int ContextFrontLayer = 50;
|
||||
|
||||
// DrawListApi
|
||||
void RegisterDrawList(const UI7::ID& id, DrawList::Ref v) {
|
||||
DrawListRegestry[id] = v;
|
||||
}
|
||||
|
||||
// Input API
|
||||
|
||||
u32 DraggedObject = 0;
|
||||
vec2 DragSourcePos = 0;
|
||||
vec2 DragPosition = 0;
|
||||
vec2 DragLastPosition = 0;
|
||||
vec4 DragDestination = 0;
|
||||
Timer::Ref DragTime;
|
||||
bool DragReleased = false;
|
||||
/** Check if an object is Dragged already */
|
||||
bool IsObjectDragged() const { return DraggedObject != 0; }
|
||||
/**
|
||||
* 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, vec4 area) {
|
||||
if (IsObjectDragged()) {
|
||||
// Only block if the Dragged Object has a difrent id
|
||||
if (DraggedObject != id) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Get a Short define for touch pos
|
||||
vec2 p = Inp->TouchPos();
|
||||
// Check if Drag starts in the area position
|
||||
if (Inp->IsDown(Inp->Touch) && Ren->InBox(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 (Inp->IsHeld(Inp->Touch) && IsObjectDragged()) {
|
||||
// Update DragLast and DragPoisition
|
||||
DragLastPosition = DragPosition;
|
||||
DragPosition = p;
|
||||
} else if (Inp->IsUp(Inp->Touch) && IsObjectDragged()) {
|
||||
// Released... Everything gets reset
|
||||
DraggedObject = 0;
|
||||
DragPosition = 0;
|
||||
DragSourcePos = 0;
|
||||
DragLastPosition = 0;
|
||||
DragDestination = 0;
|
||||
DragReleased = true; // Set Drag released to true (only one frame)
|
||||
// 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();
|
||||
}
|
||||
};
|
||||
} // namespace UI7
|
||||
} // namespace PD
|
@ -29,6 +29,7 @@ SOFTWARE.
|
||||
#include <pd/ui7/drawlist.hpp>
|
||||
#include <pd/ui7/flags.hpp>
|
||||
#include <pd/ui7/id.hpp>
|
||||
#include <pd/ui7/io.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
@ -38,13 +39,11 @@ class Menu : public SmartCtor<Menu> {
|
||||
/**
|
||||
* Menu COnstructor (Unly used by UI7::Context)
|
||||
* @param id ID of the Menu
|
||||
* @param tl Theme Reference
|
||||
* @param h Input Driver Reference
|
||||
* @param io IO Config Reference
|
||||
*/
|
||||
Menu(ID id, Theme::Ref tl, Hid::Ref h) {
|
||||
Menu(ID id, UI7::IO::Ref io) {
|
||||
/// Setup the Input Data
|
||||
theme = tl;
|
||||
this->inp = h;
|
||||
this->io = io;
|
||||
this->id = id;
|
||||
this->name = id.GetName();
|
||||
/// Set Default Values here
|
||||
@ -85,6 +84,17 @@ class Menu : public SmartCtor<Menu> {
|
||||
|
||||
// Basic API
|
||||
|
||||
/**
|
||||
* Create a Tree Node
|
||||
* @param id String ID of the Node
|
||||
* @return node open or not
|
||||
*/
|
||||
bool BeginTreeNode(const UI7::ID& id);
|
||||
/**
|
||||
* End a Tree Node
|
||||
*/
|
||||
void EndTreeNode();
|
||||
|
||||
/** Add the Next Objext to the same line */
|
||||
void SameLine();
|
||||
/** Add a Separator Line */
|
||||
@ -133,14 +143,20 @@ class Menu : public SmartCtor<Menu> {
|
||||
* Returns a Reference to the theme
|
||||
* @return Reference to the base Theme of the context
|
||||
*/
|
||||
Theme::Ref GetTheme() { return theme; }
|
||||
Theme::Ref GetTheme() { return io->Theme; }
|
||||
/**
|
||||
* Directly return a Color by using the
|
||||
* m->ThemeColor(UI7Color_Text) for example
|
||||
* @param clr The Input UI7 Color
|
||||
* @return The 32bit color value
|
||||
*/
|
||||
u32 ThemeColor(UI7Color clr) const { return theme->Get(clr); }
|
||||
u32 ThemeColor(UI7Color clr) const { return io->Theme->Get(clr); }
|
||||
|
||||
/**
|
||||
* Get IO Reference
|
||||
* @return io Reference
|
||||
*/
|
||||
UI7::IO::Ref GetIO() { return io; }
|
||||
|
||||
// API for Custom Objects
|
||||
|
||||
@ -188,7 +204,7 @@ class Menu : public SmartCtor<Menu> {
|
||||
* Init the Cursor
|
||||
* @note Useful when using with a Custom TitlebarHeight
|
||||
*/
|
||||
void CursorInit() { Cursor(vec2(5, tbh + 5)); }
|
||||
void CursorInit() { Cursor(io->MenuPadding + vec2(0, tbh)); }
|
||||
/**
|
||||
* Move the Cursor for new Object
|
||||
* @param szs Size of the current Object
|
||||
@ -345,6 +361,7 @@ class Menu : public SmartCtor<Menu> {
|
||||
u32 id; ///< Menu ID
|
||||
std::string name; ///< Menu Name
|
||||
vec2 cursor; ///< Current Cursor Position
|
||||
vec2 icursoroff; ///< Initial Cursor Offset (Also in Newline)
|
||||
vec2 bcursor; ///< Backup Cursor
|
||||
vec2 slcursor; ///< Sameline Cursor
|
||||
vec4 view_area; ///< view Area (Position and Size)
|
||||
@ -379,11 +396,9 @@ class Menu : public SmartCtor<Menu> {
|
||||
vec2 bslpos; ///< Before Sameline Position
|
||||
vec2 last_size; ///< Last Object Size
|
||||
|
||||
// Theme
|
||||
Theme::Ref theme;
|
||||
UI7::IO::Ref io; ///< IO Reference
|
||||
|
||||
// Input Reference
|
||||
Hid::Ref inp;
|
||||
std::map<u32, bool> tree_nodes; ///< Map of Tree nodes
|
||||
|
||||
// Animations System
|
||||
|
||||
|
@ -37,7 +37,7 @@ SOFTWARE.
|
||||
* Major Minor Patch Build
|
||||
* 0x01010000 -> 1.1.0-0
|
||||
*/
|
||||
#define UI7_VERSION 0x00020702
|
||||
#define UI7_VERSION 0x00020800
|
||||
|
||||
namespace PD {
|
||||
namespace UI7 {
|
||||
@ -57,14 +57,7 @@ class Context : public SmartCtor<Context> {
|
||||
*/
|
||||
Context(LI::Renderer::Ref ren, Hid::Ref hid) {
|
||||
/// Set the Internal References
|
||||
this->ren = ren;
|
||||
this->inp = hid;
|
||||
io = IO::New(hid);
|
||||
/// Init Theme and Front / Back Drawlists
|
||||
theme = Theme::New();
|
||||
back = DrawList::New(ren);
|
||||
front = DrawList::New(ren);
|
||||
s_delta = TimeStats::New(60);
|
||||
io = IO::New(hid, ren);
|
||||
}
|
||||
~Context() = default;
|
||||
|
||||
@ -97,14 +90,14 @@ class Context : public SmartCtor<Context> {
|
||||
* Get Theme reference
|
||||
* @return Reference to the base Theme of the context
|
||||
*/
|
||||
Theme::Ref GetTheme() { return theme; }
|
||||
Theme::Ref GetTheme() { return io->Theme; }
|
||||
/**
|
||||
*Directly return a Color by using the
|
||||
* ctx->ThemeColor(UI7Color_Text) for example
|
||||
* @param clr The Input UI7 Color
|
||||
* @return The 32bit color value
|
||||
*/
|
||||
u32 ThemeColor(UI7Color clr) const { return theme->Get(clr); }
|
||||
u32 ThemeColor(UI7Color clr) const { return io->Theme->Get(clr); }
|
||||
|
||||
/**
|
||||
* Update Context (Render menus)
|
||||
@ -115,9 +108,9 @@ class Context : public SmartCtor<Context> {
|
||||
// Expose DrawLists
|
||||
|
||||
/** Background DrawList Reference */
|
||||
DrawList::Ref BackList() { return back; }
|
||||
DrawList::Ref BackList() { return io->Back; }
|
||||
/** Foreground DrawList Reference */
|
||||
DrawList::Ref FrontList() { return front; }
|
||||
DrawList::Ref FrontList() { return io->Front; }
|
||||
|
||||
/**
|
||||
* Set the Root Layer of the Menu
|
||||
@ -138,41 +131,16 @@ class Context : public SmartCtor<Context> {
|
||||
/** Metrics */
|
||||
void MetricsMenu();
|
||||
|
||||
/** Style Editor Menu (Includes Theme Editor) */
|
||||
void StyleEditor();
|
||||
|
||||
private:
|
||||
// Used in Overlays
|
||||
int root_layer = 0;
|
||||
// Linked Renderer
|
||||
LI::Renderer::Ref ren;
|
||||
// Input Driver Reference
|
||||
Hid::Ref inp;
|
||||
// Delta time
|
||||
float delta;
|
||||
// Context Run Time
|
||||
float time;
|
||||
/// @brief Last Time [unused ?]
|
||||
float last;
|
||||
// In Menu [unused ?]
|
||||
bool in_menu;
|
||||
// Is Debugging [unused ?]
|
||||
bool debugging;
|
||||
// Map of The Menus by ID
|
||||
std::unordered_map<u32, Menu::Ref> menus;
|
||||
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;
|
||||
// Active Theme
|
||||
Theme::Ref theme;
|
||||
|
||||
// Metrics
|
||||
|
||||
// Deltatime Average
|
||||
TimeStats::Ref s_delta;
|
||||
|
||||
// IO
|
||||
IO::Ref io;
|
||||
};
|
||||
|
Reference in New Issue
Block a user