fixed-layout.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #if defined(Hiro_FixedLayout)
  2. auto mFixedLayout::append(sSizable sizable, Geometry geometry) -> type& {
  3. for(auto& cell : state.cells) {
  4. if(cell->state.sizable == sizable) return *this;
  5. }
  6. FixedLayoutCell cell;
  7. cell->setSizable(sizable);
  8. cell->setGeometry(geometry);
  9. cell->setParent(this, cellCount());
  10. state.cells.append(cell);
  11. return synchronize();
  12. }
  13. auto mFixedLayout::cell(uint position) const -> FixedLayoutCell {
  14. return state.cells(position, {});
  15. }
  16. auto mFixedLayout::cell(sSizable sizable) const -> FixedLayoutCell {
  17. for(auto& cell : state.cells) {
  18. if(cell->state.sizable == sizable) return cell;
  19. }
  20. return {};
  21. }
  22. auto mFixedLayout::cells() const -> vector<FixedLayoutCell> {
  23. return state.cells;
  24. }
  25. auto mFixedLayout::cellCount() const -> uint {
  26. return state.cells.size();
  27. }
  28. auto mFixedLayout::destruct() -> void {
  29. for(auto& cell : state.cells) cell->destruct();
  30. return mSizable::destruct();
  31. }
  32. auto mFixedLayout::minimumSize() const -> Size {
  33. float width = 0, height = 0;
  34. for(auto& cell : state.cells) {
  35. width = max(width, cell.sizable().minimumSize().width());
  36. height = max(height, cell.sizable().minimumSize().height());
  37. }
  38. return {width, height};
  39. }
  40. auto mFixedLayout::remove(sSizable sizable) -> type& {
  41. for(auto& cell : state.cells) {
  42. if(cell->state.sizable == sizable) return remove(cell);
  43. }
  44. return *this;
  45. }
  46. auto mFixedLayout::remove(sFixedLayoutCell cell) -> type& {
  47. if(cell->parent() != this) return *this;
  48. auto offset = cell->offset();
  49. cell->setParent();
  50. state.cells.remove(offset);
  51. for(uint n : range(offset, cellCount())) state.cells[n]->adjustOffset(-1);
  52. return synchronize();
  53. }
  54. auto mFixedLayout::reset() -> type& {
  55. while(state.cells) remove(state.cells.right());
  56. return synchronize();
  57. }
  58. auto mFixedLayout::resize() -> type& {
  59. setGeometry(geometry());
  60. return *this;
  61. }
  62. auto mFixedLayout::setEnabled(bool enabled) -> type& {
  63. mSizable::setEnabled(enabled);
  64. for(auto& cell : state.cells) cell.sizable().setEnabled(cell.sizable().enabled());
  65. return *this;
  66. }
  67. auto mFixedLayout::setFont(const Font& font) -> type& {
  68. mSizable::setFont(font);
  69. for(auto& cell : state.cells) cell.sizable().setFont(cell.sizable().font());
  70. return *this;
  71. }
  72. auto mFixedLayout::setParent(mObject* parent, int offset) -> type& {
  73. for(auto& cell : reverse(state.cells)) cell->destruct();
  74. mSizable::setParent(parent, offset);
  75. for(auto& cell : state.cells) cell->setParent(this, cell->offset());
  76. return *this;
  77. }
  78. auto mFixedLayout::setVisible(bool visible) -> type& {
  79. mSizable::setVisible(visible);
  80. for(auto& cell : state.cells) cell.sizable().setVisible(cell.sizable().visible());
  81. return synchronize();
  82. }
  83. auto mFixedLayout::synchronize() -> type& {
  84. setGeometry(geometry());
  85. return *this;
  86. }
  87. //
  88. auto mFixedLayoutCell::destruct() -> void {
  89. if(auto& sizable = state.sizable) sizable->destruct();
  90. mObject::destruct();
  91. }
  92. auto mFixedLayoutCell::geometry() const -> Geometry {
  93. return state.geometry;
  94. }
  95. auto mFixedLayoutCell::setEnabled(bool enabled) -> type& {
  96. mObject::setEnabled(enabled);
  97. state.sizable->setEnabled(state.sizable->enabled());
  98. return *this;
  99. }
  100. auto mFixedLayoutCell::setFont(const Font& font) -> type& {
  101. mObject::setFont(font);
  102. state.sizable->setFont(state.sizable->font());
  103. return *this;
  104. }
  105. auto mFixedLayoutCell::setGeometry(Geometry geometry) -> type& {
  106. state.geometry = geometry;
  107. return synchronize();
  108. }
  109. auto mFixedLayoutCell::setParent(mObject* parent, int offset) -> type& {
  110. state.sizable->destruct();
  111. mObject::setParent(parent, offset);
  112. state.sizable->setParent(this, 0);
  113. return *this;
  114. }
  115. auto mFixedLayoutCell::setSizable(sSizable sizable) -> type& {
  116. state.sizable = sizable;
  117. return synchronize();
  118. }
  119. auto mFixedLayoutCell::setVisible(bool visible) -> type& {
  120. mObject::setVisible(visible);
  121. state.sizable->setVisible(state.sizable->visible());
  122. return *this;
  123. }
  124. auto mFixedLayoutCell::sizable() const -> Sizable {
  125. return state.sizable ? state.sizable : Sizable();
  126. }
  127. auto mFixedLayoutCell::synchronize() -> type& {
  128. if(auto parent = this->parent()) {
  129. if(auto fixedLayout = dynamic_cast<mFixedLayout*>(parent)) {
  130. fixedLayout->synchronize();
  131. }
  132. }
  133. return *this;
  134. }
  135. #endif