steinbergmedia / vstgui

A user interface toolkit mainly for audio plug-ins
Other
869 stars 123 forks source link

getChildViewsOfType() with option 'deep' searches only one level deep #291

Closed clwe closed 1 year ago

clwe commented 1 year ago

I'm unsure what is the expected behaviour of

auto ui_control   = std::vector<CControl*>();
view_->getFrame()->getView(0)->asViewContainer()->getChildViewsOfType<CControl>(ui_control, true);
for(auto ui_element : ui_control)
{
     // do something on ui_element here
}

I expected this to recursively search through all child elements. Instead, it searches only until the grand children of the top view. Further elements down the tree are not found.

This behaviour can be changed in cviewcontainer.h as follows:

diff --git a/vstgui/lib/cviewcontainer.h b/vstgui/lib/cviewcontainer.h
index 6e474d67..1c6e1e60 100644
--- a/vstgui/lib/cviewcontainer.h
+++ b/vstgui/lib/cviewcontainer.h
@@ -258,38 +258,38 @@ private:
//-----------------------------------------------------------------------------
 template<class ViewClass, class ContainerClass>
 inline uint32_t CViewContainer::getChildViewsOfType (ContainerClass& result, bool deep) const
 {
        for (auto& child : getChildren ())
        {
                auto vObj = child.cast<ViewClass> ();
                if (vObj)
                {
                        result.push_back (vObj);
                }
                if (deep)
                {
                        if (auto container = child->asViewContainer ())
                        {
-                               container->getChildViewsOfType<ViewClass, ContainerClass> (result);
+                               container->getChildViewsOfType<ViewClass, ContainerClass> (result, true);
                        }
                }
        }
        return static_cast<uint32_t> (result.size ());
 }

 //-----------------------------------------------------------------------------

Beeing able to collect all children of a specific view would be great, e.g. if you want to deactivate all controls of a certain subview, i.e. it could be further split into subviews.

clwe commented 1 year ago

Thanks for fixing this!