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

Method removeItemAt

MyGUIEngine/src/MyGUI_ListBox.cpp:543–614  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

541 }
542
543 void ListBox::removeItemAt(size_t _index)
544 {
545 MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "ListBox::removeItemAt");
546
547 // удяляем физически строку
548 mItemsInfo.erase(mItemsInfo.begin() + _index);
549
550 // если надо, то меняем выделенный элемент
551 if (mItemsInfo.empty())
552 mIndexSelect = ITEM_NONE;
553 else if (mIndexSelect != ITEM_NONE)
554 {
555 if (_index < mIndexSelect)
556 mIndexSelect--;
557 else if ((_index == mIndexSelect) && (mIndexSelect == (mItemsInfo.size())))
558 mIndexSelect--;
559 }
560
561 // если виджетов стало больше , то скрываем крайний
562 if (mWidgetLines.size() > mItemsInfo.size())
563 {
564 mWidgetLines[mItemsInfo.size()]->setVisible(false);
565 }
566
567 // строка, до первого видимого элемента
568 if (_index < (size_t)mTopIndex)
569 {
570 mTopIndex--;
571 // просчитываем положение скролла
572 if (mWidgetScroll != nullptr)
573 {
574 mWidgetScroll->setScrollRange(mWidgetScroll->getScrollRange() - mHeightLine);
575 if (!mItemsInfo.empty())
576 mWidgetScroll->setTrackSize(
577 mWidgetScroll->getLineSize() * _getClientWidget()->getHeight() / mHeightLine /
578 (int)mItemsInfo.size());
579 mWidgetScroll->setScrollPosition(mTopIndex * mHeightLine + mOffsetTop);
580 }
581 mRangeIndex -= mHeightLine;
582 }
583 else
584 {
585 // высчитывам положение удаляемой строки
586 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
587
588 // строка, после последнего видимого элемента
589 if (_getClientWidget()->getHeight() < offset)
590 {
591 // просчитываем положение скролла
592 if (mWidgetScroll != nullptr)
593 {
594 mWidgetScroll->setScrollRange(mWidgetScroll->getScrollRange() - mHeightLine);
595 if (!mItemsInfo.empty())
596 mWidgetScroll->setTrackSize(
597 mWidgetScroll->getLineSize() * _getClientWidget()->getHeight() / mHeightLine /
598 (int)mItemsInfo.size());
599 mWidgetScroll->setScrollPosition(mTopIndex * mHeightLine + mOffsetTop);
600 }

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected