Line data Source code
1 : /* Copyright (C) 2023 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/ObjectTypes/CList.h"
21 : #include "gui/SettingTypes/CGUIColor.h"
22 :
23 : #include <vector>
24 :
25 : /**
26 : * Represents a column.
27 : */
28 0 : class COListColumn
29 : {
30 : public:
31 0 : COListColumn(IGUIObject* owner, const CStr& cid)
32 0 : : m_Id(cid), m_Width(0), m_Heading(owner, "heading_" + cid), m_List(owner, "list_" + cid),
33 0 : m_Hidden(owner, "hidden_" + cid, false), m_SortOrder(owner, " sort_order_" + cid, 1)
34 0 : {}
35 : // Avoid copying the strings.
36 : NONCOPYABLE(COListColumn);
37 0 : MOVABLE(COListColumn);
38 : CGUIColor m_TextColor;
39 : CStr m_Id;
40 : float m_Width;
41 : CGUISimpleSetting<CStrW> m_Heading; // CGUIString??
42 : CGUISimpleSetting<CGUIList> m_List;
43 : CGUISimpleSetting<bool> m_Hidden;
44 : CGUISimpleSetting<i32> m_SortOrder;
45 : };
46 :
47 : /**
48 : * Multi-column list. One row can be selected by the user.
49 : * Individual cells are clipped if the contained text is too long.
50 : *
51 : * The list can be sorted dynamically by JS code when a
52 : * heading is clicked.
53 : * A scroll-bar will appear when needed.
54 : */
55 0 : class COList : public CList
56 : {
57 0 : GUI_OBJECT(COList)
58 :
59 : public:
60 : COList(CGUI& pGUI);
61 :
62 : protected:
63 : void SetupText();
64 : void HandleMessage(SGUIMessage& Message);
65 :
66 : /**
67 : * Handle the \<item\> tag.
68 : */
69 : virtual bool HandleAdditionalChildren(const XMBData& xmb, const XMBElement& child);
70 : virtual void AdditionalChildrenHandled();
71 :
72 : virtual void DrawList(
73 : CCanvas2D& canvas, const int& selected, const CGUISpriteInstance& sprite, const CGUISpriteInstance& spriteOverlay,
74 : const CGUISpriteInstance& spriteSelectarea, const CGUISpriteInstance& spriteSelectAreaOverlay, const CGUIColor& textColor);
75 :
76 : virtual CRect GetListRect() const;
77 :
78 : /**
79 : * Available columns.
80 : */
81 : std::vector<COListColumn> m_Columns;
82 :
83 : CGUISimpleSetting<CGUISpriteInstance> m_SpriteHeading;
84 : CGUISimpleSetting<bool> m_Sortable;
85 : CGUISimpleSetting<CStr> m_SelectedColumn;
86 : CGUISimpleSetting<i32> m_SelectedColumnOrder;
87 : CGUISimpleSetting<CGUISpriteInstance> m_SpriteAsc;
88 : CGUISimpleSetting<CGUISpriteInstance> m_SpriteDesc;
89 : CGUISimpleSetting<CGUISpriteInstance> m_SpriteNotSorted;
90 :
91 : private:
92 : static const CStr EventNameSelectionColumnChange;
93 :
94 : // Width of space available for columns
95 : float m_TotalAvailableColumnWidth;
96 : float m_HeadingHeight;
97 : };
98 :
99 : #endif // INCLUDED_COLIST
|