diff --git a/include/pd/ui7/layout.hpp b/include/pd/ui7/layout.hpp index 2b84e15..8ecd58f 100755 --- a/include/pd/ui7/layout.hpp +++ b/include/pd/ui7/layout.hpp @@ -131,6 +131,7 @@ class PD_UI7_API Layout { // Scrolling (Only theoretical) // Rendering must be done by the Objective that uses the Lyt fvec2 ScrollOffset; + fvec2 ScrollStart; bool Scrolling[2]; // Objects diff --git a/include/pd/ui7/menu.hpp b/include/pd/ui7/menu.hpp index cf50ff2..257a8a2 100755 --- a/include/pd/ui7/menu.hpp +++ b/include/pd/ui7/menu.hpp @@ -45,6 +45,10 @@ class PD_UI7_API Menu { * @param label The text to draw */ void Label(const std::string &label); + template + void Label(std::format_string s, Args &&...args) { + Label(std::format(s, std::forward(args)...)); + } /** * Render a Button * @param label The buttons text @@ -110,6 +114,7 @@ class PD_UI7_API Menu { bool *pIsShown = nullptr; bool pIsOpen = true; std::unordered_map pTreeNodes; + fvec2 TempScrollXY; float TitleBarHeight = 0.f; }; diff --git a/pd/core/source/timer.cpp b/pd/core/source/timer.cpp index 09f511d..24d7795 100755 --- a/pd/core/source/timer.cpp +++ b/pd/core/source/timer.cpp @@ -46,5 +46,5 @@ PD_CORE_API void Timer::Pause() { pIsRunning = false; } PD_CORE_API void Timer::Rseume() { pIsRunning = true; } PD_CORE_API bool Timer::IsRunning() const { return pIsRunning; } PD_CORE_API u64 Timer::Get() { return pNow - pStart; } -PD_CORE_API double Timer::GetSeconds() { return double(Get()) / 1000.0; } +PD_CORE_API double Timer::GetSeconds() { return (double)Get() / 1000.0; } } // namespace PD \ No newline at end of file diff --git a/pd/ui7/source/menu.cpp b/pd/ui7/source/menu.cpp index 1bec39b..af53d10 100755 --- a/pd/ui7/source/menu.cpp +++ b/pd/ui7/source/menu.cpp @@ -132,7 +132,43 @@ PD_UI7_API void Menu::HandleFocus() { } /** Todo: (func name is self describing) */ -PD_UI7_API void Menu::HandleScrolling() {} +PD_UI7_API void Menu::HandleScrolling() { + if (Flags & UI7MenuFlags_VtScrolling) { + bool allowed = + pLayout->MaxPosition.y > (pLayout->WorkRect.w - pLayout->WorkRect.y); + if (allowed) { + if (PD::Hid::IsDown(PD::Hid::Key::Touch)) { + pLayout->ScrollStart = pLayout->ScrollOffset; + } + if (pIO->InputHandler->DragObject( + "sbg" + pID.pName, + fvec4(pLayout->Pos, fvec2(0.f)) + pLayout->WorkRect)) { + if (pIO->InputHandler->DragReleasedAW) { + } else { + pLayout->ScrollOffset.y = std::clamp( + pLayout->ScrollStart.y + pIO->InputHandler->DragSourcePos.y - + pIO->InputHandler->DragPosition.y, + 20.f, pLayout->MaxPosition.y - 220); + } + } + } else { + pLayout->ScrollOffset.y = 0.f; + } + + if (pLayout->ScrollOffset.y > pLayout->MaxPosition.y - 240) { + pLayout->ScrollOffset.y -= 1.5; + if (pLayout->ScrollOffset.y < pLayout->MaxPosition.y - 240) { + pLayout->ScrollOffset.y = pLayout->MaxPosition.y - 240; + } + } + if (pLayout->ScrollOffset.y < 0) { + pLayout->ScrollOffset.y += 1.5; + if (pLayout->ScrollOffset.y > 0) { + pLayout->ScrollOffset.y = 0; + } + } + } +} PD_UI7_API void Menu::HandleTitlebarActions() { // Collapse @@ -196,6 +232,7 @@ PD_UI7_API void Menu::HandleTitlebarActions() { } } } + PD_UI7_API void Menu::DrawBaseLayout() { if (pIsOpen) { /** Resize Sym (Render on Top of Everything) */ @@ -300,7 +337,15 @@ PD_UI7_API void Menu::DrawBaseLayout() { PD_UI7_API void Menu::Update() { HandleFocus(); if (!(Flags & UI7MenuFlags_NoTitlebar)) { + TitleBarHeight = pIO->FontScale * 30.f; + pLayout->WorkRect.y = 5.f + TitleBarHeight; HandleTitlebarActions(); + } else { + TitleBarHeight = 0.f; + pLayout->WorkRect.y = 5.f; + } + if (Flags & UI7MenuFlags_VtScrolling || Flags & UI7MenuFlags_HzScrolling) { + HandleScrolling(); } DrawBaseLayout(); pLayout->Update();