Sdk/BaseWidget: Widget::Add now returns a pointer (easier to use)

This commit is contained in:
Lynix 2017-01-11 19:13:40 +01:00
parent 4f1438f0f1
commit d57498be10
2 changed files with 4 additions and 4 deletions

View File

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

View File

@ -18,13 +18,13 @@ namespace Ndk
} }
template<typename T, typename... Args> template<typename T, typename... Args>
inline T& BaseWidget::Add(Args&&... args) inline T* BaseWidget::Add(Args&&... args)
{ {
std::unique_ptr<T> widget = std::make_unique<T>(this, std::forward<Args>(args)...); std::unique_ptr<T> widget = std::make_unique<T>(this, std::forward<Args>(args)...);
T& widgetRef = *widget; T* widgetPtr = widget.get();
AddChild(std::move(widget)); AddChild(std::move(widget));
return widgetRef; return widgetPtr;
} }
inline void BaseWidget::AddChild(std::unique_ptr<BaseWidget>&& widget) inline void BaseWidget::AddChild(std::unique_ptr<BaseWidget>&& widget)