# Small Update

- Start some work on scrolling
This commit is contained in:
2025-10-18 17:00:35 +02:00
parent 3823f08bab
commit 0ecf559fbb
4 changed files with 53 additions and 2 deletions

View File

@@ -131,6 +131,7 @@ class PD_UI7_API Layout {
// Scrolling (Only theoretical) // Scrolling (Only theoretical)
// Rendering must be done by the Objective that uses the Lyt // Rendering must be done by the Objective that uses the Lyt
fvec2 ScrollOffset; fvec2 ScrollOffset;
fvec2 ScrollStart;
bool Scrolling[2]; bool Scrolling[2];
// Objects // Objects

View File

@@ -45,6 +45,10 @@ class PD_UI7_API Menu {
* @param label The text to draw * @param label The text to draw
*/ */
void Label(const std::string &label); void Label(const std::string &label);
template <typename... Args>
void Label(std::format_string<Args...> s, Args &&...args) {
Label(std::format(s, std::forward<Args>(args)...));
}
/** /**
* Render a Button * Render a Button
* @param label The buttons text * @param label The buttons text
@@ -110,6 +114,7 @@ class PD_UI7_API Menu {
bool *pIsShown = nullptr; bool *pIsShown = nullptr;
bool pIsOpen = true; bool pIsOpen = true;
std::unordered_map<u32, bool> pTreeNodes; std::unordered_map<u32, bool> pTreeNodes;
fvec2 TempScrollXY;
float TitleBarHeight = 0.f; float TitleBarHeight = 0.f;
}; };

View File

@@ -46,5 +46,5 @@ PD_CORE_API void Timer::Pause() { pIsRunning = false; }
PD_CORE_API void Timer::Rseume() { pIsRunning = true; } PD_CORE_API void Timer::Rseume() { pIsRunning = true; }
PD_CORE_API bool Timer::IsRunning() const { return pIsRunning; } PD_CORE_API bool Timer::IsRunning() const { return pIsRunning; }
PD_CORE_API u64 Timer::Get() { return pNow - pStart; } 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 } // namespace PD

View File

@@ -132,7 +132,43 @@ PD_UI7_API void Menu::HandleFocus() {
} }
/** Todo: (func name is self describing) */ /** 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() { PD_UI7_API void Menu::HandleTitlebarActions() {
// Collapse // Collapse
@@ -196,6 +232,7 @@ PD_UI7_API void Menu::HandleTitlebarActions() {
} }
} }
} }
PD_UI7_API void Menu::DrawBaseLayout() { PD_UI7_API void Menu::DrawBaseLayout() {
if (pIsOpen) { if (pIsOpen) {
/** Resize Sym (Render on Top of Everything) */ /** Resize Sym (Render on Top of Everything) */
@@ -300,7 +337,15 @@ PD_UI7_API void Menu::DrawBaseLayout() {
PD_UI7_API void Menu::Update() { PD_UI7_API void Menu::Update() {
HandleFocus(); HandleFocus();
if (!(Flags & UI7MenuFlags_NoTitlebar)) { if (!(Flags & UI7MenuFlags_NoTitlebar)) {
TitleBarHeight = pIO->FontScale * 30.f;
pLayout->WorkRect.y = 5.f + TitleBarHeight;
HandleTitlebarActions(); HandleTitlebarActions();
} else {
TitleBarHeight = 0.f;
pLayout->WorkRect.y = 5.f;
}
if (Flags & UI7MenuFlags_VtScrolling || Flags & UI7MenuFlags_HzScrolling) {
HandleScrolling();
} }
DrawBaseLayout(); DrawBaseLayout();
pLayout->Update(); pLayout->Update();