mirror of
https://github.com/OpenMW/openmw.git
synced 2025-04-02 18:36:40 +00:00
Add a data field to Lua UI layouts
This commit is contained in:
parent
b35cb038d0
commit
e65c946452
5 changed files with 24 additions and 3 deletions
components/lua_ui
docs/source/reference/lua-scripting
|
@ -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)
|
LuaUi::WidgetExtension* createWidget(const sol::table& layout, LuaUi::WidgetExtension* parent)
|
||||||
{
|
{
|
||||||
std::string type = widgetType(layout);
|
std::string type = widgetType(layout);
|
||||||
|
@ -72,6 +77,7 @@ namespace LuaUi
|
||||||
|
|
||||||
setEventCallbacks(ext, layout);
|
setEventCallbacks(ext, layout);
|
||||||
setProperties(ext, layout);
|
setProperties(ext, layout);
|
||||||
|
setLayout(ext, layout);
|
||||||
|
|
||||||
Content cont = content(layout);
|
Content cont = content(layout);
|
||||||
for (size_t i = 0; i < cont.size(); i++)
|
for (size_t i = 0; i < cont.size(); i++)
|
||||||
|
@ -90,6 +96,7 @@ namespace LuaUi
|
||||||
{
|
{
|
||||||
setEventCallbacks(ext, layout);
|
setEventCallbacks(ext, layout);
|
||||||
setProperties(ext, layout);
|
setProperties(ext, layout);
|
||||||
|
setLayout(ext, layout);
|
||||||
|
|
||||||
Content newContent = content(layout);
|
Content newContent = content(layout);
|
||||||
|
|
||||||
|
|
|
@ -13,13 +13,16 @@ namespace LuaUi
|
||||||
, mAbsoluteCoord()
|
, mAbsoluteCoord()
|
||||||
, mRelativeCoord()
|
, mRelativeCoord()
|
||||||
, mAnchor()
|
, mAnchor()
|
||||||
|
, mLua{ nullptr }
|
||||||
|
, mWidget{ nullptr }
|
||||||
|
, mLayout{ sol::nil }
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void WidgetExtension::triggerEvent(std::string_view name, const sol::object& argument = sol::nil) const
|
void WidgetExtension::triggerEvent(std::string_view name, const sol::object& argument = sol::nil) const
|
||||||
{
|
{
|
||||||
auto it = mCallbacks.find(name);
|
auto it = mCallbacks.find(name);
|
||||||
if (it != mCallbacks.end())
|
if (it != mCallbacks.end())
|
||||||
it->second(argument);
|
it->second(argument, mLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WidgetExtension::create(lua_State* lua, MyGUI::Widget* self)
|
void WidgetExtension::create(lua_State* lua, MyGUI::Widget* self)
|
||||||
|
|
|
@ -43,6 +43,8 @@ namespace LuaUi
|
||||||
void setForcedCoord(const MyGUI::IntCoord& offset);
|
void setForcedCoord(const MyGUI::IntCoord& offset);
|
||||||
void updateCoord();
|
void updateCoord();
|
||||||
|
|
||||||
|
void setLayout(const sol::table& layout) { mLayout = layout; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
sol::table makeTable() const;
|
sol::table makeTable() const;
|
||||||
sol::object keyEvent(MyGUI::KeyCode) const;
|
sol::object keyEvent(MyGUI::KeyCode) const;
|
||||||
|
@ -72,6 +74,7 @@ namespace LuaUi
|
||||||
|
|
||||||
std::vector<WidgetExtension*> mContent;
|
std::vector<WidgetExtension*> mContent;
|
||||||
std::map<std::string, LuaUtil::Callback, std::less<>> mCallbacks;
|
std::map<std::string, LuaUtil::Callback, std::less<>> mCallbacks;
|
||||||
|
sol::table mLayout;
|
||||||
|
|
||||||
void updateChildrenCoord(MyGUI::Widget*);
|
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
|
.. 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
|
Widget types
|
||||||
------------
|
------------
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ Events
|
||||||
:widths: 20 20 60
|
:widths: 20 20 60
|
||||||
|
|
||||||
* - name
|
* - name
|
||||||
- type
|
- first argument type
|
||||||
- description
|
- description
|
||||||
* - keyPress
|
* - keyPress
|
||||||
- `KeyboardEvent <../openmw_input.html##(KeyboardEvent)>`_
|
- `KeyboardEvent <../openmw_input.html##(KeyboardEvent)>`_
|
||||||
|
|
Loading…
Reference in a new issue