6 Commits
Author SHA1 Message Date
tobid7 3575a6787d hotfix 2025-12-28 21:38:41 +01:00
tobid7 7fc7a2ecb9 QoL Changes
fix timetrace last diff
2025-12-27 23:35:23 +01:00
tobid7 03f65e069f Add TextMapSystem WIP 2025-12-24 18:17:58 +01:00
tobid7 c618c616fe Fix UI7 Crash by safe deleting the elements 2025-12-24 15:05:05 +01:00
tobid7 ac281dc7a9 Update
- Add data getter to DrawList
- Add NoOOS (Out Of screen Rendering) flag to text renderer (requires a textbox)
- UI7 Label Wrapping (optinal and beta)
2025-12-23 19:20:31 +01:00
tobid7 0cb5de882f Fixes and function additions
- Fixed Text pos at NoCollapse flag
- Fix Button Input Api (HandleScrolling after layout Update)
- Add getter for IO and Current Menu
- Add AdObject func wrappers to Menu
2025-12-20 19:25:20 +01:00
16 changed files with 153 additions and 34 deletions
+13 -13
View File
@@ -30,7 +30,7 @@ namespace PD {
* Class to calculate Maximum/Minimum and Average Timings
*/
class TimeStats {
public:
public:
/**
* Constructor taking a lengh for the List
* @param l Lengh of the data list
@@ -55,8 +55,7 @@ public:
* @return Average
*/
u64 GetAverage() {
if (!num_val)
return 0.f;
if (!num_val) return 0.f;
u64 res = 0;
for (int i = 0; i < num_val; i++) {
res += val[smart_idx(i)];
@@ -69,8 +68,7 @@ public:
* @return Minimum value
*/
u64 GetMin() {
if (!num_val)
return 0.f;
if (!num_val) return 0.f;
u64 res = std::numeric_limits<u64>::max();
for (int i = 0; i < num_val; i++) {
res = std::min(val[smart_idx(i)], res);
@@ -83,8 +81,7 @@ public:
* @return Max Value
*/
u64 GetMax() {
if (!num_val)
return 0.f;
if (!num_val) return 0.f;
u64 res = 0;
for (int i = 0; i < num_val; i++) {
res = std::max(val[smart_idx(i)], res);
@@ -122,7 +119,7 @@ public:
*/
const size_t GetNumValues() { return num_val; }
private:
private:
/**
* Get the Next Position to write to
* @param c current position
@@ -152,7 +149,7 @@ namespace TT {
* Data Structure for a TimeTrace Result
*/
class Res {
public:
public:
/** Constructore that Inits a protocol at size of 60 frames */
Res() : start(0), end(0) { protocol = TimeStats::New(60); }
~Res() = default;
@@ -185,6 +182,7 @@ public:
*/
void SetEnd(u64 v) {
end = v;
diff = end - start;
protocol->Add(GetLastDiff());
}
/**
@@ -197,20 +195,22 @@ public:
* Get Last Diffrence between end and start
* @return end - start
*/
u64 GetLastDiff() { return end - start; }
u64 GetLastDiff() { return diff; }
/**
* Get Protcol Reference
* @return Protocol Ref
*/
TimeStats::Ref GetProtocol() { return protocol; }
private:
private:
/** Trace ID */
std::string id;
/** Start time */
u64 start;
/** End Time */
u64 end;
/** Last Diff */
u64 diff;
/** Protocol */
TimeStats::Ref protocol;
};
@@ -240,7 +240,7 @@ PD_CORE_API void End(const std::string &id);
* ```
*/
class Scope {
public:
public:
/**
* Constructor requiring a Name for the Trace
* @param id Name of the Trace
@@ -254,7 +254,7 @@ public:
*/
~Scope() { End(ID); }
private:
private:
/** Trace Name/ID */
std::string ID;
};
+1
View File
@@ -94,6 +94,7 @@ class Gfx {
static void BindTex(Li::TexAddress addr) { pGfx->BindTex(addr); }
static void SetViewPort(const ivec2& vp) { pGfx->SetViewPort(vp); }
static void SetViewPort(int w, int h) { pGfx->SetViewPort(PD::ivec2(w, h)); }
static void RenderDrawData(const std::vector<Li::Command::Ref>& Commands) {
pGfx->RenderDrawData(Commands);
+6
View File
@@ -40,6 +40,12 @@ class Command {
IndexBuffer.push_back(VertexBuffer.size() + idx);
return *this;
}
Command& AddIdxs(const u16& a, const u16& b, const u16& c) {
IndexBuffer.push_back(VertexBuffer.size() + a);
IndexBuffer.push_back(VertexBuffer.size() + b);
IndexBuffer.push_back(VertexBuffer.size() + c);
return *this;
}
Command& AddVtx(const Vertex& v) {
VertexBuffer.push_back(std::move(v));
+9
View File
@@ -68,6 +68,12 @@ class PD_LITHIUM_API DrawList {
* @param list DrawList to move into current
*/
void Merge(DrawList::Ref list);
/**
* Copy another drawlist to this drawist.
* This is important for static prerendered Drawlists
* @param list DrawList Reference to copy from
*/
void Copy(DrawList::Ref list);
/**
* Optimize a Drawlist to a more or less perfect order
* to reduce drawcall overhead... This function also uses
@@ -80,6 +86,8 @@ class PD_LITHIUM_API DrawList {
void Clear();
void Layer(int l) { this->pLayer = l; }
int Layer() { return this->pLayer; }
void LayerUp() { this->pLayer++; }
void LayerDown() { this->pLayer--; }
void SetFont(Font::Ref font) { pCurrentFont = font; }
void SetFontScale(float scale) { pFontScale = scale; }
@@ -198,6 +206,7 @@ class PD_LITHIUM_API DrawList {
}
pClipRects.pop();
}
const std::vector<Command::Ref>& Data() const { return pDrawList; }
/** One linear Clip rect Setup */
void pClipCmd(Command* cmd);
+14
View File
@@ -39,6 +39,7 @@ enum LiTextFlags_ {
LiTextFlags_Wrap = 1 << 3, ///< Wrap Text: May be runs better with TMS
LiTextFlags_Short = 1 << 4, ///< Short Text: May be runs better with TMS
LiTextFlags_Scroll = 1 << 5, ///< Not implemented [scoll text if to long]
LiTextFlags_NoOOS = 1 << 6, ///< No Out of Screen Rendering
};
namespace PD {
@@ -95,6 +96,11 @@ class PD_LITHIUM_API Font {
void CmdTextEx(std::vector<Command::Ref>& cmds, const fvec2& pos, u32 color,
float scale, const std::string& text, LiTextFlags flags = 0,
const fvec2& box = 0);
/**
* Garbage collection for TextMapSystem
*/
void CleanupTMS();
/**
* Utility function to create a font atlas
* During TTF loading (Internal and should not be called)
@@ -115,6 +121,14 @@ class PD_LITHIUM_API Font {
* **Now using unordered map**
*/
std::unordered_map<u32, Codepoint> CodeMap;
/** TMS */
struct TMELEM {
PD::u32 ID;
PD::fvec2 Size;
std::string Text;
u64 TimeStamp;
};
std::unordered_map<u32, TMELEM> pTMS;
};
} // namespace Li
} // namespace PD
+4
View File
@@ -51,6 +51,10 @@ class PD_UI7_API Label : public Container {
* @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
+1
View File
@@ -77,6 +77,7 @@ class PD_UI7_API IO {
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::Ref>> DrawListRegestry;
+2
View File
@@ -103,6 +103,8 @@ class PD_UI7_API Layout {
void Update();
fvec2 DbgScrollOffset() { return ScrollOffset; }
private:
friend class Menu;
friend class Context;
+5
View File
@@ -103,6 +103,11 @@ class PD_UI7_API Menu {
void HandleTitlebarActions();
void DrawBaseLayout();
void AddObject(PD::UI7::Container::Ref obj) { pLayout->AddObject(obj); }
void AddObjectEx(PD::UI7::Container::Ref obj, PD::u32 flags) {
pLayout->AddObjectEx(obj, flags);
}
void Update();
/** Data Section */
+2
View File
@@ -55,10 +55,12 @@ class PD_UI7_API Context {
PD_SHARED(Context);
IO::Ref GetIO() { return pIO; }
void AddViewPort(const ID& id, const ivec4& vp);
void UseViewPort(const ID& id);
void Update();
bool BeginMenu(const ID& id, UI7MenuFlags flags = 0, bool* pShow = nullptr);
Menu::Ref CurrentMenu() { return pCurrent; }
void EndMenu();
void AboutMenu(bool* show = nullptr);
void MetricsMenu(bool* show = nullptr);
+1 -1
View File
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.22)
## The Core Core Library
project(pd-drivers LANGUAGES CXX VERSION 0.5.1)
project(pd-drivers LANGUAGES CXX VERSION 0.6.0)
set(SRC
source/hid.cpp
+3
View File
@@ -38,6 +38,9 @@ PD_LITHIUM_API void DrawList::Clear() {
pNumVertices = 0;
pDrawList.clear();
pPath.clear();
if (pCurrentFont) {
pCurrentFont->CleanupTMS();
}
while (!pClipRects.empty()) {
pClipRects.pop();
}
+52
View File
@@ -196,6 +196,11 @@ PD_LITHIUM_API Font::Codepoint &Font::GetCodepoint(u32 cp) {
}
PD_LITHIUM_API fvec2 Font::GetTextBounds(const std::string &text, float scale) {
u32 id = PD::FNV1A32(text);
if (pTMS.find(id) != pTMS.end()) {
pTMS[id].TimeStamp = PD::OS::GetTime();
return pTMS[id].Size;
}
// Use wstring for exemple for german äöü
auto wtext = Strings::MakeWstring(text);
// Create a temp position and offset as [0, 0]
@@ -237,6 +242,9 @@ PD_LITHIUM_API fvec2 Font::GetTextBounds(const std::string &text, float scale) {
}
res.x = std::max(res.x, x);
res.y += lh;
pTMS[id].ID = id;
pTMS[id].Size = res;
pTMS[id].TimeStamp = PD::OS::GetTime();
return res;
}
@@ -272,6 +280,15 @@ PD_LITHIUM_API void Font::CmdTextEx(std::vector<Command::Ref> &cmds,
}
for (auto &it : lines) {
if (flags & LiTextFlags_NoOOS) {
if (rpos.y + off.y + lh < 0) {
off.y += lh;
continue;
}
if (rpos.y + off.y > box.y && box.y != 0) {
break;
}
}
if (flags & LiTextFlags_Short) {
fvec2 tmp_dim;
it = pShortText(it, scale, box - pos, tmp_dim);
@@ -322,6 +339,14 @@ PD_LITHIUM_API void Font::CmdTextEx(std::vector<Command::Ref> &cmds,
PD_LITHIUM_API std::string Font::pWrapText(const std::string &txt, float scale,
const PD::fvec2 &max,
PD::fvec2 &dim) {
u32 id = PD::FNV1A32(txt);
if (pTMS.find(id) != pTMS.end()) {
if (pTMS[id].Text.size()) {
dim = pTMS[id].Size;
pTMS[id].TimeStamp = PD::OS::GetTime();
return pTMS[id].Text;
}
}
std::string ret;
std::string line;
int lx = 0;
@@ -341,12 +366,24 @@ PD_LITHIUM_API std::string Font::pWrapText(const std::string &txt, float scale,
}
ret += line;
dim = GetTextBounds(ret, scale);
pTMS[id].ID = id;
pTMS[id].Size = dim;
pTMS[id].Text = ret;
pTMS[id].TimeStamp = PD::OS::GetTime();
return ret;
}
PD_LITHIUM_API std::string Font::pShortText(const std::string &txt, float scale,
const PD::fvec2 &max,
PD::fvec2 &dim) {
u32 id = PD::FNV1A32(txt);
if (pTMS.find(id) != pTMS.end()) {
if (pTMS[id].Text.size()) {
dim = pTMS[id].Size;
pTMS[id].TimeStamp = PD::OS::GetTime();
return pTMS[id].Text;
}
}
auto test = GetTextBounds(txt, scale);
if (test.x < max.x) {
return txt;
@@ -373,8 +410,23 @@ PD_LITHIUM_API std::string Font::pShortText(const std::string &txt, float scale,
}
ret += it;
}
pTMS[id].ID = id;
pTMS[id].Size = dim;
pTMS[id].Text = ret;
pTMS[id].TimeStamp = PD::OS::GetTime();
return ret;
}
PD_LITHIUM_API void Font::CleanupTMS() {
u64 t = PD::OS::GetTime();
for (auto it = pTMS.begin(); it != pTMS.end();) {
if (t - it->second.TimeStamp > 1000) {
it = pTMS.erase(it);
} else {
it++;
}
}
}
} // namespace Li
} // namespace PD
+18 -1
View File
@@ -31,10 +31,27 @@ PD_UI7_API void Label::Draw() {
if (pCLipRectUsed) {
list->PushClipRect(pClipRect);
}
list->DrawText(FinalPos(), label, io->Theme->Get(UI7Color_Text));
list->DrawTextEx(FinalPos(), label, io->Theme->Get(UI7Color_Text),
LiTextFlags_NoOOS, PD::fvec2(0, io->CurrentViewPort.w));
if (pCLipRectUsed) {
list->PopClipRect();
}
}
PD_UI7_API void Label::Update() {
/**
* Todo: This is a hacky workaround
* Needs proper optimisation
* Needs a max size (to support sligning dynaically by the window size)
*/
if (io->WrapLabels) {
this->label =
io->Font->pWrapText(this->label, io->FontScale,
PD::fvec2(io->CurrentViewPort.z - FinalPos().x * 4,
io->CurrentViewPort.w),
this->tdim);
SetSize(tdim);
}
}
} // namespace UI7
} // namespace PD
+7 -7
View File
@@ -124,15 +124,15 @@ PD_UI7_API void Layout::Update() {
it->Draw();
}
}
std::vector<size_t> tbr;
for (size_t i = 0; i < IDObjects.size(); i++) {
if (IDObjects[i]->Removable()) {
tbr.push_back(i);
for (auto it = IDObjects.begin(); it != IDObjects.end();) {
if ((*it)->Removable()) {
it = IDObjects.erase(it);
} else {
it++;
}
}
for (auto& it : tbr) {
IDObjects.erase(IDObjects.begin() + it);
}
Objects.clear();
WorkRect = fvec4(fvec2(WorkRect.x, WorkRect.y), Size - IO->MenuPadding);
CursorInit();
+12 -9
View File
@@ -81,7 +81,9 @@ PD_UI7_API void Menu::Separator() {
pIO->Theme->Get(UI7Color_TextDead));
});
// Set size before pushing (cause Cursor Move will require it)
r->SetSize(fvec2(pLayout->Size.x - 10, 1));
r->SetSize(fvec2(
pLayout->Size.x - pIO->MenuPadding.x * 2 - pLayout->InitialCursorOffset.x,
1));
pLayout->AddObject(r);
}
@@ -109,8 +111,9 @@ PD_UI7_API void Menu::SeparatorText(const std::string& label) {
fvec2(pLayout->Size.x, self->GetSize().y));
});
// Set size before pushing (cause Cursor Move will require it)
r->SetSize(
fvec2(pLayout->Size.x - 10, pIO->Font->PixelHeight * pIO->FontScale));
r->SetSize(fvec2(
pLayout->Size.x - pIO->MenuPadding.x * 2 - pLayout->InitialCursorOffset.x,
pIO->Font->PixelHeight * pIO->FontScale));
pLayout->AddObject(r);
}
PD_UI7_API void Menu::HandleFocus() {
@@ -148,7 +151,7 @@ PD_UI7_API void Menu::HandleScrolling() {
pLayout->ScrollOffset.y = std::clamp(
pLayout->ScrollStart.y + pIO->InputHandler->DragSourcePos.y -
pIO->InputHandler->DragPosition.y,
20.f, pLayout->MaxPosition.y - 220);
-20.f, pLayout->MaxPosition.y - 220);
}
}
} else {
@@ -279,12 +282,12 @@ PD_UI7_API void Menu::DrawBaseLayout() {
l->pLayer = 21;
/** Inline if statement to shift the Text if collapse sym is shown */
/** What the hell is this code btw (didn't found a better way) */
l->DrawText(self->FinalPos() + fvec2(Flags & UI7MenuFlags_NoClose
? 0
l->DrawText(self->FinalPos() + fvec2((Flags & UI7MenuFlags_NoCollapse)
? pIO->FramePadding.x
: (TitleBarHeight -
pIO->FramePadding.y * 2 +
(io->FramePadding.x * 2)),
0),
2),
pID.GetName(), io->Theme->Get(UI7Color_Text));
});
r->SetSize(fvec2(pLayout->GetSize().x, TitleBarHeight));
@@ -344,11 +347,11 @@ PD_UI7_API void Menu::Update() {
TitleBarHeight = 0.f;
pLayout->WorkRect.y = 5.f;
}
DrawBaseLayout();
pLayout->Update();
if (Flags & UI7MenuFlags_VtScrolling || Flags & UI7MenuFlags_HzScrolling) {
HandleScrolling();
}
DrawBaseLayout();
pLayout->Update();
}
PD_UI7_API bool Menu::BeginTreeNode(const ID& id) {