MyGUI_ItemBox.h
Go to the documentation of this file.
/*
* This source file is part of MyGUI. For the latest info, see http://mygui.info/
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/
#ifndef MYGUI_ITEM_BOX_H_
#define MYGUI_ITEM_BOX_H_
#include "MyGUI_Prerequest.h"
#include "MyGUI_DDContainer.h"
#include "MyGUI_IBItemInfo.h"
#include "MyGUI_Any.h"
#include "MyGUI_EventPair.h"
#include "MyGUI_ScrollViewBase.h"
namespace MyGUI
{
using EventHandle_ItemBoxPtrWidgetPtr = delegates::Delegate<ItemBox*, Widget*>;
using EventHandle_ItemBoxPtrIntCoordRefBool = delegates::Delegate<ItemBox*, IntCoord&, bool>;
using EventHandle_ItemBoxPtrWidgetPtrCIBCellDrawInfoRef =
delegates::Delegate<ItemBox*, Widget*, const IBDrawItemInfo&>;
using EventHandle_ItemBoxPtrSizeT = delegates::MultiDelegate<ItemBox*, size_t>;
using EventHandle_ItemBoxPtrCIBNotifyCellDataRef = delegates::MultiDelegate<ItemBox*, const IBNotifyItemData&>;
class MYGUI_EXPORT ItemBox : public DDContainer, protected ScrollViewBase, public MemberObsolete<ItemBox>
{
MYGUI_RTTI_DERIVED(ItemBox)
public:
ItemBox();
//------------------------------------------------------------------------------//
// манипуляции айтемами
size_t getItemCount() const;
void insertItemAt(size_t _index, Any _data = Any::Null, bool update = true);
void addItem(Any _data = Any::Null, bool update = true);
void removeItemAt(size_t _index, bool update = true);
void removeAllItems();
void redrawItemAt(size_t _index);
void redrawAllItems();
//------------------------------------------------------------------------------//
// манипуляции выделениями
size_t getIndexSelected() const;
void setIndexSelected(size_t _index);
void clearIndexSelected();
//------------------------------------------------------------------------------//
// манипуляции данными
void setItemDataAt(size_t _index, Any _data);
void clearItemDataAt(size_t _index);
template<typename ValueType>
ValueType* getItemDataAt(size_t _index, bool _throw = true)
{
MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "ItemBox::getItemDataAt");
return mItemsInfo[_index].data.castType<ValueType>(_throw);
}
void setVerticalAlignment(bool _vert);
bool getVerticalAlignment() const;
size_t getIndexByWidget(Widget* _widget) const;
Widget* getWidgetDrag() const;
Widget* getWidgetByIndex(size_t _index);
void resetDrag();
void setPosition(const IntPoint& _point) override;
void setSize(const IntSize& _size) override;
void setCoord(const IntCoord& _coord) override;
using Widget::setPosition;
using Widget::setSize;
using Widget::setCoord;
void setVisibleVScroll(bool _value);
bool isVisibleVScroll() const;
void setVisibleHScroll(bool _value);
bool isVisibleHScroll() const;
void setViewOffset(const IntPoint& _value);
IntPoint getViewOffset() const;
IntSize getViewSize() const override;
/*events:*/
EventHandle_ItemBoxPtrWidgetPtr requestCreateWidgetItem;
EventHandle_ItemBoxPtrIntCoordRefBool requestCoordItem;
EventHandle_ItemBoxPtrWidgetPtrCIBCellDrawInfoRef requestDrawItem;
EventHandle_ItemBoxPtrSizeT eventSelectItemAccept;
EventHandle_ItemBoxPtrSizeT eventChangeItemPosition;
EventHandle_ItemBoxPtrSizeT eventMouseItemActivate;
EventHandle_ItemBoxPtrCIBNotifyCellDataRef eventNotifyItem;
/*internal:*/
void _resetContainer(bool _update) override;
protected:
void initialiseOverride() override;
void shutdownOverride() override;
struct ItemDataInfo
{
ItemDataInfo(Any _data) :
data(_data)
{
}
Any data;
};
using VectorItemInfo = std::vector<ItemDataInfo>;
void onMouseButtonPressed(int _left, int _top, MouseButton _id) override;
void onMouseButtonReleased(int _left, int _top, MouseButton _id) override;
void onKeyButtonPressed(KeyCode _key, Char _char) override;
void onKeyButtonReleased(KeyCode _key) override;
void onMouseDrag(int _left, int _top, MouseButton _id) override;
void onMouseWheel(int _rel) override;
void onKeyLostFocus(Widget* _new) override;
void onKeySetFocus(Widget* _old) override;
void notifyKeyButtonPressed(Widget* _sender, KeyCode _key, Char _char);
void notifyKeyButtonReleased(Widget* _sender, KeyCode _key);
void notifyScrollChangePosition(ScrollBar* _sender, size_t _index);
void notifyMouseWheel(Widget* _sender, int _rel);
void notifyRootMouseChangeFocus(Widget* _sender, bool _focus);
void notifyMouseButtonDoubleClick(Widget* _sender);
size_t _getItemIndex(Widget* _item) const override;
void notifyMouseDrag(Widget* _sender, int _left, int _top, MouseButton _id);
void notifyMouseButtonPressed(Widget* _sender, int _left, int _top, MouseButton _id);
void notifyMouseButtonReleased(Widget* _sender, int _left, int _top, MouseButton _id);
void removeDropItems() override;
void updateDropItems() override;
void updateDropItemsState(const DDWidgetState& _state) override;
// Обновляет данные о айтемах, при изменении размеров
void updateMetrics();
// просто обновляет все виджеты что видны
void _updateAllVisible(bool _redraw);
void updateFromResize();
// returns next item, create new one if requesting next one
// can be requested only sequentially
Widget* getItemWidget(size_t _index);
void _setContainerItemInfo(size_t _index, bool _set, bool _accept) override;
// сбрасываем старую подсветку
void resetCurrentActiveItem();
// ищет и устанавливает подсвеченный айтем
void findCurrentActiveItem();
// запрашиваем у конейтера айтем по позиции мыши
size_t _getContainerIndex(const IntPoint& _point) const override;
void setPropertyOverride(std::string_view _key, std::string_view _value) override;
private:
size_t calcIndexByWidget(Widget* _widget) const;
void requestItemSize();
IntSize getContentSize() const override;
IntPoint getContentPosition() const override;
void eraseContent() override;
size_t getHScrollPage() const override;
size_t getVScrollPage() const override;
Align getContentAlign() const override;
void setContentPosition(const IntPoint& _point) override;
private:
// наши дети в строках
VectorWidgetPtr mVectorItems;
// размер одного айтема
IntSize mSizeItem;
// размерность скролла в пикселях
IntSize mContentSize;
// позиция скролла п пикселях
IntPoint mContentPosition;
// колличество айтемов в одной строке
int mCountItemInLine{0};
// колличество линий
int mCountLines{0};
// самая верхняя строка
int mFirstVisibleIndex{0};
// текущее смещение верхнего элемента в пикселях
// сколько его пикселей не видно сверху
int mFirstOffsetIndex{0};
// текущий выделенный элемент или ITEM_NONE
size_t mIndexSelect{ITEM_NONE};
// подсвеченный элемент или ITEM_NONE
size_t mIndexActive{ITEM_NONE};
// индекс со свойством приема или ITEM_NONE
size_t mIndexAccept{ITEM_NONE};
// индекс со свойством отказа или ITEM_NONE
size_t mIndexRefuse{ITEM_NONE};
// имеем ли мы фокус ввода
bool mIsFocus{false};
// структура данных об айтеме
VectorItemInfo mItemsInfo;
Widget* mItemDrag{nullptr};
IntPoint mPointDragOffset;
bool mAlignVert{true};
std::string mDragLayer;
};
} // namespace MyGUI
#endif // MYGUI_ITEM_BOX_H_
MyGUI_Any.h
MyGUI_DDContainer.h
MYGUI_ASSERT_RANGE
#define MYGUI_ASSERT_RANGE(index, size, owner)
Definition MyGUI_Diagnostic.h:44
MyGUI_EventPair.h
MyGUI_IBItemInfo.h
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition MyGUI_Platform.h:77
MyGUI_Prerequest.h
MYGUI_RTTI_DERIVED
#define MYGUI_RTTI_DERIVED(DerivedType)
Definition MyGUI_RTTI.h:69
MyGUI_ScrollViewBase.h
MyGUI::Any
Definition MyGUI_Any.h:56
MyGUI::Any::Null
static const Any Null
Definition MyGUI_Any.h:58
MyGUI::DDContainer
widget description should be here.
Definition MyGUI_DDContainer.h:31
MyGUI::ItemBox::onMouseButtonPressed
void onMouseButtonPressed(int _left, int _top, MouseButton _id) override
Definition MyGUI_ItemBox.cpp:534
MyGUI::ItemBox::onKeyButtonPressed
void onKeyButtonPressed(KeyCode _key, Char _char) override
Definition MyGUI_ItemBox.cpp:1019
MyGUI::ItemBox::clearItemDataAt
void clearItemDataAt(size_t _index)
Clear an item data at a specified position.
Definition MyGUI_ItemBox.cpp:893
MyGUI::ItemBox::notifyMouseDrag
void notifyMouseDrag(Widget *_sender, int _left, int _top, MouseButton _id)
Definition MyGUI_ItemBox.cpp:599
MyGUI::ItemBox::notifyMouseButtonReleased
void notifyMouseButtonReleased(Widget *_sender, int _left, int _top, MouseButton _id)
Definition MyGUI_ItemBox.cpp:642
MyGUI::ItemBox::getItemCount
size_t getItemCount() const
Get number of items.
Definition MyGUI_ItemBox.cpp:873
MyGUI::ItemBox::requestDrawItem
EventHandle_ItemBoxPtrWidgetPtrCIBCellDrawInfoRef requestDrawItem
Definition MyGUI_ItemBox.h:164
MyGUI::ItemBox::notifyMouseWheel
void notifyMouseWheel(Widget *_sender, int _rel)
Definition MyGUI_ItemBox.cpp:733
MyGUI::ItemBox::updateFromResize
void updateFromResize()
Definition MyGUI_ItemBox.cpp:106
MyGUI::ItemBox::shutdownOverride
void shutdownOverride() override
Definition MyGUI_ItemBox.cpp:68
MyGUI::ItemBox::removeItemAt
void removeItemAt(size_t _index, bool update=true)
Remove item at a specified position.
Definition MyGUI_ItemBox.cpp:355
MyGUI::ItemBox::notifyMouseButtonDoubleClick
void notifyMouseButtonDoubleClick(Widget *_sender)
Definition MyGUI_ItemBox.cpp:449
MyGUI::ItemBox::onKeySetFocus
void onKeySetFocus(Widget *_old) override
Definition MyGUI_ItemBox.cpp:214
MyGUI::ItemBox::redrawItemAt
void redrawItemAt(size_t _index)
Redraw at a specified position.
Definition MyGUI_ItemBox.cpp:405
MyGUI::ItemBox::onMouseWheel
void onMouseWheel(int _rel) override
Definition MyGUI_ItemBox.cpp:207
MyGUI::ItemBox::onKeyButtonReleased
void onKeyButtonReleased(KeyCode _key) override
Definition MyGUI_ItemBox.cpp:1026
MyGUI::ItemBox::notifyScrollChangePosition
void notifyScrollChangePosition(ScrollBar *_sender, size_t _index)
Definition MyGUI_ItemBox.cpp:719
MyGUI::ItemBox::getItemWidget
Widget * getItemWidget(size_t _index)
Definition MyGUI_ItemBox.cpp:171
MyGUI::ItemBox::ItemBox
ItemBox()
Definition MyGUI_ItemBox.cpp:19
MyGUI::ItemBox::setIndexSelected
void setIndexSelected(size_t _index)
Select specified _index.
Definition MyGUI_ItemBox.cpp:417
MyGUI::ItemBox::redrawAllItems
void redrawAllItems()
Redraw all items.
Definition MyGUI_ItemBox.cpp:823
MyGUI::ItemBox::initialiseOverride
void initialiseOverride() override
Definition MyGUI_ItemBox.cpp:24
MyGUI::ItemBox::resetCurrentActiveItem
void resetCurrentActiveItem()
Definition MyGUI_ItemBox.cpp:228
MyGUI::ItemBox::onMouseDrag
void onMouseDrag(int _left, int _top, MouseButton _id) override
Definition MyGUI_ItemBox.cpp:544
MyGUI::ItemBox::onKeyLostFocus
void onKeyLostFocus(Widget *_new) override
Definition MyGUI_ItemBox.cpp:221
MyGUI::ItemBox::insertItemAt
void insertItemAt(size_t _index, Any _data=Any::Null, bool update=true)
Insert an item into a array at a specified position.
Definition MyGUI_ItemBox.cpp:324
MyGUI::ItemBox::_getContainerIndex
size_t _getContainerIndex(const IntPoint &_point) const override
Definition MyGUI_ItemBox.cpp:489
MyGUI::ItemBox::notifyMouseButtonPressed
void notifyMouseButtonPressed(Widget *_sender, int _left, int _top, MouseButton _id)
Definition MyGUI_ItemBox.cpp:604
MyGUI::ItemBox::setPropertyOverride
void setPropertyOverride(std::string_view _key, std::string_view _value) override
Definition MyGUI_ItemBox.cpp:930
MyGUI::ItemBox::eventMouseItemActivate
EventHandle_ItemBoxPtrSizeT eventMouseItemActivate
Definition MyGUI_ItemBox.h:185
MyGUI::ItemBox::updateMetrics
void updateMetrics()
Definition MyGUI_ItemBox.cpp:686
MyGUI::ItemBox::requestCreateWidgetItem
EventHandle_ItemBoxPtrWidgetPtr requestCreateWidgetItem
Definition MyGUI_ItemBox.h:148
MyGUI::ItemBox::eventSelectItemAccept
EventHandle_ItemBoxPtrSizeT eventSelectItemAccept
Definition MyGUI_ItemBox.h:171
MyGUI::ItemBox::notifyKeyButtonReleased
void notifyKeyButtonReleased(Widget *_sender, KeyCode _key)
Definition MyGUI_ItemBox.cpp:471
MyGUI::ItemBox::VectorItemInfo
std::vector< ItemDataInfo > VectorItemInfo
Definition MyGUI_ItemBox.h:209
MyGUI::ItemBox::setItemDataAt
void setItemDataAt(size_t _index, Any _data)
Replace an item data at a specified position.
Definition MyGUI_ItemBox.cpp:309
MyGUI::ItemBox::updateDropItems
void updateDropItems() override
Definition MyGUI_ItemBox.cpp:555
MyGUI::ItemBox::_getItemIndex
size_t _getItemIndex(Widget *_item) const override
Definition MyGUI_ItemBox.cpp:282
MyGUI::ItemBox::_updateAllVisible
void _updateAllVisible(bool _redraw)
Definition MyGUI_ItemBox.cpp:117
MyGUI::ItemBox::updateDropItemsState
void updateDropItemsState(const DDWidgetState &_state) override
Definition MyGUI_ItemBox.cpp:583
MyGUI::ItemBox::getIndexSelected
size_t getIndexSelected() const
Get index of selected item (ITEM_NONE if none selected).
Definition MyGUI_ItemBox.cpp:883
MyGUI::ItemBox::_resetContainer
void _resetContainer(bool _update) override
Definition MyGUI_ItemBox.cpp:504
MyGUI::ItemBox::notifyRootMouseChangeFocus
void notifyRootMouseChangeFocus(Widget *_sender, bool _focus)
Definition MyGUI_ItemBox.cpp:653
MyGUI::ItemBox::getItemDataAt
ValueType * getItemDataAt(size_t _index, bool _throw=true)
Get item data from specified position.
Definition MyGUI_ItemBox.h:86
MyGUI::ItemBox::findCurrentActiveItem
void findCurrentActiveItem()
Definition MyGUI_ItemBox.cpp:247
MyGUI::ItemBox::onMouseButtonReleased
void onMouseButtonReleased(int _left, int _top, MouseButton _id) override
Definition MyGUI_ItemBox.cpp:539
MyGUI::ItemBox::removeAllItems
void removeAllItems()
Remove all items.
Definition MyGUI_ItemBox.cpp:388
MyGUI::ItemBox::notifyKeyButtonPressed
void notifyKeyButtonPressed(Widget *_sender, KeyCode _key, Char _char)
Definition MyGUI_ItemBox.cpp:466
MyGUI::ItemBox::removeDropItems
void removeDropItems() override
Definition MyGUI_ItemBox.cpp:549
MyGUI::ItemBox::_setContainerItemInfo
void _setContainerItemInfo(size_t _index, bool _set, bool _accept) override
Definition MyGUI_ItemBox.cpp:292
MyGUI::ItemBox::clearIndexSelected
void clearIndexSelected()
Clear item selection.
Definition MyGUI_ItemBox.cpp:888
MyGUI::ItemBox::addItem
void addItem(Any _data=Any::Null, bool update=true)
Add an item to the end of a array.
Definition MyGUI_ItemBox.cpp:878
MyGUI::ItemBox::requestCoordItem
EventHandle_ItemBoxPtrIntCoordRefBool requestCoordItem
Definition MyGUI_ItemBox.h:156
MyGUI::ItemBox::eventNotifyItem
EventHandle_ItemBoxPtrCIBNotifyCellDataRef eventNotifyItem
Definition MyGUI_ItemBox.h:192
MyGUI::ItemBox::eventChangeItemPosition
EventHandle_ItemBoxPtrSizeT eventChangeItemPosition
Definition MyGUI_ItemBox.h:178
MyGUI::MemberObsolete
Definition MyGUI_DeprecatedTypes.h:14
MyGUI::ScrollBar
widget description should be here.
Definition MyGUI_ScrollBar.h:24
MyGUI::ScrollViewBase
Definition MyGUI_ScrollViewBase.h:17
MyGUI::Widget
widget description should be here.
Definition MyGUI_Widget.h:40
MyGUI::Widget::setSize
void setSize(const IntSize &_size) override
Definition MyGUI_Widget.cpp:693
MyGUI::Widget::setPosition
void setPosition(const IntPoint &_point) override
Definition MyGUI_Widget.cpp:676
MyGUI::Widget::setCoord
void setCoord(const IntCoord &_coord) override
Definition MyGUI_Widget.cpp:730
MyGUI::delegates::Delegate
Definition MyGUI_Delegate.h:158
MyGUI::delegates::MultiDelegate
Definition MyGUI_Delegate.h:190
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::EventHandle_ItemBoxPtrCIBNotifyCellDataRef
delegates::MultiDelegate< ItemBox *, const IBNotifyItemData & > EventHandle_ItemBoxPtrCIBNotifyCellDataRef
Definition MyGUI_ItemBox.h:25
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:27
MyGUI::EventHandle_ItemBoxPtrWidgetPtrCIBCellDrawInfoRef
delegates::Delegate< ItemBox *, Widget *, const IBDrawItemInfo & > EventHandle_ItemBoxPtrWidgetPtrCIBCellDrawInfoRef
Definition MyGUI_ItemBox.h:22
MyGUI::EventHandle_ItemBoxPtrIntCoordRefBool
delegates::Delegate< ItemBox *, IntCoord &, bool > EventHandle_ItemBoxPtrIntCoordRefBool
Definition MyGUI_ItemBox.h:21
MyGUI::EventHandle_ItemBoxPtrWidgetPtr
delegates::Delegate< ItemBox *, Widget * > EventHandle_ItemBoxPtrWidgetPtr
Definition MyGUI_ItemBox.h:20
MyGUI::Char
unsigned int Char
Definition MyGUI_Types.h:50
MyGUI::ITEM_NONE
constexpr size_t ITEM_NONE
Definition MyGUI_Macros.h:19
MyGUI::IntCoord
types::TCoord< int > IntCoord
Definition MyGUI_Types.h:36
MyGUI::IntSize
types::TSize< int > IntSize
Definition MyGUI_Types.h:30
MyGUI::VectorWidgetPtr
std::vector< Widget * > VectorWidgetPtr
Definition MyGUI_WidgetDefines.h:20
MyGUI::EventHandle_ItemBoxPtrSizeT
delegates::MultiDelegate< ItemBox *, size_t > EventHandle_ItemBoxPtrSizeT
Definition MyGUI_ItemBox.h:24
MyGUI::Align
Definition MyGUI_Align.h:20
MyGUI::DDWidgetState
Definition MyGUI_DDItemInfo.h:100
MyGUI::ItemBox::ItemDataInfo::ItemDataInfo
ItemDataInfo(Any _data)
Definition MyGUI_ItemBox.h:203
MyGUI::ItemBox::ItemDataInfo::data
Any data
Definition MyGUI_ItemBox.h:207
MyGUI::KeyCode
Definition MyGUI_KeyCode.h:16
MyGUI::MouseButton
Definition MyGUI_MouseButton.h:16