MyGUI_ListBox.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_LIST_BOX_H_
#define MYGUI_LIST_BOX_H_
#include "MyGUI_Prerequest.h"
#include "MyGUI_Button.h"
#include "MyGUI_Any.h"
#include "MyGUI_EventPair.h"
#include "MyGUI_IItem.h"
#include "MyGUI_IItemContainer.h"
#include "MyGUI_IBItemInfo.h"
namespace MyGUI
{
using EventHandle_ListPtrSizeT = delegates::MultiDelegate<ListBox*, size_t>;
using EventHandle_ListBoxPtrCIBNotifyCellDataRef = delegates::MultiDelegate<ListBox*, const IBNotifyItemData&>;
class MYGUI_EXPORT ListBox : public Widget, public IItemContainer, public MemberObsolete<ListBox>
{
MYGUI_RTTI_DERIVED(ListBox)
public:
//------------------------------------------------------------------------------//
// манипуляции айтемами
size_t getItemCount() const;
void insertItemAt(size_t _index, const UString& _name, Any _data = Any::Null);
void addItem(const UString& _name, Any _data = Any::Null);
void removeItemAt(size_t _index);
void removeAllItems();
void swapItemsAt(size_t _index1, size_t _index2);
size_t findItemIndexWith(const UString& _name);
//------------------------------------------------------------------------------//
// манипуляции выделениями
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) const
{
MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "ListBox::getItemDataAt");
return mItemsInfo.at(_index).second.castType<ValueType>(_throw);
}
//------------------------------------------------------------------------------//
// манипуляции отображением
void setItemNameAt(size_t _index, const UString& _name);
const UString& getItemNameAt(size_t _index) const;
//------------------------------------------------------------------------------//
// манипуляции выдимостью
void beginToItemAt(size_t _index);
void beginToItemFirst();
void beginToItemLast();
void beginToItemSelected();
//------------------------------------------------------------------------------//
// видим ли мы элемент, полностью или нет
bool isItemVisibleAt(size_t _index, bool _fill = true);
bool isItemSelectedVisible(bool _fill = true);
void setScrollVisible(bool _visible);
void setScrollPosition(size_t _position);
//------------------------------------------------------------------------------------//
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;
int getOptimalHeight() const;
void setActivateOnClick(bool activateOnClick);
Widget* getWidgetByIndex(size_t _index);
/*events:*/
EventPair<EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT> eventListSelectAccept;
EventPair<EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT> eventListChangePosition;
EventPair<EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT> eventListMouseItemActivate;
EventPair<EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT> eventListMouseItemFocus;
EventPair<EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT> eventListChangeScroll;
EventHandle_ListBoxPtrCIBNotifyCellDataRef eventNotifyItem;
/*internal:*/
// дебажная проверка на правильность выравнивания списка
void _checkAlign();
// вспомогательные методы для составных списков
void _setItemFocus(size_t _index, bool _focus);
void _sendEventChangeScroll(size_t _position);
// IItemContainer impl
size_t _getItemCount() const override;
void _addItem(const MyGUI::UString& _name) override;
void _removeItemAt(size_t _index) override;
void _setItemNameAt(size_t _index, const UString& _name) override;
const UString& _getItemNameAt(size_t _index) const override;
void _resetContainer(bool _update) override;
protected:
void initialiseOverride() override;
void shutdownOverride() override;
void onMouseWheel(int _rel) override;
void onKeyButtonPressed(KeyCode _key, Char _char) override;
void onKeyButtonReleased(KeyCode _key) override;
void notifyScrollChangePosition(ScrollBar* _sender, size_t _position);
void notifyMousePressed(Widget* _sender, int _left, int _top, MouseButton _id);
void notifyMouseClick(Widget* _sender);
void notifyMouseDoubleClick(Widget* _sender);
void notifyMouseWheel(Widget* _sender, int _rel);
void notifyMouseSetFocus(Widget* _sender, Widget* _old);
void notifyMouseLostFocus(Widget* _sender, Widget* _new);
void notifyKeyButtonPressed(Widget* _sender, KeyCode _key, Char _char);
void notifyKeyButtonReleased(Widget* _sender, KeyCode _key);
void notifyMouseButtonReleased(Widget* _sender, int _left, int _top, MouseButton _id);
void updateScroll();
void updateLine(bool _reset = false);
void _activateItem(Widget* _sender);
void _setScrollView(size_t _position);
// перерисовывает от индекса до низа
void _redrawItemRange(size_t _start = 0);
// перерисовывает индекс
void _redrawItem(size_t _index);
// ищет и выделяет елемент
void _selectIndex(size_t _index, bool _select);
// метод для запроса номера айтема и контейнера
size_t _getItemIndex(Widget* _item) const override;
void setPropertyOverride(std::string_view _key, std::string_view _value) override;
private:
size_t getIndexByWidget(Widget* _widget) const;
private:
std::string mSkinLine;
ScrollBar* mWidgetScroll{nullptr};
// наши дети в строках
using VectorButton = std::vector<Button*>;
VectorButton mWidgetLines;
bool mActivateOnClick{false}; // Require a full mouse click rather than only mouse press to activate an item
int mHeightLine{1}; // высота одной строки
int mTopIndex{0}; // индекс самого верхнего элемента
int mOffsetTop{0}; // текущее смещение
int mRangeIndex{-1}; // размерность скрола
size_t mLastRedrawLine{0}; // последняя перерисованная линия
size_t mIndexSelect{ITEM_NONE}; // текущий выделенный элемент или ITEM_NONE
size_t mLineActive{ITEM_NONE}; // текущий виджет над которым мыша
using PairItem = std::pair<UString, Any>;
using VectorItemInfo = std::vector<PairItem>;
VectorItemInfo mItemsInfo;
// имеем ли мы фокус ввода
bool mNeedVisibleScroll{true};
IntSize mOldSize;
};
} // namespace MyGUI
#endif // MYGUI_LIST_BOX_H_
MyGUI_Any.h
MyGUI_Button.h
MYGUI_ASSERT_RANGE
#define MYGUI_ASSERT_RANGE(index, size, owner)
Definition MyGUI_Diagnostic.h:44
MyGUI_EventPair.h
MyGUI_IBItemInfo.h
MyGUI_IItem.h
MyGUI_IItemContainer.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::Any
Definition MyGUI_Any.h:56
MyGUI::Any::Null
static const Any Null
Definition MyGUI_Any.h:58
MyGUI::EventPair
Definition MyGUI_EventPair.h:99
MyGUI::IItemContainer
Definition MyGUI_IItemContainer.h:19
MyGUI::ListBox
widget description should be here.
Definition MyGUI_ListBox.h:28
MyGUI::ListBox::_setItemNameAt
void _setItemNameAt(size_t _index, const UString &_name) override
Definition MyGUI_ListBox.cpp:1014
MyGUI::ListBox::addItem
void addItem(const UString &_name, Any _data=Any::Null)
Add an item to the end of a array.
Definition MyGUI_ListBox.cpp:873
MyGUI::ListBox::notifyMouseWheel
void notifyMouseWheel(Widget *_sender, int _rel)
Definition MyGUI_ListBox.cpp:183
MyGUI::ListBox::_removeItemAt
void _removeItemAt(size_t _index) override
Definition MyGUI_ListBox.cpp:1009
MyGUI::ListBox::updateLine
void updateLine(bool _reset=false)
Definition MyGUI_ListBox.cpp:296
MyGUI::ListBox::eventNotifyItem
EventHandle_ListBoxPtrCIBNotifyCellDataRef eventNotifyItem
Definition MyGUI_ListBox.h:226
MyGUI::ListBox::_redrawItem
void _redrawItem(size_t _index)
Definition MyGUI_ListBox.cpp:466
MyGUI::ListBox::_getItemIndex
size_t _getItemIndex(Widget *_item) const override
Definition MyGUI_ListBox.cpp:916
MyGUI::ListBox::_setScrollView
void _setScrollView(size_t _position)
Definition MyGUI_ListBox.cpp:784
MyGUI::ListBox::notifyKeyButtonReleased
void notifyKeyButtonReleased(Widget *_sender, KeyCode _key)
Definition MyGUI_ListBox.cpp:1036
MyGUI::ListBox::notifyMousePressed
void notifyMousePressed(Widget *_sender, int _left, int _top, MouseButton _id)
Definition MyGUI_ListBox.cpp:218
MyGUI::ListBox::_sendEventChangeScroll
void _sendEventChangeScroll(size_t _position)
Definition MyGUI_ListBox.cpp:809
MyGUI::ListBox::getItemDataAt
ValueType * getItemDataAt(size_t _index, bool _throw=true) const
Get item data from specified position.
Definition MyGUI_ListBox.h:94
MyGUI::ListBox::notifyMouseButtonReleased
void notifyMouseButtonReleased(Widget *_sender, int _left, int _top, MouseButton _id)
Definition MyGUI_ListBox.cpp:1041
MyGUI::ListBox::_checkAlign
void _checkAlign()
Definition MyGUI_ListBox.cpp:830
MyGUI::ListBox::_resetContainer
void _resetContainer(bool _update) override
Definition MyGUI_ListBox.cpp:926
MyGUI::ListBox::_getItemNameAt
const UString & _getItemNameAt(size_t _index) const override
Definition MyGUI_ListBox.cpp:1019
MyGUI::ListBox::notifyMouseClick
void notifyMouseClick(Widget *_sender)
Definition MyGUI_ListBox.cpp:228
MyGUI::ListBox::clearIndexSelected
void clearIndexSelected()
Definition MyGUI_ListBox.cpp:883
MyGUI::ListBox::_addItem
void _addItem(const MyGUI::UString &_name) override
Definition MyGUI_ListBox.cpp:1004
MyGUI::ListBox::_activateItem
void _activateItem(Widget *_sender)
Definition MyGUI_ListBox.cpp:955
MyGUI::ListBox::_redrawItemRange
void _redrawItemRange(size_t _start=0)
Definition MyGUI_ListBox.cpp:416
MyGUI::ListBox::notifyMouseLostFocus
void notifyMouseLostFocus(Widget *_sender, Widget *_new)
Definition MyGUI_ListBox.cpp:749
MyGUI::ListBox::shutdownOverride
void shutdownOverride() override
Definition MyGUI_ListBox.cpp:56
MyGUI::ListBox::getItemCount
size_t getItemCount() const
Get number of items.
Definition MyGUI_ListBox.cpp:868
MyGUI::ListBox::initialiseOverride
void initialiseOverride() override
Definition MyGUI_ListBox.cpp:19
MyGUI::ListBox::notifyScrollChangePosition
void notifyScrollChangePosition(ScrollBar *_sender, size_t _position)
Definition MyGUI_ListBox.cpp:212
MyGUI::ListBox::notifyMouseSetFocus
void notifyMouseSetFocus(Widget *_sender, Widget *_old)
Definition MyGUI_ListBox.cpp:739
MyGUI::ListBox::swapItemsAt
void swapItemsAt(size_t _index1, size_t _index2)
Swap items at a specified positions.
Definition MyGUI_ListBox.cpp:816
MyGUI::ListBox::onKeyButtonReleased
void onKeyButtonReleased(KeyCode _key) override
Definition MyGUI_ListBox.cpp:1048
MyGUI::ListBox::insertItemAt
void insertItemAt(size_t _index, const UString &_name, Any _data=Any::Null)
Insert an item into a array at a specified position.
Definition MyGUI_ListBox.cpp:481
MyGUI::ListBox::removeAllItems
void removeAllItems()
Remove all items.
Definition MyGUI_ListBox.cpp:698
MyGUI::ListBox::eventListChangePosition
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListChangePosition
Definition MyGUI_ListBox.h:198
MyGUI::ListBox::onMouseWheel
void onMouseWheel(int _rel) override
Definition MyGUI_ListBox.cpp:63
MyGUI::ListBox::clearItemDataAt
void clearItemDataAt(size_t _index)
Clear an item data at a specified position.
Definition MyGUI_ListBox.cpp:888
MyGUI::ListBox::updateScroll
void updateScroll()
Definition MyGUI_ListBox.cpp:261
MyGUI::ListBox::getIndexSelected
size_t getIndexSelected() const
Definition MyGUI_ListBox.cpp:878
MyGUI::ListBox::_selectIndex
void _selectIndex(size_t _index, bool _select)
Definition MyGUI_ListBox.cpp:627
MyGUI::ListBox::_getItemCount
size_t _getItemCount() const override
Definition MyGUI_ListBox.cpp:999
MyGUI::ListBox::_setItemFocus
void _setItemFocus(size_t _index, bool _focus)
Definition MyGUI_ListBox.cpp:758
MyGUI::ListBox::eventListMouseItemFocus
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListMouseItemFocus
Definition MyGUI_ListBox.h:212
MyGUI::ListBox::setPropertyOverride
void setPropertyOverride(std::string_view _key, std::string_view _value) override
Definition MyGUI_ListBox.cpp:939
MyGUI::ListBox::findItemIndexWith
size_t findItemIndexWith(const UString &_name)
Search item, returns the position of the first occurrence in array or ITEM_NONE if item not found.
Definition MyGUI_ListBox.cpp:853
MyGUI::ListBox::eventListChangeScroll
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListChangeScroll
Definition MyGUI_ListBox.h:219
MyGUI::ListBox::notifyKeyButtonPressed
void notifyKeyButtonPressed(Widget *_sender, KeyCode _key, Char _char)
Definition MyGUI_ListBox.cpp:1031
MyGUI::ListBox::onKeyButtonPressed
void onKeyButtonPressed(KeyCode _key, Char _char) override
Definition MyGUI_ListBox.cpp:70
MyGUI::ListBox::setItemDataAt
void setItemDataAt(size_t _index, Any _data)
Replace an item data at a specified position.
Definition MyGUI_ListBox.cpp:726
MyGUI::ListBox::notifyMouseDoubleClick
void notifyMouseDoubleClick(Widget *_sender)
Definition MyGUI_ListBox.cpp:234
MyGUI::ListBox::eventListSelectAccept
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListSelectAccept
Definition MyGUI_ListBox.h:191
MyGUI::ListBox::removeItemAt
void removeItemAt(size_t _index)
Remove item at a specified position.
Definition MyGUI_ListBox.cpp:543
MyGUI::ListBox::setIndexSelected
void setIndexSelected(size_t _index)
Definition MyGUI_ListBox.cpp:616
MyGUI::ListBox::eventListMouseItemActivate
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListMouseItemActivate
Definition MyGUI_ListBox.h:205
MyGUI::MemberObsolete
Definition MyGUI_DeprecatedTypes.h:14
MyGUI::ScrollBar
widget description should be here.
Definition MyGUI_ScrollBar.h:24
MyGUI::UString
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
Definition MyGUI_UString.h:144
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::MultiDelegate
Definition MyGUI_Delegate.h:190
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:27
MyGUI::EventHandle_ListPtrSizeT
delegates::MultiDelegate< ListBox *, size_t > EventHandle_ListPtrSizeT
Definition MyGUI_ListBox.h:21
MyGUI::EventHandle_ListBoxPtrCIBNotifyCellDataRef
delegates::MultiDelegate< ListBox *, const IBNotifyItemData & > EventHandle_ListBoxPtrCIBNotifyCellDataRef
Definition MyGUI_ListBox.h:22
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::KeyCode
Definition MyGUI_KeyCode.h:16
MyGUI::MouseButton
Definition MyGUI_MouseButton.h:16