From 420edd0677500b95108df21ac1b945a4b6d86923 Mon Sep 17 00:00:00 2001 From: tobid7 Date: Sun, 6 Sep 2026 14:46:22 +0200 Subject: [PATCH] move and fix scrolling to layout Scrolling was hardcoded to 3ds sCrEeNhEiGhT wTh --- include/pd/ui7/flags.hpp | 2 ++ include/pd/ui7/layout.hpp | 2 ++ include/pd/ui7/menu.hpp | 1 - source/ui7/layout.cpp | 38 ++++++++++++++++++++++++++++++++ source/ui7/menu.cpp | 46 ++++----------------------------------- 5 files changed, 46 insertions(+), 43 deletions(-) diff --git a/include/pd/ui7/flags.hpp b/include/pd/ui7/flags.hpp index 960d95e..2e88022 100644 --- a/include/pd/ui7/flags.hpp +++ b/include/pd/ui7/flags.hpp @@ -58,6 +58,8 @@ enum UI7MenuFlags_ { enum UI7LayoutFlags_ { UI7LayoutFlags_None = 0, ///< No Flags used UI7LayoutFlags_UseClipRect = 1 << 0, ///< Enable ClipRect + UI7LayoutFlags_HzScrolling = 1 << 1, ///< Scrolling Horizontal + UI7LayoutFlags_VtScrolling = 1 << 2, ///< Scrolling Vertical }; /** UI7 Context Flags */ diff --git a/include/pd/ui7/layout.hpp b/include/pd/ui7/layout.hpp index 79d2945..2ce377c 100644 --- a/include/pd/ui7/layout.hpp +++ b/include/pd/ui7/layout.hpp @@ -163,6 +163,8 @@ class PD_API Layout { void SetAlign(UI7Align a) { Alignment = a; } void NextAlign(UI7Align a) { TempAlign = a; } + void HandleScrolling(); + void Update(); fvec2 DbgScrollOffset() { return ScrollOffset; } diff --git a/include/pd/ui7/menu.hpp b/include/pd/ui7/menu.hpp index 05553bf..93f3a7d 100644 --- a/include/pd/ui7/menu.hpp +++ b/include/pd/ui7/menu.hpp @@ -110,7 +110,6 @@ class PD_API Menu { void EndTreeNode(); void HandleFocus(); - void HandleScrolling(); void HandleTitlebarActions(); void DrawBaseLayout(); diff --git a/source/ui7/layout.cpp b/source/ui7/layout.cpp index d94049f..d6cb1cb 100644 --- a/source/ui7/layout.cpp +++ b/source/ui7/layout.cpp @@ -21,6 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include #include #include @@ -122,6 +123,42 @@ PD_API fvec2 Layout::AlignPosition(fvec2 pos, fvec2 size, fvec4 area, return p; } +PD_API void Layout::HandleScrolling() { + if (Flags & UI7LayoutFlags_VtScrolling) { + bool allowed = MaxPosition.y > WorkRect.w; + if (allowed) { + if (PD::Hid::IsEvent(Hid::Event::Down, PD::Hid::Gamepad::Touch) || + PD::Hid::IsEvent(Hid::Event::Down, PD::Hid::Keyboard::MouseLeft)) { + ScrollStart = ScrollOffset; + } + if (IO.InputHandler.DragObject(UI7::ID("sbg" + ID.GetName()), + fvec4(Pos, fvec2(0.f)) + WorkRect)) { + if (!IO.InputHandler.DragReleasedAW) { + ScrollOffset.y = + std::clamp(ScrollStart.y + IO.InputHandler.DragSourcePos.y - + IO.InputHandler.DragPosition.y, + -20.f, MaxPosition.y - WorkRect.w + 20.f); + } + } + } else { + ScrollOffset.y = 0.f; + } + + if (ScrollOffset.y > MaxPosition.y - WorkRect.w) { + ScrollOffset.y -= 1.5f; + if (ScrollOffset.y < MaxPosition.y - WorkRect.w) { + ScrollOffset.y = MaxPosition.y - WorkRect.w; + } + } + if (ScrollOffset.y < 0) { + ScrollOffset.y += 1.5f; + if (ScrollOffset.y > 0) { + ScrollOffset.y = 0; + } + } + } +} + PD_API void Layout::Update() { if (Size == fvec2(0.f)) { Size = fvec2(MaxPosition) + IO.MenuPadding * 2; @@ -155,6 +192,7 @@ PD_API void Layout::Update() { Objects.clear(); WorkRect = fvec4(fvec2(WorkRect.x, WorkRect.y), Size - IO.MenuPadding); CursorInit(); + HandleScrolling(); } /** SECTION CONTAINERS (STOLEN FROM FORMER MENU) */ diff --git a/source/ui7/menu.cpp b/source/ui7/menu.cpp index f6b273b..45e0fde 100644 --- a/source/ui7/menu.cpp +++ b/source/ui7/menu.cpp @@ -147,45 +147,6 @@ PD_API void Menu::HandleFocus() { } } -/** Todo: (func name is self describing) */ -PD_API void Menu::HandleScrolling() { - if (Flags & UI7MenuFlags_VtScrolling) { - bool allowed = - pLayout.MaxPosition.y > (pLayout.WorkRect.w - pLayout.WorkRect.y); - if (allowed) { - if (PD::Hid::IsEvent(Hid::Event::Down, PD::Hid::Gamepad::Touch)) { - pLayout.ScrollStart = pLayout.ScrollOffset; - } - if (pIO.InputHandler.DragObject( - "sbg" + pID.GetName(), - 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_API void Menu::HandleTitlebarActions() { // Collapse if (!(Flags & UI7MenuFlags_NoCollapse)) { @@ -358,6 +319,10 @@ PD_API void Menu::Update() { if (pLayout.Size == fvec2(0.f) || Flags & UI7MenuFlags_AlwaysAutoSize) { pLayout.Size = fvec2(pLayout.MaxPosition) + pIO.MenuPadding * 2; } + if (Flags & UI7MenuFlags_VtScrolling) + pLayout.Flags |= UI7LayoutFlags_VtScrolling; + if (Flags & UI7MenuFlags_HzScrolling) + pLayout.Flags |= UI7LayoutFlags_HzScrolling; if (!(Flags & UI7MenuFlags_NoTitlebar)) { TitleBarHeight = pIO.FontScale * pIO.Font->PixelHeight + pIO.MenuPadding.y; pLayout.WorkRect.y = 5.f + TitleBarHeight; @@ -368,9 +333,6 @@ PD_API void Menu::Update() { } DrawBaseLayout(); pLayout.Update(); - if (Flags & UI7MenuFlags_VtScrolling || Flags & UI7MenuFlags_HzScrolling) { - HandleScrolling(); - } } PD_API bool Menu::BeginTreeNode(const ID& id) {