ElementStyle.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #pragma once
  2. /*
  3. This is the definition of an ElementStyle Lua object
  4. This object is returned when you have an element, and access Element.style
  5. You can access it like a regular table, with the exception of iterating
  6. over the properties.
  7. A few peculiarities/rules:
  8. You are unable to create an instance of this object, only use one returned by
  9. the "style" value of an 'Element' item. Of course, you can store the object in
  10. a local variable in Lua and still have everything be valid
  11. When setting a property of a style, both the key and value need to be strings
  12. --Examples assume "e" is an element object
  13. e.style["width"] = "40px"
  14. e.style.width = "40px" --does the same as above
  15. When getting a property of a style, it spits out exactly what you put in.
  16. If you used the above width setting to "40px" then
  17. --Examples assume "e" is an element object
  18. local w = e.style["width"] --or e.style.width
  19. w would be "40px"
  20. If you need to iterate over the values, you'll have to call style:GetTable()
  21. Because of the way that I made the object, the following will not work
  22. for k,v in pairs(element.style) do --assumes "element" is an element object
  23. print(k .. " " ..v)
  24. end
  25. This is because I don't actually have any properties stored in the Lua table
  26. To do it, you'd have to say
  27. local properties = element.style:GetTable() --assumes "element" is an element object
  28. for k,v in pairs(properties) do
  29. print(k .. " " .. v)
  30. end
  31. However, the table returned from style:GetTable() is read only. Whatever changes you
  32. make to that table will not be saved to the 'style' object. To do that, just do whatever
  33. operation you were going to on the table before, but do it on the 'style' object instead.
  34. At the moment, you are unable to say element.style = {} and have a table of key,value pairs
  35. added to the style. That is planned for a little later
  36. */
  37. #include <Rocket/Core/Lua/LuaType.h>
  38. #include <Rocket/Core/Lua/lua.hpp>
  39. #include <ElementStyle.h>
  40. namespace Rocket {
  41. namespace Core {
  42. namespace Lua {
  43. template<> void LuaType<ElementStyle>::extra_init(lua_State* L, int metatable_index);
  44. int ElementStyle__index(lua_State* L);
  45. int ElementStyle__newindex(lua_State* L);
  46. //methods
  47. int ElementStyleGetTable(lua_State* L, ElementStyle* obj);
  48. RegType<ElementStyle> ElementStyleMethods[];
  49. luaL_reg ElementStyleGetters[];
  50. luaL_reg ElementStyleSetters[];
  51. /*
  52. template<> const char* GetTClassName<ElementStyle>();
  53. template<> RegType<ElementStyle>* GetMethodTable<ElementStyle>();
  54. template<> luaL_reg* GetAttrTable<ElementStyle>();
  55. template<> luaL_reg* SetAttrTable<ElementStyle>();
  56. */
  57. }
  58. }
  59. }