wavelength 1.0.0
Loading...
Searching...
No Matches
uilist.h
Go to the documentation of this file.
1#pragma once
2
3#include <list>
4#include <vector>
5
7#include "os/prnstream.h"
8#include "rnd/rndfont.h"
9#include "rnd/rndmat.h"
10#include "rnd/rndmesh.h"
11#include "rnd/rndtext.h"
13#include "rnd/rndview.h"
14#include "script/dataarray.h"
15#include "ui/uicomponent.h"
16#include "ui/uistyle.h"
17
31class UIList : public UIComponent {
32public:
34 static constexpr int kKeepSelection = -99999;
35
37 struct Cell {
40 };
41
50 UIList(DataArray *pData, const char *pszPanel);
51
58 ~UIList() override;
59
71 static UIComponent *New(DataArray *pData, const char *pszPanel) {
72 return new UIList(pData, pszPanel);
73 }
74
83 bool DispatchPriv(Message *pMsg) override;
84
92 void Print(PrnStream &stream) override;
93
104 virtual void UpdateRow([[maybe_unused]] int nRow, [[maybe_unused]] int nItem) {
105 }
106
113 virtual void UpdateCursor();
114
122 virtual void SetCursorSelected(bool bSelected);
123
132 virtual bool HandleJoypad(JoypadInputMsg *pMsg);
133
140 virtual void ScrollUp();
141
148 virtual void ScrollDown();
149
159 RndView *CloneRow(int nRow, RndView *pTemplate);
160
169
179 void SetCellMat(int nRow, int nColumn, RndMat *pMat);
180
190 void SetCellText(int nRow, int nColumn, const char *pszText);
191
201 void SetCellFont(int nRow, int nColumn, RndFont *pFont);
202
211 void SetRowFont(int nRow, RndFont *pFont);
212
220 void SetSelected(int nSelected);
221
232 void Refresh(int nItemCount, int nSelected);
233
235 int GetSelected() const {
236 return mSelected;
237 }
238
240 int GetItemCount() const {
241 return mItemCount;
242 }
243
245 int GetRowCount() const {
246 return mRowCount;
247 }
248
251 return mUpArrow;
252 }
253
256 return mDownArrow;
257 }
258
260 void SetShowUpArrow(int nShow) {
261 mShowUpArrow = nShow;
262 }
263
265 void SetShowDownArrow(int nShow) {
266 mShowDownArrow = nShow;
267 }
268
269protected:
277 std::list<std::vector<Cell> > mRowCells;
278 std::vector<RndView *> mRows;
279 std::vector<RndText *> mTextCells;
280 const char *mPanelName;
284 alignas(16) Transform mCursorXfm;
287};
Reference-counted array of script data nodes.
Definition dataarray.h:20
Message the controller poll sends when a button is pressed or released.
Definition joypadinputmsg.h:23
Base of every event the game passes between a MsgSource and a MsgSink.
Definition message.h:40
Text output stream.
Definition prnstream.h:16
Bitmap font, a grid of character cells in the texture of a material's first stage.
Definition rndfont.h:20
Surface description: blending, lighting colours, culling, and a list of texture stages.
Definition rndmat.h:20
Triangle mesh with a material.
Definition rndmesh.h:31
Text drawn with a bitmap font as a mesh of one quad per character.
Definition rndtext.h:27
View that shows the children of another view, its children owner, under its own transform and frame.
Definition rndview.h:27
UIComponent(DataArray *pData)
Construct a showing component in the normal state.
Definition uicomponent.h:37
virtual void ScrollUp()
Select the previous item.
void SetShowDownArrow(int nShow)
Definition uilist.h:265
RndMesh * mUpArrow
Definition uilist.h:282
void SetSelected(int nSelected)
Select an item, keeping the number of items.
int GetSelected() const
Definition uilist.h:235
int mColumnCount
Definition uilist.h:273
int mCursorRow
Definition uilist.h:274
Transform mCursorXfm
Definition uilist.h:284
void Refresh(int nItemCount, int nSelected)
Set the number of items and the selection, and fill the rows.
RndMesh * mCursor
Definition uilist.h:281
RndMesh * GetDownArrow() const
Definition uilist.h:255
int GetItemCount() const
Definition uilist.h:240
static UIComponent * New(DataArray *pData, const char *pszPanel)
Create a list from its script description.
Definition uilist.h:71
int mShowUpArrow
Definition uilist.h:285
int mShowDownArrow
Definition uilist.h:286
void SetCellFont(int nRow, int nColumn, RndFont *pFont)
Set the font of a cell's text.
const char * mPanelName
Definition uilist.h:280
virtual bool HandleJoypad(JoypadInputMsg *pMsg)
Scroll for up and down, and pass the cross button to the panel's cursor component.
void SetRowFont(int nRow, RndFont *pFont)
Set the font of every text of a row.
std::vector< RndText * > mTextCells
Definition uilist.h:279
void Print(PrnStream &stream) override
Write a description of the list.
void SetCellMat(int nRow, int nColumn, RndMat *pMat)
Show the mesh of a cell with a material.
virtual void SetCursorSelected(bool bSelected)
Give the cursor the material of the selected or of the normal state.
static constexpr int kKeepSelection
The value of Refresh()'s selection that keeps the selected item.
Definition uilist.h:34
virtual void ScrollDown()
Select the next item.
RndMesh * GetUpArrow() const
Definition uilist.h:250
int mRowPitch
Definition uilist.h:276
void BuildRowCells(RndView *pRow)
Record the cells of a row, emptying each text and hiding each mesh.
int mSelected
Definition uilist.h:275
RndMesh * mDownArrow
Definition uilist.h:283
std::list< std::vector< Cell > > mRowCells
Definition uilist.h:277
UIList(DataArray *pData, const char *pszPanel)
Construct a list from its script description, cloning the template row once for each row.
virtual void UpdateCursor()
Move the cursor to the row with the selection, or dim it when the list is empty.
virtual void UpdateRow(int nRow, int nItem)
Fill the cells of a row with an item.
Definition uilist.h:104
void SetShowUpArrow(int nShow)
Definition uilist.h:260
~UIList() override
Destroy the row clones and every object cloned with them.
void SetCellText(int nRow, int nColumn, const char *pszText)
Set the text of a cell.
int GetRowCount() const
Definition uilist.h:245
int mItemCount
Definition uilist.h:271
int mRowCount
Definition uilist.h:272
RndView * CloneRow(int nRow, RndView *pTemplate)
Clone the template row for one row.
bool DispatchPriv(Message *pMsg) override
Pass a controller button to HandleJoypad().
UIStyle * mStyle
Definition uilist.h:270
std::vector< RndView * > mRows
Definition uilist.h:278
Material and font a component draws with in each of its states.
Definition uistyle.h:15
Affine transform stored as three basis rows and a translation row.
Definition transform.h:18
One cell of a row.
Definition uilist.h:37
RndText * mText
Definition uilist.h:38
RndMesh * mMesh
Definition uilist.h:39