Sdk/BaseWidget: Add shortcut to create children widgets

Former-commit-id: 5d5ca1d1097086c33133440c08806aec9e478b09 [formerly ca22426131332606a26dc3f33fcda615c7c03d81] [formerly 38913198afa19aa2f5f2ee0f90f99d3780cb3333 [formerly b592a482e9f71b01a3b068276c3bbdcf8dcdda49]]
Former-commit-id: f464592f3d951614bc333bab9e0662fc1f8ad18e [formerly dd7f97b064a63188d227577e5f1f8dcc1526c2a3]
Former-commit-id: 6463d207bbf06bcfb811abb249fe257ee5336c85
This commit is contained in:
Lynix 2016-10-11 15:40:56 +02:00
parent f10ed46035
commit 2fdc7a8878
2 changed files with 11 additions and 0 deletions

View File

@ -31,6 +31,7 @@ namespace Ndk
BaseWidget(BaseWidget&&) = default;
virtual ~BaseWidget();
template<typename T, typename... Args> T& Add(Args&&... args);
inline void AddChild(std::unique_ptr<BaseWidget>&& widget);
void EnableBackground(bool enable);

View File

@ -17,6 +17,16 @@ namespace Ndk
SetPadding(5.f, 5.f, 5.f, 5.f);
}
template<typename T, typename... Args>
inline T& BaseWidget::Add(Args&&... args)
{
std::unique_ptr<T> widget = std::make_unique<T>(this, std::forward<Args>(args)...);
T& widgetRef = *widget;
AddChild(std::move(widget));
return widgetRef;
}
inline void BaseWidget::AddChild(std::unique_ptr<BaseWidget>&& widget)
{
m_children.emplace_back(std::move(widget));