TCoreGridPanel

A responsive grid panel container using CSS Grid. Supports breakpoints for different layouts at different viewport widths with automatic mobile stacking.

Container CSS Grid Responsive TMS Web Core

Overview

TCoreGridPanel provides a flexible grid layout system that adapts to different screen sizes. It uses CSS Grid at runtime for optimal performance and responsive behaviour. At design time, it displays cells with color-coding and position indicators.

+------------------+------------------+------------------+ | [0,0] | [1,0] | [2,0] | | Cell 0 | Cell 1 | Cell 2 | +------------------+------------------+------------------+ | [0,1] | [1,1] | [2,1] | | Cell 3 | Cell 4 | Cell 5 | +------------------+------------------+------------------+ Desktop: 3 columns (1fr 1fr 1fr) Tablet: 2 columns (1fr 1fr) Mobile: 1 column (1fr) - stacked vertically

Unit & Inheritance

UNIT Obj.Container.GridPanel;

TCoreGridPanel = CLASS(TCoreDiv)
   // Inherits from TCoreDiv for CSS class support

Key Concepts

Rows and Columns

The grid is defined by RowCollection and ColumnCollection. Each row/column can specify:

Cells

Cells are automatically created as TSubCoreDiv components based on the grid dimensions. Access cells using GetCell(ColIndex, RowIndex). Drop controls onto cells at design time - they become children of that cell.

Responsive Layouts

The Layout collection defines breakpoints for different viewport widths. Each layout specifies a CSS grid-template-columns value that determines how many columns appear at that breakpoint.

Published Properties

Property Type Description
ColumnCollection TCoreGridPanelColumns Collection of column definitions with size, alignment, and margins.
RowCollection TCoreGridPanelRows Collection of row definitions with size, alignment, and margins.
Layout TResponsiveLayoutCollection Collection of responsive breakpoints defining grid layouts at different viewport widths.
GridLineWidth Integer Width of grid lines between cells (0 = no lines, just dotted guides at design time).
GridLineColor TColor Color of grid lines when GridLineWidth > 0. Default: clSilver.
OnLayoutChange TLayoutChangeEvent Fired when the active responsive layout changes due to viewport resize.

Column/Row Collection Item Properties

TCoreGridPanelColumn Properties

Property Type Default Description
SizeStyle TSizeStyle ssPercent ssPercent = proportional sizing, ssAbsolute = fixed pixel width.
Value Integer 50 The size value - percentage (0-100) or pixels depending on SizeStyle.
Alignment TAlignment taCenter Horizontal alignment of content: taLeftJustify, taCenter, taRightJustify.
MarginLeft Integer 0 Left margin in pixels for cells in this column.
MarginRight Integer 0 Right margin in pixels for cells in this column.

TCoreGridPanelRow Properties

Property Type Default Description
SizeStyle TSizeStyle ssPercent ssPercent = proportional sizing, ssAbsolute = fixed pixel height.
Value Integer 50 The size value - percentage or pixels.
Alignment TVerticalCellAlignment vcaCenter Vertical alignment: vcaTop, vcaCenter, vcaBottom.
MarginTop Integer 0 Top margin in pixels for cells in this row.
MarginBottom Integer 0 Bottom margin in pixels for cells in this row.

Responsive Layout Item Properties

Property Type Description
Width Integer Maximum viewport width for this layout (0 = default/largest, no limit).
Style STRING CSS grid-template-columns value (e.g. '1fr', '1fr 1fr', '200px 1fr').
ColumnGap STRING Gap between columns (e.g. '10px', '1rem').
RowGap STRING Gap between rows (e.g. '10px', '1rem').
Description STRING Description for IDE display (e.g. 'Mobile', 'Tablet', 'Desktop').

Public Methods

FUNCTION GetCell(ColIndex, RowIndex: Integer): TSubCoreDiv;

Returns the cell component at the specified column and row index. Returns nil if indices are out of range.

FUNCTION CellCount: Integer;

Returns the total number of cells in the grid (Rows × Columns).

PROCEDURE AlignAllChildrenInCells;

Re-aligns all child controls within their cells according to the column/row alignment settings. Called automatically on resize.

Default Layouts

When you drop a TCoreGridPanel on a form, it creates three default responsive layouts:

Description Width Style Behaviour
Mobile 576 1fr Single column, cells stack vertically
Tablet 768 1fr 1fr Two equal columns
Desktop 0 1fr 1fr 1fr 1fr 1fr Five equal columns (default)
Layout Selection: The grid selects the layout with the smallest Width value that is greater than or equal to the current viewport width. Width = 0 means "no limit" and acts as the default/largest layout.

Design-Time Behaviour

At design time:

At runtime, cell colors become transparent and indices are hidden.

Usage Examples

Basic Setup - 2x2 Grid

// In Form Designer or code:
GridPanel1.RowCollection.Clear;
GridPanel1.ColumnCollection.Clear;

// Add 2 rows
GridPanel1.RowCollection.Add.Value := 50;  // 50%
GridPanel1.RowCollection.Add.Value := 50;  // 50%

// Add 2 columns
GridPanel1.ColumnCollection.Add.Value := 50;  // 50%
GridPanel1.ColumnCollection.Add.Value := 50;  // 50%

Accessing Cells

VAR
   Cell: TSubCoreDiv;
BEGIN
   // Get cell at column 1, row 0
   Cell := GridPanel1.GetCell(1, 0);
   
   IF Assigned(Cell) THEN
      BEGIN
         // Add a label to the cell
         MyLabel.Parent := Cell;
      END;
END;

Custom Responsive Layouts

// Clear default layouts
GridPanel1.Layout.Clear;

// Mobile: single column
WITH GridPanel1.Layout.Add DO
   BEGIN
      Width       := 480;
      Style       := '1fr';
      ColumnGap   := '8px';
      RowGap      := '8px';
      Description := 'Mobile';
   END;

// Tablet: 2 columns with fixed sidebar
WITH GridPanel1.Layout.Add DO
   BEGIN
      Width       := 1024;
      Style       := '250px 1fr';
      ColumnGap   := '16px';
      RowGap      := '16px';
      Description := 'Tablet';
   END;

// Desktop: 3 columns
WITH GridPanel1.Layout.Add DO
   BEGIN
      Width       := 0;  // Default (largest)
      Style       := '250px 1fr 300px';
      ColumnGap   := '20px';
      RowGap      := '20px';
      Description := 'Desktop';
   END;

Responding to Layout Changes

PROCEDURE TMainForm.GridPanel1LayoutChange(Sender: TObject; 
   ALayout: TResponsiveLayoutItem);
BEGIN
   IF ALayout.Description = 'Mobile' THEN
      BEGIN
         // Hide sidebar content on mobile
         SidebarPanel.Visible := False;
      END
   ELSE
      BEGIN
         SidebarPanel.Visible := True;
      END;
END;

Fixed + Proportional Columns

// Create a layout with fixed sidebar and flexible content
GridPanel1.ColumnCollection.Clear;

// Fixed 200px sidebar
WITH GridPanel1.ColumnCollection.Add DO
   BEGIN
      SizeStyle := ssAbsolute;
      Value     := 200;
   END;

// Flexible content area (takes remaining space)
WITH GridPanel1.ColumnCollection.Add DO
   BEGIN
      SizeStyle := ssPercent;
      Value     := 100;
   END;

CSS Classes

TCoreGridPanel applies the CSS class core-grid-panel to itself. Cells can be styled via their ElementClassName property.

Important: At runtime, CSS Grid handles all layout. The RowCollection and ColumnCollection values are used to build the grid-template-rows CSS property, while the Layout collection's Style property defines grid-template-columns. Cell positioning is automatic - do NOT set absolute positions on cells.

Cell Styling

Cells are TSubCoreDiv components. By default they use flex layout with alignment based on column/row settings. To override:

See Also