Skip to content

Commit

Permalink
Also remove the container area for the tree search since it is now in…
Browse files Browse the repository at this point in the history
… the containers as well.
  • Loading branch information
linuscu committed Aug 24, 2024
1 parent 0ca5e18 commit dcd76be
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 33 deletions.
8 changes: 4 additions & 4 deletions packages/rendering/include/rendering/ui/UIContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<class T>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<UIContainer*> mContent;
std::vector<ContainerArea> mContentAreas;
};

enum class UISplitMode {
Expand All @@ -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;
};
Expand Down
46 changes: 18 additions & 28 deletions packages/rendering/source/common/ui/UIContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
}
Expand All @@ -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++;
Expand All @@ -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

Expand All @@ -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) {
Expand All @@ -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<float>(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:
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/rendering/source/common/ui/UIVisitors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit dcd76be

Please sign in to comment.