MCPcopy Create free account
hub / github.com/MyGUI/mygui / insertItemAt

Method insertItemAt

MyGUIEngine/src/MyGUI_ListBox.cpp:481–541  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

479 }
480
481 void ListBox::insertItemAt(size_t _index, const UString& _name, Any _data)
482 {
483 MYGUI_ASSERT_RANGE_INSERT(_index, mItemsInfo.size(), "ListBox::insertItemAt");
484 if (_index == ITEM_NONE)
485 _index = mItemsInfo.size();
486
487 // вставляем физически
488 mItemsInfo.insert(mItemsInfo.begin() + _index, PairItem(_name, _data));
489
490 // если надо, то меняем выделенный элемент
491 if ((mIndexSelect != ITEM_NONE) && (_index <= mIndexSelect))
492 mIndexSelect++;
493
494 // строка, до первого видимого элемента
495 if ((_index <= (size_t)mTopIndex) && (mRangeIndex > 0))
496 {
497 mTopIndex++;
498 // просчитываем положение скролла
499 if (mWidgetScroll != nullptr)
500 {
501 mWidgetScroll->setScrollRange(mWidgetScroll->getScrollRange() + mHeightLine);
502 if (!mItemsInfo.empty())
503 mWidgetScroll->setTrackSize(
504 mWidgetScroll->getLineSize() * _getClientWidget()->getHeight() / mHeightLine /
505 (int)mItemsInfo.size());
506 mWidgetScroll->setScrollPosition(mTopIndex * mHeightLine + mOffsetTop);
507 }
508 mRangeIndex += mHeightLine;
509 }
510 else
511 {
512 // высчитывам положение строки
513 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
514
515 // строка, после последнего видимого элемента, плюс одна строка (потому что для прокрутки нужно на одну строчку больше)
516 if (_getClientWidget()->getHeight() < (offset - mHeightLine))
517 {
518 // просчитываем положение скролла
519 if (mWidgetScroll != nullptr)
520 {
521 mWidgetScroll->setScrollRange(mWidgetScroll->getScrollRange() + mHeightLine);
522 if (!mItemsInfo.empty())
523 mWidgetScroll->setTrackSize(
524 mWidgetScroll->getLineSize() * _getClientWidget()->getHeight() / mHeightLine /
525 (int)mItemsInfo.size());
526 mWidgetScroll->setScrollPosition(mTopIndex * mHeightLine + mOffsetTop);
527 }
528 mRangeIndex += mHeightLine;
529
530 // строка в видимой области
531 }
532 else
533 {
534 // обновляем все
535 updateScroll();
536 updateLine(true);
537
538 // позже сюда еще оптимизацию по колличеству перерисовок

Callers

nothing calls this directly

Calls 10

setScrollRangeMethod · 0.80
getScrollRangeMethod · 0.80
setTrackSizeMethod · 0.80
getLineSizeMethod · 0.80
sizeMethod · 0.45
insertMethod · 0.45
beginMethod · 0.45
emptyMethod · 0.45
getHeightMethod · 0.45
setScrollPositionMethod · 0.45

Tested by

no test coverage detected