UI7 Add Containers to Layout

- Hotfix in CommandPool
- Add UI7 ItemRowHeight (Universal Item Size/Height)
- Add Containers to Layout
- Add ColorEdit to Menu
- Switch Back to COlorEdit in UI7::StyleEditor
- Add DrawList Layer Sorting to UI7 (Not working as expected)
- STart Work at ColorEdit container
This commit is contained in:
2026-01-24 11:58:41 +01:00
parent 4a73e8c8da
commit b2c7c1fdbf
11 changed files with 196 additions and 40 deletions

View File

@@ -67,8 +67,8 @@ class Command {
std::vector<u16> IndexBuffer;
ivec4 ScissorRect;
bool ScissorOn = false;
int Layer;
int Index;
int Layer = 0;
int Index = 0;
Texture::Ref Tex;
};
@@ -94,7 +94,7 @@ class PD_LITHIUM_API CmdPool {
static bool pTheOrder(const Command::Ref& a, const Command::Ref& b);
friend class DrawList;
Command::Ref* begin() { return &pPool[0]; }
Command::Ref* end() { return &pPool[pPoolIdx]; }
Command::Ref* end() { return &pPool[pPoolIdx - 1]; }
std::vector<Command::Ref> pPool;
u32 pPoolIdx = 0;
int Layer = 0;

View File

@@ -73,6 +73,7 @@ class PD_UI7_API IO {
UI7::Theme::Ref Theme;
fvec2 MenuPadding = 5.f;
fvec2 FramePadding = 5.f;
float ItemRowHeight = 0.f;
float FrameRounding = 0.f;
fvec2 ItemSpace = vec2(5.f, 2.f);
fvec2 MinSliderDragSize = 10.f; // Min height (Vt) and Min Width (Hz)

View File

@@ -26,6 +26,8 @@ SOFTWARE.
#include <pd/core/core.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/pd_p_api.hpp>
@@ -35,7 +37,7 @@ namespace PD {
namespace UI7 {
class PD_UI7_API Layout {
public:
Layout(const ID& id, IO::Ref io) : ID(id) {
Layout(const ID &id, IO::Ref io) : ID(id) {
this->IO = io;
DrawList = Li::DrawList::New();
DrawList->SetFont(IO->Font);
@@ -51,21 +53,86 @@ class PD_UI7_API Layout {
PD_SHARED(Layout);
const std::string GetName() const { return ID.GetName(); }
const UI7::ID& GetID() const { return this->ID; }
/** 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::Ref 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::Ref r = FindObject(id);
if (!r) {
r = UI7::DragData<T>::New(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::Ref r = FindObject(id);
if (!r) {
r = UI7::Slider<T>::New(label, data, this->IO, min, max, precision);
r->SetID(id);
}
AddObject(r);
}
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; }
/** 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::Ref GetDrawList() { return DrawList; }
void CursorInit();
void SameLine();
void CursorMove(const fvec2& size);
void CursorMove(const fvec2 &size);
bool ObjectWorkPos(fvec2& movpos);
bool ObjectWorkPos(fvec2 &movpos);
/**
* Extended Object Add Func to Add Object in Front or disable

View File

@@ -105,6 +105,7 @@ class PD_UI7_API Menu {
}
pLayout->AddObject(r);
}
void ColorEdit(const std::string &label, u32 &clr);
void SameLine() { pLayout->SameLine(); }
void Separator();
void SeparatorText(const std::string &label);

View File

@@ -65,6 +65,7 @@ PD_LITHIUM_API void PD::Li::CmdPool::Copy(CmdPool& p) {
}
PD_LITHIUM_API void PD::Li::CmdPool::Sort() {
if (pPoolIdx < 2) return;
std::sort(begin(), end(), pTheOrder);
}

View File

@@ -61,6 +61,7 @@ PD_UI7_API void Checkbox::Draw() {
PD_UI7_API void Checkbox::Update() {
// Assert(io.get(), "Did you run Container::Init correctly?");
cbs = io->ItemRowHeight;
this->SetSize(cbs + fvec2(tdim.x + io->ItemSpace.x, 0));
}
} // namespace UI7

View File

@@ -22,7 +22,7 @@ SOFTWARE.
*/
#include <pd/ui7/container/coloredit.hpp>
#include <pd/ui7/container/label.hpp>
#include <pd/ui7/containers.hpp>
namespace PD {
namespace UI7 {
@@ -33,8 +33,9 @@ PD_UI7_API void ColorEdit::HandleInput() {
}
// Assert(screen.get(), "Screen is not set up!");
// if (screen->ScreenType() == Screen::Bottom) {
if (io->InputHandler->DragObject(this->GetID(), fvec4(FinalPos(), size))) {
if (io->InputHandler->DragReleased) {
if (io->InputHandler->DragObject(this->GetID() + 2,
fvec4(FinalPos(), size))) {
if (io->InputHandler->DragReleasedAW) {
is_shown = !is_shown;
}
}
@@ -44,15 +45,45 @@ PD_UI7_API void ColorEdit::HandleInput() {
PD_UI7_API void ColorEdit::Draw() {
// Assert(io.get() && list.get(), "Did you run Container::Init correctly?");
// io->Ren->OnScreen(screen);
list->PathRect(FinalPos(), FinalPos() + 18, io->FrameRounding);
list->PathRect(FinalPos(), FinalPos() + io->ItemRowHeight, io->FrameRounding);
list->PathFill(*color_ref);
list->DrawText(FinalPos() + fvec2(io->ItemSpace.x + 18, 0), label,
io->Theme->Get(UI7Color_Text));
list->DrawText(FinalPos() + fvec2(io->ItemSpace.x + io->ItemRowHeight, 0),
label, io->Theme->Get(UI7Color_Text));
if (is_shown) {
if (!layout) {
layout = Layout::New(GetID(), io);
}
layout->AddObject(Label::New("Hello World!", io));
layout->SetPosition(FinalPos());
layout->AddObjectEx(
DynObj::New(
[=, this](UI7::IO::Ref io, Li::DrawList::Ref l, Container* thiz) {
thiz->SetSize(layout->GetSize());
l->Layer(30);
l->PathRect(thiz->GetPos(), thiz->GetPos() + thiz->GetSize(),
io->FrameRounding);
l->PathFill(io->Theme->Get(UI7Color_FrameBackground));
}),
UI7LytAdd_Front | UI7LytAdd_NoCursorUpdate | UI7LytAdd_NoScrollHandle);
auto obj = DynObj::New(
[=, this](UI7::IO::Ref io, Li::DrawList::Ref l, Container* thiz) {
l->PathRect(thiz->FinalPos(), thiz->FinalPos() + io->ItemRowHeight,
io->FrameRounding);
l->PathFill(*color_ref);
l->DrawText(
thiz->FinalPos() + fvec2(io->ItemSpace.x + io->ItemRowHeight, 0),
label, io->Theme->Get(UI7Color_Text));
});
obj->SetSize(PD::fvec2(200, io->ItemRowHeight));
layout->AddObject(obj);
layout->Label("RGBA: ({}, {}, {}, {})", *((u8*)color_ref),
*(((u8*)color_ref) + 1), *(((u8*)color_ref) + 2),
*(((u8*)color_ref) + 3));
layout->Label("Hex: {}", PD::Color(*color_ref).Hex(true));
layout->Slider<u8>("R", ((u8*)color_ref));
layout->Slider<u8>("G", ((u8*)color_ref) + 1);
layout->Slider<u8>("B", ((u8*)color_ref) + 2);
layout->Slider<u8>("A", ((u8*)color_ref) + 3);
layout->Update();
list->Merge(layout->GetDrawList());
// io->RegisterDrawList(GetID(), layout->GetDrawList());
@@ -61,7 +92,8 @@ PD_UI7_API void ColorEdit::Draw() {
PD_UI7_API void ColorEdit::Update() {
// Assert(io.get(), "Did you run Container::Init correctly?");
this->SetSize(fvec2(tdim.x + io->ItemSpace.x + 18, 18));
this->SetSize(
fvec2(tdim.x + io->ItemSpace.x + io->ItemRowHeight, io->ItemRowHeight));
}
} // namespace UI7
} // namespace PD

View File

@@ -36,6 +36,7 @@ PD_UI7_API void UI7::IO::Update() {
Framerate = 1000.f / Delta;
DrawListRegestry.clear();
DrawListRegestry.push_front(std::make_pair("CtxBackList", Back));
if (Font) ItemRowHeight = FontScale * Font->PixelHeight;
// RegisterDrawList("CtxBackList", Back);
NumIndices = FDL->pNumIndices;
NumVertices = FDL->pNumVertices;

View File

@@ -21,6 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/ui7/containers.hpp>
#include <pd/ui7/layout.hpp>
namespace PD {
@@ -114,7 +115,7 @@ PD_UI7_API fvec2 Layout::AlignPosition(fvec2 pos, fvec2 size, fvec4 area,
PD_UI7_API void Layout::Update() {
if (Size == fvec2(0.f)) {
Size = fvec2(MaxPosition);
Size = fvec2(MaxPosition) + IO->MenuPadding * 2;
}
for (auto& it : Objects) {
if (it->GetID() != 0 && !FindObject(it->GetID())) {
@@ -140,5 +141,45 @@ PD_UI7_API void Layout::Update() {
WorkRect = fvec4(fvec2(WorkRect.x, WorkRect.y), Size - IO->MenuPadding);
CursorInit();
}
/** SECTION CONTAINERS (STOLEN FROM FORMER MENU) */
PD_UI7_API void Layout::Label(const std::string& label) {
// Layout API
auto r = Label::New(label, IO);
r->SetClipRect(fvec4(GetPosition(), GetPosition() + GetSize()));
AddObject(r);
}
PD_UI7_API bool Layout::Button(const std::string& label) {
bool ret = false;
u32 id = Strings::FastHash("btn" + label + std::to_string(Objects.size()));
Container::Ref r = FindObject(id);
if (!r) {
r = Button::New(label, IO);
r->SetID(id);
}
AddObject(r);
if (!r->Skippable()) {
ret = std::static_pointer_cast<UI7::Button>(r)->IsPressed();
}
return ret;
}
PD_UI7_API void Layout::Checkbox(const std::string& label, bool& v) {
u32 id = Strings::FastHash("cbx" + label + std::to_string(Objects.size()));
Container::Ref r = FindObject(id);
if (!r) {
r = Checkbox::New(label, v, IO);
r->SetID(id);
}
AddObject(r);
}
PD_UI7_API void Layout::Image(Li::Texture::Ref img, fvec2 size, Li::Rect uv) {
Container::Ref r = Image::New(img, size, uv);
AddObject(r);
}
} // namespace UI7
} // namespace PD

View File

@@ -29,7 +29,7 @@ namespace PD {
namespace UI7 {
Menu::Menu(const ID& id, IO::Ref io) : pIO(io), pID(id) {
pLayout = Layout::New(id, io);
TitleBarHeight = io->FontScale * 30.f;
TitleBarHeight = pIO->FontScale * pIO->Font->PixelHeight + pIO->MenuPadding.y;
pLayout->WorkRect.y += TitleBarHeight;
pLayout->CursorInit();
}
@@ -74,6 +74,16 @@ PD_UI7_API void Menu::Image(Li::Texture::Ref img, fvec2 size, Li::Rect uv) {
pLayout->AddObject(r);
}
PD_UI7_API void Menu::ColorEdit(const std::string& label, u32& clr) {
u32 id = Strings::FastHash("drd" + label);
Container::Ref r = pLayout->FindObject(id);
if (!r) {
r = UI7::ColorEdit::New(label, &clr, pIO);
r->SetID(id);
}
pLayout->AddObject(r);
}
PD_UI7_API void Menu::Separator() {
// Dynamic Objects are very simple...
Container::Ref r = DynObj::New(

View File

@@ -151,6 +151,7 @@ PD_UI7_API void Context::Update() {
}
pCurrentMenus.clear();
pIO->Update();
pIO->FDL->pPool.Sort();
}
PD_UI7_API void Context::AboutMenu(bool *show) {
@@ -322,27 +323,27 @@ PD_UI7_API void UI7::Context::StyleEditor(bool *show) {
UI7::Theme::Flashbang(*pIO->Theme.get());
}
/// Small trick to print without prefix
#define ts(x) m->ColorEdit(std::string(#x).substr(9), &pIO->Theme->GetRef(x));
#define ts(x) m->ColorEdit(std::string(#x).substr(9), pIO->Theme->GetRef(x));
#define ts2(x) \
m->DragData(std::string(#x).substr(9), (u8 *)&pIO->Theme->GetRef(x), 4, \
(u8)0, (u8)255);
ts2(UI7Color_Background);
ts2(UI7Color_Border);
ts2(UI7Color_Button);
ts2(UI7Color_ButtonDead);
ts2(UI7Color_ButtonActive);
ts2(UI7Color_ButtonHovered);
ts2(UI7Color_Text);
ts2(UI7Color_TextDead);
ts2(UI7Color_Header);
ts2(UI7Color_HeaderDead);
ts2(UI7Color_Selector);
ts2(UI7Color_Checkmark);
ts2(UI7Color_FrameBackground);
ts2(UI7Color_FrameBackgroundHovered);
ts2(UI7Color_Progressbar);
ts2(UI7Color_ListEven);
ts2(UI7Color_ListOdd);
ts(UI7Color_Background);
ts(UI7Color_Border);
ts(UI7Color_Button);
ts(UI7Color_ButtonDead);
ts(UI7Color_ButtonActive);
ts(UI7Color_ButtonHovered);
ts(UI7Color_Text);
ts(UI7Color_TextDead);
ts(UI7Color_Header);
ts(UI7Color_HeaderDead);
ts(UI7Color_Selector);
ts(UI7Color_Checkmark);
ts(UI7Color_FrameBackground);
ts(UI7Color_FrameBackgroundHovered);
ts(UI7Color_Progressbar);
ts(UI7Color_ListEven);
ts(UI7Color_ListOdd);
this->EndMenu();
}
}