22 mFirstVisibleIndex(0),
42 mDragLayer =
"DragAndDrop";
104 void ItemBox::requestItemSize()
111 mSizeItem = coord.size();
112 MYGUI_ASSERT((mSizeItem.
width > 0 && mSizeItem.
height > 0),
"(mSizeItem.width > 0 && mSizeItem.height > 0) at requestCoordWidgetItem");
128 int count_visible = 0;
138 size_t start = (mFirstVisibleIndex * mCountItemInLine);
139 size_t count = (count_visible * mCountItemInLine) + start;
142 for (
size_t pos = start; pos < count; ++pos, ++index)
145 if (pos >= mItemsInfo.size())
break;
151 (((
int)index / mCountItemInLine) * mSizeItem.
height) - mFirstOffsetIndex);
155 item->
setPosition((((
int)index / mCountItemInLine) * mSizeItem.
width) - mFirstOffsetIndex,
156 ((
int)index % mCountItemInLine) * mSizeItem.
height - mContentPosition.
top);
164 IBDrawItemInfo data(pos, mIndexSelect, mIndexActive, mIndexAccept, mIndexRefuse,
true,
false);
171 while (index < mVectorItems.size())
173 mVectorItems[index]->setVisible(
false);
181 if (_index == mVectorItems.size())
202 mVectorItems.push_back(item);
208 return mVectorItems[_index];
237 size_t start = (size_t)(mFirstVisibleIndex * mCountItemInLine);
238 size_t index = mIndexActive;
242 if ((mIndexActive >= start) && (mIndexActive < (start + mVectorItems.size())))
244 IBDrawItemInfo data(index, mIndexSelect, mIndexActive, mIndexAccept, mIndexRefuse,
false,
false);
264 for (
size_t pos = 0; pos < mVectorItems.size(); ++pos)
266 Widget* item = mVectorItems[pos];
271 size_t index = calcIndexByWidget(item);
273 if (index < mItemsInfo.size())
276 mIndexActive = index;
277 IBDrawItemInfo data(index, mIndexSelect, mIndexActive, mIndexAccept, mIndexRefuse,
false,
false);
291 size_t index = calcIndexByWidget(_item);
292 if (index < mItemsInfo.size())
302 mIndexAccept = (_set && _accept ) ? _index :
ITEM_NONE;
303 mIndexRefuse = (_set && !_accept) ? _index :
ITEM_NONE;
305 size_t start = (size_t)(mFirstVisibleIndex * mCountItemInLine);
306 if ((_index >= start) && (_index < (start + mVectorItems.size())))
308 IBDrawItemInfo data(_index, mIndexSelect, mIndexActive, mIndexAccept, mIndexRefuse,
false,
false);
316 mItemsInfo[_index].data = _data;
318 size_t start = (size_t)(mFirstVisibleIndex * mCountItemInLine);
319 if ((_index >= start) && (_index < (start + mVectorItems.size())))
321 IBDrawItemInfo data(_index, mIndexSelect, mIndexActive, mIndexAccept, mIndexRefuse,
true,
false);
331 if (_index ==
ITEM_NONE) _index = mItemsInfo.size();
336 mItemsInfo.insert(mItemsInfo.begin() + _index,
ItemDataInfo(_data));
341 if (mIndexSelect >= _index)
365 mItemsInfo.erase(mItemsInfo.begin() + _index);
370 if (mItemsInfo.empty())
374 else if ((mIndexSelect > _index) || (mIndexSelect == mItemsInfo.size()))
393 if (mItemsInfo.empty())
412 size_t start = (size_t)(mFirstVisibleIndex * mCountItemInLine);
413 if ((_index >= start) && (_index < (start + mVectorItems.size())))
415 IBDrawItemInfo data(_index, mIndexSelect, mIndexActive, mIndexAccept, mIndexRefuse,
true,
false);
423 if (_index == mIndexSelect)
return;
425 size_t start = (size_t)(mFirstVisibleIndex * mCountItemInLine);
430 size_t index = mIndexSelect;
433 if ((index >= start) && (index < (start + mVectorItems.size())))
435 IBDrawItemInfo data(index, mIndexSelect, mIndexActive, mIndexAccept, mIndexRefuse,
false,
false);
440 mIndexSelect = _index;
443 if ((_index >= start) && (_index < (start + mVectorItems.size())))
445 IBDrawItemInfo data(_index, mIndexSelect, mIndexActive, mIndexAccept, mIndexRefuse,
false,
false);
461 if (mAlignVert == _vert)
465 mCountItemInLine = -1;
481 MYGUI_ASSERT(_widget,
"ItemBox::getIndexByWidget : Widget == nullptr");
485 size_t index = calcIndexByWidget(_widget);
493 for (
const auto& item : mVectorItems)
495 if (item->getVisible())
497 if (item->getAbsoluteRect().inside(_point))
514 for (VectorWidgetPtr::iterator iter = mVectorItems.begin(); iter != mVectorItems.end(); ++iter)
523 for (VectorWidgetPtr::iterator iter = mVectorItems.begin(); iter != mVectorItems.end(); ++iter)
525 if ((*iter)->getVisible())
529 if (index == _index)
return (*iter);
557 if (
nullptr == mItemDrag)
564 mPointDragOffset = coord.
point();
604 size_t old = mIndexSelect;
643 size_t index = calcIndexByWidget(_sender);
651 size_t old_index = mIndexActive;
653 IBDrawItemInfo data(old_index, mIndexSelect, mIndexActive, mIndexAccept, mIndexRefuse,
false,
false);
654 requestDrawItem(
this, mVectorItems[old_index - (mFirstVisibleIndex * mCountItemInLine)], data);
657 mIndexActive = index;
658 IBDrawItemInfo data(index, mIndexSelect, mIndexActive, mIndexAccept, mIndexRefuse,
false,
false);
665 if (index < mItemsInfo.size() && mIndexActive == index)
668 IBDrawItemInfo data(index, mIndexSelect, mIndexActive, mIndexAccept, mIndexRefuse,
false,
false);
687 if (1 > mCountItemInLine) mCountItemInLine = 1;
690 mCountLines = mItemsInfo.size() / mCountItemInLine;
691 if (0 != (mItemsInfo.size() % mCountItemInLine)) mCountLines ++;
695 mContentSize.
width = (mSizeItem.
width * mCountItemInLine);
700 mContentSize.
width = (mSizeItem.
width * mCountLines);
701 mContentSize.
height = (mSizeItem.
height * mCountItemInLine);
709 mContentPosition.
top = (int)_index;
713 mContentPosition.
left = (int)_index;
716 setContentPosition(mContentPosition);
723 if (mContentSize.
height <= 0)
726 int offset = mContentPosition.
top;
728 offset += mSizeItem.
height;
730 offset -= mSizeItem.
height;
739 if (mContentPosition.
top == offset)
746 mContentPosition.
top = offset;
750 if (mContentSize.
width <= 0)
753 int offset = mContentPosition.
left;
755 offset += mSizeItem.
width;
757 offset -= mSizeItem.
width;
766 if (mContentPosition.
left == offset)
773 mContentPosition.
left = offset;
776 setContentPosition(mContentPosition);
788 void ItemBox::setContentPosition(
const IntPoint& _point)
790 mContentPosition = _point;
792 int old = mFirstVisibleIndex;
796 mFirstVisibleIndex = mContentPosition.
top / mSizeItem.
height;
797 mFirstOffsetIndex = mContentPosition.
top % mSizeItem.
height;
801 mFirstVisibleIndex = mContentPosition.
left / mSizeItem.
width;
802 mFirstOffsetIndex = mContentPosition.
left % mSizeItem.
width;
819 size_t ItemBox::calcIndexByWidget(
Widget* _widget)
const
821 return *_widget->
_getInternalData<
size_t>() + (mFirstVisibleIndex * mCountItemInLine);
824 IntSize ItemBox::getContentSize()
const
829 IntPoint ItemBox::getContentPosition()
const
831 return mContentPosition;
839 void ItemBox::eraseContent()
844 size_t ItemBox::getHScrollPage()
const
846 return mSizeItem.
width;
849 size_t ItemBox::getVScrollPage()
const
854 Align ItemBox::getContentAlign()
const
861 return mItemsInfo.size();
919 if (_key ==
"VerticalAlignment")
923 else if (_key ==
"VisibleVScroll")
927 else if (_key ==
"VisibleHScroll")
943 if (mContentSize.
height <= 0)
946 int offset = _value.
top;
955 if (mContentPosition.
top == offset)
962 mContentPosition.
top = offset;
966 if (mContentSize.
width <= 0)
969 int offset = _value.
left;
978 if (mContentPosition.
left == offset)
985 mContentPosition.
left = offset;
988 setContentPosition(mContentPosition);
1002 return getContentPosition();
#define MYGUI_ASSERT(exp, dest)
#define MYGUI_DEBUG_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)
void onMouseDrag(int _left, int _top, MouseButton _id) override
void onMouseButtonPressed(int _left, int _top, MouseButton _id) override
void mouseButtonPressed(MouseButton _id)
void onMouseButtonReleased(int _left, int _top, MouseButton _id) override
void mouseButtonReleased(MouseButton _id)
void setPropertyOverride(const std::string &_key, const std::string &_value) override
void mouseDrag(MouseButton _id)
void endDrop(bool _reset)
static Gui & getInstance()
T * createWidget(const std::string &_skin, const IntCoord &_coord, Align _align, const std::string &_layer, const std::string &_name="")
const IntPoint & getAbsolutePosition() const
IntRect getAbsoluteRect() const
void onMouseButtonPressed(int _left, int _top, MouseButton _id) override
void onKeyButtonPressed(KeyCode _key, Char _char) override
void clearItemDataAt(size_t _index)
Clear an item data at a specified position.
void notifyMouseDrag(Widget *_sender, int _left, int _top, MouseButton _id)
void setVisibleHScroll(bool _value)
size_t getIndexByWidget(Widget *_widget) const
void notifyMouseButtonReleased(Widget *_sender, int _left, int _top, MouseButton _id)
size_t getItemCount() const
Get number of items.
EventHandle_ItemBoxPtrWidgetPtrCIBCellDrawInfoRef requestDrawItem
IntPoint getViewOffset() const
void notifyMouseWheel(Widget *_sender, int _rel)
void shutdownOverride() override
void setVisibleVScroll(bool _value)
void removeItemAt(size_t _index, bool update=true)
Remove item at a specified position.
void notifyMouseButtonDoubleClick(Widget *_sender)
bool getVerticalAlignment() const
void setPosition(const IntPoint &_value) override
bool isVisibleHScroll() const
void onKeySetFocus(Widget *_old) override
void redrawItemAt(size_t _index)
Redraw at a specified position.
void setPropertyOverride(const std::string &_key, const std::string &_value) override
void onMouseWheel(int _rel) override
void onKeyButtonReleased(KeyCode _key) override
Widget * getWidgetDrag() const
void setSize(const IntSize &_value) override
void notifyScrollChangePosition(ScrollBar *_sender, size_t _index)
void setViewOffset(const IntPoint &_value)
Widget * getItemWidget(size_t _index)
void setIndexSelected(size_t _index)
Select specified _index.
void redrawAllItems()
Redraw all items.
void initialiseOverride() override
void resetCurrentActiveItem()
void onMouseDrag(int _left, int _top, MouseButton _id) override
void onKeyLostFocus(Widget *_new) override
void insertItemAt(size_t _index, Any _data=Any::Null, bool update=true)
Insert an item into a array at a specified position.
size_t _getContainerIndex(const IntPoint &_point) const override
void setCoord(const IntCoord &_value) override
IntSize getViewSize() const override
void notifyMouseButtonPressed(Widget *_sender, int _left, int _top, MouseButton _id)
EventHandle_ItemBoxPtrSizeT eventMouseItemActivate
EventHandle_ItemBoxPtrWidgetPtr requestCreateWidgetItem
EventHandle_ItemBoxPtrSizeT eventSelectItemAccept
void notifyKeyButtonReleased(Widget *_sender, KeyCode _key)
void setItemDataAt(size_t _index, Any _data)
Replace an item data at a specified position.
Widget * getWidgetByIndex(size_t _index)
void updateDropItems() override
size_t _getItemIndex(Widget *_item) const override
void _updateAllVisible(bool _redraw)
void updateDropItemsState(const DDWidgetState &_state) override
void setVerticalAlignment(bool _value)
size_t getIndexSelected() const
Get index of selected item (ITEM_NONE if none selected)
void _resetContainer(bool _update) override
void notifyRootMouseChangeFocus(Widget *_sender, bool _focus)
void findCurrentActiveItem()
void onMouseButtonReleased(int _left, int _top, MouseButton _id) override
void removeAllItems()
Remove all items.
void notifyKeyButtonPressed(Widget *_sender, KeyCode _key, Char _char)
void removeDropItems() override
void _setContainerItemInfo(size_t _index, bool _set, bool _accept) override
bool isVisibleVScroll() const
void clearIndexSelected()
Clear item selection.
void addItem(Any _data=Any::Null, bool update=true)
Add an item to the end of a array.
EventHandle_ItemBoxPtrIntCoordRefBool requestCoordItem
EventHandle_ItemBoxPtrCIBNotifyCellDataRef eventNotifyItem
EventHandle_ItemBoxPtrSizeT eventChangeItemPosition
bool isUserString(const std::string &_key) const
void _setInternalData(Any _data)
const std::string & getUserString(const std::string &_key) const
ValueType * _getInternalData(bool _throw=true) const
types::TCoord< int > IntCoord
types::TSize< int > IntSize
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))
types::TPoint< int > IntPoint
TPoint< T > point() const