diff --git a/include/pd/lithium/drawlist.hpp b/include/pd/lithium/drawlist.hpp index 6367c7d..69dac7c 100755 --- a/include/pd/lithium/drawlist.hpp +++ b/include/pd/lithium/drawlist.hpp @@ -198,6 +198,7 @@ class PD_LITHIUM_API DrawList { } pClipRects.pop(); } + const std::vector& Data() const { return pDrawList; } /** One linear Clip rect Setup */ void pClipCmd(Command* cmd); diff --git a/include/pd/lithium/font.hpp b/include/pd/lithium/font.hpp index 4f7d34a..4aed25e 100755 --- a/include/pd/lithium/font.hpp +++ b/include/pd/lithium/font.hpp @@ -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 { @@ -104,7 +105,7 @@ class PD_LITHIUM_API Font { std::string pWrapText(const std::string& txt, float scale, const PD::fvec2& max, PD::fvec2& dim); std::string pShortText(const std::string& txt, float scale, - const PD::fvec2& max, PD::fvec2& dim); + const PD::fvec2& max, PD::fvec2& dim); /** Data Section */ int PixelHeight; diff --git a/include/pd/ui7/container/label.hpp b/include/pd/ui7/container/label.hpp index 90246d3..a535b24 100755 --- a/include/pd/ui7/container/label.hpp +++ b/include/pd/ui7/container/label.hpp @@ -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 diff --git a/include/pd/ui7/io.hpp b/include/pd/ui7/io.hpp index 87ea83c..da5a776 100755 --- a/include/pd/ui7/io.hpp +++ b/include/pd/ui7/io.hpp @@ -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> DrawListRegestry; diff --git a/pd/lithium/source/font.cpp b/pd/lithium/source/font.cpp index bb57c67..c602467 100755 --- a/pd/lithium/source/font.cpp +++ b/pd/lithium/source/font.cpp @@ -272,6 +272,15 @@ PD_LITHIUM_API void Font::CmdTextEx(std::vector &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); diff --git a/pd/ui7/source/container/label.cpp b/pd/ui7/source/container/label.cpp index 4616f03..67b7dfd 100755 --- a/pd/ui7/source/container/label.cpp +++ b/pd/ui7/source/container/label.cpp @@ -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 \ No newline at end of file diff --git a/pd/ui7/source/menu.cpp b/pd/ui7/source/menu.cpp index 621d3e9..717d6ae 100755 --- a/pd/ui7/source/menu.cpp +++ b/pd/ui7/source/menu.cpp @@ -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() {