diff --git a/packages/rendering/include/rendering/ui/UIContainer.h b/packages/rendering/include/rendering/ui/UIContainer.h index fe2681cb..001f7358 100644 --- a/packages/rendering/include/rendering/ui/UIContainer.h +++ b/packages/rendering/include/rendering/ui/UIContainer.h @@ -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 { @@ -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 diff --git a/packages/rendering/source/common/ui/UIContainer.cpp b/packages/rendering/source/common/ui/UIContainer.cpp index 7cbfa13e..17006c59 100644 --- a/packages/rendering/source/common/ui/UIContainer.cpp +++ b/packages/rendering/source/common/ui/UIContainer.cpp @@ -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; @@ -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; @@ -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; @@ -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()) { @@ -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;