From 0501a4f87c232fd5cd65e472676b7666e137cb17 Mon Sep 17 00:00:00 2001 From: tobid7 Date: Wed, 18 Mar 2026 21:33:35 +0100 Subject: [PATCH] Make UI7::IO::CurrentViewPort a Reference (finally) --- include/pd/ui7/container/slider.hpp | 2 +- include/pd/ui7/io.hpp | 7 ++++--- include/pd/ui7/layout.hpp | 2 +- source/ui7/container/label.cpp | 13 +++++++------ source/ui7/menu.cpp | 7 ++++--- source/ui7/ui7.cpp | 2 +- 6 files changed, 18 insertions(+), 15 deletions(-) diff --git a/include/pd/ui7/container/slider.hpp b/include/pd/ui7/container/slider.hpp index 5b0fa67..6201ebc 100644 --- a/include/pd/ui7/container/slider.hpp +++ b/include/pd/ui7/container/slider.hpp @@ -55,7 +55,7 @@ class PD_API Slider : public Container { this->min = min; this->max = max; this->precision = precision; - this->width = io->CurrentViewPort.z * 0.3f; + this->width = io->CurrentViewPort->pSize.z * 0.3f; this->tdim = io->Font->GetTextBounds(label, io->FontScale); } ~Slider() = default; diff --git a/include/pd/ui7/io.hpp b/include/pd/ui7/io.hpp index 656b8ff..9aaf4ba 100644 --- a/include/pd/ui7/io.hpp +++ b/include/pd/ui7/io.hpp @@ -43,8 +43,8 @@ class PD_API IO { FDL = Li::DrawList::New(pCtx); DeltaStats = TimeStats::New(60); /** Probably not the best solution i guess */ - CurrentViewPort.z = pCtx.Gfx()->ViewPort.x; - CurrentViewPort.w = pCtx.Gfx()->ViewPort.y; + CurrentViewPort = + ViewPort::New("Default", ivec4(ivec2(0, 0), pCtx.Gfx()->ViewPort)); } ~IO() {} @@ -61,7 +61,8 @@ class PD_API IO { * Possible thanks to the DrawList::Merge Feature */ Li::DrawList::Ref FDL = nullptr; - ivec4 CurrentViewPort = ivec4(0, 0, 0, 0); + ViewPort::Ref CurrentViewPort; + // ivec4 CurrentViewPort = ivec4(0, 0, 0, 0); std::unordered_map ViewPorts; float Framerate = 0.f; float Delta = 0.f; diff --git a/include/pd/ui7/layout.hpp b/include/pd/ui7/layout.hpp index b6cbaef..b69fc87 100644 --- a/include/pd/ui7/layout.hpp +++ b/include/pd/ui7/layout.hpp @@ -45,7 +45,7 @@ class PD_API Layout { Scrolling[0] = false; Scrolling[1] = false; CursorInit(); - Pos = fvec2(io->CurrentViewPort.x, io->CurrentViewPort.y); + Pos = fvec2(io->CurrentViewPort->pSize.x, io->CurrentViewPort->pSize.y); Size = 0; WorkRect = fvec4(IO->MenuPadding, Size - (fvec2(2) * IO->MenuPadding)); } diff --git a/source/ui7/container/label.cpp b/source/ui7/container/label.cpp index b91cf07..a50807a 100755 --- a/source/ui7/container/label.cpp +++ b/source/ui7/container/label.cpp @@ -29,7 +29,8 @@ PD_API void Label::Draw() { // Assert(io.get() && list.get(), "Did you run Container::Init correctly?"); // io->Ren->OnScreen(screen); list->DrawTextEx(FinalPos(), label, io->Theme->Get(UI7Color_Text), - LiTextFlags_NoOOS, PD::fvec2(0, io->CurrentViewPort.w)); + LiTextFlags_NoOOS, + PD::fvec2(0, io->CurrentViewPort->pSize.w)); } PD_API void Label::Update() { @@ -39,11 +40,11 @@ PD_API void Label::Update() { * 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); + this->label = io->Font->pWrapText( + this->label, io->FontScale, + PD::fvec2(io->CurrentViewPort->pSize.z - FinalPos().x * 4, + io->CurrentViewPort->pSize.w), + this->tdim); SetSize(tdim); } } diff --git a/source/ui7/menu.cpp b/source/ui7/menu.cpp index 0c6ba15..d3a7b14 100755 --- a/source/ui7/menu.cpp +++ b/source/ui7/menu.cpp @@ -239,9 +239,10 @@ PD_API void Menu::HandleTitlebarActions() { // Keep Window In Viewport // Maybe i need to add some operators to vec pLayout->Pos.x = std::clamp(pLayout->Pos.x, -pLayout->Size.x + 10, - pIO->CurrentViewPort.z - 10); - pLayout->Pos.y = std::clamp(pLayout->Pos.y, pIO->CurrentViewPort.y, - pIO->CurrentViewPort.w - 10); + pIO->CurrentViewPort->pSize.z - 10); + pLayout->Pos.y = + std::clamp(pLayout->Pos.y, pIO->CurrentViewPort->pSize.y, + pIO->CurrentViewPort->pSize.w - 10); } } } diff --git a/source/ui7/ui7.cpp b/source/ui7/ui7.cpp index 76628be..56fcaa8 100644 --- a/source/ui7/ui7.cpp +++ b/source/ui7/ui7.cpp @@ -48,7 +48,7 @@ PD_API void Context::UseViewPort(const ID& id) { if (!pIO->ViewPorts.count(id)) { return; } - pIO->CurrentViewPort = pIO->ViewPorts[id]->GetSize(); + pIO->CurrentViewPort = pIO->ViewPorts[id]; } PD_API Menu::Ref Context::BeginMenu(const ID& id, UI7MenuFlags flags,