DataGrid.h
1 /*
2 
3 Copyright (c) 2018, Johnathan Corkery. (jcorkery@umich.edu)
4 All rights reserved.
5 
6 This file is part of the Dynacoe project (https://github.com/jcorks/Dynacoe)
7 Dynacoe was released under the MIT License, as detailed below.
8 
9 
10 
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is furnished
16 to do so, subject to the following conditions:
17 
18 The above copyright notice and this permission notice shall
19 be included in all copies or substantial portions of the Software.
20 
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
28 
29 */
30 
31 #ifndef DC_DATA_GRID_INCLUDED
32 #define DC_DATA_GRID_INCLUDED
33 
34 #include <Dynacoe/Entity.h>
35 #include <Dynacoe/Components/Text2D.h>
36 #include <Dynacoe/Components/Shape2D.h>
37 #include <Dynacoe/Components/GUI.h>
38 #include <Dynacoe/Color.h>
39 
40 namespace Dynacoe {
41 
44 class DataGrid : public Entity {
45  public:
46 
50 
54 
58 
59 
60  DataGrid();
61  ~DataGrid(){}
62 
66  void AddColumn(const std::string & title, int width, const Color & color = Color("#EFEFEF"));
67 
70  void SetColumnWidth(uint32_t column, uint32_t width);
71 
76 
78  //
79  void AddRow();
80 
83  void RemoveRow(uint32_t);
84 
87  void SetRowsVisible(uint32_t);
88 
89 
92  uint32_t GetRowCount();
93 
96  void Clear();
97 
100  std::string & Get(uint32_t x, uint32_t y);
101 
106  std::string & GetTooltip(uint32_t y);
107 
110  void SetViewPosition(uint32_t i);
111 
115  uint32_t GetViewPosition();
116 
120  uint32_t GetMaxViewPosition();
121 
124  uint32_t GetRowsVisible();
125 
128  uint32_t Width();
129 
132  uint32_t RowHeight();
133 
134  private:
135 
136  struct Column {
137  std::string title;
138  int x;
139  int width;
140  Color color;
141  std::vector<std::string> rows;
142  };
143 
144  uint32_t spanWidth;
145 
146  std::vector<Column> columns;
147  std::vector<Shape2D *> visibleRows;
148  std::vector<GUI *> visibleGUI;
149  std::vector<std::vector<Text2D *>> visibleText;
150  std::vector<std::string> tooltipText;
151  Color real_backgroundEvenColor;
152  Color real_backgroundOddColor;
153  Color real_titleColor;
154  Color real_defaultTextColor;
155 
156  GUI * wheelZone;
157  Shape2D * scroll;
158  GUI * scrollGrab;
159 
160  uint32_t rowCount;
161  uint32_t viewIndex;
162 
163  const int lineHeight = 12;
164  Text2D error;
165 
166 
167  void OnStep();
168  void AddNeededView();
169  void RefreshView();
170 
171  float scrollAlpha;
172  bool isDragging;
173 
174  std::map<GUI *, uint32_t> rowmap;
175  static DynacoeEvent(master_click);
176  static DynacoeEvent(hover_enter);
177  static DynacoeEvent(hover_leave);
178  static DynacoeEvent(begin_scroll_drag);
179 };
180 }
181 
182 #endif
void SetColumnWidth(uint32_t column, uint32_t width)
Sets the width in pixels for the specified column.
A standard object representing an RGBA color.
Definition: Color.h:47
Basic interactive object.
Definition: Entity.h:62
uint32_t GetRowsVisible()
Returns the currently viewable number of rows at a time.
Aspect2D class that handles text rendering.
Definition: Text2D.h:60
bool(*)(void *, Component *component, Entity::ID self, Entity::ID source, const std::vector< std::string > &args) EventHandler
A handler for an event.
Definition: Component.h:132
Color titleColor
Color for the title text.
Definition: DataGrid.h:57
void SetRowsVisible(uint32_t)
Will only draw display up to the given number of rows.
void AddColumn(const std::string &title, int width, const Color &color=Color("#EFEFEF"))
Adds a new column with a title, a specified width, and an optional color for the text.
Definition: AssetID.h:37
std::string & Get(uint32_t x, uint32_t y)
Returns the string @ the column and row given.
uint32_t GetViewPosition()
Returns the current viewing index at the top. 0 is the default (aka the first row) ...
void SetViewPosition(uint32_t i)
Sets the initial viewing row.
void AddRow()
Appends a new row to the grid.
uint32_t GetRowCount()
Returns the number of rows.
Built-in Entity for drawing a grid of values.
Definition: DataGrid.h:44
A component that provides managed input interaction suitable for making things like buttons...
Definition: GUI.h:52
void RemoveRow(uint32_t)
removes the specified row by index.
std::string & GetTooltip(uint32_t y)
Returns the tooltip string @ the row given.
Component::EventHandler clickCallback
Callback called when a cell is clicked.
Definition: DataGrid.h:75
An aspect that can express basic 2D objects, such as images and shapes.
Definition: Shape2D.h:46
void Clear()
Clears all rows.
uint32_t Width()
Returns the row in pixels.
uint32_t GetMaxViewPosition()
Returns the maximum currently allowable viewing position based on the current DataGrid parameters...
Color backgroundOddColor
Background color for odd-count cells.
Definition: DataGrid.h:53
uint32_t RowHeight()
Returns the height of a row.
Color backgroundEvenColor
Background color for even-count cells.
Definition: DataGrid.h:49