Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
COList.h
Go to the documentation of this file.
1/* Copyright (C) 2026 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17#ifndef INCLUDED_COLIST
18#define INCLUDED_COLIST
19
20#include "gui/CGUISetting.h"
21#include "gui/CGUISprite.h"
26#include "lib/code_annotation.h"
27#include "ps/CStr.h"
28
29#include <string>
30#include <vector>
31
32class CGUI;
33
34/**
35 * Represents a column.
36 */
38{
39public:
40 COListColumn(IGUIObject* owner, const CStr& cid)
41 : m_Id(cid), m_Width(0), m_Heading(owner, "heading_" + cid), m_List(owner, "list_" + cid),
42 m_Hidden(owner, "hidden_" + cid, false), m_SortOrder(owner, " sort_order_" + cid, 1)
43 {}
44 // Avoid copying the strings.
48
51 CStr m_Id;
52 float m_Width;
57};
58
59/**
60 * Multi-column list. One row can be selected by the user.
61 * Individual cells are clipped if the contained text is too long.
62 *
63 * The list can be sorted dynamically by JS code when a
64 * heading is clicked.
65 * A scroll-bar will appear when needed.
66 */
67class COList : public CList
68{
70
71public:
72 COList(CGUI& pGUI);
73
74protected:
75 void SetupText();
76 void HandleMessage(SGUIMessage& Message);
77
78 /**
79 * Handle the <item> tag.
80 */
81 virtual bool HandleAdditionalChildren(const XMBData& xmb, const XMBElement& child);
82 virtual void AdditionalChildrenHandled();
83
84 virtual void DrawList(
85 CCanvas2D& canvas, const int& selected, const CGUISpriteInstance& sprite, const CGUISpriteInstance& spriteOverlay,
86 const CGUISpriteInstance& spriteSelectarea, const CGUISpriteInstance& spriteSelectAreaOverlay, const CGUIColor& textColor);
87
88 virtual CRect GetListRect() const;
89
90 /**
91 * Available columns.
92 */
93 std::vector<COListColumn> m_Columns;
94
102
103private:
105
106 // Width of space available for columns
109};
110
111#endif // INCLUDED_COLIST
#define GUI_OBJECT(obj)
Definition: IGUIObject.h:53
Definition: Canvas2D.h:36
Definition: CGUISprite.h:137
The main object that represents a whole GUI page.
Definition: CGUI.h:80
Create a list of elements, where one can be selected by the user.
Definition: CList.h:48
Represents a column.
Definition: COList.h:38
float m_Width
Definition: COList.h:52
CGUISimpleSetting< CGUIList > m_List
Definition: COList.h:54
NONCOPYABLE(COListColumn)
COListColumn(COListColumn &&)=default
COListColumn(IGUIObject *owner, const CStr &cid)
Definition: COList.h:40
CGUIColor m_TextColorSelected
Definition: COList.h:50
CGUISimpleSetting< std::int32_t > m_SortOrder
Definition: COList.h:56
COListColumn & operator=(COListColumn &&)=delete
CGUISimpleSetting< CStrW > m_Heading
Definition: COList.h:53
CGUIColor m_TextColor
Definition: COList.h:49
CGUISimpleSetting< bool > m_Hidden
Definition: COList.h:55
CStr m_Id
Definition: COList.h:51
Multi-column list.
Definition: COList.h:68
void HandleMessage(SGUIMessage &Message)
Definition: COList.cpp:138
CGUISimpleSetting< CStr > m_SelectedColumn
Definition: COList.h:97
CGUISimpleSetting< std::int32_t > m_SelectedColumnOrder
Definition: COList.h:98
CGUISimpleSetting< CGUISpriteInstance > m_SpriteHeading
Definition: COList.h:95
CGUISimpleSetting< CGUISpriteInstance > m_SpriteDesc
Definition: COList.h:100
static const CStr EventNameSelectionColumnChange
Definition: COList.h:104
CGUISimpleSetting< bool > m_Sortable
Definition: COList.h:96
virtual void DrawList(CCanvas2D &canvas, const int &selected, const CGUISpriteInstance &sprite, const CGUISpriteInstance &spriteOverlay, const CGUISpriteInstance &spriteSelectarea, const CGUISpriteInstance &spriteSelectAreaOverlay, const CGUIColor &textColor)
Definition: COList.cpp:328
std::vector< COListColumn > m_Columns
Available columns.
Definition: COList.h:93
void SetupText()
Sets up text, should be called every time changes has been made that can change the visual.
Definition: COList.cpp:61
float m_HeadingHeight
Definition: COList.h:108
float m_TotalAvailableColumnWidth
Definition: COList.h:107
virtual void AdditionalChildrenHandled()
Allow the GUI object to process after all child items were handled.
Definition: COList.cpp:323
CGUISimpleSetting< CGUISpriteInstance > m_SpriteAsc
Definition: COList.h:99
virtual bool HandleAdditionalChildren(const XMBData &xmb, const XMBElement &child)
Handle the <item> tag.
Definition: COList.cpp:199
COList(CGUI &pGUI)
Definition: COList.cpp:49
CGUISimpleSetting< CGUISpriteInstance > m_SpriteNotSorted
Definition: COList.h:101
virtual CRect GetListRect() const
Definition: COList.cpp:133
Rectangle class used for screen rectangles.
Definition: Rect.h:31
GUI object such as a button or an input-box.
Definition: IGUIObject.h:63
Definition: XMBData.h:95
Definition: XMBData.h:135
Same as the CColor class, but this one can also parse colors predefined in the GUI page (such as "yel...
Definition: CGUIColor.h:31
Message send to IGUIObject::HandleMessage() in order to give life to Objects manually with a derived ...
Definition: SGUIMessage.h:73