ElementStyle.h 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * This source file is part of libRocket, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://www.librocket.com
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. */
  27. #ifndef ROCKETCORELUAELEMENTSTYLE_H
  28. #define ROCKETCORELUAELEMENTSTYLE_H
  29. /*
  30. This is the definition of an ElementStyle Lua object
  31. This object is returned when you have an element, and access Element.style
  32. You can access it like a regular table, with the exception of iterating
  33. over the properties.
  34. A few peculiarities/rules:
  35. You are unable to create an instance of this object, only use one returned by
  36. the "style" value of an 'Element' item. Of course, you can store the object in
  37. a local variable in Lua and still have everything be valid
  38. When setting a property of a style, both the key and value need to be strings
  39. --Examples assume "e" is an element object
  40. e.style["width"] = "40px"
  41. e.style.width = "40px" --does the same as above
  42. When getting a property of a style, it spits out exactly what you put in.
  43. If you used the above width setting to "40px" then
  44. --Examples assume "e" is an element object
  45. local w = e.style["width"] --or e.style.width
  46. w would be "40px"
  47. If you need to iterate over the values, you'll have to call style:GetTable()
  48. Because of the way that I made the object, the following will not work
  49. for k,v in pairs(element.style) do --assumes "element" is an element object
  50. print(k .. " " ..v)
  51. end
  52. This is because I don't actually have any properties stored in the Lua table
  53. To do it, you'd have to say
  54. local properties = element.style:GetTable() --assumes "element" is an element object
  55. for k,v in pairs(properties) do
  56. print(k .. " " .. v)
  57. end
  58. However, the table returned from style:GetTable() is read only. Whatever changes you
  59. make to that table will not be saved to the 'style' object. To do that, just do whatever
  60. operation you were going to on the table before, but do it on the 'style' object instead.
  61. */
  62. #include <Rocket/Core/Lua/LuaType.h>
  63. #include <Rocket/Core/Lua/lua.hpp>
  64. #include <ElementStyle.h>
  65. namespace Rocket {
  66. namespace Core {
  67. namespace Lua {
  68. template<> void LuaType<ElementStyle>::extra_init(lua_State* L, int metatable_index);
  69. int ElementStyle__index(lua_State* L);
  70. int ElementStyle__newindex(lua_State* L);
  71. //methods
  72. int ElementStyleGetTable(lua_State* L, ElementStyle* obj);
  73. RegType<ElementStyle> ElementStyleMethods[];
  74. luaL_reg ElementStyleGetters[];
  75. luaL_reg ElementStyleSetters[];
  76. /*
  77. template<> const char* GetTClassName<ElementStyle>();
  78. template<> RegType<ElementStyle>* GetMethodTable<ElementStyle>();
  79. template<> luaL_reg* GetAttrTable<ElementStyle>();
  80. template<> luaL_reg* SetAttrTable<ElementStyle>();
  81. */
  82. }
  83. }
  84. }
  85. #endif