UIElement.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #include "UIElement.h"
  2. UIElement::UIElement()
  3. : Framework::ReferenceCounter(),
  4. marginLeft(0),
  5. marginRight(0),
  6. marginTop(0),
  7. marginBottom(0),
  8. width(0),
  9. height(0)
  10. {}
  11. void UIElement::setId(const Framework::Text& id)
  12. {
  13. this->id = id;
  14. }
  15. const Framework::Text& UIElement::getId() const
  16. {
  17. return id;
  18. }
  19. void UIElement::setMarginLeft(const Framework::Text& marginLeft)
  20. {
  21. this->marginLeft = marginLeft;
  22. }
  23. const Framework::Text& UIElement::getMarginLeft() const
  24. {
  25. return marginLeft;
  26. }
  27. void UIElement::setMarginRight(const Framework::Text& marginRight)
  28. {
  29. this->marginRight = marginRight;
  30. }
  31. const Framework::Text& UIElement::getMarginRight() const
  32. {
  33. return marginRight;
  34. }
  35. void UIElement::setMarginTop(const Framework::Text& marginTop)
  36. {
  37. this->marginTop = marginTop;
  38. }
  39. const Framework::Text& UIElement::getMarginTop() const
  40. {
  41. return marginTop;
  42. }
  43. void UIElement::setMarginBottom(const Framework::Text& marginBottom)
  44. {
  45. this->marginBottom = marginBottom;
  46. }
  47. const Framework::Text& UIElement::getMarginBottom() const
  48. {
  49. return marginBottom;
  50. }
  51. void UIElement::setWidth(const Framework::Text& width)
  52. {
  53. this->width = width;
  54. }
  55. const Framework::Text& UIElement::getWidth() const
  56. {
  57. return width;
  58. }
  59. void UIElement::setHeight(const Framework::Text& height)
  60. {
  61. this->height = height;
  62. }
  63. const Framework::Text& UIElement::getHeight() const
  64. {
  65. return height;
  66. }
  67. void UIElement::setAlignLeft(const Framework::Text& alignLeft)
  68. {
  69. this->alignLeft = alignLeft;
  70. }
  71. const Framework::Text& UIElement::getAlignLeft() const
  72. {
  73. return alignLeft;
  74. }
  75. void UIElement::setAlignRight(const Framework::Text& alignRight)
  76. {
  77. this->alignRight = alignRight;
  78. }
  79. const Framework::Text& UIElement::getAlignRight() const
  80. {
  81. return alignRight;
  82. }
  83. void UIElement::setAlignTop(const Framework::Text& alignTop)
  84. {
  85. this->alignTop = alignTop;
  86. }
  87. const Framework::Text& UIElement::getAlignTop() const
  88. {
  89. return alignTop;
  90. }
  91. void UIElement::setAlignBottom(const Framework::Text& alignBottom)
  92. {
  93. this->alignBottom = alignBottom;
  94. }
  95. const Framework::Text& UIElement::getAlignBottom() const
  96. {
  97. return alignBottom;
  98. }
  99. void UIElement::setStyle(const Framework::Text& style)
  100. {
  101. this->style = style;
  102. }
  103. const Framework::Text& UIElement::getStyle() const
  104. {
  105. return style;
  106. }
  107. Framework::XML::Element* UIElement::toUIML(
  108. Framework::Either<Block*, Entity*> zTarget, Entity* zActor) const
  109. {
  110. Framework::XML::Element* result = new Framework::XML::Element();
  111. result->setAttribute("id", id);
  112. if (!marginLeft.istGleich("0"))
  113. {
  114. result->setAttribute("margin-left", marginLeft);
  115. }
  116. if (!marginRight.istGleich("0"))
  117. {
  118. result->setAttribute("margin-right", marginRight);
  119. }
  120. if (!marginTop.istGleich("0"))
  121. {
  122. result->setAttribute("margin-top", marginTop);
  123. }
  124. if (!marginBottom.istGleich("0"))
  125. {
  126. result->setAttribute("margin-bottom", marginBottom);
  127. }
  128. result->setAttribute("width", width);
  129. result->setAttribute("height", height);
  130. if (alignLeft.getLength() > 0)
  131. {
  132. result->setAttribute("align-left", alignLeft);
  133. }
  134. if (alignRight.getLength() > 0)
  135. {
  136. result->setAttribute("align-right", alignRight);
  137. }
  138. if (alignTop.getLength() > 0)
  139. {
  140. result->setAttribute("align-top", alignTop);
  141. }
  142. if (alignBottom.getLength() > 0)
  143. {
  144. result->setAttribute("align-bottom", alignBottom);
  145. }
  146. if (style.getLength() > 0)
  147. {
  148. result->setAttribute("style", style);
  149. }
  150. return result;
  151. }
  152. UIContainerElement::UIContainerElement()
  153. : UIElement()
  154. {}
  155. void UIContainerElement::addChild(UIElement* child)
  156. {
  157. children.add(child);
  158. }
  159. const Framework::RCArray<UIElement>& UIContainerElement::getChildren() const
  160. {
  161. return children;
  162. }
  163. Framework::XML::Element* UIContainerElement::toUIML(
  164. Framework::Either<Block*, Entity*> zTarget, Entity* zActor) const
  165. {
  166. Framework::XML::Element* result = UIElement::toUIML(zTarget, zActor);
  167. for (UIElement* child : children)
  168. {
  169. result->addChild(child->toUIML(zTarget, zActor));
  170. }
  171. return result;
  172. }