From d214f6f6ef2ceb726e029d0be3b9df9f1e1a808b Mon Sep 17 00:00:00 2001 From: uramer Date: Fri, 17 Nov 2023 18:02:34 +0100 Subject: [PATCH] Get rid of unncesesary onCoordChange --- components/lua_ui/adapter.cpp | 7 ++++++- components/lua_ui/adapter.hpp | 2 ++ components/lua_ui/widget.cpp | 4 ---- components/lua_ui/widget.hpp | 7 ------- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/components/lua_ui/adapter.cpp b/components/lua_ui/adapter.cpp index c9afd4db0d..44493f6f46 100644 --- a/components/lua_ui/adapter.cpp +++ b/components/lua_ui/adapter.cpp @@ -19,10 +19,15 @@ namespace LuaUi mContainer = MyGUI::Gui::getInstancePtr()->createWidget( "", MyGUI::IntCoord(), MyGUI::Align::Default, "", ""); mContainer->initialize(luaState, mContainer, false); - mContainer->onCoordChange([this](WidgetExtension* ext, MyGUI::IntCoord coord) { setSize(coord.size()); }); + mContainer->widget()->eventChangeCoord += MyGUI::newDelegate(this, &LuaAdapter::containerChangedCoord); mContainer->widget()->attachToWidget(this); } + void LuaAdapter::containerChangedCoord(MyGUI::Widget*) + { + setSize(mContainer->getSize()); + } + void LuaAdapter::attach(const std::shared_ptr& element) { detachElement(); diff --git a/components/lua_ui/adapter.hpp b/components/lua_ui/adapter.hpp index d699e4992f..1524a55425 100644 --- a/components/lua_ui/adapter.hpp +++ b/components/lua_ui/adapter.hpp @@ -25,6 +25,8 @@ namespace LuaUi void attachElement(); void detachElement(); + + void containerChangedCoord(MyGUI::Widget*); }; } diff --git a/components/lua_ui/widget.cpp b/components/lua_ui/widget.cpp index 2e505ff9a8..855ba29b3c 100644 --- a/components/lua_ui/widget.cpp +++ b/components/lua_ui/widget.cpp @@ -42,8 +42,6 @@ namespace LuaUi clearCallbacks(); clearEvents(mWidget); - mOnCoordChange.reset(); - for (WidgetExtension* w : mChildren) w->deinitialize(); for (WidgetExtension* w : mTemplateChildren) @@ -264,8 +262,6 @@ namespace LuaUi if (oldCoord != newCoord) mWidget->setCoord(newCoord); updateChildrenCoord(); - if (oldCoord != newCoord && mOnCoordChange.has_value()) - mOnCoordChange.value()(this, newCoord); } void WidgetExtension::setProperties(const sol::object& props) diff --git a/components/lua_ui/widget.hpp b/components/lua_ui/widget.hpp index 0902434e19..1cda09b41b 100644 --- a/components/lua_ui/widget.hpp +++ b/components/lua_ui/widget.hpp @@ -69,11 +69,6 @@ namespace LuaUi return parseExternal(mExternal, name, defaultValue); } - void onCoordChange(const std::optional>& callback) - { - mOnCoordChange = callback; - } - virtual MyGUI::IntSize calculateSize(); virtual MyGUI::IntPoint calculatePosition(const MyGUI::IntSize& size); MyGUI::IntCoord calculateCoord(); @@ -176,8 +171,6 @@ namespace LuaUi void focusGain(MyGUI::Widget*, MyGUI::Widget*); void focusLoss(MyGUI::Widget*, MyGUI::Widget*); - std::optional> mOnCoordChange; - void updateVisible(); };