46 if (mWidgetScroll !=
nullptr)
49 mWidgetScroll->setScrollPage((
size_t)mHeightLine);
58 mWidgetScroll =
nullptr;
80 size_t sel = mIndexSelect;
162 if (sel != mIndexSelect)
169 if (mWidgetScroll !=
nullptr)
185 if (mRangeIndex <= 0)
188 if (mWidgetScroll ==
nullptr)
191 int offset = (int)mWidgetScroll->getScrollPosition();
193 offset += mHeightLine;
195 offset -= mHeightLine;
197 if (offset >= mRangeIndex)
198 offset = mRangeIndex;
202 if ((
int)mWidgetScroll->getScrollPosition() == offset)
205 mWidgetScroll->setScrollPosition(offset);
230 if (mActivateOnClick)
265 if (mWidgetScroll ==
nullptr)
270 if (mWidgetScroll->getVisible())
272 mWidgetScroll->setVisible(
false);
280 else if (!mWidgetScroll->getVisible())
286 mWidgetScroll->setVisible(
true);
289 mWidgetScroll->setScrollRange(mRangeIndex + 1);
291 if (!mItemsInfo.empty())
292 mWidgetScroll->setTrackSize(
307 int position = mTopIndex * mHeightLine + mOffsetTop;
310 if (mOldSize.height <
mCoord.height)
312 int height = (int)mWidgetLines.size() * mHeightLine - mOffsetTop;
316 (mWidgetLines.size() < mItemsInfo.size()))
342 mWidgetLines.push_back(line);
343 height += mHeightLine;
347 if (position >= mRangeIndex)
350 if (mRangeIndex <= 0)
353 if (position || mOffsetTop || mTopIndex)
362 for (
auto& widgetLine : mWidgetLines)
364 widgetLine->setPosition(0, offset);
365 offset += mHeightLine;
375 if (mOffsetTop == mHeightLine)
381 int top = (int)mItemsInfo.size() - count - 1;
384 int offset = 0 - mOffsetTop;
385 for (
auto& widgetLine : mWidgetLines)
387 widgetLine->setPosition(0, offset);
388 offset += mHeightLine;
392 position = top * mHeightLine + mOffsetTop;
395 if (top != mTopIndex)
409 if (mWidgetScroll !=
nullptr)
410 mWidgetScroll->setScrollPosition(position);
412 mOldSize.width =
mCoord.width;
413 mOldSize.height =
mCoord.height;
420 for (; pos < mWidgetLines.size(); pos++)
423 size_t index = pos + (size_t)mTopIndex;
426 if (index >= mItemsInfo.size())
429 mLastRedrawLine = pos;
435 mLastRedrawLine = pos;
440 mWidgetLines[pos]->setVisible(
true);
442 mWidgetLines[pos]->setCaption(mItemsInfo[index].first);
445 static_cast<Button*
>(mWidgetLines[pos])->setStateSelected(index == mIndexSelect);
449 if (pos >= mWidgetLines.size())
451 mLastRedrawLine = pos;
456 for (; pos < mWidgetLines.size(); pos++)
458 static_cast<Button*
>(mWidgetLines[pos])->setStateSelected(
false);
469 if (_index < (
size_t)mTopIndex)
471 _index -= (size_t)mTopIndex;
473 if (_index >= mLastRedrawLine)
478 mWidgetLines[_index]->setCaption(mItemsInfo[_index + mTopIndex].first);
485 _index = mItemsInfo.size();
488 mItemsInfo.insert(mItemsInfo.begin() + _index, PairItem(_name, _data));
491 if ((mIndexSelect !=
ITEM_NONE) && (_index <= mIndexSelect))
495 if ((_index <= (
size_t)mTopIndex) && (mRangeIndex > 0))
499 if (mWidgetScroll !=
nullptr)
501 mWidgetScroll->setScrollRange(mWidgetScroll->getScrollRange() + mHeightLine);
502 if (!mItemsInfo.empty())
503 mWidgetScroll->setTrackSize(
505 (
int)mItemsInfo.size());
506 mWidgetScroll->setScrollPosition(mTopIndex * mHeightLine + mOffsetTop);
508 mRangeIndex += mHeightLine;
513 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
519 if (mWidgetScroll !=
nullptr)
521 mWidgetScroll->setScrollRange(mWidgetScroll->getScrollRange() + mHeightLine);
522 if (!mItemsInfo.empty())
523 mWidgetScroll->setTrackSize(
525 (
int)mItemsInfo.size());
526 mWidgetScroll->setScrollPosition(mTopIndex * mHeightLine + mOffsetTop);
528 mRangeIndex += mHeightLine;
548 mItemsInfo.erase(mItemsInfo.begin() + _index);
551 if (mItemsInfo.empty())
555 if (_index < mIndexSelect)
557 else if ((_index == mIndexSelect) && (mIndexSelect == (mItemsInfo.size())))
562 if (mWidgetLines.size() > mItemsInfo.size())
564 mWidgetLines[mItemsInfo.size()]->setVisible(
false);
568 if (_index < (
size_t)mTopIndex)
572 if (mWidgetScroll !=
nullptr)
574 mWidgetScroll->setScrollRange(mWidgetScroll->getScrollRange() - mHeightLine);
575 if (!mItemsInfo.empty())
576 mWidgetScroll->setTrackSize(
578 (
int)mItemsInfo.size());
579 mWidgetScroll->setScrollPosition(mTopIndex * mHeightLine + mOffsetTop);
581 mRangeIndex -= mHeightLine;
586 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
592 if (mWidgetScroll !=
nullptr)
594 mWidgetScroll->setScrollRange(mWidgetScroll->getScrollRange() - mHeightLine);
595 if (!mItemsInfo.empty())
596 mWidgetScroll->setTrackSize(
598 (
int)mItemsInfo.size());
599 mWidgetScroll->setScrollPosition(mTopIndex * mHeightLine + mOffsetTop);
601 mRangeIndex -= mHeightLine;
619 if (mIndexSelect != _index)
623 mIndexSelect = _index;
632 if (_index < (
size_t)mTopIndex)
635 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
640 size_t index = _index - mTopIndex;
641 if (index < mWidgetLines.size())
642 static_cast<Button*
>(mWidgetLines[index])->setStateSelected(_select);
648 if (mRangeIndex <= 0)
651 int offset = (int)_index * mHeightLine;
652 if (offset >= mRangeIndex)
653 offset = mRangeIndex;
655 if (mWidgetScroll !=
nullptr)
657 if ((
int)mWidgetScroll->getScrollPosition() == offset)
659 mWidgetScroll->setScrollPosition(offset);
668 if (_index >= mItemsInfo.size())
671 if (mRangeIndex <= 0)
675 if (_index < (
size_t)mTopIndex)
679 if (_index == (
size_t)mTopIndex)
681 return mOffsetTop == 0 || !_fill;
685 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
707 for (
auto& widgetLine : mWidgetLines)
709 widgetLine->setVisible(
false);
710 widgetLine->setPosition(0, offset);
711 offset += mHeightLine;
722 mItemsInfo[_index].first = _name;
729 mItemsInfo[_index].second = std::move(_data);
736 return mItemsInfo[_index].first;
741#if MYGUI_DEBUG_MODE == 1
761 static_cast<Button*
>(mWidgetLines[_index])->_setMouseFocus(_focus);
766 if (mNeedVisibleScroll == _visible)
768 mNeedVisibleScroll = _visible;
774 if (mWidgetScroll !=
nullptr)
776 if (mWidgetScroll->getScrollRange() > _position)
778 mWidgetScroll->setScrollPosition(_position);
786 mOffsetTop = ((int)_position % mHeightLine);
789 int offset = 0 - mOffsetTop;
791 for (
auto& widgetLine : mWidgetLines)
793 widgetLine->setPosition(
IntPoint(0, offset));
794 offset += mHeightLine;
798 int top = ((int)_position / mHeightLine);
799 if (top != mTopIndex)
821 if (_index1 == _index2)
824 std::swap(mItemsInfo[_index1], mItemsInfo[_index2]);
833 int max_height = mItemsInfo.size() * mHeightLine;
838 if (visible_height >= max_height)
843 for (
size_t pos = 0; pos < mWidgetLines.size(); pos++)
845 if (pos >= mItemsInfo.size())
847 MYGUI_ASSERT(mWidgetLines[pos]->
getTop() == height,
"mWidgetLines[pos]->getTop() == height");
848 height += mWidgetLines[pos]->getHeight();
855 for (
size_t pos = 0; pos < mItemsInfo.size(); pos++)
857 if (mItemsInfo[pos].first == _name)
870 return mItemsInfo.size();
918 for (
const auto& line : mWidgetLines)
921 return *line->_getInternalData<
size_t>() + mTopIndex;
934 for (
const auto& line : mWidgetLines)
942 if (_key ==
"AddItem")
944 else if (_key ==
"ActivateOnClick")
973#if MYGUI_DEBUG_MODE == 1
977 "ListBox::notifyMousePressed");
981 "ListBox::notifyMousePressed");
986 if (mIndexSelect != index)
990 mIndexSelect = index;
1024 size_t ListBox::getIndexByWidget(
Widget* _widget)
const
1057 mActivateOnClick = activateOnClick;
1066 size_t index = _index - (size_t)mTopIndex;
1068 if (index < mWidgetLines.size())
1069 return mWidgetLines[index];
#define MYGUI_ASSERT(exp, dest)
#define MYGUI_ASSERT_RANGE_INSERT(index, size, owner)
#define MYGUI_ASSERT_RANGE(index, size, owner)
#define MYGUI_ASSERT_RANGE_AND_NONE(index, size, owner)
Type * castType(bool _throw=true)
static LanguageManager & getInstance()
void _setItemNameAt(size_t _index, const UString &_name) override
void addItem(const UString &_name, Any _data=Any::Null)
Add an item to the end of a array.
void notifyMouseWheel(Widget *_sender, int _rel)
void _removeItemAt(size_t _index) override
void updateLine(bool _reset=false)
EventHandle_ListBoxPtrCIBNotifyCellDataRef eventNotifyItem
void beginToItemAt(size_t _index)
Move all elements so specified becomes visible.
void _redrawItem(size_t _index)
size_t _getItemIndex(Widget *_item) const override
void _setScrollView(size_t _position)
void notifyKeyButtonReleased(Widget *_sender, KeyCode _key)
void notifyMousePressed(Widget *_sender, int _left, int _top, MouseButton _id)
void _sendEventChangeScroll(size_t _position)
void setScrollPosition(size_t _position)
Set scroll position.
void notifyMouseButtonReleased(Widget *_sender, int _left, int _top, MouseButton _id)
void setSize(const IntSize &_size) override
bool isItemSelectedVisible(bool _fill=true)
Same as ListBox::isItemVisibleAt for selected item.
void _resetContainer(bool _update) override
const UString & _getItemNameAt(size_t _index) const override
bool isItemVisibleAt(size_t _index, bool _fill=true)
const UString & getItemNameAt(size_t _index) const
Get item name from specified position.
void notifyMouseClick(Widget *_sender)
void setActivateOnClick(bool activateOnClick)
void clearIndexSelected()
void _addItem(const MyGUI::UString &_name) override
void setScrollVisible(bool _visible)
Set scroll visible when it needed.
void _activateItem(Widget *_sender)
void _redrawItemRange(size_t _start=0)
void notifyMouseLostFocus(Widget *_sender, Widget *_new)
void shutdownOverride() override
size_t getItemCount() const
Get number of items.
void initialiseOverride() override
void notifyScrollChangePosition(ScrollBar *_sender, size_t _position)
void notifyMouseSetFocus(Widget *_sender, Widget *_old)
void swapItemsAt(size_t _index1, size_t _index2)
Swap items at a specified positions.
int getOptimalHeight() const
Return optimal height to fit all items in ListBox.
void onKeyButtonReleased(KeyCode _key) override
void setCoord(const IntCoord &_coord) override
void insertItemAt(size_t _index, const UString &_name, Any _data=Any::Null)
Insert an item into a array at a specified position.
void removeAllItems()
Remove all items.
void setPosition(const IntPoint &_point) override
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListChangePosition
void onMouseWheel(int _rel) override
void clearItemDataAt(size_t _index)
Clear an item data at a specified position.
size_t getIndexSelected() const
void _selectIndex(size_t _index, bool _select)
size_t _getItemCount() const override
void _setItemFocus(size_t _index, bool _focus)
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListMouseItemFocus
void setPropertyOverride(std::string_view _key, std::string_view _value) override
size_t findItemIndexWith(const UString &_name)
Search item, returns the position of the first occurrence in array or ITEM_NONE if item not found.
void beginToItemFirst()
Move all elements so first becomes visible.
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListChangeScroll
void notifyKeyButtonPressed(Widget *_sender, KeyCode _key, Char _char)
void onKeyButtonPressed(KeyCode _key, Char _char) override
void setItemDataAt(size_t _index, Any _data)
Replace an item data at a specified position.
void notifyMouseDoubleClick(Widget *_sender)
Widget * getWidgetByIndex(size_t _index)
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListSelectAccept
void beginToItemSelected()
Move all elements so selected becomes visible.
void removeItemAt(size_t _index)
Remove item at a specified position.
void setItemNameAt(size_t _index, const UString &_name)
Replace an item name at a specified position.
void setIndexSelected(size_t _index)
void beginToItemLast()
Move all elements so last becomes visible.
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListMouseItemActivate
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
bool isUserString(std::string_view _key) const
std::string_view getUserString(std::string_view _key) const
void _setInternalData(Any _data)
ValueType * _getInternalData(bool _throw=true) const
bool parseBool(std::string_view _value)
int parseInt(std::string_view _value)
types::TPoint< int > IntPoint
constexpr size_t ITEM_NONE
types::TCoord< int > IntCoord
types::TSize< int > IntSize
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))