Line data Source code
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" 22 : #include "gui/ObjectBases/IGUIObject.h" 23 : #include "gui/ObjectTypes/CList.h" 24 : #include "gui/SettingTypes/CGUIColor.h" 25 : #include "gui/SettingTypes/CGUIList.h" 26 : #include "lib/code_annotation.h" 27 : #include "ps/CStr.h" 28 : 29 : #include <string> 30 : #include <vector> 31 : 32 : class CGUI; 33 : 34 : /** 35 : * Represents a column. 36 : */ 37 : class COListColumn 38 : { 39 : public: 40 0 : COListColumn(IGUIObject* owner, const CStr& cid) 41 0 : : m_Id(cid), m_Width(0), m_Heading(owner, "heading_" + cid), m_List(owner, "list_" + cid), 42 0 : m_Hidden(owner, "hidden_" + cid, false), m_SortOrder(owner, " sort_order_" + cid, 1) 43 0 : {} 44 : // Avoid copying the strings. 45 : NONCOPYABLE(COListColumn); 46 0 : COListColumn(COListColumn&&) = default; 47 : COListColumn& operator=(COListColumn&&) = delete; 48 : 49 : CGUIColor m_TextColor; 50 : CGUIColor m_TextColorSelected; 51 : CStr m_Id; 52 : float m_Width; 53 : CGUISimpleSetting<CStrW> m_Heading; // CGUIString?? 54 : CGUISimpleSetting<CGUIList> m_List; 55 : CGUISimpleSetting<bool> m_Hidden; 56 : CGUISimpleSetting<std::int32_t> m_SortOrder; 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 : */ 67 : class COList : public CList 68 : { 69 0 : GUI_OBJECT(COList) 70 : 71 : public: 72 : COList(CGUI& pGUI); 73 : 74 : protected: 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 : 95 : CGUISimpleSetting<CGUISpriteInstance> m_SpriteHeading; 96 : CGUISimpleSetting<bool> m_Sortable; 97 : CGUISimpleSetting<CStr> m_SelectedColumn; 98 : CGUISimpleSetting<std::int32_t> m_SelectedColumnOrder; 99 : CGUISimpleSetting<CGUISpriteInstance> m_SpriteAsc; 100 : CGUISimpleSetting<CGUISpriteInstance> m_SpriteDesc; 101 : CGUISimpleSetting<CGUISpriteInstance> m_SpriteNotSorted; 102 : 103 : private: 104 : static const CStr EventNameSelectionColumnChange; 105 : 106 : // Width of space available for columns 107 : float m_TotalAvailableColumnWidth; 108 : float m_HeadingHeight; 109 : }; 110 : 111 : #endif // INCLUDED_COLIST