Skip to content

Commit

Permalink
Remove container area from visitor interface as it now comes from the…
Browse files Browse the repository at this point in the history
… container being visited instead.
  • Loading branch information
linuscu committed Aug 24, 2024
1 parent e0a8d4d commit 0ca5e18
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/rendering/include/rendering/ui/UIContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ namespace l::ui {
virtual bool Active(UIContainer&, const InputState&) {
return true;
}
virtual bool Visit(UIContainer&, const InputState&, const ContainerArea&) {
virtual bool Visit(UIContainer&, const InputState&) {
return false;
}
virtual void Debug(bool on = true) {
Expand Down
12 changes: 6 additions & 6 deletions packages/rendering/include/rendering/ui/UIVisitors.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ namespace l::ui {
class UIZoom : public UIVisitor {
public:
virtual bool Active(UIContainer& container, const InputState& input);
virtual bool Visit(UIContainer& container, const InputState& input, const ContainerArea& parent);
virtual bool Visit(UIContainer& container, const InputState& input);
};

class UIDrag : public UIVisitor {
public:
virtual bool Active(UIContainer& container, const InputState& input);
virtual bool Visit(UIContainer& container, const InputState& input, const ContainerArea& parent);
virtual bool Visit(UIContainer& container, const InputState& input);
protected:
bool mDragging = false;
UIContainer* mSourceContainer = nullptr;
Expand All @@ -40,15 +40,15 @@ namespace l::ui {
class UIMove : public UIVisitor {
public:
virtual bool Active(UIContainer& container, const InputState& input);
virtual bool Visit(UIContainer& container, const InputState& input, const ContainerArea& parent);
virtual bool Visit(UIContainer& container, const InputState& input);
protected:
bool mMoving = false;
UIContainer* mSourceContainer = nullptr;
};

class UIResize : public UIVisitor {
public:
virtual bool Visit(UIContainer& container, const InputState& input, const ContainerArea& parent);
virtual bool Visit(UIContainer& container, const InputState& input);
protected:
bool mResizing = false;
float mResizeAreaSize = 8.0f;
Expand All @@ -60,7 +60,7 @@ namespace l::ui {
UIDraw(ImDrawList* drawList) : mDrawList(drawList) {}
~UIDraw() = default;

virtual bool Visit(UIContainer& container, const InputState& input, const ContainerArea& parent);
virtual bool Visit(UIContainer& container, const InputState& input);
protected:
ImDrawList* mDrawList;
};
Expand All @@ -72,7 +72,7 @@ namespace l::ui {
UILinkIO(UICreator* creator = nullptr) : mCreator(creator) {}
~UILinkIO() = default;

virtual bool Visit(UIContainer& container, const InputState& input, const ContainerArea& parent);
virtual bool Visit(UIContainer& container, const InputState& input);
protected:
bool mDragging = false;
bool mPossibleLinkImminent = false;
Expand Down
10 changes: 5 additions & 5 deletions packages/rendering/source/common/ui/UIContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,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 @@ -231,7 +231,7 @@ namespace l::ui {
}

if (mode == UITraversalMode::BFS && visitor.Active(*this, input)) {
if (visitor.Visit(*this, input, contentArea)) {
if (visitor.Visit(*this, input)) {
return true;
}
}
Expand Down Expand Up @@ -259,7 +259,7 @@ namespace l::ui {
}

if (mode == UITraversalMode::DFS && visitor.Active(*this, input)) {
return visitor.Visit(*this, input, contentArea);
return visitor.Visit(*this, input);
}
return false;
}
Expand Down Expand Up @@ -315,7 +315,7 @@ namespace l::ui {
}

if (mode == UITraversalMode::BFS && visitor.Active(*this, input)) {
if (visitor.Visit(*this, input, contentArea)) {
if (visitor.Visit(*this, input)) {
return true;
}
}
Expand Down Expand Up @@ -356,7 +356,7 @@ namespace l::ui {
}

if ((mode == UITraversalMode::DFS) && visitor.Active(*this, input)) {
return visitor.Visit(*this, input, contentArea);
return visitor.Visit(*this, input);
}
return false;
}
Expand Down
28 changes: 22 additions & 6 deletions packages/rendering/source/common/ui/UIVisitors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace l::ui {
return input.mScroll != 0;
}

bool UIZoom::Visit(UIContainer& container, const InputState& input, const ContainerArea& contentArea) {
bool UIZoom::Visit(UIContainer& container, const InputState& input) {
if (!container.HasConfigFlag(UIContainer_ZoomFlag)) {
return false;
}
Expand All @@ -25,6 +25,8 @@ namespace l::ui {
return true;
}

auto& contentArea = container.GetLayoutArea();

ImVec2 mousePos = input.GetLocalPos();
ImVec2 localMousePos = ImVec2(contentArea.mPosition.x - mousePos.x, contentArea.mPosition.y - mousePos.y);
ImVec2 p = container.GetPosition();
Expand All @@ -41,7 +43,7 @@ namespace l::ui {
return (input.mStarted && !mDragging) || mDragging;
}

bool UIDrag::Visit(UIContainer& container, const InputState& input, const ContainerArea& contentArea) {
bool UIDrag::Visit(UIContainer& container, const InputState& input) {
if (!container.HasConfigFlag(UIContainer_DragFlag)) {
return false;
}
Expand All @@ -52,6 +54,8 @@ namespace l::ui {
}
}
if (mDragging && mSourceContainer == &container) {
auto& contentArea = container.GetLayoutArea();

ImVec2 move = DragMovement(input.mPrevPos, input.mCurPos, contentArea.mScale * container.GetScale());
container.Move(move);
container.Notification(UIContainer_DragFlag);
Expand All @@ -69,17 +73,19 @@ namespace l::ui {
return (input.mStarted && !mMoving) || mMoving;
}

bool UIMove::Visit(UIContainer& container, const InputState& input, const ContainerArea& contentArea) {
bool UIMove::Visit(UIContainer& container, const InputState& input) {
if(!container.HasConfigFlag(UIContainer_MoveFlag)){
return false;
}
if (input.mStarted && !mMoving) {
auto& contentArea = container.GetLayoutArea();
if (Overlap(input.GetLocalPos(), container.GetPosition(), container.GetPositionAtSize(), contentArea)) {
mMoving = true;
mSourceContainer = &container;
}
}
if (mMoving && mSourceContainer == &container) {
auto& contentArea = container.GetLayoutArea();
ImVec2 move = DragMovement(input.mPrevPos, input.mCurPos, contentArea.mScale);
container.Move(move);
container.Notification(UIContainer_MoveFlag);
Expand All @@ -93,13 +99,14 @@ namespace l::ui {
return false;
}

bool UIResize::Visit(UIContainer& container, const InputState& input, const ContainerArea& contentArea) {
bool UIResize::Visit(UIContainer& container, const InputState& input) {
if (!container.HasConfigFlag(UIContainer_ResizeFlag)) {
return false;
}
if (!mResizing) {
const float radii = mResizeAreaSize * 0.5f;
ImVec2 p = container.GetPositionAtSize();
auto& contentArea = container.GetLayoutArea();
if (OverlapScreenRect(input.GetLocalPos(), p, ImVec2(radii, radii), contentArea)) {
mSourceContainer = &container;
container.Notification(UIContainer_ResizeFlag);
Expand All @@ -117,6 +124,7 @@ namespace l::ui {
}
}
if (mResizing && mSourceContainer == &container) {
auto& contentArea = container.GetLayoutArea();
ImVec2 move = DragMovement(input.mPrevPos, input.mCurPos, contentArea.mScale);
container.Resize(move);

Expand All @@ -130,11 +138,13 @@ namespace l::ui {
return false;
}

bool UIDraw::Visit(UIContainer& container, const InputState& input, const ContainerArea& contentArea) {
bool UIDraw::Visit(UIContainer& container, const InputState& input) {
if (!mDebug && !container.HasConfigFlag(UIContainer_DrawFlag)) {
return false;
}

auto& contentArea = container.GetLayoutArea();

float splineThickness = 2.0f;
ImU32 color = container.GetRenderData().mColor;
ImVec2 pTopLeft = container.GetPosition();
Expand Down Expand Up @@ -253,11 +263,13 @@ namespace l::ui {
return container.HasConfigFlag(UIContainer_InputFlag) || container.HasConfigFlag(UIContainer_OutputFlag) || container.HasConfigFlag(UIContainer_LinkFlag);
}

bool UILinkIO::Visit(UIContainer& container, const InputState& input, const ContainerArea& contentArea) {
bool UILinkIO::Visit(UIContainer& container, const InputState& input) {
// Create link at from a clicked output container
if (container.HasConfigFlag(UIContainer_OutputFlag) && !mDragging && input.mStarted && mLinkContainer.get() == nullptr) {
ImVec2 pCenter = container.GetPosition();
ImVec2 size = container.GetSize();
auto& contentArea = container.GetLayoutArea();

ImVec2 pT = contentArea.Transform(pCenter, input.mRootPos);
if (OverlapCircle(input.mCurPos, pT, size.x * contentArea.mScale)) {
mDragging = true;
Expand All @@ -279,13 +291,17 @@ namespace l::ui {

if (mDragging && mLinkContainer.get() != nullptr && container.HasConfigFlag(UIContainer_LinkFlag) && mLinkContainer.get() == &container) {
// On the newly created link container, drag the end point along the mouse movement
auto& contentArea = container.GetLayoutArea();

ImVec2 move = DragMovement(input.mPrevPos, input.mCurPos, contentArea.mScale * container.GetScale());
mLinkContainer->Move(move);
}

if (mDragging && mLinkContainer.get() != nullptr && container.HasConfigFlag(UIContainer_InputFlag)) {
ImVec2 pCenter = container.GetPosition();
ImVec2 size = container.GetSize();
auto& contentArea = container.GetLayoutArea();

ImVec2 pT = contentArea.Transform(pCenter, input.mRootPos);

if (OverlapCircle(input.mCurPos, pT, size.x * contentArea.mScale)) {
Expand Down

0 comments on commit 0ca5e18

Please sign in to comment.