ElementStyle.h 2.5 KB

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