move and fix scrolling to layout

Scrolling was hardcoded to 3ds sCrEeNhEiGhT wTh
This commit is contained in:
2026-09-06 14:46:22 +02:00
parent e8a9055090
commit 420edd0677
5 changed files with 46 additions and 43 deletions
+2
View File
@@ -58,6 +58,8 @@ enum UI7MenuFlags_ {
enum UI7LayoutFlags_ { enum UI7LayoutFlags_ {
UI7LayoutFlags_None = 0, ///< No Flags used UI7LayoutFlags_None = 0, ///< No Flags used
UI7LayoutFlags_UseClipRect = 1 << 0, ///< Enable ClipRect UI7LayoutFlags_UseClipRect = 1 << 0, ///< Enable ClipRect
UI7LayoutFlags_HzScrolling = 1 << 1, ///< Scrolling Horizontal
UI7LayoutFlags_VtScrolling = 1 << 2, ///< Scrolling Vertical
}; };
/** UI7 Context Flags */ /** UI7 Context Flags */
+2
View File
@@ -163,6 +163,8 @@ class PD_API Layout {
void SetAlign(UI7Align a) { Alignment = a; } void SetAlign(UI7Align a) { Alignment = a; }
void NextAlign(UI7Align a) { TempAlign = a; } void NextAlign(UI7Align a) { TempAlign = a; }
void HandleScrolling();
void Update(); void Update();
fvec2 DbgScrollOffset() { return ScrollOffset; } fvec2 DbgScrollOffset() { return ScrollOffset; }
-1
View File
@@ -110,7 +110,6 @@ class PD_API Menu {
void EndTreeNode(); void EndTreeNode();
void HandleFocus(); void HandleFocus();
void HandleScrolling();
void HandleTitlebarActions(); void HandleTitlebarActions();
void DrawBaseLayout(); void DrawBaseLayout();
+38
View File
@@ -21,6 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
#include <algorithm>
#include <pd/ui7/containers.hpp> #include <pd/ui7/containers.hpp>
#include <pd/ui7/layout.hpp> #include <pd/ui7/layout.hpp>
@@ -122,6 +123,42 @@ PD_API fvec2 Layout::AlignPosition(fvec2 pos, fvec2 size, fvec4 area,
return p; 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() { PD_API void Layout::Update() {
if (Size == fvec2(0.f)) { if (Size == fvec2(0.f)) {
Size = fvec2(MaxPosition) + IO.MenuPadding * 2; Size = fvec2(MaxPosition) + IO.MenuPadding * 2;
@@ -155,6 +192,7 @@ PD_API void Layout::Update() {
Objects.clear(); Objects.clear();
WorkRect = fvec4(fvec2(WorkRect.x, WorkRect.y), Size - IO.MenuPadding); WorkRect = fvec4(fvec2(WorkRect.x, WorkRect.y), Size - IO.MenuPadding);
CursorInit(); CursorInit();
HandleScrolling();
} }
/** SECTION CONTAINERS (STOLEN FROM FORMER MENU) */ /** SECTION CONTAINERS (STOLEN FROM FORMER MENU) */
+4 -42
View File
@@ -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() { PD_API void Menu::HandleTitlebarActions() {
// Collapse // Collapse
if (!(Flags & UI7MenuFlags_NoCollapse)) { if (!(Flags & UI7MenuFlags_NoCollapse)) {
@@ -358,6 +319,10 @@ PD_API void Menu::Update() {
if (pLayout.Size == fvec2(0.f) || Flags & UI7MenuFlags_AlwaysAutoSize) { if (pLayout.Size == fvec2(0.f) || Flags & UI7MenuFlags_AlwaysAutoSize) {
pLayout.Size = fvec2(pLayout.MaxPosition) + pIO.MenuPadding * 2; 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)) { if (!(Flags & UI7MenuFlags_NoTitlebar)) {
TitleBarHeight = pIO.FontScale * pIO.Font->PixelHeight + pIO.MenuPadding.y; TitleBarHeight = pIO.FontScale * pIO.Font->PixelHeight + pIO.MenuPadding.y;
pLayout.WorkRect.y = 5.f + TitleBarHeight; pLayout.WorkRect.y = 5.f + TitleBarHeight;
@@ -368,9 +333,6 @@ PD_API void Menu::Update() {
} }
DrawBaseLayout(); DrawBaseLayout();
pLayout.Update(); pLayout.Update();
if (Flags & UI7MenuFlags_VtScrolling || Flags & UI7MenuFlags_HzScrolling) {
HandleScrolling();
}
} }
PD_API bool Menu::BeginTreeNode(const ID& id) { PD_API bool Menu::BeginTreeNode(const ID& id) {