Skip to content

Commit

Permalink
Simplify some things in ui container implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
linuscu committed Aug 24, 2024
1 parent 23b2da2 commit e0a8d4d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
10 changes: 4 additions & 6 deletions packages/rendering/include/rendering/ui/UIContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ namespace l::ui {
};

enum class UITraversalMode {
AllDFS = 0, // when a visitor performs an action on all containers of its type for example rendering (visiting leaves first)
AllBFS = 1, // when a visitor performs an action on all containers starting with the root (visiting leaves last)
Once = 2, // when a visitor performs an action on one container of its type for example resizing
Twice = 3, // when a visitor performs an action on two containers of its type for example drag and drop actions like connecting input/output between two containers
DFS = 0, // Depth first search, leaves first, root last
BFS = 1, // Breadth first search, root first, leaves last
};

struct UIRenderData {
Expand Down Expand Up @@ -270,8 +268,8 @@ namespace l::ui {
}
virtual ~UIContainer() = default;

bool Accept(UIVisitor& visitor, const InputState& input, UITraversalMode mode = UITraversalMode::AllBFS);
virtual bool Accept(UIVisitor& visitor, const InputState& input, const ContainerArea& contentArea, UITraversalMode mode = UITraversalMode::AllBFS);
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 void Add(UIContainer* container, int32_t i = -1);

template<class T>
Expand Down
24 changes: 12 additions & 12 deletions packages/rendering/source/common/ui/UIContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,10 @@ namespace l::ui {
}
}

if (mode == UITraversalMode::AllBFS && visitor.Active(*this, input)) {
visitor.Visit(*this, input, contentArea);
if (mode == UITraversalMode::BFS && visitor.Active(*this, input)) {
if (visitor.Visit(*this, input, contentArea)) {
return true;
}
}

size_t i = 0;
Expand All @@ -251,14 +253,12 @@ namespace l::ui {
}

if (content->Accept(visitor, input, mContentAreas.at(i), mode)) {
if (mode == UITraversalMode::Once) {
return true;
}
return true;
}
i++;
}

if ((mode == UITraversalMode::AllDFS || mode == UITraversalMode::Once || mode == UITraversalMode::Twice) && visitor.Active(*this, input)) {
if (mode == UITraversalMode::DFS && visitor.Active(*this, input)) {
return visitor.Visit(*this, input, contentArea);
}
return false;
Expand Down Expand Up @@ -314,8 +314,10 @@ namespace l::ui {
}
}

if (mode == UITraversalMode::AllBFS && visitor.Active(*this, input)) {
visitor.Visit(*this, input, contentArea);
if (mode == UITraversalMode::BFS && visitor.Active(*this, input)) {
if (visitor.Visit(*this, input, contentArea)) {
return true;
}
}

size_t i = 0;
Expand All @@ -327,9 +329,7 @@ namespace l::ui {
}

if (content->Accept(visitor, input, mContentAreas.at(i), mode)) {
if (mode == UITraversalMode::Once) {
return true;
}
return true;
}

if (visitor.ShouldUpdateContainer()) {
Expand All @@ -355,7 +355,7 @@ namespace l::ui {
i++;
}

if ((mode == UITraversalMode::AllDFS || mode == UITraversalMode::Once || mode == UITraversalMode::Twice) && visitor.Active(*this, input)) {
if ((mode == UITraversalMode::DFS) && visitor.Active(*this, input)) {
return visitor.Visit(*this, input, contentArea);
}
return false;
Expand Down

0 comments on commit e0a8d4d

Please sign in to comment.