Add a data field to Lua UI layouts

switch-to-ppa
uramer 3 years ago committed by Petr Mikheev
parent b35cb038d0
commit e65c946452

@ -46,6 +46,11 @@ namespace LuaUi
}
}
void setLayout(LuaUi::WidgetExtension* ext, const sol::table& layout)
{
ext->setLayout(layout);
}
LuaUi::WidgetExtension* createWidget(const sol::table& layout, LuaUi::WidgetExtension* parent)
{
std::string type = widgetType(layout);
@ -72,6 +77,7 @@ namespace LuaUi
setEventCallbacks(ext, layout);
setProperties(ext, layout);
setLayout(ext, layout);
Content cont = content(layout);
for (size_t i = 0; i < cont.size(); i++)
@ -90,6 +96,7 @@ namespace LuaUi
{
setEventCallbacks(ext, layout);
setProperties(ext, layout);
setLayout(ext, layout);
Content newContent = content(layout);

@ -13,13 +13,16 @@ namespace LuaUi
, mAbsoluteCoord()
, mRelativeCoord()
, mAnchor()
, mLua{ nullptr }
, mWidget{ nullptr }
, mLayout{ sol::nil }
{}
void WidgetExtension::triggerEvent(std::string_view name, const sol::object& argument = sol::nil) const
{
auto it = mCallbacks.find(name);
if (it != mCallbacks.end())
it->second(argument);
it->second(argument, mLayout);
}
void WidgetExtension::create(lua_State* lua, MyGUI::Widget* self)

@ -43,6 +43,8 @@ namespace LuaUi
void setForcedCoord(const MyGUI::IntCoord& offset);
void updateCoord();
void setLayout(const sol::table& layout) { mLayout = layout; }
protected:
sol::table makeTable() const;
sol::object keyEvent(MyGUI::KeyCode) const;
@ -72,6 +74,7 @@ namespace LuaUi
std::vector<WidgetExtension*> mContent;
std::map<std::string, LuaUtil::Callback, std::less<>> mCallbacks;
sol::table mLayout;
void updateChildrenCoord(MyGUI::Widget*);

@ -46,6 +46,14 @@ A container holding all the widget's children. It has a few important difference
.. TODO: Talk about skins/templates here when they are ready
Events
------
| A table mapping event names to `openmw.async.callback` s.
| When an event triggers, the callback is called with two arguments:
an event-specific value, and that widget's layout table.
| See the Widget type pages for information on what events exist, and which first argument they pass.
Widget types
------------

@ -41,7 +41,7 @@ Events
:widths: 20 20 60
* - name
- type
- first argument type
- description
* - keyPress
- `KeyboardEvent <../openmw_input.html##(KeyboardEvent)>`_

Loading…
Cancel
Save