khanat-opennel-code/code/nel/include/nel/gui/group_table.h
Nimetu 66ca072948 Render table with rowspan, colspan.
Borders, if enabled, adds +1 to cell padding.
2014-10-14 15:29:06 +03:00

232 lines
5 KiB
C++

// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef NL_GROUP_TABLE_H
#define NL_GROUP_TABLE_H
#include "nel/misc/types_nl.h"
#include "nel/gui/group_frame.h"
#include "nel/gui/view_text.h"
#include "nel/gui/ctrl_button.h"
namespace NLGUI
{
/**
* This group is used to simulate HTML cells.
* They have specific parameters to be aligned like HTML cells.
* (Percent of the table size
*/
class CGroupCell: public CInterfaceGroup
{
friend class CGroupTable;
public:
DECLARE_UI_CLASS( CGroupCell )
CGroupCell(const TCtorParam &param);
enum TAlign
{
Left,
Center,
Right
};
enum TVAlign
{
Top,
Middle,
Bottom
};
/// \from CInterfaceElement
virtual void draw();
virtual sint32 getMaxUsedW() const;
virtual sint32 getMinUsedW() const;
std::string getProperty( const std::string &name ) const;
void setProperty( const std::string &name, const std::string &value );
xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const;
// to be called by CGroupTable
bool parse (xmlNodePtr cur, CInterfaceGroup * parentGroup, uint columnIndex, uint rowIndex);
// If the cell is a new line. This is the first <td> after a <tr>
bool NewLine;
bool IgnoreMaxWidth;
bool IgnoreMinWidth;
bool AddChildW;
// The table width cell ratio. This is the <td width="50%"> parameter
float TableRatio;
// The Width you want in pixel. This is the <td width="100"> parameter
sint32 WidthWanted;
sint32 ColSpan;
sint32 RowSpan;
sint32 TableColumnIndex;
// The min height of the cell
sint32 Height;
// Memorize max width
sint32 WidthMax;
// The cell color
NLMISC::CRGBA BgColor;
// Texture
CViewRenderer::CTextureId _TextureId; /// Accelerator
bool _UserTexture;
bool _TextureTiled;
bool _TextureScaled;
// Alignment
TAlign Align;
TVAlign VAlign;
sint32 LeftMargin;
// The cell group
CInterfaceGroup *Group;
// The cell is nowrap
bool NoWrap;
void setTexture(const std::string & TxName);
void setTextureTile(bool tiled);
void setTextureScale(bool scaled);
static void setDebugUICell( bool d ){ DebugUICell = d; }
static bool getDebugUICell(){ return DebugUICell; }
private:
void setEnclosedGroupDefaultParams();
static bool DebugUICell;
};
/**
* This group is used to simulate HTML table. Support "percent of the parent width" sizeRef mode.
*/
class CGroupTable : public CInterfaceGroup
{
public:
DECLARE_UI_CLASS( CGroupTable )
///constructor
CGroupTable(const TCtorParam &param);
// dtor
~CGroupTable();
// Add a cell in the table
void addChild (CGroupCell* child);
// The ratio you want [0 ~1]. This is the <table width="50%"> parameter
float TableRatio;
// The Width you want in pixel. This is the <table width="100"> parameter
sint32 ForceWidthMin;
// Table borders
sint32 Border;
NLMISC::CRGBA BorderColor;
sint32 CellPadding;
sint32 CellSpacing;
// The table color
NLMISC::CRGBA BgColor;
uint8 CurrentAlpha;
bool ContinuousUpdate;
std::string getProperties( const std::string &name ) const;
void setProperty( const std::string &name, const std::string &value );
xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const;
protected:
/// \from CInterfaceElement
void onInvalidateContent();
sint32 getMaxUsedW() const;
sint32 getMinUsedW() const;
void draw ();
/**
* init or reset the children element coords. Orverloaded from CInterfaceGroup because we begin with the last inserted element here
*/
virtual void updateCoords();
virtual void checkCoords();
virtual bool parse (xmlNodePtr cur, CInterfaceGroup * parentGroup);
// Content validated
bool _ContentValidated;
// Last parent width
sint32 _LastParentW;
// Children
std::vector<CGroupCell *> _Cells;
// Table column
class CColumn
{
public:
CColumn()
{
Width = 0;
WidthMax = 0;
WidthWanted = 0;
TableRatio = 0;
RowSpan = 1;
}
sint32 Width;
sint32 Height;
sint32 WidthWanted;
sint32 WidthMax;
float TableRatio;
sint32 RowSpan;
};
// Table row
class CRow
{
public:
CRow()
{
Height = 0;
}
sint32 Height;
};
// Column table
std::vector<CColumn> _Columns;
// Column table
std::vector<CRow> _Rows;
};
}
#endif // NL_GROUP_TABLE_H
/* End of group_table.h */