diff --git a/packages/rendering/include/rendering/ui/UIContainer.h b/packages/rendering/include/rendering/ui/UIContainer.h index 972328c1..3e952c7f 100644 --- a/packages/rendering/include/rendering/ui/UIContainer.h +++ b/packages/rendering/include/rendering/ui/UIContainer.h @@ -265,11 +265,11 @@ namespace l::ui { mArea.mLayout.mAlignV = alignV; mArea.mLayout.mLayoutH = layoutH; mArea.mLayout.mLayoutV = layoutV; + mAreaT.mBorder = 0.0f; } virtual ~UIContainer() = default; - bool Accept(UIVisitor& visitor, const InputState& input, UITraversalMode mode = UITraversalMode::BFS); - virtual bool Accept(UIVisitor& visitor, const InputState& input, const ContainerArea& contentArea, UITraversalMode mode = UITraversalMode::BFS); + virtual bool Accept(UIVisitor& visitor, const InputState& input, UITraversalMode mode = UITraversalMode::BFS); virtual void Add(UIContainer* container, int32_t i = -1); template @@ -300,6 +300,7 @@ namespace l::ui { void SetScale(float scale); void SetPosition(ImVec2 p); void SetSize(ImVec2 s); + void SetLayoutSize(ImVec2 s); void SetDisplayName(std::string_view id); void SetId(std::string_view id); void SetContainerArea(const ContainerArea& area); @@ -346,7 +347,6 @@ namespace l::ui { UIContainer* mParent = nullptr; UIContainer* mCoParent = nullptr; // when a container is influenced by two parent in a specific way defined by the type of container and the visitor std::vector mContent; - std::vector mContentAreas; }; enum class UISplitMode { @@ -368,7 +368,7 @@ namespace l::ui { } ~UISplit() = default; - virtual bool Accept(UIVisitor& visitor, const InputState& input, const ContainerArea& contentArea, UITraversalMode mode); + virtual bool Accept(UIVisitor& visitor, const InputState& input, UITraversalMode mode); protected: UISplitMode mSplitMode; }; diff --git a/packages/rendering/source/common/ui/UIContainer.cpp b/packages/rendering/source/common/ui/UIContainer.cpp index b945899e..9ed92e8a 100644 --- a/packages/rendering/source/common/ui/UIContainer.cpp +++ b/packages/rendering/source/common/ui/UIContainer.cpp @@ -123,6 +123,10 @@ namespace l::ui { mArea.mSize = s; } + void UIContainer::SetLayoutSize(ImVec2 s) { + mAreaT.mSize = s; + } + void UIContainer::SetDisplayName(std::string_view displayName) { mDisplayName = displayName; } @@ -200,14 +204,6 @@ namespace l::ui { } bool UIContainer::Accept(UIVisitor& visitor, const InputState& input, UITraversalMode mode) { - ContainerArea current; - if (visitor.Active(*this, input)) { - return Accept(visitor, input, current, mode); - } - return false; - } - - bool UIContainer::Accept(UIVisitor& visitor, const InputState& input, const ContainerArea& contentArea, UITraversalMode mode) { if (visitor.ShouldUpdateContainer()) { auto& layout = GetContainerArea().mLayout; switch (layout.mLayoutH) { @@ -225,7 +221,7 @@ namespace l::ui { case UILayoutV::Scaled: break; case UILayoutV::Parent: - mArea.mSize.y = contentArea.GetLocalSize().y; + mArea.mSize.y = GetLayoutArea().GetLocalSize().y; break; } } @@ -242,17 +238,13 @@ namespace l::ui { auto contentSize = content->GetSize(); auto& contentLayout = content->GetContainerArea().mLayout; ContainerArea current; - current.mScale = mArea.GetWorldScale(contentArea.mScale); - current.mSize = mArea.GetWorldSizeLayout(contentArea.mScale); - current.mPosition = mArea.GetWorldPosLayout(contentArea.mScale, contentArea.mPosition, contentSize, contentLayout.mAlignH, contentLayout.mAlignV); - - mContentAreas.resize(mContent.size()); - mContentAreas.at(i) = current; - + current.mScale = mArea.GetWorldScale(GetLayoutArea().mScale); + current.mSize = mArea.GetWorldSizeLayout(GetLayoutArea().mScale); + current.mPosition = mArea.GetWorldPosLayout(GetLayoutArea().mScale, GetLayoutArea().mPosition, contentSize, contentLayout.mAlignH, contentLayout.mAlignV); content->SetLayoutArea(current); } - if (content->Accept(visitor, input, mContentAreas.at(i), mode)) { + if (content->Accept(visitor, input, mode)) { return true; } i++; @@ -264,7 +256,7 @@ namespace l::ui { return false; } - bool UISplit::Accept(UIVisitor& visitor, const InputState& input, const ContainerArea& contentArea, UITraversalMode mode) { + bool UISplit::Accept(UIVisitor& visitor, const InputState& input, UITraversalMode mode) { // Since we can have multiple layouts in a container for different content, it will act as // an anchor rather than a container, therefore it has to align within it and size @@ -278,7 +270,7 @@ namespace l::ui { case UILayoutH::Scaled: break; case UILayoutH::Parent: - mArea.mSize.x = contentArea.GetLocalSize().x; + mArea.mSize.x = GetLayoutArea().GetLocalSize().x; break; } switch (layout.mLayoutV) { @@ -287,14 +279,14 @@ namespace l::ui { case UILayoutV::Scaled: break; case UILayoutV::Parent: - mArea.mSize.y = contentArea.GetLocalSize().y; + mArea.mSize.y = GetLayoutArea().GetLocalSize().y; break; } float contentCount = static_cast(mContent.size()); - current.mScale = mArea.GetWorldScale(contentArea.mScale); - current.mSize = mArea.GetWorldSize(contentArea.mScale); - current.mPosition = mArea.GetWorldPos(contentArea.mScale, contentArea.mPosition); + current.mScale = mArea.GetWorldScale(GetLayoutArea().mScale); + current.mSize = mArea.GetWorldSize(GetLayoutArea().mScale); + current.mPosition = mArea.GetWorldPos(GetLayoutArea().mScale, GetLayoutArea().mPosition); switch (mSplitMode) { case UISplitMode::EqualSplitH: @@ -323,12 +315,10 @@ namespace l::ui { size_t i = 0; for (auto& content : mContent) { if (visitor.ShouldUpdateContainer()) { - mContentAreas.resize(mContent.size()); - mContentAreas.at(i) = current; content->SetLayoutArea(current); } - if (content->Accept(visitor, input, mContentAreas.at(i), mode)) { + if (content->Accept(visitor, input, mode)) { return true; } @@ -341,10 +331,10 @@ namespace l::ui { current.mPosition.y += current.mSize.y; break; case UISplitMode::AppendH: - current.mPosition.x += content->GetSize().x * contentArea.mScale; + current.mPosition.x += content->GetSize().x * GetLayoutArea().mScale; break; case UISplitMode::AppendV: - current.mPosition.y += content->GetSize().y * contentArea.mScale; + current.mPosition.y += content->GetSize().y * GetLayoutArea().mScale; break; case UISplitMode::EqualResizeH: break; diff --git a/packages/rendering/source/common/ui/UIVisitors.cpp b/packages/rendering/source/common/ui/UIVisitors.cpp index c91d32f7..9bd9f4c5 100644 --- a/packages/rendering/source/common/ui/UIVisitors.cpp +++ b/packages/rendering/source/common/ui/UIVisitors.cpp @@ -206,7 +206,7 @@ namespace l::ui { } } else { - float d12 = sqrt(0.25f * ((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y))); + float d12 = sqrt(0.25f * ((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y)) / (contentArea.mScale * contentArea.mScale)); p11 = contentArea.Transform(ImVec2(pTopLeft.x + d12, pTopLeft.y), input.mRootPos); p22 = contentArea.Transform(ImVec2(pLowRight.x - d12, pLowRight.y), input.mRootPos); }