| 187 | } |
| 188 | |
| 189 | void ListBox::update() |
| 190 | { |
| 191 | Control::update(); |
| 192 | if (scroller == nullptr) |
| 193 | { |
| 194 | configureInternalScrollBar(); |
| 195 | } |
| 196 | if (scroller) |
| 197 | { |
| 198 | size_t scrollerLength = Controls.empty() ? 0 : ItemSpacing * (Controls.size() - 1); |
| 199 | // deduct the listbox size from the content size |
| 200 | // assume item sizes are variable if ItemSize is 0 (ie: need to calculate manually) |
| 201 | switch (ListOrientation) |
| 202 | { |
| 203 | case Orientation::Vertical: |
| 204 | { |
| 205 | if (ItemSize == 0) |
| 206 | { |
| 207 | for (const auto &i : Controls) |
| 208 | scrollerLength += i->Size.y; |
| 209 | } |
| 210 | else |
| 211 | { |
| 212 | scrollerLength += Controls.size() * ItemSize; |
| 213 | } |
| 214 | scrollerLength = scrollerLength > Size.y ? scrollerLength - Size.y : 0; |
| 215 | break; |
| 216 | } |
| 217 | case Orientation::Horizontal: |
| 218 | { |
| 219 | if (ItemSize == 0) |
| 220 | { |
| 221 | for (const auto &i : Controls) |
| 222 | scrollerLength += i->Size.x; |
| 223 | } |
| 224 | else |
| 225 | { |
| 226 | scrollerLength += Controls.size() * ItemSize; |
| 227 | } |
| 228 | scrollerLength = scrollerLength > Size.x ? scrollerLength - Size.x : 0; |
| 229 | break; |
| 230 | } |
| 231 | default: |
| 232 | LogWarning("Unknown ListBox::ListOrientation value: %d", |
| 233 | static_cast<int>(ListOrientation)); |
| 234 | break; |
| 235 | } |
| 236 | scroller->setMaximum(scroller->getMinimum() + scrollerLength); |
| 237 | scroller->update(); |
| 238 | Vec2<int> newScrollOffset = this->scrollOffset; |
| 239 | switch (ScrollOrientation) |
| 240 | { |
| 241 | case Orientation::Vertical: |
| 242 | newScrollOffset.y = scroller->getValue(); |
| 243 | break; |
| 244 | case Orientation::Horizontal: |
| 245 | newScrollOffset.x = scroller->getValue(); |
| 246 | break; |
nothing calls this directly
no test coverage detected