Basic implementation of grid control. This class is meant to be used as a base class for more specific grid controls.
You can find more information in comments below. Overrided methods can be found in corresponding base classes and interfaces.
class CCustomGrid :public virtual ICustomGrid, public CControl
{
public:
enum class State // Control states
{
Normal, // Normal
Hovered, // Mouse pointer is over the control
Focused, // Control is focused
FocusedHovered, // Control is focused and mouse pointer is over the control
Disabled // Control is disabled
};
protected:
void ForceRepaint(); // Cleanup buffer(canvas) and repaint the control
bool ScrollToCell(const Point &coords); // Scroll to specified cell
bool ScrollToActiveCell(); // Scroll to active cell
virtual void UpdateFromStyle(IStyle *style); // Update stylable properties. If you overwrite this method, call CCustomGrid::UpdateFromStyle(style) in it to apply style to the CCustomGrid properties
virtual void CreateColumn( // Called when new column is being created
float &width, // Column width. By default equal to DefaultColumnWidth property value
bool &resizable, // Whether column should be resizable or not. By default equal to DefaultColumnResizable property value
bool &autosize, // Whether column width should depend on cell content(associated IListItem). By default equal to DefaultColumnAutosize property value
bool &enabled, // Whether column enabled or disabled. By default equal to DefaultColumnEnabled property value
bool &fixed, // Whether column is fixed and could not be scrolled in X direction. By default equal to DefaultColumnFixed property value
bool &overflow_hidden); // Whether new cells in column should be drawn with cutting areas which are out of cell(could be overwritten by cell settings). By default equal to DefaultColumnOverflowHidden property value
virtual void CreateRow( // Called when new row is being created
float &height, // Column height. By default equal to DefaultRowHeight property value
bool &resizable, // Whether row should be resizable or not. By default equal to DefaultRowResizable property value
bool &autosize, // Whether row height should depend on cell content(assocciated IListItem). By default equal to DefaultRowAutosize property value
bool &enabled, // Whether row enabled or disabled. By default equal to DefaultRowEnabled property value
bool &fixed, // Whether row is fixed and could not be scrolled in Y direction. By default equal to DefaultRowFixed property value
bool &overflow_hidden); // Whether new cells in row should be drawn with cutting areas which are out of cell(could be overwritten by cell settings). By default equal to DefaultRowOverflowHidden property value
virtual void RenderCell( // Called when cell content should be drawn. By default calls item render method if item is not empty
const int column, // Cell column index
const int row, // Cell row index
IListItem *item, // Item associated with cell. Can be nullptr
const Mat4f &matrix, // Transformation matrix to be applied when drawing
const Block *block); // Block constraints to be applied when rendering
virtual PointF GetItemRequiredSize( // Should return cell required size. By default get it from item if it is not empty
const int column, // Cell column index
const int row, // Cell row index
IListItem *item); // Associated item. Can be nullptr
virtual IListItem * CreateItem(const int column, const int row) = 0; // Called to create item for newly created cell with specified coordinates. Can return nullptr if no item should be assigned to the cell
public:
// IControl getters
RectF getClientRect() override;
RectF getRenderRect() override;
CursorType getCursor() override;
// IControl setters
bool setDPI(const Point &value) override;
// IControl methods
void Refresh(const bool refresh_children) override;
// ICustomGrid getters
bool isMultiselect() override;
int getColumns() override;
int getRows() override;
bool isCellEnabled(const int column, const int row) override;
bool isCellHovered(const int column, const int row) override;
bool isCellActive(const int column, const int row) override;
bool isCellSelected(const int column, const int row) override;
bool isCellOverflowHidden(const int column, const int row) override;
float getColumnWidth(const int index) override;
bool isColumnResizable(const int index) override;
bool isColumnAutosize(const int index) override;
bool isColumnEnabled(const int index) override;
bool isColumnFixed(const int index) override;
bool isColumnOverflowHidden(const int index) override;
float getRowHeight(const int index) override;
bool isRowResizable(const int index) override;
bool isRowAutosize(const int index) override;
bool isRowEnabled(const int index) override;
bool isRowFixed(const int index) override;
bool isRowOverflowHidden(const int index) override;
Point getCellAtPosition(const PointF &position, const bool bound) override;
// ICustomGrid setters
bool setMultiselect(const bool value) override;
bool setColumns(const int value) override;
bool setRows(const int value) override;
bool setCellEnabled(const int column, const int row, const bool value) override;
bool setCellActive(const int column, const int row, const bool value) override;
bool setCellSelected(const int column, const int row, const bool value) override;
bool setCellOverflowHidden(const int column, const int row, const bool value) override;
bool setColumnWidth(const int index, const float value) override;
bool setColumnResizable(const int index, const bool value) override;
bool setColumnAutosize(const int index, const bool value) override;
bool setColumnEnabled(const int index, const bool value) override;
bool setColumnFixed(const int index, const bool value) override;
bool setColumnOverflowHidden(const int index, const bool value) override;
bool setRowHeight(const int index, const float value) override;
bool setRowResizable(const int index, const bool value) override;
bool setRowAutosize(const int index, const bool value) override;
bool setRowEnabled(const int index, const bool value) override;
bool setRowFixed(const int index, const bool value) override;
bool setRowOverflowHidden(const int index, const bool value) override;
// ICustomGrid methods
bool SelectAllCells() override;
bool DeselectAllCells() override;
bool DeleteColumn(const int index) override;
bool DeleteRow(const int index) override;
void LockUpdate() override;
void UnlockUpdate() override;
CCustomGrid(const String &class_name);
~CCustomGrid() override;
// Getters
State getState(); // Return control state
ScrollVisibility getVerticalScrollVisibility() const; // Return vertical scroll visibility. Default svAuto
ScrollVisibility getHorizontalScrollVisibility() const; // Return horizontal scroll visibility. Default svAuto
RectF getBorderWidth() const; // Return border widths. Default { 1, 1, 1, 1 }
RectF getPadding() const; // Return padding. Default { 0, 0, 0, 0 }
float getGridWidth() const; // Return grid line width. Default 1
Color getGridColor(const State state) const; // Return grid line color
RectF getBorderRadius(const State state) const; // Return border radius
Color getBackgroundColor(const State state) const; // Return background color
Gradient *getBackgroundGradient(const State state); // Return background gradient
BorderColor getBorderColor(const State state) const; // Return border colors
int getShadowRadius(const State state) const; // Return shadow radius
PointF getShadowShift(const State state) const; // Return shadow shift
Color getShadowColor(const State state) const; // Return shadow color
Color getCornerColor(const State state) const; // Return rectangle color between scrollbars
float getScrollInterval() const; // Return scroll interval(in seconds)
float getDefaultColumnWidth() const; // Return default column width. Default 64
float getDefaultRowHeight() const; // Return default row height. Default 24
bool isDefaultColumnResizable() const; // Return whether a column is resizable by default. Default false
bool isDefaultRowResizable() const; // Return whether a row is resizable by default. Default false
bool isDefaultColumnAutosize() const; // Return whether a column width is calculated automatically by default. Default false
bool isDefaultRowAutosize() const; // Return whether a row height is calculated automatically by default. Default false
bool isDefaultColumnEnabled() const; // Return whether a column is enabled by default. Default true
bool isDefaultRowEnabled() const; // Return whether a row is enabled by default. Default true
bool isDefaultColumnFixed() const; // Return whether a column is fixed by default. Default false
bool isDefaultRowFixed() const; // Return whether a row is fixed by default. Default false
bool isDefaultColumnOverflowHidden() const; // Return whether a column content should be clipped by default. Default true
bool isDefaultRowOverflowHidden() const; // Return whether a row content should be clipped by default. Default true
Point getActiveCell() const; // Return active cell coordinates. Return { -1, -1 } if there is no active cell
PointF getCellPosition(const int column, const int row); // Return cell position in control coordinate space
// Setters
bool setVerticalScroll(IBuiltInScroll *value); // Set new vertical scrollbar
bool setHorizontalScroll(IBuiltInScroll *value); // Set new horizontal scrollbar
bool setVerticalScrollVisibility(const ScrollVisibility value); // Set vertical scroll visibility
bool setHorizontalScrollVisibility(const ScrollVisibility value); // Set horizontal scroll visibility
bool setBorderWidth(const RectF &value); // Set border widths
bool setPadding(const RectF &value); // Set padding
bool setGridWidth(const float value); // Set grid line width
bool setGridColor(const State state, const Color &value); // Set grid line color
bool setBorderRadius(const State state, const RectF value); // Set border radius
bool setBackgroundColor(const State state, const Color &value); // Set background color
bool setBorderColor(const State state, const BorderColor &value); // Set border colors
bool setShadowRadius(const State state, const int value); // Set shadow radius
bool setShadowShift(const State state, const PointF &value); // Set shadow shift
bool setShadowColor(const State state, const Color &value); // Set shadow color
bool setCornerColor(const State state, const Color &value); // Set rectangle color between scrollbars
bool setScrollInterval(const float value); // Set scroll interval(in seconds)
bool setDefaultColumnWidth(const float value); // Set default column width
bool setDefaultRowHeight(const float value); // Set default row height
bool setDefaultColumnResizable(const bool value); // Set whether a column is resizable by default
bool setDefaultRowResizable(const bool value); // Set whether a row is resizable by default
bool setDefaultColumnAutosize(const bool value); // Set whether a column width is calculated automatically by default
bool setDefaultRowAutosize(const bool value); // Set whether a row height is calculated automatically by default
bool setDefaultColumnEnabled(const bool value); // Set whether a column is enabled by default
bool setDefaultRowEnabled(const bool value); // Set whether a row is enabled by default
bool setDefaultColumnFixed(const bool value); // Set whether a column is fixed by default
bool setDefaultRowFixed(const bool value); // Set whether a row is fixed by default
bool setDefaultColumnOverflowHidden(const bool value); // Set whether a column content should be clipped by default
bool setDefaultRowOverflowHidden(const bool value); // Set whether a row content should be clipped by default
};
Namespace: | nitisa::standard |
Include: | Standard/Controls/DrawGrid/CustomGrid.h |