2013-06-19 01:12:30 +00:00
# pragma once
2014-06-20 01:30:09 +00:00
# include "GuiComponent.h"
2013-06-19 01:12:30 +00:00
2014-03-12 03:00:08 +00:00
namespace GridFlags
2013-06-19 01:12:30 +00:00
{
2014-03-12 03:00:08 +00:00
enum UpdateType
2013-06-19 01:12:30 +00:00
{
2014-03-12 03:00:08 +00:00
UPDATE_ALWAYS ,
UPDATE_WHEN_SELECTED ,
UPDATE_NEVER
2013-06-19 01:12:30 +00:00
} ;
2014-03-12 03:00:08 +00:00
enum Border : unsigned int
2013-06-19 01:12:30 +00:00
{
2014-03-12 03:00:08 +00:00
BORDER_NONE = 0 ,
BORDER_TOP = 1 ,
BORDER_BOTTOM = 2 ,
BORDER_LEFT = 4 ,
BORDER_RIGHT = 8
2013-06-19 01:12:30 +00:00
} ;
2014-03-12 03:00:08 +00:00
} ;
2013-06-19 01:12:30 +00:00
2014-03-12 03:00:08 +00:00
// Used to arrange a bunch of components in a spreadsheet-esque grid.
class ComponentGrid : public GuiComponent
{
public :
ComponentGrid ( Window * window , const Eigen : : Vector2i & gridDimensions ) ;
virtual ~ ComponentGrid ( ) ;
2013-06-19 01:12:30 +00:00
2014-03-12 03:00:08 +00:00
bool removeEntry ( const std : : shared_ptr < GuiComponent > & comp ) ;
2013-09-19 23:41:14 +00:00
2014-03-12 03:00:08 +00:00
void setEntry ( const std : : shared_ptr < GuiComponent > & comp , const Eigen : : Vector2i & pos , bool canFocus , bool resize = true ,
const Eigen : : Vector2i & size = Eigen : : Vector2i ( 1 , 1 ) , unsigned int border = GridFlags : : BORDER_NONE , GridFlags : : UpdateType updateType = GridFlags : : UPDATE_ALWAYS ) ;
2013-06-19 01:12:30 +00:00
2013-08-19 15:36:48 +00:00
void textInput ( const char * text ) override ;
2013-06-19 01:12:30 +00:00
bool input ( InputConfig * config , Input input ) override ;
void update ( int deltaTime ) override ;
2013-07-10 11:29:43 +00:00
void render ( const Eigen : : Affine3f & parentTrans ) override ;
2014-03-12 03:00:08 +00:00
void onSizeChanged ( ) override ;
2013-06-19 01:12:30 +00:00
void resetCursor ( ) ;
bool cursorValid ( ) ;
2014-03-12 03:00:08 +00:00
float getColWidth ( int col ) ;
float getRowHeight ( int row ) ;
2014-05-14 22:47:28 +00:00
void setColWidthPerc ( int col , float width , bool update = true ) ; // if update is false, will not call an onSizeChanged() which triggers a (potentially costly) repositioning + resizing of every element
void setRowHeightPerc ( int row , float height , bool update = true ) ; // if update is false, will not call an onSizeChanged() which triggers a (potentially costly) repositioning + resizing of every element
2014-03-12 03:00:08 +00:00
bool moveCursor ( Eigen : : Vector2i dir ) ;
void setCursorTo ( const std : : shared_ptr < GuiComponent > & comp ) ;
inline std : : shared_ptr < GuiComponent > getSelectedComponent ( )
{
GridEntry * e = getCellAt ( mCursor ) ;
if ( e )
return e - > component ;
else
return nullptr ;
}
2013-06-19 21:02:42 +00:00
2014-03-12 03:00:08 +00:00
void onFocusLost ( ) override ;
void onFocusGained ( ) override ;
2013-09-19 23:41:14 +00:00
2014-01-25 23:34:29 +00:00
virtual std : : vector < HelpPrompt > getHelpPrompts ( ) override ;
2013-06-19 01:12:30 +00:00
private :
2014-03-12 03:00:08 +00:00
class GridEntry
2013-06-19 01:12:30 +00:00
{
public :
2013-07-10 11:29:43 +00:00
Eigen : : Vector2i pos ;
Eigen : : Vector2i dim ;
2014-03-12 03:00:08 +00:00
std : : shared_ptr < GuiComponent > component ;
2013-06-19 01:12:30 +00:00
bool canFocus ;
2014-03-12 03:00:08 +00:00
bool resize ;
GridFlags : : UpdateType updateType ;
unsigned int border ;
2013-06-19 01:12:30 +00:00
2014-03-12 03:00:08 +00:00
GridEntry ( const Eigen : : Vector2i & p = Eigen : : Vector2i : : Zero ( ) , const Eigen : : Vector2i & d = Eigen : : Vector2i : : Zero ( ) ,
const std : : shared_ptr < GuiComponent > & cmp = nullptr , bool f = false , bool r = true ,
GridFlags : : UpdateType u = GridFlags : : UPDATE_ALWAYS , unsigned int b = GridFlags : : BORDER_NONE ) :
pos ( p ) , dim ( d ) , component ( cmp ) , canFocus ( f ) , resize ( r ) , updateType ( u ) , border ( b )
{ } ;
2013-06-19 01:12:30 +00:00
operator bool ( ) const
{
return component ! = NULL ;
}
} ;
2014-03-12 03:00:08 +00:00
float * mRowHeights ;
float * mColWidths ;
struct Vert
{
Vert ( float xi = 0 , float yi = 0 ) : x ( xi ) , y ( yi ) { } ;
float x ;
float y ;
} ;
2013-06-19 01:12:30 +00:00
2014-03-12 03:00:08 +00:00
std : : vector < Vert > mLines ;
std : : vector < unsigned int > mLineColors ;
2013-06-19 01:12:30 +00:00
2014-03-12 03:00:08 +00:00
// Update position & size
void updateCellComponent ( const GridEntry & cell ) ;
void updateSeparators ( ) ;
2013-06-19 01:12:30 +00:00
2014-03-12 03:00:08 +00:00
GridEntry * getCellAt ( int x , int y ) ;
inline GridEntry * getCellAt ( const Eigen : : Vector2i & pos ) { return getCellAt ( pos . x ( ) , pos . y ( ) ) ; }
Eigen : : Vector2i mGridSize ;
2013-06-19 01:12:30 +00:00
2014-03-12 03:00:08 +00:00
std : : vector < GridEntry > mCells ;
2013-06-19 01:12:30 +00:00
2013-08-18 14:16:11 +00:00
void onCursorMoved ( Eigen : : Vector2i from , Eigen : : Vector2i to ) ;
2013-07-10 11:29:43 +00:00
Eigen : : Vector2i mCursor ;
2013-06-19 01:12:30 +00:00
} ;