From c9b84e3852b0494e1806c785edff3932a3ead8e0 Mon Sep 17 00:00:00 2001 From: Lynix Date: Wed, 11 Jan 2017 17:12:35 +0100 Subject: [PATCH 1/9] Core/Signal: Make move constructor/operator noexcept --- include/Nazara/Core/Signal.hpp | 4 ++-- include/Nazara/Core/Signal.inl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/Nazara/Core/Signal.hpp b/include/Nazara/Core/Signal.hpp index 613502f80..897c32ef9 100644 --- a/include/Nazara/Core/Signal.hpp +++ b/include/Nazara/Core/Signal.hpp @@ -33,7 +33,7 @@ namespace Nz Signal(); Signal(const Signal&) = delete; - Signal(Signal&& signal); + Signal(Signal&& signal) noexcept; ~Signal() = default; void Clear(); @@ -48,7 +48,7 @@ namespace Nz void operator()(Args... args) const; Signal& operator=(const Signal&) = delete; - Signal& operator=(Signal&& signal); + Signal& operator=(Signal&& signal) noexcept; private: struct Slot; diff --git a/include/Nazara/Core/Signal.inl b/include/Nazara/Core/Signal.inl index 93e0166c0..07a950d89 100644 --- a/include/Nazara/Core/Signal.inl +++ b/include/Nazara/Core/Signal.inl @@ -32,7 +32,7 @@ namespace Nz */ template - Signal::Signal(Signal&& signal) + Signal::Signal(Signal&& signal) noexcept { operator=(std::move(signal)); } @@ -182,7 +182,7 @@ namespace Nz */ template - Signal& Signal::operator=(Signal&& signal) + Signal& Signal::operator=(Signal&& signal) noexcept { m_slots = std::move(signal.m_slots); m_slotIterator = signal.m_slotIterator; From 4f1438f0f1acec0c6b4b6095b9df45ee0fa73024 Mon Sep 17 00:00:00 2001 From: Lynix Date: Wed, 11 Jan 2017 18:27:32 +0100 Subject: [PATCH 2/9] SDK/BaseWidget: Add OnParentResized method --- SDK/include/NDK/BaseWidget.hpp | 2 ++ SDK/include/NDK/BaseWidget.inl | 9 ++++++++- SDK/src/NDK/BaseWidget.cpp | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/SDK/include/NDK/BaseWidget.hpp b/SDK/include/NDK/BaseWidget.hpp index 1e6fe7c64..9ec787890 100644 --- a/SDK/include/NDK/BaseWidget.hpp +++ b/SDK/include/NDK/BaseWidget.hpp @@ -78,11 +78,13 @@ namespace Ndk virtual void OnMouseButtonPress(int x, int y, Nz::Mouse::Button button); virtual void OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button); virtual void OnMouseExit(); + virtual void OnParentResized(const Nz::Vector2f& newSize); virtual void OnTextEntered(char32_t character, bool repeated); private: inline BaseWidget(); + inline void NotifyParentResized(const Nz::Vector2f& newSize); inline void UpdateCanvasIndex(std::size_t index); std::size_t m_canvasIndex; diff --git a/SDK/include/NDK/BaseWidget.inl b/SDK/include/NDK/BaseWidget.inl index 0b13ee7c7..4bc1be8b3 100644 --- a/SDK/include/NDK/BaseWidget.inl +++ b/SDK/include/NDK/BaseWidget.inl @@ -63,8 +63,9 @@ namespace Ndk inline void BaseWidget::SetContentSize(const Nz::Vector2f& size) { + NotifyParentResized(size); m_contentSize = size; - + Layout(); } @@ -78,6 +79,12 @@ namespace Ndk Layout(); } + inline void BaseWidget::NotifyParentResized(const Nz::Vector2f& newSize) + { + for (const auto& widgetPtr : m_children) + widgetPtr->OnParentResized(newSize); + } + inline void BaseWidget::UpdateCanvasIndex(std::size_t index) { m_canvasIndex = index; diff --git a/SDK/src/NDK/BaseWidget.cpp b/SDK/src/NDK/BaseWidget.cpp index 43ffbeb52..dcaccd756 100644 --- a/SDK/src/NDK/BaseWidget.cpp +++ b/SDK/src/NDK/BaseWidget.cpp @@ -126,6 +126,10 @@ namespace Ndk { } + void BaseWidget::OnParentResized(const Nz::Vector2f& newSize) + { + } + void BaseWidget::OnTextEntered(char32_t character, bool repeated) { } From d57498be108f32dc59d0463f49bfbf2cf56472cb Mon Sep 17 00:00:00 2001 From: Lynix Date: Wed, 11 Jan 2017 19:13:40 +0100 Subject: [PATCH 3/9] Sdk/BaseWidget: Widget::Add now returns a pointer (easier to use) --- SDK/include/NDK/BaseWidget.hpp | 2 +- SDK/include/NDK/BaseWidget.inl | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/SDK/include/NDK/BaseWidget.hpp b/SDK/include/NDK/BaseWidget.hpp index 9ec787890..e2fe6d438 100644 --- a/SDK/include/NDK/BaseWidget.hpp +++ b/SDK/include/NDK/BaseWidget.hpp @@ -32,7 +32,7 @@ namespace Ndk BaseWidget(BaseWidget&&) = default; virtual ~BaseWidget(); - template T& Add(Args&&... args); + template T* Add(Args&&... args); inline void AddChild(std::unique_ptr&& widget); inline void Center(); diff --git a/SDK/include/NDK/BaseWidget.inl b/SDK/include/NDK/BaseWidget.inl index 4bc1be8b3..aa2b222b6 100644 --- a/SDK/include/NDK/BaseWidget.inl +++ b/SDK/include/NDK/BaseWidget.inl @@ -18,13 +18,13 @@ namespace Ndk } template - inline T& BaseWidget::Add(Args&&... args) + inline T* BaseWidget::Add(Args&&... args) { std::unique_ptr widget = std::make_unique(this, std::forward(args)...); - T& widgetRef = *widget; + T* widgetPtr = widget.get(); AddChild(std::move(widget)); - return widgetRef; + return widgetPtr; } inline void BaseWidget::AddChild(std::unique_ptr&& widget) From 6acf101d77eb6c6b0fcd2e1af99e1fa039e63ebe Mon Sep 17 00:00:00 2001 From: Lynix Date: Wed, 11 Jan 2017 19:14:21 +0100 Subject: [PATCH 4/9] Sdk/BaseWidget: Fix crash at Canvas destruction --- SDK/include/NDK/BaseWidget.inl | 2 ++ SDK/src/NDK/BaseWidget.cpp | 3 ++- SDK/src/NDK/Canvas.cpp | 18 ++++++++++-------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/SDK/include/NDK/BaseWidget.inl b/SDK/include/NDK/BaseWidget.inl index aa2b222b6..1833a2224 100644 --- a/SDK/include/NDK/BaseWidget.inl +++ b/SDK/include/NDK/BaseWidget.inl @@ -5,10 +5,12 @@ #include #include #include +#include namespace Ndk { inline BaseWidget::BaseWidget() : + m_canvasIndex(std::numeric_limits::max()), m_backgroundColor(Nz::Color(230, 230, 230, 255)), m_canvas(nullptr), m_contentSize(50.f, 50.f), diff --git a/SDK/src/NDK/BaseWidget.cpp b/SDK/src/NDK/BaseWidget.cpp index dcaccd756..b7476dd30 100644 --- a/SDK/src/NDK/BaseWidget.cpp +++ b/SDK/src/NDK/BaseWidget.cpp @@ -25,7 +25,8 @@ namespace Ndk BaseWidget::~BaseWidget() { - m_canvas->UnregisterWidget(m_canvasIndex); + if (m_canvasIndex != std::numeric_limits::max()) + m_canvas->UnregisterWidget(m_canvasIndex); } inline void BaseWidget::EnableBackground(bool enable) diff --git a/SDK/src/NDK/Canvas.cpp b/SDK/src/NDK/Canvas.cpp index c06d320c1..b13b7ef6a 100644 --- a/SDK/src/NDK/Canvas.cpp +++ b/SDK/src/NDK/Canvas.cpp @@ -49,21 +49,23 @@ namespace Ndk void Canvas::UnregisterWidget(std::size_t index) { + WidgetBox& entry = m_widgetBoxes[index]; + + if (m_hoveredWidget == &entry) + m_hoveredWidget = nullptr; + + if (m_keyboardOwner == entry.widget) + m_keyboardOwner = nullptr; + if (m_widgetBoxes.size() > 1U) { - WidgetBox& entry = m_widgetBoxes[index]; WidgetBox& lastEntry = m_widgetBoxes.back(); - if (m_hoveredWidget == &entry) - m_hoveredWidget = nullptr; - - if (m_keyboardOwner == entry.widget) - m_keyboardOwner = nullptr; - entry = std::move(lastEntry); entry.widget->UpdateCanvasIndex(index); - m_widgetBoxes.pop_back(); } + + m_widgetBoxes.pop_back(); } void Canvas::OnMouseButtonPressed(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseButtonEvent& event) From fd923ed58b252e9de8ddd55749eec2451c5b1125 Mon Sep 17 00:00:00 2001 From: Lynix Date: Wed, 11 Jan 2017 19:14:32 +0100 Subject: [PATCH 5/9] Sdk/BaseWidget: Add Destroy method --- SDK/include/NDK/BaseWidget.hpp | 3 +++ SDK/src/NDK/BaseWidget.cpp | 22 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/SDK/include/NDK/BaseWidget.hpp b/SDK/include/NDK/BaseWidget.hpp index e2fe6d438..76def4b1b 100644 --- a/SDK/include/NDK/BaseWidget.hpp +++ b/SDK/include/NDK/BaseWidget.hpp @@ -37,6 +37,8 @@ namespace Ndk inline void Center(); + inline void Destroy(); + void EnableBackground(bool enable); //virtual BaseWidget* Clone() const = 0; @@ -84,6 +86,7 @@ namespace Ndk private: inline BaseWidget(); + inline void DestroyChild(BaseWidget* widget); inline void NotifyParentResized(const Nz::Vector2f& newSize); inline void UpdateCanvasIndex(std::size_t index); diff --git a/SDK/src/NDK/BaseWidget.cpp b/SDK/src/NDK/BaseWidget.cpp index b7476dd30..c627019ea 100644 --- a/SDK/src/NDK/BaseWidget.cpp +++ b/SDK/src/NDK/BaseWidget.cpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace Ndk { @@ -29,7 +30,14 @@ namespace Ndk m_canvas->UnregisterWidget(m_canvasIndex); } - inline void BaseWidget::EnableBackground(bool enable) + void BaseWidget::Destroy() + { + NazaraAssert(this != m_canvas, "Canvas cannot be destroyed by calling Destroy()"); + + m_widgetParent->DestroyChild(this); //< This does delete us + } + + void BaseWidget::EnableBackground(bool enable) { if (m_backgroundEntity.IsValid() == enable) return; @@ -134,4 +142,16 @@ namespace Ndk void BaseWidget::OnTextEntered(char32_t character, bool repeated) { } + + void BaseWidget::DestroyChild(BaseWidget* widget) + { + auto it = std::find_if(m_children.begin(), m_children.end(), [widget] (const std::unique_ptr& widgetPtr) -> bool + { + return widgetPtr.get() == widget; + }); + + NazaraAssert(it != m_children.end(), "Child widget not found in parent"); + + m_children.erase(it); + } } From 14e327c603e35f16a6052b99c58c03ea5ae3031a Mon Sep 17 00:00:00 2001 From: Lynix Date: Sun, 15 Jan 2017 12:11:15 +0100 Subject: [PATCH 6/9] Sdk/TextAreaWidget: Add SetTextColor --- SDK/include/NDK/Widgets/TextAreaWidget.hpp | 4 +++- SDK/include/NDK/Widgets/TextAreaWidget.inl | 19 +++++++++++++++++++ SDK/src/NDK/Widgets/TextAreaWidget.cpp | 7 ------- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/SDK/include/NDK/Widgets/TextAreaWidget.hpp b/SDK/include/NDK/Widgets/TextAreaWidget.hpp index 8236b1689..2b0774ec8 100644 --- a/SDK/include/NDK/Widgets/TextAreaWidget.hpp +++ b/SDK/include/NDK/Widgets/TextAreaWidget.hpp @@ -35,6 +35,7 @@ namespace Ndk inline std::size_t GetCursorPosition() const; inline std::size_t GetLineCount() const; inline const Nz::String& GetText() const; + inline const Nz::Color& GetTextColor() const; std::size_t GetHoveredGlyph(float x, float y) const; @@ -47,7 +48,8 @@ namespace Ndk inline void SetCursorPosition(std::size_t cursorPosition); inline void SetReadOnly(bool readOnly = true); - void SetText(const Nz::String& text); + inline void SetText(const Nz::String& text); + inline void SetTextColor(const Nz::Color& text); void Write(const Nz::String& text); diff --git a/SDK/include/NDK/Widgets/TextAreaWidget.inl b/SDK/include/NDK/Widgets/TextAreaWidget.inl index d923e7223..711f8de8c 100644 --- a/SDK/include/NDK/Widgets/TextAreaWidget.inl +++ b/SDK/include/NDK/Widgets/TextAreaWidget.inl @@ -35,6 +35,11 @@ namespace Ndk return m_drawer.GetText(); } + inline const Nz::Color& TextAreaWidget::GetTextColor() const + { + return m_drawer.GetColor(); + } + inline bool Ndk::TextAreaWidget::IsMultilineEnabled() const { return m_multiLineEnabled; @@ -72,4 +77,18 @@ namespace Ndk m_cursorEntity->Enable(!m_readOnly); } + + inline void TextAreaWidget::SetText(const Nz::String& text) + { + m_drawer.SetText(text); + + m_textSprite->Update(m_drawer); + } + + inline void TextAreaWidget::SetTextColor(const Nz::Color& text) + { + m_drawer.SetColor(text); + + m_textSprite->Update(m_drawer); + } } diff --git a/SDK/src/NDK/Widgets/TextAreaWidget.cpp b/SDK/src/NDK/Widgets/TextAreaWidget.cpp index 0e0f82f57..0c9b7b3d5 100644 --- a/SDK/src/NDK/Widgets/TextAreaWidget.cpp +++ b/SDK/src/NDK/Widgets/TextAreaWidget.cpp @@ -77,13 +77,6 @@ namespace Ndk SetContentSize(Nz::Vector2f(m_textSprite->GetBoundingVolume().obb.localBox.GetLengths())); } - void TextAreaWidget::SetText(const Nz::String& text) - { - m_drawer.SetText(text); - - m_textSprite->Update(m_drawer); - } - void TextAreaWidget::Write(const Nz::String& text) { if (m_cursorPosition >= m_drawer.GetGlyphCount()) From 58656798914443f8b272e0c64d6e1c37bb7fd278 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sun, 15 Jan 2017 12:11:59 +0100 Subject: [PATCH 7/9] Sdk/BaseWidget: Add a way to change background color --- SDK/include/NDK/BaseWidget.hpp | 2 ++ SDK/include/NDK/BaseWidget.inl | 5 +++++ SDK/src/NDK/BaseWidget.cpp | 11 +++++++++++ 3 files changed, 18 insertions(+) diff --git a/SDK/include/NDK/BaseWidget.hpp b/SDK/include/NDK/BaseWidget.hpp index 76def4b1b..aa47446f3 100644 --- a/SDK/include/NDK/BaseWidget.hpp +++ b/SDK/include/NDK/BaseWidget.hpp @@ -43,6 +43,7 @@ namespace Ndk //virtual BaseWidget* Clone() const = 0; + inline const Nz::Color& GetBackgroundColor() const; inline Canvas* GetCanvas(); inline const Padding& GetPadding() const; inline const Nz::Vector2f& GetContentSize() const; @@ -52,6 +53,7 @@ namespace Ndk virtual void ResizeToContent() = 0; + void SetBackgroundColor(const Nz::Color& color); inline void SetContentSize(const Nz::Vector2f& size); inline void SetPadding(float left, float top, float right, float bottom); void SetSize(const Nz::Vector2f& size); diff --git a/SDK/include/NDK/BaseWidget.inl b/SDK/include/NDK/BaseWidget.inl index 1833a2224..d5a91a2ed 100644 --- a/SDK/include/NDK/BaseWidget.inl +++ b/SDK/include/NDK/BaseWidget.inl @@ -43,6 +43,11 @@ namespace Ndk SetPosition((parentSize.x - mySize.x) / 2.f, (parentSize.y - mySize.y) / 2.f); } + inline const Nz::Color& BaseWidget::GetBackgroundColor() const + { + return m_backgroundColor; + } + inline Canvas* BaseWidget::GetCanvas() { return m_canvas; diff --git a/SDK/src/NDK/BaseWidget.cpp b/SDK/src/NDK/BaseWidget.cpp index c627019ea..8bcf972d3 100644 --- a/SDK/src/NDK/BaseWidget.cpp +++ b/SDK/src/NDK/BaseWidget.cpp @@ -61,6 +61,17 @@ namespace Ndk } } + void BaseWidget::SetBackgroundColor(const Nz::Color& color) + { + m_backgroundColor = color; + + if (m_backgroundSprite) + { + m_backgroundSprite->SetColor(color); + m_backgroundSprite->GetMaterial()->Configure((color.IsOpaque()) ? "Basic2D" : "Translucent2D"); //< Our sprite has its own material (see EnableBackground) + } + } + void BaseWidget::SetSize(const Nz::Vector2f& size) { SetContentSize({std::max(size.x - m_padding.left - m_padding.right, 0.f), std::max(size.y - m_padding.top - m_padding.bottom, 0.f)}); From e1e290808a15ce3ba59607b9f1fadebd964809b5 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sun, 15 Jan 2017 12:12:58 +0100 Subject: [PATCH 8/9] Sdk/Canvas: Fix crash at Canvas destruction --- SDK/include/NDK/BaseWidget.hpp | 1 + SDK/include/NDK/Canvas.hpp | 2 +- SDK/include/NDK/Canvas.inl | 6 ++++++ SDK/src/NDK/BaseWidget.cpp | 5 +++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/SDK/include/NDK/BaseWidget.hpp b/SDK/include/NDK/BaseWidget.hpp index aa47446f3..22bfa9dcf 100644 --- a/SDK/include/NDK/BaseWidget.hpp +++ b/SDK/include/NDK/BaseWidget.hpp @@ -89,6 +89,7 @@ namespace Ndk inline BaseWidget(); inline void DestroyChild(BaseWidget* widget); + void DestroyChildren(); inline void NotifyParentResized(const Nz::Vector2f& newSize); inline void UpdateCanvasIndex(std::size_t index); diff --git a/SDK/include/NDK/Canvas.hpp b/SDK/include/NDK/Canvas.hpp index a8da5d04e..db271051f 100644 --- a/SDK/include/NDK/Canvas.hpp +++ b/SDK/include/NDK/Canvas.hpp @@ -23,7 +23,7 @@ namespace Ndk inline Canvas(WorldHandle world, Nz::EventHandler& eventHandler); Canvas(const Canvas&) = delete; Canvas(Canvas&&) = delete; - ~Canvas() = default; + inline ~Canvas(); inline const WorldHandle& GetWorld() const; diff --git a/SDK/include/NDK/Canvas.inl b/SDK/include/NDK/Canvas.inl index d0d05bf12..173474bdf 100644 --- a/SDK/include/NDK/Canvas.inl +++ b/SDK/include/NDK/Canvas.inl @@ -22,6 +22,12 @@ namespace Ndk m_textEnteredSlot.Connect(eventHandler.OnTextEntered, this, &Canvas::OnTextEntered); } + inline Canvas::~Canvas() + { + // Destroy children explicitly because they signal us when getting destroyed, and that can't happend after our own destruction + DestroyChildren(); + } + inline const WorldHandle& Canvas::GetWorld() const { return m_world; diff --git a/SDK/src/NDK/BaseWidget.cpp b/SDK/src/NDK/BaseWidget.cpp index 8bcf972d3..a65a8a889 100644 --- a/SDK/src/NDK/BaseWidget.cpp +++ b/SDK/src/NDK/BaseWidget.cpp @@ -165,4 +165,9 @@ namespace Ndk m_children.erase(it); } + + void BaseWidget::DestroyChildren() + { + m_children.clear(); + } } From c9458eeb1714e3f5285c40407f75cdfd086ab826 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sun, 15 Jan 2017 12:13:29 +0100 Subject: [PATCH 9/9] Sdk/BaseWidget: Add visibility control --- SDK/include/NDK/BaseWidget.hpp | 5 +++++ SDK/include/NDK/BaseWidget.inl | 9 ++++++++- SDK/src/NDK/BaseWidget.cpp | 33 +++++++++++++++++++++++++-------- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/SDK/include/NDK/BaseWidget.hpp b/SDK/include/NDK/BaseWidget.hpp index 22bfa9dcf..2bdf0dd81 100644 --- a/SDK/include/NDK/BaseWidget.hpp +++ b/SDK/include/NDK/BaseWidget.hpp @@ -49,6 +49,8 @@ namespace Ndk inline const Nz::Vector2f& GetContentSize() const; inline Nz::Vector2f GetSize() const; + inline bool IsVisible() const; + void GrabKeyboard(); virtual void ResizeToContent() = 0; @@ -58,6 +60,8 @@ namespace Ndk inline void SetPadding(float left, float top, float right, float bottom); void SetSize(const Nz::Vector2f& size); + void Show(bool show = true); + BaseWidget& operator=(const BaseWidget&) = delete; BaseWidget& operator=(BaseWidget&&) = default; @@ -104,6 +108,7 @@ namespace Ndk Nz::SpriteRef m_backgroundSprite; Nz::Vector2f m_contentSize; BaseWidget* m_widgetParent; + bool m_visible; }; } diff --git a/SDK/include/NDK/BaseWidget.inl b/SDK/include/NDK/BaseWidget.inl index d5a91a2ed..041abe9bd 100644 --- a/SDK/include/NDK/BaseWidget.inl +++ b/SDK/include/NDK/BaseWidget.inl @@ -14,7 +14,8 @@ namespace Ndk m_backgroundColor(Nz::Color(230, 230, 230, 255)), m_canvas(nullptr), m_contentSize(50.f, 50.f), - m_widgetParent(nullptr) + m_widgetParent(nullptr), + m_visible(true) { SetPadding(5.f, 5.f, 5.f, 5.f); } @@ -31,6 +32,7 @@ namespace Ndk inline void BaseWidget::AddChild(std::unique_ptr&& widget) { + widget->Show(m_visible); m_children.emplace_back(std::move(widget)); } @@ -68,6 +70,11 @@ namespace Ndk return Nz::Vector2f(m_contentSize.x + m_padding.left + m_padding.right, m_contentSize.y + m_padding.top + m_padding.bottom); } + inline bool BaseWidget::IsVisible() const + { + return m_visible; + } + inline void BaseWidget::SetContentSize(const Nz::Vector2f& size) { NotifyParentResized(size); diff --git a/SDK/src/NDK/BaseWidget.cpp b/SDK/src/NDK/BaseWidget.cpp index a65a8a889..69d60965e 100644 --- a/SDK/src/NDK/BaseWidget.cpp +++ b/SDK/src/NDK/BaseWidget.cpp @@ -48,7 +48,7 @@ namespace Ndk m_backgroundSprite->SetColor(m_backgroundColor); m_backgroundSprite->SetMaterial(Nz::Material::New((m_backgroundColor.IsOpaque()) ? "Basic2D" : "Translucent2D")); - m_backgroundEntity = m_world->CreateEntity(); + m_backgroundEntity = CreateEntity(); m_backgroundEntity->AddComponent().Attach(m_backgroundSprite, -1); m_backgroundEntity->AddComponent().SetParent(this); @@ -61,6 +61,11 @@ namespace Ndk } } + void BaseWidget::GrabKeyboard() + { + m_canvas->SetKeyboardOwner(this); + } + void BaseWidget::SetBackgroundColor(const Nz::Color& color) { m_backgroundColor = color; @@ -77,10 +82,27 @@ namespace Ndk SetContentSize({std::max(size.x - m_padding.left - m_padding.right, 0.f), std::max(size.y - m_padding.top - m_padding.bottom, 0.f)}); } + void BaseWidget::Show(bool show) + { + if (m_visible != show) + { + m_visible = show; + + for (const EntityHandle& entity : m_entities) + entity->Enable(show); + + for (const auto& widgetPtr : m_children) + widgetPtr->Show(show); + } + } + EntityHandle BaseWidget::CreateEntity() { - m_entities.emplace_back(m_world->CreateEntity()); - return m_entities.back(); + EntityHandle newEntity = m_world->CreateEntity(); + newEntity->Enable(m_visible); + + m_entities.emplace_back(newEntity); + return newEntity; } void BaseWidget::DestroyEntity(Entity* entity) @@ -91,11 +113,6 @@ namespace Ndk m_entities.erase(it); } - void BaseWidget::GrabKeyboard() - { - m_canvas->SetKeyboardOwner(this); - } - void BaseWidget::Layout() { if (m_canvas)