DDraceNetwork Docs
ui_listbox.h
Go to the documentation of this file.
1/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2/* If you are missing that file, acquire a complete release at teeworlds.com. */
3#ifndef GAME_CLIENT_UI_LISTBOX_H
4#define GAME_CLIENT_UI_LISTBOX_H
5
6#include "ui_scrollregion.h"
7
9{
13};
14
15// Instances of CListBox must be static, as member addresses are used as UI item IDs
16class CListBox : private CUIElementBase
17{
18private:
32 const char *m_pBottomText;
42
43protected:
45
46public:
47 CListBox();
48
49 void DoBegin(const CUIRect *pRect);
50 void DoHeader(const CUIRect *pRect, const char *pTitle, float HeaderHeight = 20.0f, float Spacing = 2.0f);
51 void DoAutoSpacing(float Spacing = 20.0f) { m_AutoSpacing = Spacing; }
52 void DoSpacing(float Spacing = 20.0f);
53 void DoFooter(const char *pBottomText, float FooterHeight = 20.0f); // call before DoStart to create a footer
54 void DoStart(float RowHeight, int NumItems, int ItemsPerRow, int RowsPerScroll, int SelectedIndex, const CUIRect *pRect = nullptr, bool Background = true, int BackgroundCorners = IGraphics::CORNER_ALL, bool ForceShowScrollbar = false);
56 CListboxItem DoNextItem(const void *pId, bool Selected = false, float CornerRadius = 5.0f);
58 int DoEnd();
59
60 // Active state must be set before calling DoStart.
61 bool Active() const { return m_Active; }
62 void SetActive(bool Active) { m_Active = Active; }
63
64 bool WasItemSelected() const { return m_ListBoxItemSelected; }
66
67 bool ScrollbarShown() const { return m_ScrollbarShown; }
68 float ScrollbarWidth() const { return ScrollbarShown() ? ScrollbarWidthMax() : 0.0f; }
69 float ScrollbarWidthMax() const { return m_ScrollbarWidth; }
70 void SetScrollbarWidth(float Width) { m_ScrollbarWidth = Width; }
71 float ScrollbarMargin() const { return m_ScrollbarMargin; }
72 void SetScrollbarMargin(float Margin) { m_ScrollbarMargin = Margin; }
73};
74
75#endif
Definition: ui_listbox.h:17
int m_ListBoxItemIndex
Definition: ui_listbox.h:22
CListboxItem DoNextRow()
Definition: ui_listbox.cpp:131
void SetActive(bool Active)
Definition: ui_listbox.h:62
bool m_ScrollbarShown
Definition: ui_listbox.h:31
void DoHeader(const CUIRect *pRect, const char *pTitle, float HeaderHeight=20.0f, float Spacing=2.0f)
Definition: ui_listbox.cpp:31
bool m_HasHeader
Definition: ui_listbox.h:40
void DoBegin(const CUIRect *pRect)
Definition: ui_listbox.cpp:25
int m_ListBoxSelectedIndex
Definition: ui_listbox.h:23
float m_FooterHeight
Definition: ui_listbox.h:33
const char * m_pBottomText
Definition: ui_listbox.h:32
float ScrollbarMargin() const
Definition: ui_listbox.h:71
float ScrollbarWidth() const
Definition: ui_listbox.h:68
bool m_ListBoxUpdateScroll
Definition: ui_listbox.h:26
CUIRect m_RowView
Definition: ui_listbox.h:20
float m_ScrollbarWidth
Definition: ui_listbox.h:38
bool m_ListBoxItemActivated
Definition: ui_listbox.h:30
void SetScrollbarMargin(float Margin)
Definition: ui_listbox.h:72
CListboxItem DoNextItem(const void *pId, bool Selected=false, float CornerRadius=5.0f)
Definition: ui_listbox.cpp:153
bool WasItemSelected() const
Definition: ui_listbox.h:64
int m_ListBoxNewSelected
Definition: ui_listbox.h:24
CScrollRegion m_ScrollRegion
Definition: ui_listbox.h:35
int m_ListBoxNewSelOffset
Definition: ui_listbox.h:25
bool ScrollbarShown() const
Definition: ui_listbox.h:67
int DoEnd()
Definition: ui_listbox.cpp:204
vec2 m_ScrollOffset
Definition: ui_listbox.h:36
bool Active() const
Definition: ui_listbox.h:61
bool WasItemActivated() const
Definition: ui_listbox.h:65
int m_ListBoxNumItems
Definition: ui_listbox.h:27
void DoSpacing(float Spacing=20.0f)
Definition: ui_listbox.cpp:51
void DoFooter(const char *pBottomText, float FooterHeight=20.0f)
Definition: ui_listbox.cpp:58
float m_ScrollbarMargin
Definition: ui_listbox.h:39
CListboxItem DoSubheader()
Definition: ui_listbox.cpp:197
void DoStart(float RowHeight, int NumItems, int ItemsPerRow, int RowsPerScroll, int SelectedIndex, const CUIRect *pRect=nullptr, bool Background=true, int BackgroundCorners=IGraphics::CORNER_ALL, bool ForceShowScrollbar=false)
Definition: ui_listbox.cpp:64
void DoAutoSpacing(float Spacing=20.0f)
Definition: ui_listbox.h:51
int m_BackgroundCorners
Definition: ui_listbox.h:37
CUIRect m_ListBoxView
Definition: ui_listbox.h:19
bool m_Active
Definition: ui_listbox.h:41
void SetScrollbarWidth(float Width)
Definition: ui_listbox.h:70
void ScrollToSelected()
Definition: ui_listbox.h:55
float m_AutoSpacing
Definition: ui_listbox.h:34
CListBox()
Definition: ui_listbox.cpp:13
int m_ListBoxItemsPerRow
Definition: ui_listbox.h:28
float ScrollbarWidthMax() const
Definition: ui_listbox.h:69
float m_ListBoxRowHeight
Definition: ui_listbox.h:21
bool m_ListBoxItemSelected
Definition: ui_listbox.h:29
Definition: ui_scrollregion.h:90
Definition: ui.h:233
Definition: ui_rect.h:11
@ CORNER_ALL
Definition: graphics.h:430
Definition: ui_listbox.h:9
CUIRect m_Rect
Definition: ui_listbox.h:12
bool m_Selected
Definition: ui_listbox.h:11
bool m_Visible
Definition: ui_listbox.h:10