YSTest  PreAlpha_b380_20130211
The YSLib Test Project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
YSLib::Components::Menu Class Reference

文本菜单。 More...

#include <menu.h>

Inheritance diagram for YSLib::Components::Menu:
Collaboration diagram for YSLib::Components::Menu:

Public Types

typedef size_t ID
 菜单标识类型。
 
typedef map< IndexType, Menu * > SubMap
 子菜单映射表类型。
 
typedef SubMap::value_type ValueType
 子菜单映射表项目类型。
 
- Public Types inherited from YSLib::Components::TextList
typedef GSequenceViewer< ListTypeViewerType
 视图类型。
 
typedef GValueEventArgs< bool > ViewArgs
 视图参数类型。
 
typedef GHEvent< void(ViewArgs)> HViewEvent
 视图事件委托类型。
 
typedef String ItemType
 项目类型:字符串。
 
typedef vector< ItemTypeListType
 列表类型。
 
typedef ListType::size_type IndexType
 索引类型。
 

Public Member Functions

 Menu (const Rect &={}, const shared_ptr< ListType > &={}, ID=0)
 构造:使用指定边界、文本列表和菜单标识。
 
 Menu (Menu &&)=delete
 禁止转移构造。
 
Menuoperator[] (size_t idx)
 访问索引指定的子菜单。

Exceptions
std::out_of_range异常中立:指定子菜单越界或不存在:由 at 抛出。

 
void operator+= (const ValueType &)
 向子菜单组添加关联索引和指针指定的菜单。
 
bool operator-= (IndexType)
 向菜单组移除指定子菜单索引项。
 
bool IsItemEnabled (ListType::size_type) const
 判断菜单项是否有效。
 
ID GetID () const ynothrow
 
MenuGetParentPtr () const ynothrow
 
void SetItemEnabled (ListType::size_type idx, bool=true)
 设置 idx 指定的菜单项的可用性。
 
bool CheckConfirmed (ListType::size_type) const override
 检查列表中的指定项是否可用。
 
bool Show (ZOrderType=DefaultMenuZOrder)
 按指定 Z 顺序显示菜单。
 
MenuShowSub (IndexType, ZOrderType=DefaultMenuZOrder)
 按指定 Z 顺序显示索引指定的子菜单。
 
bool Hide ()
 隐藏菜单。
 
- Public Member Functions inherited from YSLib::Components::TextList
 TextList (const Rect &={}, const shared_ptr< ListType > &={}, pair< Color, Color >=FetchGUIState().Colors.GetPair(Styles::Highlight, Styles::HighlightText))
 构造:使用指定边界、文本列表和高亮背景色/文本色对。
 
 TextList (TextList &&)=default
 
bool IsSelected () const ynothrow
 
bool Contains (ListType::size_type i)
 
GEvent< void(HViewEvent::EventArgsType)> & GetViewChanged () ynothrow
 视图变更事件。
 
GEvent< void(HIndexEvent::EventArgsType)> & GetSelected () ynothrow
 项目选择状态变更事件。
 
GEvent< void(HIndexEvent::EventArgsType)> & GetConfirmed () ynothrow
 项目选中确定事件。
 
ListType::size_type GetHeadIndex () const ynothrow
 
ListType::size_type GetSelectedIndex () const ynothrow
 
SDst GetFullViewHeight () const
 取完整视图高。
 
SDst GetViewPosition () const
 取视图顶端竖直位置。
 
void SetList (const shared_ptr< ListType > &)
 设置文本列表。
 
void SetSelected (ListType::size_type)
 按指定项目索引设置选中项目。
 
void SetSelected (SPos, SPos)
 按接触点设置选中项目。
 
void SetSelected (const Point &pt)
 按接触点设置选中项目。
 
void AdjustViewLength ()
 调整视图长度。
 
ListType::size_type CheckPoint (SPos, SPos)
 检查点(相对于所在缓冲区的控件坐标)是否在选择范围内,
 
ListType::size_type CheckPoint (const Point &pt)
 检查点(相对于所在缓冲区的控件坐标)是否在选择范围内,
 
void ClearSelected ()
 
void LocateViewPosition (SDst)
 定位视图顶端至指定竖直位置。
 
void Refresh (PaintEventArgs &&) override
 刷新:按指定参数绘制界面并更新状态。
 
void ResetView ()
 复位视图。
 
void SelectFirst ()
 选择第一个项目。
 
void SelectLast ()
 选择最后一个项目。
 
void UpdateView (bool is_active=false, bool need_invalidation=true)
 更新视图。
 
- Public Member Functions inherited from YSLib::Components::Control
 Control (const Rect &={})
 构造:使用指定边界,默认背景(同 Widget 默认构造)。
 
 Control (const Rect &, NoBackgroundTag)
 构造:使用指定边界,无背景。
 
 Control (const Control &)
 复制构造:除容器为空外深复制。
 
 Control (Control &&)=default
 
virtual IWidgetGetBoundControlPtr (const KeyInput &)
 取按键-指针设备输入默认事件组映射。
 
void OnTouch_Close (TouchEventArgs &&)
 处理屏幕事件:关闭显示。
 
- Public Member Functions inherited from YSLib::Components::Widget
 Widget (const Rect &={}, Color=Drawing::ColorSpace::White, Color=Drawing::ColorSpace::Black)
 
template<typename _tView , typename _tRenderer , typename _tController >
 Widget (_tView &&pView_=make_unique< View >(), _tRenderer &&pRenderer_=make_unique< Renderer >(), _tController &&pController_={})
 构造:使用视图指针、渲染器指针和控制器指针,无背景。
 
 Widget (const Widget &)
 复制构造:除容器指针为空外深复制。
 
 Widget (Widget &&)=default
 
virtual ~Widget ()
 析构:虚实现。
 
SPos GetX () const ynothrow
 
SPos GetY () const ynothrow
 
SDst GetWidth () const ynothrow
 
SDst GetHeight () const ynothrow
 
virtual RendererGetRenderer () const ynothrow
 取渲染器。
 
virtual ViewGetView () const ynothrow
 取部件视图。
 
virtual AControllerGetController () const override
 取控制器。
 
virtual WidgetRange GetChildren () override
 
void SetX (SDst _tempArgName)
 
void SetY (SDst _tempArgName)
 
void SetWidth (SDst _tempArgName)
 
void SetHeight (SDst _tempArgName)
 
void SetRenderer (unique_ptr< Renderer > &&)
 设置渲染器为指定指针指向的对象,同时更新渲染器状态。
 
void SetView (unique_ptr< View > &&)
 设置渲染器为指定指针指向的对象,同时更新渲染器状态。
 
- Public Member Functions inherited from YSLib::Components::IWidget
virtual ~IWidget ()
 

Protected Member Functions

void AdjustSize () const
 调整 vDisabled 大小。
 
void DrawItem (const Graphics &, const Rect &mask, const Rect &, ListType::size_type) override
 绘制菜单项。
 
- Protected Member Functions inherited from YSLib::Components::TextList
void InvalidateSelected (ListType::difference_type offset, ListType::size_type diff=1)
 无效化偏移量对应的列表项区域。
 
void InvalidateSelected2 (ListType::difference_type, ListType::difference_type)
 无效化偏移量对应的列表项区域。
 
virtual void DrawItemBackground (const PaintContext &, const Rect &r)
 描画列表项背景。
 
virtual void DrawItems (const PaintContext &)
 绘制列表。
 
- Protected Member Functions inherited from YSLib::Components::MTextList
ListTypeGetList () const ynothrow
 取文本列表。
 
ItemTypeGetItemPtr (IndexType) const
 取指定项目索引的项目指针。
 
SDst GetItemHeight () const ynothrow
 取项目行高。
 
SDst GetMaxTextWidth () const
 取文本列表中的最大文本宽度。
 
void SetList (const shared_ptr< ListType > &h)
 设置文本列表。
 
IndexType Find (const ItemType &) const
 查找项。
 
void RefreshTextState ()
 刷新文本状态。
 
 MTextList (const shared_ptr< ListType > &={}, const Drawing::Font &={})
 构造:使用文本列表句柄和字体指针。
 
 MTextList (MTextList &&)=default
 

Protected Attributes

MenuHostpHost
 宿主指针。
 
MenupParent
 父菜单指针。
 
SubMap mSubMenus
 子菜单映射表:存储非空子菜单指针。
 
vector< bool > vDisabled
 未启用菜单项。
 

Private Attributes

ID id
 菜单标识。
 

Friends

class MenuHost
 

Additional Inherited Members

- Public Attributes inherited from YSLib::Components::TextList
Color HilightBackColor
 高亮背景色。
 
Color HilightTextColor
 高亮文本色。
 
bool CyclicTraverse
 循环选择遍历。
 
- Protected Types inherited from YSLib::Components::MTextList
typedef String ItemType
 项目类型:字符串。
 
typedef vector< ItemTypeListType
 列表类型。
 
typedef ListType::size_type IndexType
 索引类型。
 

Detailed Description

文本菜单。

Since
build 252

Definition at line 47 of file menu.h.

Member Typedef Documentation

菜单标识类型。

Definition at line 52 of file menu.h.

子菜单映射表类型。

Definition at line 53 of file menu.h.

typedef SubMap::value_type YSLib::Components::Menu::ValueType

子菜单映射表项目类型。

Definition at line 54 of file menu.h.

Constructor & Destructor Documentation

YSLib::Components::Menu::Menu ( const Rect = {},
const shared_ptr< ListType > &  = {},
ID  = 0 
)
explicit

构造:使用指定边界、文本列表和菜单标识。

Since
build 327
YSLib::Components::Menu::Menu ( Menu &&  )
delete

禁止转移构造。

Since
build 379
Todo:
实现转移操作。

Member Function Documentation

void Menu::AdjustSize ( ) const
protected

调整 vDisabled 大小。

Postcondition
vDisabled.size() == GetList().size()

Definition at line 154 of file menu.cpp.

bool Menu::CheckConfirmed ( ListType::size_type  ) const
overridevirtual

检查列表中的指定项是否可用。

Note
当且仅当可用时响应 Confirmed 事件。

Reimplemented from YSLib::Components::TextList.

Definition at line 163 of file menu.cpp.

void Menu::DrawItem ( const Graphics g,
const Rect mask,
const Rect unit,
ListType::size_type  i 
)
overrideprotectedvirtual
ID YSLib::Components::Menu::GetID ( ) const
inline

Definition at line 108 of file menu.h.

Menu* YSLib::Components::Menu::GetParentPtr ( ) const
inline

Definition at line 109 of file menu.h.

bool Menu::Hide ( )

隐藏菜单。

Note
菜单宿主指针为空时忽略。

Definition at line 199 of file menu.cpp.

bool Menu::IsItemEnabled ( ListType::size_type  idx) const

判断菜单项是否有效。

Precondition
断言: IsInInterval(idx, GetList().size())
Postcondition
vDisabled.size() == GetList().size()

Definition at line 136 of file menu.cpp.

References YSLib::IsInInterval(), and YAssert.

Here is the call graph for this function:

void Menu::operator+= ( const ValueType val)

向子菜单组添加关联索引和指针指定的菜单。

Note
若索引越界或菜单指针为空则忽略。

Definition at line 108 of file menu.cpp.

References YSLib::IsInInterval().

Here is the call graph for this function:

bool Menu::operator-= ( IndexType  idx)

向菜单组移除指定子菜单索引项。

Note
若索引越界或不存在则忽略。

Definition at line 118 of file menu.cpp.

References YSLib::IsInInterval().

Here is the call graph for this function:

Menu& YSLib::Components::Menu::operator[] ( size_t  idx)
inline

访问索引指定的子菜单。

Exceptions
std::out_of_range异常中立:指定子菜单越界或不存在:由 at 抛出。

Definition at line 83 of file menu.h.

void Menu::SetItemEnabled ( ListType::size_type  idx,
bool  = true 
)

设置 idx 指定的菜单项的可用性。

Precondition
断言: IsInInterval(idx, GetList().size())
Postcondition
vDisabled.size() == GetList().size() ; IsItemEnabled(idx) 。

Definition at line 145 of file menu.cpp.

References YSLib::IsInInterval(), and YAssert.

Here is the call graph for this function:

bool Menu::Show ( ZOrderType  z = DefaultMenuZOrder)

按指定 Z 顺序显示菜单。

Note
菜单宿主指针为空时忽略。
Returns
菜单宿主指针非空。

Definition at line 169 of file menu.cpp.

Menu * Menu::ShowSub ( IndexType  idx,
ZOrderType  z = DefaultMenuZOrder 
)

按指定 Z 顺序显示索引指定的子菜单。

Note
菜单宿主指针为空时忽略。
Returns
菜单宿主指针非空且索引指定的子菜单存在时为子菜单指针,否则为空指针。

Definition at line 180 of file menu.cpp.

References LocateMenu().

Here is the call graph for this function:

Friends And Related Function Documentation

friend class MenuHost
friend

Definition at line 49 of file menu.h.

Member Data Documentation

ID YSLib::Components::Menu::id
private

菜单标识。

Definition at line 57 of file menu.h.

SubMap YSLib::Components::Menu::mSubMenus
protected

子菜单映射表:存储非空子菜单指针。

Definition at line 62 of file menu.h.

MenuHost* YSLib::Components::Menu::pHost
protected

宿主指针。

Definition at line 60 of file menu.h.

Menu* YSLib::Components::Menu::pParent
protected

父菜单指针。

Definition at line 61 of file menu.h.

vector<bool> YSLib::Components::Menu::vDisabled
mutableprotected

未启用菜单项。

Definition at line 63 of file menu.h.


The documentation for this class was generated from the following files: