WIP: Add CLipRects to UI7 Layouts

- Added Scissor Support to Font Rendering
This commit is contained in:
2026-01-28 07:11:56 +01:00
parent 090656b30c
commit 21b45f5855
10 changed files with 34 additions and 14 deletions

View File

@@ -90,6 +90,7 @@ file(GLOB_RECURSE PD_FMTFILES CONFIGURE_DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/backends/3ds/include/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/backends/desktop/include/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/backends/3ds/include/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/source*.cpp
)
add_custom_target(pd-clang-format

View File

@@ -44,6 +44,7 @@ enum LiTextFlags_ {
namespace PD {
class Context;
namespace Li {
class DrawList;
class PD_API Font {
public:
/** Codepoint Data holder */
@@ -93,7 +94,7 @@ class PD_API Font {
/**
* Extended Draw Text Function that vreates a Command List
*/
void CmdTextEx(CmdPool& cmds, const fvec2& pos, u32 color, float scale,
void CmdTextEx(DrawList& dl, const fvec2& pos, u32 color, float scale,
const std::string& text, LiTextFlags flags = 0,
const fvec2& box = 0);

View File

@@ -113,6 +113,11 @@ class PD_API Container {
/** Template function to update internal data (if needed) */
virtual void Update() {}
/** Internal function */
void PreDraw();
/** Internal function */
void PostDraw();
/** Internal Input Handler */
void HandleInternalInput();

View File

@@ -178,6 +178,7 @@ class PD_API Layout {
UI7::ID ID;
UI7::IO::Ref IO;
Li::DrawList::Ref DrawList;
UI7LayoutFlags Flags;
// Positioning
fvec2 Pos;

View File

@@ -288,7 +288,7 @@ PD_API void DrawList::DrawText(const fvec2& pos, const std::string& text,
if (!pCurrentFont) {
return;
}
pCurrentFont->CmdTextEx(pPool, pos, color, pFontScale, text);
pCurrentFont->CmdTextEx(*this, pos, color, pFontScale, text);
}
PD_API void DrawList::DrawTextEx(const fvec2& p, const std::string& text,
@@ -297,7 +297,7 @@ PD_API void DrawList::DrawTextEx(const fvec2& p, const std::string& text,
if (!pCurrentFont) {
return;
}
pCurrentFont->CmdTextEx(pPool, p, color, pFontScale, text, flags, box);
pCurrentFont->CmdTextEx(*this, p, color, pFontScale, text, flags, box);
}
PD_API void DrawList::DrawLine(const fvec2& a, const fvec2& b, u32 color,

View File

@@ -28,6 +28,7 @@ SOFTWARE.
#define PD_TRUETYPE_IMPLEMENTATION
#endif
#include <pd/external/stb_truetype.hpp>
#include <pd/lithium/drawlist.hpp>
#include <pd/lithium/renderer.hpp>
#ifdef PD_LI_INCLUDE_FONTS
@@ -246,7 +247,7 @@ PD_API fvec2 Font::GetTextBounds(const std::string& text, float scale) {
return res;
}
PD_API void Font::CmdTextEx(CmdPool& cmds, const fvec2& pos, u32 color,
PD_API void Font::CmdTextEx(DrawList& dl, const fvec2& pos, u32 color,
float scale, const std::string& text,
LiTextFlags flags, const fvec2& box) {
fvec2 off;
@@ -291,7 +292,7 @@ PD_API void Font::CmdTextEx(CmdPool& cmds, const fvec2& pos, u32 color,
it = pShortText(it, scale, box - pos, tmp_dim);
}
auto wline = Strings::MakeWstring(it);
auto cmd = cmds.NewCmd();
auto cmd = dl.GetNewCmd();
auto Tex = GetCodepoint(wline[0]).Tex;
if (Tex) {
cmd->Tex = Tex->Address;
@@ -303,7 +304,7 @@ PD_API void Font::CmdTextEx(CmdPool& cmds, const fvec2& pos, u32 color,
continue;
}
if (Tex != cp.Tex) {
cmd = cmds.NewCmd();
cmd = dl.GetNewCmd();
Tex = cp.Tex;
if (Tex) {
cmd->Tex = Tex->Address;

View File

@@ -40,5 +40,18 @@ PD_API void Container::HandleScrolling(fvec2 scrolling, fvec4 viewport) {
PD_API void Container::HandleInternalInput() {
/** Requires Handle Scrolling First */
}
/** Internal function */
PD_API void Container::PreDraw() {
if (pCLipRectUsed) {
list->PushClipRect(pClipRect);
}
}
/** Internal function */
PD_API void Container::PostDraw() {
if (pCLipRectUsed) {
list->PopClipRect();
}
}
} // namespace UI7
} // namespace PD

View File

@@ -28,14 +28,8 @@ namespace UI7 {
PD_API void Label::Draw() {
// Assert(io.get() && list.get(), "Did you run Container::Init correctly?");
// io->Ren->OnScreen(screen);
if (pCLipRectUsed) {
list->PushClipRect(pClipRect);
}
list->DrawTextEx(FinalPos(), label, io->Theme->Get(UI7Color_Text),
LiTextFlags_NoOOS, PD::fvec2(0, io->CurrentViewPort.w));
if (pCLipRectUsed) {
list->PopClipRect();
}
}
PD_API void Label::Update() {

View File

@@ -125,7 +125,12 @@ PD_API void Layout::Update() {
it->SetPos(it->GetPos() + Pos);
it->HandleInput();
it->UnlockInput();
if (Flags & UI7LayoutFlags_UseClipRect) {
it->SetClipRect(fvec4(Pos, Size));
}
it->PreDraw();
it->Draw();
it->PostDraw();
}
}

View File

@@ -30,14 +30,13 @@ Menu::Menu(const ID& id, IO::Ref io) : pIO(io), pID(id) {
pLayout = Layout::New(id, io);
TitleBarHeight = pIO->FontScale * pIO->Font->PixelHeight + pIO->MenuPadding.y;
pLayout->WorkRect.y += TitleBarHeight;
pLayout->Flags |= UI7LayoutFlags_UseClipRect;
pLayout->CursorInit();
}
PD_API void Menu::Label(const std::string& label) {
// Layout API
auto r = Label::New(label, pIO);
r->SetClipRect(fvec4(pLayout->GetPosition(),
pLayout->GetPosition() + pLayout->GetSize()));
pLayout->AddObject(r);
}