2021-09-07 17:36:50 +03:00
package rui
import (
"fmt"
"strconv"
"strings"
)
2024-09-12 14:05:11 +03:00
// Constants for [TableView] specific properties and events
2021-09-07 17:36:50 +03:00
const (
2024-09-18 13:50:06 +03:00
// TableVerticalAlign is the constant for "table-vertical-align" property tag.
//
// Used by `TableView`.
// Set the vertical alignment of the content inside a table cell.
//
// Supported types: `int`, `string`.
//
// Values:
// `0`(`TopAlign`) or "top" - Top alignment.
// `1`(`BottomAlign`) or "bottom" - Bottom alignment.
// `2`(`CenterAlign`) or "center" - Center alignment.
// `3`(`StretchAlign`) or "stretch" - Work as baseline alignment, see below.
// `4`(`BaselineAlign`) or "baseline" - Baseline alignment.
2024-11-13 12:56:39 +03:00
TableVerticalAlign PropertyName = "table-vertical-align"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// HeadHeight is the constant for "head-height" property tag.
//
// Used by `TableView`.
// Sets the number of rows in the table header. The default value is `0` (no header).
//
// Supported types: `int`, `string`.
//
// Values:
// `0` or "0" - No header.
// > `0` or > "0" - Number of rows act as a header.
2024-11-13 12:56:39 +03:00
HeadHeight PropertyName = "head-height"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// HeadStyle is the constant for "head-style" property tag.
//
// Used by `TableView`.
// Set the header style name or description of style properties.
//
// Supported types: `string`, `Params`.
//
// Internal type is either `string` or `Params`.
//
// Conversion rules:
// `string` - must contain style name defined in resources.
// `Params` - must contain style properties.
2024-11-13 12:56:39 +03:00
HeadStyle PropertyName = "head-style"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// FootHeight is the constant for "foot-height" property tag.
//
// Used by `TableView`.
// Sets the number of rows in the table footer. The default value is `0` (no footer).
//
// Supported types: `int`, `string`.
//
// Values:
// `0` or "0" - No footer.
// > `0` or > "0" - Number of rows act as a footer.
2024-11-13 12:56:39 +03:00
FootHeight PropertyName = "foot-height"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// FootStyle is the constant for "foot-style" property tag.
//
// Used by `TableView`.
// Set the footer style name or description of style properties.
//
// Supported types: `string`, `Params`.
//
// Internal type is either `string` or `Params`.
//
// Conversion rules:
// `string` - must contain style name defined in resources.
// `Params` - must contain style properties.
2024-11-13 12:56:39 +03:00
FootStyle PropertyName = "foot-style"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// RowSpan is the constant for "row-span" property tag.
//
// Used by `TableView`.
2024-11-13 12:56:39 +03:00
// Set the number of table row to span. Used only when specifying cell parameters in the implementation of
2024-09-18 13:50:06 +03:00
// `TableCellStyle`.
//
// Supported types: `int`, `string`.
//
// Values:
// `0` or "0" - No merging will be applied.
// > `0` or > "0" - Number of rows including current one to be merged together.
2024-11-13 12:56:39 +03:00
RowSpan PropertyName = "row-span"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// ColumnSpan is the constant for "column-span" property tag.
//
// Used by `TableView`.
2024-11-13 12:56:39 +03:00
// Sets the number of table column cells to be merged together. Used only when specifying cell parameters in the
2024-09-18 13:50:06 +03:00
// implementation of `TableCellStyle`.
//
// Supported types: `int`, `string`.
//
// Values:
// `0` or "0" - No merging will be applied.
// > `0` or > "0" - Number of columns including current one to be merged together.
2024-11-13 12:56:39 +03:00
ColumnSpan PropertyName = "column-span"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// RowStyle is the constant for "row-style" property tag.
//
// Used by `TableView`.
// Set the adapter which specifies styles of each table row.
//
// Supported types: `TableRowStyle`, `[]Params`.
//
// Internal type is `TableRowStyle`, other types converted to it during assignment.
// See `TableRowStyle` description for more details.
2024-11-13 12:56:39 +03:00
RowStyle PropertyName = "row-style"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// ColumnStyle is the constant for "column-style" property tag.
//
// Used by `TableView`.
// Set the adapter which specifies styles of each table column.
//
// Supported types: `TableColumnStyle`, `[]Params`.
//
// Internal type is `TableColumnStyle`, other types converted to it during assignment.
// See `TableColumnStyle` description for more details.
2024-11-13 12:56:39 +03:00
ColumnStyle PropertyName = "column-style"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// CellStyle is the constant for "cell-style" property tag.
//
// Used by `TableView`.
2024-11-13 12:56:39 +03:00
// Set the adapter which specifies styles of each table cell. This property can be assigned only by an implementation of
2024-09-18 13:50:06 +03:00
// `TableCellStyle` interface.
//
// Supported types: `TableCellStyle`.
2024-11-13 12:56:39 +03:00
CellStyle PropertyName = "cell-style"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// CellPadding is the constant for "cell-padding" property tag.
//
// Used by `TableView`.
2024-11-13 12:56:39 +03:00
// Sets the padding area on all four sides of a table cell at once. An element's padding area is the space between its
2024-09-18 13:50:06 +03:00
// content and its border.
//
// Supported types: `BoundsProperty`, `Bounds`, `SizeUnit`, `float32`, `float64`, `int`.
//
// Internal type is `BoundsProperty`, other types converted to it during assignment.
// See `BoundsProperty`, `Bounds` and `SizeUnit` description for more details.
2024-11-13 12:56:39 +03:00
CellPadding PropertyName = "cell-padding"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// CellPaddingLeft is the constant for "cell-padding-left" property tag.
//
// Used by `TableView`.
2024-11-13 12:56:39 +03:00
// Set the width of the padding area to the left of a cell content. An element's padding area is the space between its
2024-09-18 13:50:06 +03:00
// content and its border.
//
// Supported types: `SizeUnit`, `SizeFunc`, `string`, `float`, `int`.
//
// Internal type is `SizeUnit`, other types converted to it during assignment.
// See `SizeUnit` description for more details.
2024-11-13 12:56:39 +03:00
CellPaddingLeft PropertyName = "cell-padding-left"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// CellPaddingRight is the constant for "cell-padding-right" property tag.
//
// Used by `TableView`.
2024-11-13 12:56:39 +03:00
// Set the width of the padding area to the left of a cell content. An element's padding area is the space between its
2024-09-18 13:50:06 +03:00
// content and its border.
//
// Supported types: `SizeUnit`, `SizeFunc`, `string`, `float`, `int`.
//
// Internal type is `SizeUnit`, other types converted to it during assignment.
// See `SizeUnit` description for more details.
2024-11-13 12:56:39 +03:00
CellPaddingRight PropertyName = "cell-padding-right"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// CellPaddingTop is the constant for "cell-padding-top" property tag.
//
// Used by `TableView`.
2024-11-13 12:56:39 +03:00
// Set the height of the padding area to the top of a cell content. An element's padding area is the space between its
2024-09-18 13:50:06 +03:00
// content and its border.
//
// Supported types: `SizeUnit`, `SizeFunc`, `string`, `float`, `int`.
//
// Internal type is `SizeUnit`, other types converted to it during assignment.
// See `SizeUnit` description for more details.
2024-11-13 12:56:39 +03:00
CellPaddingTop PropertyName = "cell-padding-top"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// CellPaddingBottom is the constant for "cell-padding-bottom" property tag.
//
// Used by `TableView`.
// Set the height of the padding area to the bottom of a cell content.
//
// Supported types: `SizeUnit`, `SizeFunc`, `string`, `float`, `int`.
//
// Internal type is `SizeUnit`, other types converted to it during assignment.
// See `SizeUnit` description for more details.
2024-11-13 12:56:39 +03:00
CellPaddingBottom PropertyName = "cell-padding-bottom"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// CellBorder is the constant for "cell-border" property tag.
//
// Used by `TableView`.
2024-11-13 12:56:39 +03:00
// Set a table cell's border. It sets the values of a border width, style, and color. Can also be used when setting
2024-09-18 13:50:06 +03:00
// parameters in properties "row-style", "column-style", "foot-style" and "head-style".
//
// Supported types: `BorderProperty`, `ViewBorder`, `ViewBorders`.
//
// Internal type is `BorderProperty`, other types converted to it during assignment.
// See `BorderProperty`, `ViewBorder` and `ViewBorders` description for more details.
2024-11-13 12:56:39 +03:00
CellBorder PropertyName = "cell-border"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// CellBorderLeft is the constant for "cell-border-left" property tag.
//
// Used by `TableView`.
2024-11-13 12:56:39 +03:00
// Set a view's left border. It sets the values of a border width, style, and color. This property can be assigned a value
2024-09-18 13:50:06 +03:00
// of `BorderProperty`, `ViewBorder` types or `BorderProperty` text representation.
//
// Supported types: `ViewBorder`, `BorderProperty`, `string`.
//
// Internal type is `BorderProperty`, other types converted to it during assignment.
// See `ViewBorder` and `BorderProperty` description for more details.
2024-11-13 12:56:39 +03:00
CellBorderLeft PropertyName = "cell-border-left"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// CellBorderRight is the constant for "cell-border-right" property tag.
//
// Used by `TableView`.
2024-11-13 12:56:39 +03:00
// Set a view's right border. It sets the values of a border width, style, and color. This property can be assigned a
2024-09-18 13:50:06 +03:00
// value of `BorderProperty`, `ViewBorder` types or `BorderProperty` text representation.
//
// Supported types: `ViewBorder`, `BorderProperty`, `string`.
//
// Internal type is `BorderProperty`, other types converted to it during assignment.
// See `ViewBorder` and `BorderProperty` description for more details.
2024-11-13 12:56:39 +03:00
CellBorderRight PropertyName = "cell-border-right"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// CellBorderTop is the constant for "cell-border-top" property tag.
//
// Used by `TableView`.
2024-11-13 12:56:39 +03:00
// Set a view's top border. It sets the values of a border width, style, and color. This property can be assigned a value
2024-09-18 13:50:06 +03:00
// of `BorderProperty`, `ViewBorder` types or `BorderProperty` text representation.
//
// Supported types: `ViewBorder`, `BorderProperty`, `string`.
//
// Internal type is `BorderProperty`, other types converted to it during assignment.
// See `ViewBorder` and `BorderProperty` description for more details.
2024-11-13 12:56:39 +03:00
CellBorderTop PropertyName = "cell-border-top"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// CellBorderBottom is the constant for "cell-border-bottom" property tag.
//
// Used by `TableView`.
// Set a view's bottom border. It sets the values of a border width, style, and color.
//
// Supported types: `ViewBorder`, `BorderProperty`, `string`.
//
// Internal type is `BorderProperty`, other types converted to it during assignment.
// See `ViewBorder` and `BorderProperty` description for more details.
2024-11-13 12:56:39 +03:00
CellBorderBottom PropertyName = "cell-border-bottom"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// CellBorderStyle is the constant for "cell-border-style" property tag.
//
// Used by `TableView`.
// Set the line style for all four sides of a table cell's border. Default value is "none".
//
// Supported types: `int`, `string`.
//
// Values:
// `0`(`NoneLine`) or "none" - The border will not be drawn.
// `1`(`SolidLine`) or "solid" - Solid line as a border.
// `2`(`DashedLine`) or "dashed" - Dashed line as a border.
// `3`(`DottedLine`) or "dotted" - Dotted line as a border.
// `4`(`DoubleLine`) or "double" - Double line as a border.
2024-11-13 12:56:39 +03:00
CellBorderStyle PropertyName = "cell-border-style"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// CellBorderLeftStyle is the constant for "cell-border-left-style" property tag.
//
// Used by `TableView`.
// Set the line style of a table cell's left border. Default value is "none".
//
// Supported types: `int`, `string`.
//
// Values:
// `0`(`NoneLine`) or "none" - The border will not be drawn.
// `1`(`SolidLine`) or "solid" - Solid line as a border.
// `2`(`DashedLine`) or "dashed" - Dashed line as a border.
// `3`(`DottedLine`) or "dotted" - Dotted line as a border.
// `4`(`DoubleLine`) or "double" - Double line as a border.
2024-11-13 12:56:39 +03:00
CellBorderLeftStyle PropertyName = "cell-border-left-style"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// CellBorderRightStyle is the constant for "cell-border-right-style" property tag.
//
// Used by `TableView`.
// Set the line style of a table cell's right border. Default value is "none".
//
// Supported types: `int`, `string`.
//
// Values:
// `0`(`NoneLine`) or "none" - The border will not be drawn.
// `1`(`SolidLine`) or "solid" - Solid line as a border.
// `2`(`DashedLine`) or "dashed" - Dashed line as a border.
// `3`(`DottedLine`) or "dotted" - Dotted line as a border.
// `4`(`DoubleLine`) or "double" - Double line as a border.
2024-11-13 12:56:39 +03:00
CellBorderRightStyle PropertyName = "cell-border-right-style"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// CellBorderTopStyle is the constant for "cell-border-top-style" property tag.
//
// Used by `TableView`.
// Set the line style of a table cell's top border. Default value is "none".
//
// Supported types: `int`, `string`.
//
// Values:
// `0`(`NoneLine`) or "none" - The border will not be drawn.
// `1`(`SolidLine`) or "solid" - Solid line as a border.
// `2`(`DashedLine`) or "dashed" - Dashed line as a border.
// `3`(`DottedLine`) or "dotted" - Dotted line as a border.
// `4`(`DoubleLine`) or "double" - Double line as a border.
2024-11-13 12:56:39 +03:00
CellBorderTopStyle PropertyName = "cell-border-top-style"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// CellBorderBottomStyle is the constant for "cell-border-bottom-style" property tag.
//
// Used by `TableView`.
// Sets the line style of a table cell's bottom border. Default value is "none".
//
// Supported types: `int`, `string`.
//
// Values:
// `0`(`NoneLine`) or "none" - The border will not be drawn.
// `1`(`SolidLine`) or "solid" - Solid line as a border.
// `2`(`DashedLine`) or "dashed" - Dashed line as a border.
// `3`(`DottedLine`) or "dotted" - Dotted line as a border.
// `4`(`DoubleLine`) or "double" - Double line as a border.
2024-11-13 12:56:39 +03:00
CellBorderBottomStyle PropertyName = "cell-border-bottom-style"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// CellBorderWidth is the constant for "cell-border-width" property tag.
//
// Used by `TableView`.
// Set the line width for all four sides of a table cell's border.
//
// Supported types: `SizeUnit`, `SizeFunc`, `string`, `float`, `int`.
//
// Internal type is `SizeUnit`, other types converted to it during assignment.
// See `SizeUnit` description for more details.
2024-11-13 12:56:39 +03:00
CellBorderWidth PropertyName = "cell-border-width"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// CellBorderLeftWidth is the constant for "cell-border-left-width" property tag.
//
// Used by `TableView`.
// Set the line width of a table cell's left border.
//
// Supported types: `SizeUnit`, `SizeFunc`, `string`, `float`, `int`.
//
// Internal type is `SizeUnit`, other types converted to it during assignment.
// See `SizeUnit` description for more details.
2024-11-13 12:56:39 +03:00
CellBorderLeftWidth PropertyName = "cell-border-left-width"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// CellBorderRightWidth is the constant for "cell-border-right-width" property tag.
//
// Used by `TableView`.
// Set the line width of a table cell's right border.
//
// Supported types: `SizeUnit`, `SizeFunc`, `string`, `float`, `int`.
//
// Internal type is `SizeUnit`, other types converted to it during assignment.
// See `SizeUnit` description for more details.
2024-11-13 12:56:39 +03:00
CellBorderRightWidth PropertyName = "cell-border-right-width"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// CellBorderTopWidth is the constant for "cell-border-top-width" property tag.
//
// Used by `TableView`.
// Set the line width of a table cell's top border.
//
// Supported types: `SizeUnit`, `SizeFunc`, `string`, `float`, `int`.
//
// Internal type is `SizeUnit`, other types converted to it during assignment.
// See `SizeUnit` description for more details.
2024-11-13 12:56:39 +03:00
CellBorderTopWidth PropertyName = "cell-border-top-width"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// CellBorderBottomWidth is the constant for "cell-border-bottom-width" property tag.
//
// Used by `TableView`.
// Set the line width of a table cell's bottom border.
//
// Supported types: `SizeUnit`, `SizeFunc`, `string`, `float`, `int`.
//
// Internal type is `SizeUnit`, other types converted to it during assignment.
// See `SizeUnit` description for more details.
2024-11-13 12:56:39 +03:00
CellBorderBottomWidth PropertyName = "cell-border-bottom-width"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// CellBorderColor is the constant for "cell-border-color" property tag.
//
// Used by `TableView`.
// Set the line color for all four sides of a table cell's border.
//
// Supported types: `Color`, `string`.
//
// Internal type is `Color`, other types converted to it during assignment.
// See `Color` description for more details.
2024-11-13 12:56:39 +03:00
CellBorderColor PropertyName = "cell-border-color"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// CellBorderLeftColor is the constant for "cell-border-left-color" property tag.
//
// Used by `TableView`.
// Set the line color of a table cell's left border.
//
// Supported types: `Color`, `string`.
//
// Internal type is `Color`, other types converted to it during assignment.
// See `Color` description for more details.
2024-11-13 12:56:39 +03:00
CellBorderLeftColor PropertyName = "cell-border-left-color"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// CellBorderRightColor is the constant for "cell-border-right-color" property tag.
//
// Used by `TableView`.
// Set the line color of a table cell's right border.
//
// Supported types: `Color`, `string`.
//
// Internal type is `Color`, other types converted to it during assignment.
// See `Color` description for more details.
2024-11-13 12:56:39 +03:00
CellBorderRightColor PropertyName = "cell-border-right-color"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// CellBorderTopColor is the constant for "cell-border-top-color" property tag.
//
// Used by `TableView`.
// Set the line color of a table cell's top border.
//
// Supported types: `Color`, `string`.
//
// Internal type is `Color`, other types converted to it during assignment.
// See `Color` description for more details.
2024-11-13 12:56:39 +03:00
CellBorderTopColor PropertyName = "cell-border-top-color"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// CellBorderBottomColor is the constant for "cell-border-bottom-color" property tag.
//
// Used by `TableView`.
// Set the line color of a table cell's bottom border.
//
// Supported types: `Color`, `string`.
//
// Internal type is `Color`, other types converted to it during assignment.
// See `Color` description for more details.
2024-11-13 12:56:39 +03:00
CellBorderBottomColor PropertyName = "cell-border-bottom-color"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// SelectionMode is the constant for "selection-mode" property tag.
//
// Used by `TableView`.
// Sets the mode of the table elements selection. Default value is "none".
//
// Supported types: `int`, `string`.
//
// Values:
// `0`(`NoneSelection`) or "none" - Table elements are not selectable. The table cannot receive input focus.
// `1`(`CellSelection`) or "cell" - One table cell can be selected(highlighted). The cell is selected interactively using the mouse or keyboard(using the cursor keys).
// `2`(`RowSelection`) or "row" - The entire table row can be selected (highlighted). The row is selected interactively using the mouse or keyboard (using the cursor keys).
2024-11-13 12:56:39 +03:00
SelectionMode PropertyName = "selection-mode"
2022-01-05 18:33:18 +03:00
// TableCellClickedEvent is the constant for "table-cell-clicked" property tag.
2024-09-18 13:50:06 +03:00
//
// Used by `TableView`.
// Occur when the user clicks on a table cell.
//
// General listener format:
// `func(table rui.TableView, row, col int)`.
//
// where:
// table - Interface of a table view which generated this event,
// row - Row of the clicked cell,
// col - Column of the clicked cell.
//
// Allowed listener formats:
// `func(row, col int)`.
2024-11-13 12:56:39 +03:00
TableCellClickedEvent PropertyName = "table-cell-clicked"
2022-01-05 18:33:18 +03:00
// TableCellSelectedEvent is the constant for "table-cell-selected" property tag.
2024-09-18 13:50:06 +03:00
//
// Used by `TableView`.
// Occur when a table cell becomes selected.
//
// General listener format:
// `func(table rui.TableView, row, col int)`.
//
// where:
// table - Interface of a table view which generated this event,
// row - Row of the selected cell,
// col - Column of the selected cell.
//
// Allowed listener formats:
// `func(row, col int)`.
2024-11-13 12:56:39 +03:00
TableCellSelectedEvent PropertyName = "table-cell-selected"
2022-01-05 18:33:18 +03:00
// TableRowClickedEvent is the constant for "table-row-clicked" property tag.
2024-09-18 13:50:06 +03:00
//
// Used by `TableView`.
// Occur when the user clicks on a table row.
//
// General listener format:
// `func(table rui.TableView, row int)`.
//
// where:
// table - Interface of a table view which generated this event,
// row - Clicked row.
//
// Allowed listener formats:
// `func(row int)`.
2024-11-13 12:56:39 +03:00
TableRowClickedEvent PropertyName = "table-row-clicked"
2022-01-05 18:33:18 +03:00
// TableRowSelectedEvent is the constant for "table-row-selected" property tag.
2024-09-18 13:50:06 +03:00
//
// Used by `TableView`.
// Occur when a table row becomes selected.
//
// General listener format:
// `func(table rui.TableView, row int)`.
//
// where:
// table - Interface of a table view which generated this event,
// row - Selected row.
//
// Allowed listener formats:
// `func(row int)`.
2024-11-13 12:56:39 +03:00
TableRowSelectedEvent PropertyName = "table-row-selected"
2022-01-05 18:33:18 +03:00
2024-09-18 13:50:06 +03:00
// AllowSelection is the constant for "allow-selection" property tag.
//
// Used by `TableView`.
2024-11-13 12:56:39 +03:00
// Set the adapter which specifies whether cell/row selection is allowed. This property can be assigned by an
2024-09-18 13:50:06 +03:00
// implementation of `TableAllowCellSelection` or `TableAllowRowSelection` interface.
//
// Supported types: `TableAllowCellSelection`, `TableAllowRowSelection`.
//
// Internal type is either `TableAllowCellSelection`, `TableAllowRowSelection`, see their description for more details.
2024-11-13 12:56:39 +03:00
AllowSelection PropertyName = "allow-selection"
2024-09-12 14:05:11 +03:00
)
2022-01-15 02:06:10 +03:00
2024-09-12 14:05:11 +03:00
// Constants which represent values of "selection-mode" property of a [TableView]
const (
// NoneSelection the selection is forbidden.
2022-01-05 18:33:18 +03:00
NoneSelection = 0
2024-09-12 14:05:11 +03:00
// CellSelection the selection of a single cell only is enabled.
2022-01-05 18:33:18 +03:00
CellSelection = 1
2024-09-12 14:05:11 +03:00
// RowSelection the selection of a table row only is enabled.
2022-01-05 18:33:18 +03:00
RowSelection = 2
2021-09-07 17:36:50 +03:00
)
2024-09-12 14:05:11 +03:00
// CellIndex defines coordinates of the [TableView] cell
2022-01-05 18:33:18 +03:00
type CellIndex struct {
Row , Column int
}
2024-09-12 14:05:11 +03:00
// TableView represents a TableView view
2021-09-07 17:36:50 +03:00
type TableView interface {
View
2022-11-23 15:10:29 +03:00
ParentView
2024-09-12 14:05:11 +03:00
// ReloadTableData forces the table view to reload all data and redraw the entire table
2021-09-07 17:36:50 +03:00
ReloadTableData ( )
2024-09-12 14:05:11 +03:00
// ReloadCell forces the table view to reload the data for a specific cell and redraw it
2023-05-14 17:53:26 +03:00
ReloadCell ( row , column int )
2024-09-12 14:05:11 +03:00
// CellFrame returns the frame of a specific cell, describing its position and size within the table view
2022-01-15 01:20:04 +03:00
CellFrame ( row , column int ) Frame
2021-09-07 17:36:50 +03:00
}
type tableViewData struct {
viewData
2024-11-13 12:56:39 +03:00
cellViews [ ] View
cellFrame [ ] Frame
2021-09-07 17:36:50 +03:00
}
type tableCellView struct {
viewData
}
// NewTableView create new TableView object and return it
func NewTableView ( session Session , params Params ) TableView {
view := new ( tableViewData )
2022-09-01 11:04:50 +03:00
view . init ( session )
2021-09-07 17:36:50 +03:00
setInitParams ( view , params )
return view
}
func newTableView ( session Session ) View {
2024-11-13 12:56:39 +03:00
return new ( tableViewData ) // NewTableView(session, nil)
2021-09-07 17:36:50 +03:00
}
// Init initialize fields of TableView by default values
2022-09-01 11:04:50 +03:00
func ( table * tableViewData ) init ( session Session ) {
table . viewData . init ( session )
2021-09-07 17:36:50 +03:00
table . tag = "TableView"
2022-01-05 18:33:18 +03:00
table . cellViews = [ ] View { }
2022-01-15 01:20:04 +03:00
table . cellFrame = [ ] Frame { }
2024-11-13 12:56:39 +03:00
/ *
table . cellSelectedListener = [ ] func ( TableView , int , int ) { }
table . cellClickedListener = [ ] func ( TableView , int , int ) { }
table . rowSelectedListener = [ ] func ( TableView , int ) { }
table . rowClickedListener = [ ] func ( TableView , int ) { }
table . current . Row = - 1
table . current . Column = - 1
* /
table . normalize = normalizeTableViewTag
table . set = tableViewSet
table . changed = tableViewPropertyChanged
2022-05-22 12:54:02 +03:00
}
2024-11-13 12:56:39 +03:00
func normalizeTableViewTag ( tag PropertyName ) PropertyName {
switch tag = defaultNormalize ( tag ) ; tag {
2021-11-20 11:15:28 +03:00
case "top-cell-padding" :
tag = CellPaddingTop
case "right-cell-padding" :
tag = CellPaddingRight
case "bottom-cell-padding" :
tag = CellPaddingBottom
case "left-cell-padding" :
tag = CellPaddingLeft
}
return tag
}
2022-01-15 01:20:04 +03:00
func ( table * tableViewData ) Focusable ( ) bool {
2022-08-31 22:17:46 +03:00
return GetTableSelectionMode ( table ) != NoneSelection
2022-01-15 01:20:04 +03:00
}
2024-11-13 12:56:39 +03:00
func tableViewSet ( view View , tag PropertyName , value any ) [ ] PropertyName {
2022-01-05 18:33:18 +03:00
2024-11-13 12:56:39 +03:00
setLineStyle := func ( ) [ ] PropertyName {
params := [ ] Params { }
switch value := value . ( type ) {
case [ ] Params :
params = value
2022-01-05 18:33:18 +03:00
2024-11-13 12:56:39 +03:00
case DataNode :
params = value . ArrayAsParams ( )
2021-09-07 17:36:50 +03:00
2024-11-13 12:56:39 +03:00
default :
notCompatibleType ( tag , params )
return nil
}
2021-09-07 17:36:50 +03:00
2024-11-13 12:56:39 +03:00
if len ( params ) > 0 {
style := new ( simpleTableLineStyle )
style . params = params
view . setRaw ( tag , style )
} else if view . getRaw ( tag ) != nil {
view . setRaw ( tag , nil )
} else {
return [ ] PropertyName { }
}
return [ ] PropertyName { tag }
2021-09-07 17:36:50 +03:00
}
switch tag {
case Content :
switch val := value . ( type ) {
case TableAdapter :
2024-11-13 12:56:39 +03:00
view . setRaw ( Content , value )
2021-09-07 17:36:50 +03:00
2022-07-26 18:36:00 +03:00
case [ ] [ ] any :
2024-11-13 12:56:39 +03:00
view . setRaw ( Content , NewSimpleTableAdapter ( val ) )
2021-09-07 17:36:50 +03:00
case [ ] [ ] string :
2024-11-13 12:56:39 +03:00
view . setRaw ( Content , NewTextTableAdapter ( val ) )
2021-09-07 17:36:50 +03:00
default :
notCompatibleType ( tag , value )
2024-11-13 12:56:39 +03:00
return nil
2021-09-07 17:36:50 +03:00
}
2024-11-13 12:56:39 +03:00
return [ ] PropertyName { tag }
2021-09-07 17:36:50 +03:00
2024-11-13 12:56:39 +03:00
case TableCellClickedEvent , TableCellSelectedEvent :
return setEventWithOldListener [ TableView , int ] ( view , tag , value )
2022-01-05 18:33:18 +03:00
2024-11-13 12:56:39 +03:00
case TableRowClickedEvent , TableRowSelectedEvent :
return setViewEventListener [ TableView , int ] ( view , tag , value )
2022-01-05 18:33:18 +03:00
2021-09-07 17:36:50 +03:00
case CellStyle :
if style , ok := value . ( TableCellStyle ) ; ok {
2024-11-13 12:56:39 +03:00
view . setRaw ( tag , style )
return [ ] PropertyName { tag }
2021-09-07 17:36:50 +03:00
}
2024-11-13 12:56:39 +03:00
notCompatibleType ( tag , value )
return nil
2021-09-07 17:36:50 +03:00
case RowStyle :
2024-11-13 12:56:39 +03:00
if style , ok := value . ( TableRowStyle ) ; ok {
view . setRaw ( tag , style )
return [ ] PropertyName { tag }
2021-09-07 17:36:50 +03:00
}
2024-11-13 12:56:39 +03:00
return setLineStyle ( )
2021-09-07 17:36:50 +03:00
case ColumnStyle :
2024-11-13 12:56:39 +03:00
if style , ok := value . ( TableColumnStyle ) ; ok {
view . setRaw ( tag , style )
return [ ] PropertyName { tag }
2021-09-07 17:36:50 +03:00
}
2024-11-13 12:56:39 +03:00
return setLineStyle ( )
2021-09-07 17:36:50 +03:00
case HeadHeight , FootHeight :
switch value := value . ( type ) {
case string :
if isConstantName ( value ) {
2024-11-13 12:56:39 +03:00
view . setRaw ( tag , value )
2021-09-07 17:36:50 +03:00
} else if n , err := strconv . Atoi ( value ) ; err == nil {
2024-11-13 12:56:39 +03:00
view . setRaw ( tag , n )
2021-09-07 17:36:50 +03:00
} else {
ErrorLog ( err . Error ( ) )
notCompatibleType ( tag , value )
2024-11-13 12:56:39 +03:00
return nil
2021-09-07 17:36:50 +03:00
}
default :
if n , ok := isInt ( value ) ; ok {
2024-11-13 12:56:39 +03:00
view . setRaw ( tag , n )
} else {
notCompatibleType ( tag , value )
return nil
2021-09-07 17:36:50 +03:00
}
}
2024-11-13 12:56:39 +03:00
return [ ] PropertyName { tag }
2021-09-07 17:36:50 +03:00
case HeadStyle , FootStyle :
switch value := value . ( type ) {
case string :
2024-11-13 12:56:39 +03:00
view . setRaw ( tag , value )
2021-09-07 17:36:50 +03:00
case Params :
if len ( value ) > 0 {
2024-11-13 12:56:39 +03:00
view . setRaw ( tag , value )
} else if view . getRaw ( tag ) != nil {
view . setRaw ( tag , nil )
2021-09-07 17:36:50 +03:00
} else {
2024-11-13 12:56:39 +03:00
return [ ] PropertyName { }
2021-09-07 17:36:50 +03:00
}
2022-09-07 12:28:58 +03:00
case DataObject :
params := Params { }
for k := 0 ; k < value . PropertyCount ( ) ; k ++ {
if prop := value . Property ( k ) ; prop != nil && prop . Type ( ) == TextNode {
2024-11-13 12:56:39 +03:00
params [ PropertyName ( prop . Tag ( ) ) ] = prop . Text ( )
2022-09-07 12:28:58 +03:00
}
}
2024-11-13 12:56:39 +03:00
return tableViewSet ( view , tag , params )
2022-09-07 12:28:58 +03:00
2021-09-07 17:36:50 +03:00
case DataNode :
switch value . Type ( ) {
case ObjectNode :
2024-11-13 12:56:39 +03:00
return tableViewSet ( view , tag , value . Object ( ) )
2021-09-07 17:36:50 +03:00
case TextNode :
2024-11-13 12:56:39 +03:00
view . setRaw ( tag , value . Text ( ) )
2021-09-07 17:36:50 +03:00
default :
notCompatibleType ( tag , value )
2024-11-13 12:56:39 +03:00
return nil
2021-09-07 17:36:50 +03:00
}
default :
notCompatibleType ( tag , value )
2024-11-13 12:56:39 +03:00
return nil
2021-09-07 17:36:50 +03:00
}
2024-11-13 12:56:39 +03:00
return [ ] PropertyName { tag }
2021-09-07 17:36:50 +03:00
2022-01-15 02:06:10 +03:00
case AllowSelection :
switch value . ( type ) {
case TableAllowCellSelection :
2024-11-13 12:56:39 +03:00
view . setRaw ( tag , value )
2022-01-15 02:06:10 +03:00
case TableAllowRowSelection :
2024-11-13 12:56:39 +03:00
view . setRaw ( tag , value )
2022-01-15 02:06:10 +03:00
default :
notCompatibleType ( tag , value )
2024-11-13 12:56:39 +03:00
return nil
2022-01-15 02:06:10 +03:00
}
2024-11-13 12:56:39 +03:00
return [ ] PropertyName { tag }
2022-01-15 02:06:10 +03:00
2022-01-05 18:33:18 +03:00
case Current :
2024-11-13 12:56:39 +03:00
current := CellIndex { Row : - 1 , Column : - 1 }
2022-01-15 01:20:04 +03:00
switch value := value . ( type ) {
case CellIndex :
2024-11-13 12:56:39 +03:00
current = value
2022-01-05 18:33:18 +03:00
2022-01-15 01:20:04 +03:00
case DataObject :
if row , ok := dataIntProperty ( value , "row" ) ; ok {
2024-11-13 12:56:39 +03:00
current . Row = row
2022-01-15 01:20:04 +03:00
}
if column , ok := dataIntProperty ( value , "column" ) ; ok {
2024-11-13 12:56:39 +03:00
current . Column = column
2022-01-15 01:20:04 +03:00
}
case string :
if strings . Contains ( value , "," ) {
if values := strings . Split ( value , "," ) ; len ( values ) == 2 {
var n = [ ] int { 0 , 0 }
for i := 0 ; i < 2 ; i ++ {
var err error
if n [ i ] , err = strconv . Atoi ( values [ i ] ) ; err != nil {
ErrorLog ( err . Error ( ) )
2024-11-13 12:56:39 +03:00
return nil
2022-01-15 01:20:04 +03:00
}
}
2024-11-13 12:56:39 +03:00
current . Row = n [ 0 ]
current . Column = n [ 1 ]
2022-01-15 01:20:04 +03:00
} else {
notCompatibleType ( tag , value )
2024-11-13 12:56:39 +03:00
return nil
2022-01-15 01:20:04 +03:00
}
} else {
n , err := strconv . Atoi ( value )
if err != nil {
ErrorLog ( err . Error ( ) )
2024-11-13 12:56:39 +03:00
return nil
2022-01-15 01:20:04 +03:00
}
2024-11-13 12:56:39 +03:00
current . Row = n
2022-01-15 01:20:04 +03:00
}
default :
2023-05-07 19:26:02 +03:00
if n , ok := isInt ( value ) ; ok {
2024-11-13 12:56:39 +03:00
current . Row = n
2023-05-07 19:26:02 +03:00
} else {
notCompatibleType ( tag , value )
2024-11-13 12:56:39 +03:00
return nil
2023-05-07 19:26:02 +03:00
}
2022-01-05 18:33:18 +03:00
}
2024-11-13 12:56:39 +03:00
view . setRaw ( Current , current )
return [ ] PropertyName { tag }
2021-09-07 17:36:50 +03:00
}
2024-11-13 12:56:39 +03:00
return viewSet ( view , tag , value )
2021-09-07 17:36:50 +03:00
}
2024-11-13 12:56:39 +03:00
func tableViewPropertyChanged ( view View , tag PropertyName ) {
htmlID := view . htmlID ( )
session := view . Session ( )
2023-05-07 19:26:02 +03:00
2024-11-13 12:56:39 +03:00
switch tag {
case Content , TableVerticalAlign , RowStyle , ColumnStyle , CellStyle , CellPadding ,
CellBorder , HeadHeight , HeadStyle , FootHeight , FootStyle ,
CellPaddingTop , CellPaddingRight , CellPaddingBottom , CellPaddingLeft ,
TableCellClickedEvent , TableCellSelectedEvent , TableRowClickedEvent ,
TableRowSelectedEvent , AllowSelection , AccentColor :
ReloadTableViewData ( view )
case Current :
switch GetTableSelectionMode ( view ) {
case CellSelection :
current := tableViewCurrent ( view )
session . callFunc ( "setTableCellCursorByID" , htmlID , current . Row , current . Column )
case RowSelection :
session . callFunc ( "setTableRowCursorByID" , htmlID , tableViewCurrent ( view ) . Row )
}
case Gap :
gap , ok := sizeProperty ( view , Gap , session )
if ! ok || gap . Type == Auto || gap . Value <= 0 {
session . updateCSSProperty ( htmlID , "border-spacing" , "0" )
session . updateCSSProperty ( htmlID , "border-collapse" , "collapse" )
} else {
session . updateCSSProperty ( htmlID , "border-spacing" , gap . cssString ( "0" , session ) )
session . updateCSSProperty ( htmlID , "border-collapse" , "separate" )
}
case SelectionMode :
switch GetTableSelectionMode ( view ) {
case CellSelection :
tabIndex , _ := intProperty ( view , TabIndex , session , 0 )
session . updateProperty ( htmlID , "tabindex" , tabIndex )
session . updateProperty ( htmlID , "onfocus" , "tableViewFocusEvent(this, event)" )
session . updateProperty ( htmlID , "onblur" , "tableViewBlurEvent(this, event)" )
session . updateProperty ( htmlID , "data-selection" , "cell" )
session . updateProperty ( htmlID , "data-focusitemstyle" , tableViewCurrentStyle ( view ) )
session . updateProperty ( htmlID , "data-bluritemstyle" , tableViewCurrentInactiveStyle ( view ) )
current := tableViewCurrent ( view )
if current . Row >= 0 && current . Column >= 0 {
session . updateProperty ( htmlID , "data-current" , tableViewCellID ( view , current . Row , current . Column ) )
2021-11-20 11:15:28 +03:00
} else {
2024-11-13 12:56:39 +03:00
session . removeProperty ( htmlID , "data-current" )
2021-11-20 11:15:28 +03:00
}
2024-11-13 12:56:39 +03:00
session . updateProperty ( htmlID , "onkeydown" , "tableViewCellKeyDownEvent(this, event)" )
2022-01-15 01:20:04 +03:00
2024-11-13 12:56:39 +03:00
case RowSelection :
tabIndex , _ := intProperty ( view , TabIndex , session , 0 )
session . updateProperty ( htmlID , "tabindex" , tabIndex )
session . updateProperty ( htmlID , "onfocus" , "tableViewFocusEvent(this, event)" )
session . updateProperty ( htmlID , "onblur" , "tableViewBlurEvent(this, event)" )
session . updateProperty ( htmlID , "data-selection" , "row" )
session . updateProperty ( htmlID , "data-focusitemstyle" , tableViewCurrentStyle ( view ) )
session . updateProperty ( htmlID , "data-bluritemstyle" , tableViewCurrentInactiveStyle ( view ) )
current := tableViewCurrent ( view )
if current . Row >= 0 {
session . updateProperty ( htmlID , "data-current" , tableViewRowID ( view , current . Row ) )
} else {
session . removeProperty ( htmlID , "data-current" )
}
session . updateProperty ( htmlID , "onkeydown" , "tableViewRowKeyDownEvent(this, event)" )
2022-01-15 01:20:04 +03:00
2024-11-13 12:56:39 +03:00
default : // NoneSelection
if tabIndex , ok := intProperty ( view , TabIndex , session , - 1 ) ; ! ok || tabIndex < 0 {
session . removeProperty ( htmlID , "tabindex" )
}
2022-12-20 18:38:39 +03:00
2024-11-13 12:56:39 +03:00
for _ , prop := range [ ] string { "data-current" , "onfocus" , "onblur" , "onkeydown" , "data-selection" } {
session . removeProperty ( htmlID , prop )
2022-01-15 01:20:04 +03:00
}
2021-09-07 17:36:50 +03:00
}
2024-11-13 12:56:39 +03:00
updateInnerHTML ( htmlID , session )
default :
viewPropertyChanged ( view , tag )
2021-09-07 17:36:50 +03:00
}
}
2024-11-13 12:56:39 +03:00
func tableViewCurrentStyle ( view View ) string {
if value := view . getRaw ( CurrentStyle ) ; value != nil {
2022-01-15 01:20:04 +03:00
if style , ok := value . ( string ) ; ok {
2024-11-13 12:56:39 +03:00
if style , ok = view . Session ( ) . resolveConstants ( style ) ; ok {
2022-01-15 01:20:04 +03:00
return style
}
}
}
2024-11-13 12:56:39 +03:00
if value := valueFromStyle ( view , CurrentStyle ) ; value != nil {
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
if style , ok := value . ( string ) ; ok {
2024-11-13 12:56:39 +03:00
if style , ok = view . Session ( ) . resolveConstants ( style ) ; ok {
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
return style
}
}
}
2022-01-15 01:20:04 +03:00
return "ruiCurrentTableCellFocused"
}
2024-11-13 12:56:39 +03:00
func tableViewCurrentInactiveStyle ( view View ) string {
if value := view . getRaw ( CurrentInactiveStyle ) ; value != nil {
2022-01-15 01:20:04 +03:00
if style , ok := value . ( string ) ; ok {
2024-11-13 12:56:39 +03:00
if style , ok = view . Session ( ) . resolveConstants ( style ) ; ok {
2022-01-15 01:20:04 +03:00
return style
}
}
}
2024-11-13 12:56:39 +03:00
if value := valueFromStyle ( view , CurrentInactiveStyle ) ; value != nil {
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
if style , ok := value . ( string ) ; ok {
2024-11-13 12:56:39 +03:00
if style , ok = view . Session ( ) . resolveConstants ( style ) ; ok {
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
return style
}
}
}
2022-01-15 01:20:04 +03:00
return "ruiCurrentTableCell"
}
2024-11-13 12:56:39 +03:00
/ *
2022-07-26 18:36:00 +03:00
func ( table * tableViewData ) valueToCellListeners ( value any ) [ ] func ( TableView , int , int ) {
2022-01-05 18:33:18 +03:00
if value == nil {
return [ ] func ( TableView , int , int ) { }
}
switch value := value . ( type ) {
case func ( TableView , int , int ) :
return [ ] func ( TableView , int , int ) { value }
case func ( int , int ) :
2022-07-19 18:22:19 +03:00
fn := func ( _ TableView , row , column int ) {
2022-01-05 18:33:18 +03:00
value ( row , column )
}
return [ ] func ( TableView , int , int ) { fn }
case [ ] func ( TableView , int , int ) :
return value
case [ ] func ( int , int ) :
listeners := make ( [ ] func ( TableView , int , int ) , len ( value ) )
for i , val := range value {
if val == nil {
return nil
}
2022-07-19 18:22:19 +03:00
listeners [ i ] = func ( _ TableView , row , column int ) {
2022-01-05 18:33:18 +03:00
val ( row , column )
}
}
return listeners
2022-07-26 18:36:00 +03:00
case [ ] any :
2022-01-05 18:33:18 +03:00
listeners := make ( [ ] func ( TableView , int , int ) , len ( value ) )
for i , val := range value {
if val == nil {
return nil
}
switch val := val . ( type ) {
case func ( TableView , int , int ) :
listeners [ i ] = val
case func ( int , int ) :
2022-07-19 18:22:19 +03:00
listeners [ i ] = func ( _ TableView , row , column int ) {
2022-01-05 18:33:18 +03:00
val ( row , column )
}
default :
return nil
}
}
return listeners
}
return nil
}
2024-11-13 12:56:39 +03:00
* /
2022-01-05 18:33:18 +03:00
2021-09-07 17:36:50 +03:00
func ( table * tableViewData ) htmlTag ( ) string {
return "table"
}
2024-11-13 12:56:39 +03:00
func tableViewRowID ( view View , index int ) string {
return fmt . Sprintf ( "%s-%d" , view . htmlID ( ) , index )
2022-01-15 01:20:04 +03:00
}
2022-01-05 18:33:18 +03:00
2024-11-13 12:56:39 +03:00
func tableViewCellID ( view View , row , column int ) string {
return fmt . Sprintf ( "%s-%d-%d" , view . htmlID ( ) , row , column )
2022-01-15 01:20:04 +03:00
}
func ( table * tableViewData ) htmlProperties ( self View , buffer * strings . Builder ) {
2024-11-13 12:56:39 +03:00
if content := GetTableContent ( table ) ; content != nil {
2022-01-15 01:20:04 +03:00
buffer . WriteString ( ` data-rows=" ` )
buffer . WriteString ( strconv . Itoa ( content . RowCount ( ) ) )
buffer . WriteString ( ` " data-columns=" ` )
buffer . WriteString ( strconv . Itoa ( content . ColumnCount ( ) ) )
buffer . WriteRune ( '"' )
}
2022-08-31 22:17:46 +03:00
if selectionMode := GetTableSelectionMode ( table ) ; selectionMode != NoneSelection {
2022-01-15 01:20:04 +03:00
buffer . WriteString ( ` onfocus="tableViewFocusEvent(this, event)" onblur="tableViewBlurEvent(this, event)" data-focusitemstyle=" ` )
2024-11-13 12:56:39 +03:00
buffer . WriteString ( tableViewCurrentStyle ( table ) )
2022-01-15 01:20:04 +03:00
buffer . WriteString ( ` " data-bluritemstyle=" ` )
2024-11-13 12:56:39 +03:00
buffer . WriteString ( tableViewCurrentInactiveStyle ( table ) )
2022-01-15 01:20:04 +03:00
buffer . WriteRune ( '"' )
2024-11-13 12:56:39 +03:00
current := tableViewCurrent ( table )
2022-01-15 01:20:04 +03:00
switch selectionMode {
case RowSelection :
buffer . WriteString ( ` data-selection="row" onkeydown="tableViewRowKeyDownEvent(this, event)" ` )
2024-11-13 12:56:39 +03:00
if current . Row >= 0 {
2022-01-15 01:20:04 +03:00
buffer . WriteString ( ` data-current=" ` )
2024-11-13 12:56:39 +03:00
buffer . WriteString ( tableViewRowID ( table , current . Row ) )
2022-01-15 01:20:04 +03:00
buffer . WriteRune ( '"' )
}
case CellSelection :
buffer . WriteString ( ` data-selection="cell" onkeydown="tableViewCellKeyDownEvent(this, event)" ` )
2024-11-13 12:56:39 +03:00
if current . Row >= 0 && current . Column >= 0 {
2022-01-15 01:20:04 +03:00
buffer . WriteString ( ` data-current=" ` )
2024-11-13 12:56:39 +03:00
buffer . WriteString ( tableViewCellID ( table , current . Row , current . Column ) )
2022-01-15 01:20:04 +03:00
buffer . WriteRune ( '"' )
}
}
}
table . viewData . htmlProperties ( self , buffer )
}
func ( table * tableViewData ) htmlSubviews ( self View , buffer * strings . Builder ) {
table . cellViews = [ ] View { }
table . cellFrame = [ ] Frame { }
2024-11-13 12:56:39 +03:00
adapter := GetTableContent ( table )
2022-01-15 01:20:04 +03:00
if adapter == nil {
2021-09-07 17:36:50 +03:00
return
}
rowCount := adapter . RowCount ( )
columnCount := adapter . ColumnCount ( )
if rowCount == 0 || columnCount == 0 {
return
}
2022-01-15 01:20:04 +03:00
table . cellFrame = make ( [ ] Frame , rowCount * columnCount )
2024-11-13 12:56:39 +03:00
rowStyle := GetTableRowStyle ( table )
cellStyle := GetTableCellStyle ( table )
2021-09-07 17:36:50 +03:00
session := table . Session ( )
2024-11-13 12:56:39 +03:00
current := tableViewCurrent ( table )
2021-09-07 17:36:50 +03:00
if ! session . ignoreViewUpdates ( ) {
session . setIgnoreViewUpdates ( true )
defer session . setIgnoreViewUpdates ( false )
}
2022-10-29 20:16:40 +03:00
cssBuilder := viewCSSBuilder { buffer : allocStringBuilder ( ) }
2021-09-07 17:36:50 +03:00
defer freeStringBuilder ( cssBuilder . buffer )
2024-11-13 12:56:39 +03:00
view := newTableCellView ( session )
2021-09-07 17:36:50 +03:00
2022-12-20 17:48:00 +03:00
ignoreCells := [ ] struct { row , column int } { }
2022-08-31 22:17:46 +03:00
selectionMode := GetTableSelectionMode ( table )
2021-09-07 17:36:50 +03:00
2022-01-15 02:06:10 +03:00
var allowCellSelection TableAllowCellSelection = nil
if allow , ok := adapter . ( TableAllowCellSelection ) ; ok {
allowCellSelection = allow
}
if value := table . getRaw ( AllowSelection ) ; value != nil {
if style , ok := value . ( TableAllowCellSelection ) ; ok {
allowCellSelection = style
}
}
var allowRowSelection TableAllowRowSelection = nil
if allow , ok := adapter . ( TableAllowRowSelection ) ; ok {
allowRowSelection = allow
}
if value := table . getRaw ( AllowSelection ) ; value != nil {
if style , ok := value . ( TableAllowRowSelection ) ; ok {
allowRowSelection = style
}
}
2022-01-16 20:25:45 +03:00
vAlignCss := enumProperties [ TableVerticalAlign ] . cssValues
2022-08-31 22:17:46 +03:00
vAlignValue := GetTableVerticalAlign ( table )
2022-01-16 20:25:45 +03:00
if vAlignValue < 0 || vAlignValue >= len ( vAlignCss ) {
vAlignValue = 0
}
vAlign := vAlignCss [ vAlignValue ]
2021-09-07 17:36:50 +03:00
tableCSS := func ( startRow , endRow int , cellTag string , cellBorder BorderProperty , cellPadding BoundsProperty ) {
2023-05-14 17:53:26 +03:00
//var namedColors []NamedColor = nil
2021-09-07 17:36:50 +03:00
2022-05-16 17:43:06 +03:00
for row := startRow ; row < endRow ; row ++ {
2021-09-07 17:36:50 +03:00
cssBuilder . buffer . Reset ( )
if rowStyle != nil {
if styles := rowStyle . RowStyle ( row ) ; styles != nil {
view . Clear ( )
for tag , value := range styles {
view . Set ( tag , value )
}
2024-11-13 12:56:39 +03:00
view . cssStyle ( view , & cssBuilder )
2021-09-07 17:36:50 +03:00
}
}
2022-01-15 01:20:04 +03:00
buffer . WriteString ( ` <tr id=" ` )
2024-11-13 12:56:39 +03:00
buffer . WriteString ( tableViewRowID ( table , row ) )
2022-01-15 01:20:04 +03:00
buffer . WriteRune ( '"' )
if selectionMode == RowSelection {
2024-11-13 12:56:39 +03:00
if row == current . Row {
2022-01-15 01:20:04 +03:00
buffer . WriteString ( ` class=" ` )
if table . HasFocus ( ) {
2024-11-13 12:56:39 +03:00
buffer . WriteString ( tableViewCurrentStyle ( table ) )
2022-01-15 01:20:04 +03:00
} else {
2024-11-13 12:56:39 +03:00
buffer . WriteString ( tableViewCurrentInactiveStyle ( table ) )
2022-01-15 01:20:04 +03:00
}
buffer . WriteRune ( '"' )
}
buffer . WriteString ( ` onclick="tableRowClickEvent(this, event)" ` )
2022-01-15 02:06:10 +03:00
if allowRowSelection != nil && ! allowRowSelection . AllowRowSelection ( row ) {
buffer . WriteString ( ` data-disabled="1" ` )
}
2022-01-15 01:20:04 +03:00
}
2021-09-07 17:36:50 +03:00
if cssBuilder . buffer . Len ( ) > 0 {
2022-01-15 01:20:04 +03:00
buffer . WriteString ( ` style=" ` )
2021-09-07 17:36:50 +03:00
buffer . WriteString ( cssBuilder . buffer . String ( ) )
2022-01-15 01:20:04 +03:00
buffer . WriteString ( ` " ` )
2021-09-07 17:36:50 +03:00
}
2022-01-15 01:20:04 +03:00
buffer . WriteString ( ">" )
2021-09-07 17:36:50 +03:00
for column := 0 ; column < columnCount ; column ++ {
ignore := false
2022-12-20 17:48:00 +03:00
for _ , cell := range ignoreCells {
2021-09-07 17:36:50 +03:00
if cell . row == row && cell . column == column {
ignore = true
break
}
}
if ! ignore {
rowSpan := 0
columnSpan := 0
cssBuilder . buffer . Reset ( )
view . Clear ( )
if cellBorder != nil {
2024-11-13 12:56:39 +03:00
view . Set ( Border , cellBorder )
2021-09-07 17:36:50 +03:00
}
if cellPadding != nil {
2024-11-13 12:56:39 +03:00
view . Set ( Padding , cellPadding )
2021-09-07 17:36:50 +03:00
}
2022-01-16 20:25:45 +03:00
if cellStyle != nil {
if styles := cellStyle . CellStyle ( row , column ) ; styles != nil {
for tag , value := range styles {
valueToInt := func ( ) int {
switch value := value . ( type ) {
case int :
return value
case string :
if value , ok := session . resolveConstants ( value ) ; ok {
if n , err := strconv . Atoi ( value ) ; err == nil {
return n
2021-09-07 17:36:50 +03:00
}
}
}
2022-01-16 20:25:45 +03:00
return 0
}
2021-09-07 17:36:50 +03:00
2024-11-13 12:56:39 +03:00
switch tag = defaultNormalize ( tag ) ; tag {
2022-01-16 20:25:45 +03:00
case RowSpan :
rowSpan = valueToInt ( )
2021-09-07 17:36:50 +03:00
2022-01-16 20:25:45 +03:00
case ColumnSpan :
columnSpan = valueToInt ( )
2021-09-07 17:36:50 +03:00
2022-01-16 20:25:45 +03:00
default :
2024-11-13 12:56:39 +03:00
view . Set ( tag , value )
2021-09-07 17:36:50 +03:00
}
}
}
}
if len ( view . properties ) > 0 {
2024-11-13 12:56:39 +03:00
view . cssStyle ( view , & cssBuilder )
2021-09-07 17:36:50 +03:00
}
buffer . WriteRune ( '<' )
buffer . WriteString ( cellTag )
2022-01-15 01:20:04 +03:00
buffer . WriteString ( ` id=" ` )
2024-11-13 12:56:39 +03:00
buffer . WriteString ( tableViewCellID ( table , row , column ) )
2022-01-15 01:20:04 +03:00
buffer . WriteString ( ` " class="ruiView ` )
2024-11-13 12:56:39 +03:00
if selectionMode == CellSelection && row == current . Row && column == current . Column {
2022-01-15 01:20:04 +03:00
buffer . WriteRune ( ' ' )
if table . HasFocus ( ) {
2024-11-13 12:56:39 +03:00
buffer . WriteString ( tableViewCurrentStyle ( table ) )
2022-01-15 01:20:04 +03:00
} else {
2024-11-13 12:56:39 +03:00
buffer . WriteString ( tableViewCurrentInactiveStyle ( table ) )
2022-01-15 01:20:04 +03:00
}
}
buffer . WriteRune ( '"' )
if selectionMode == CellSelection {
buffer . WriteString ( ` onclick="tableCellClickEvent(this, event)" ` )
2022-01-15 02:06:10 +03:00
if allowCellSelection != nil && ! allowCellSelection . AllowCellSelection ( row , column ) {
buffer . WriteString ( ` data-disabled="1" ` )
}
2022-01-15 01:20:04 +03:00
}
2021-09-07 17:36:50 +03:00
if columnSpan > 1 {
buffer . WriteString ( ` colspan=" ` )
buffer . WriteString ( strconv . Itoa ( columnSpan ) )
buffer . WriteRune ( '"' )
for c := column + 1 ; c < column + columnSpan ; c ++ {
2022-12-20 17:48:00 +03:00
ignoreCells = append ( ignoreCells , struct {
2021-09-07 17:36:50 +03:00
row int
column int
} { row : row , column : c } )
}
}
if rowSpan > 1 {
buffer . WriteString ( ` rowspan=" ` )
buffer . WriteString ( strconv . Itoa ( rowSpan ) )
buffer . WriteRune ( '"' )
if columnSpan < 1 {
columnSpan = 1
}
for r := row + 1 ; r < row + rowSpan ; r ++ {
for c := column ; c < column + columnSpan ; c ++ {
2022-12-20 17:48:00 +03:00
ignoreCells = append ( ignoreCells , struct {
2021-09-07 17:36:50 +03:00
row int
column int
} { row : r , column : c } )
}
}
}
if cssBuilder . buffer . Len ( ) > 0 {
buffer . WriteString ( ` style=" ` )
buffer . WriteString ( cssBuilder . buffer . String ( ) )
buffer . WriteRune ( '"' )
}
buffer . WriteRune ( '>' )
2023-05-14 17:53:26 +03:00
table . writeCellHtml ( adapter , row , column , buffer )
/ *
switch value := adapter . Cell ( row , column ) . ( type ) {
case string :
buffer . WriteString ( value )
case View :
viewHTML ( value , buffer )
table . cellViews = append ( table . cellViews , value )
case Color :
buffer . WriteString ( ` <div style="display: inline; height: 1em; background-color: ` )
buffer . WriteString ( value . cssString ( ) )
buffer . WriteString ( ` "> </div> ` )
buffer . WriteString ( value . String ( ) )
if namedColors == nil {
namedColors = NamedColors ( )
}
for _ , namedColor := range namedColors {
if namedColor . Color == value {
buffer . WriteString ( " (" )
buffer . WriteString ( namedColor . Name )
buffer . WriteRune ( ')' )
break
}
2022-05-16 17:43:06 +03:00
}
2021-09-07 17:36:50 +03:00
2023-05-14 17:53:26 +03:00
case fmt . Stringer :
buffer . WriteString ( value . String ( ) )
2021-09-07 17:36:50 +03:00
2023-05-14 17:53:26 +03:00
case rune :
buffer . WriteString ( string ( value ) )
2021-09-07 17:36:50 +03:00
2023-05-14 17:53:26 +03:00
case float32 :
buffer . WriteString ( fmt . Sprintf ( "%g" , float64 ( value ) ) )
2021-09-07 17:36:50 +03:00
2023-05-14 17:53:26 +03:00
case float64 :
buffer . WriteString ( fmt . Sprintf ( "%g" , value ) )
2021-09-07 17:36:50 +03:00
2023-05-14 17:53:26 +03:00
case bool :
if value {
buffer . WriteString ( session . checkboxOnImage ( ) )
} else {
buffer . WriteString ( session . checkboxOffImage ( ) )
}
2021-09-07 17:36:50 +03:00
2023-05-14 17:53:26 +03:00
default :
if n , ok := isInt ( value ) ; ok {
buffer . WriteString ( fmt . Sprintf ( "%d" , n ) )
} else {
buffer . WriteString ( "<Unsupported value>" )
}
2021-09-07 17:36:50 +03:00
}
2023-05-14 17:53:26 +03:00
* /
2021-09-07 17:36:50 +03:00
buffer . WriteString ( ` </ ` )
buffer . WriteString ( cellTag )
buffer . WriteRune ( '>' )
}
}
buffer . WriteString ( "</tr>" )
}
}
2024-11-13 12:56:39 +03:00
if columnStyle := GetTableColumnStyle ( table ) ; columnStyle != nil {
2021-09-07 17:36:50 +03:00
buffer . WriteString ( "<colgroup>" )
for column := 0 ; column < columnCount ; column ++ {
cssBuilder . buffer . Reset ( )
if styles := columnStyle . ColumnStyle ( column ) ; styles != nil {
view . Clear ( )
for tag , value := range styles {
view . Set ( tag , value )
}
2024-11-13 12:56:39 +03:00
view . cssStyle ( view , & cssBuilder )
2021-09-07 17:36:50 +03:00
}
if cssBuilder . buffer . Len ( ) > 0 {
buffer . WriteString ( ` <col style=" ` )
buffer . WriteString ( cssBuilder . buffer . String ( ) )
buffer . WriteString ( ` "> ` )
} else {
buffer . WriteString ( "<col>" )
}
}
buffer . WriteString ( "</colgroup>" )
}
2022-08-31 22:17:46 +03:00
headHeight := GetTableHeadHeight ( table )
footHeight := GetTableFootHeight ( table )
2021-09-07 17:36:50 +03:00
cellBorder := table . getCellBorder ( )
2024-11-13 12:56:39 +03:00
cellPadding := getBoundsProperty ( table , CellPadding )
2023-05-04 16:45:03 +03:00
if cellPadding == nil || len ( cellPadding . AllTags ( ) ) == 0 {
cellPadding = nil
2021-09-07 17:36:50 +03:00
if style , ok := stringProperty ( table , Style , table . Session ( ) ) ; ok {
if style , ok := table . Session ( ) . resolveConstants ( style ) ; ok {
cellPadding = table . cellPaddingFromStyle ( style )
}
}
}
2024-11-13 12:56:39 +03:00
headFootStart := func ( htmlTag string , styleTag PropertyName ) ( BorderProperty , BoundsProperty ) {
2021-09-07 17:36:50 +03:00
buffer . WriteRune ( '<' )
buffer . WriteString ( htmlTag )
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
value := table . getRaw ( styleTag )
if value == nil {
value = valueFromStyle ( table , styleTag )
}
if value != nil {
2021-09-07 17:36:50 +03:00
switch value := value . ( type ) {
case string :
if style , ok := session . resolveConstants ( value ) ; ok {
buffer . WriteString ( ` class=" ` )
buffer . WriteString ( style )
2022-01-16 20:25:45 +03:00
buffer . WriteString ( ` " style="vertical-align: ` )
buffer . WriteString ( vAlign )
buffer . WriteString ( ` ;"> ` )
2021-09-07 17:36:50 +03:00
return table . cellBorderFromStyle ( style ) , table . cellPaddingFromStyle ( style )
}
case Params :
cssBuilder . buffer . Reset ( )
view . Clear ( )
2022-01-16 20:25:45 +03:00
view . Set ( TableVerticalAlign , vAlignValue )
2021-09-07 17:36:50 +03:00
for tag , val := range value {
view . Set ( tag , val )
}
var border BorderProperty = nil
if value := view . Get ( CellBorder ) ; value != nil {
border = value . ( BorderProperty )
}
var padding BoundsProperty = nil
if value := view . Get ( CellPadding ) ; value != nil {
switch value := value . ( type ) {
case SizeUnit :
padding = NewBoundsProperty ( Params {
Top : value ,
Right : value ,
Bottom : value ,
Left : value ,
} )
case BoundsProperty :
padding = value
}
}
2024-11-13 12:56:39 +03:00
view . cssStyle ( view , & cssBuilder )
2021-09-07 17:36:50 +03:00
if cssBuilder . buffer . Len ( ) > 0 {
buffer . WriteString ( ` style=" ` )
buffer . WriteString ( cssBuilder . buffer . String ( ) )
buffer . WriteString ( ` " ` )
}
buffer . WriteRune ( '>' )
return border , padding
}
}
2022-01-16 20:25:45 +03:00
buffer . WriteString ( ` style="vertical-align: ` )
buffer . WriteString ( vAlign )
buffer . WriteString ( ` ;"> ` )
2021-09-07 17:36:50 +03:00
return nil , nil
}
if headHeight > 0 {
headCellBorder := cellBorder
headCellPadding := cellPadding
if headHeight > rowCount {
headHeight = rowCount
}
border , padding := headFootStart ( "thead" , HeadStyle )
if border != nil {
headCellBorder = border
}
if padding != nil {
headCellPadding = padding
}
tableCSS ( 0 , headHeight , "th" , headCellBorder , headCellPadding )
buffer . WriteString ( "</thead>" )
}
if footHeight > rowCount - headHeight {
footHeight = rowCount - headHeight
}
if rowCount > footHeight + headHeight {
2022-01-16 20:25:45 +03:00
buffer . WriteString ( ` <tbody style="vertical-align: ` )
buffer . WriteString ( vAlign )
buffer . WriteString ( ` ;"> ` )
2021-09-07 17:36:50 +03:00
tableCSS ( headHeight , rowCount - footHeight , "td" , cellBorder , cellPadding )
buffer . WriteString ( "</tbody>" )
}
if footHeight > 0 {
footCellBorder := cellBorder
footCellPadding := cellPadding
border , padding := headFootStart ( "tfoot" , FootStyle )
if border != nil {
footCellBorder = border
}
if padding != nil {
footCellPadding = padding
}
tableCSS ( rowCount - footHeight , rowCount , "td" , footCellBorder , footCellPadding )
buffer . WriteString ( "</tfoot>" )
}
}
func ( table * tableViewData ) cellPaddingFromStyle ( style string ) BoundsProperty {
2022-05-23 15:22:14 +03:00
if value := table . Session ( ) . styleProperty ( style , CellPadding ) ; value != nil {
switch value := value . ( type ) {
case SizeUnit :
return NewBoundsProperty ( Params {
Top : value ,
Right : value ,
Bottom : value ,
Left : value ,
} )
2021-09-07 17:36:50 +03:00
2022-05-23 15:22:14 +03:00
case BoundsProperty :
return value
case string :
if value , ok := table . Session ( ) . resolveConstants ( value ) ; ok {
if strings . Contains ( value , "," ) {
values := split4Values ( value )
switch len ( values ) {
case 1 :
value = values [ 0 ]
case 4 :
result := NewBoundsProperty ( nil )
n := 0
2024-11-13 12:56:39 +03:00
for i , tag := range [ ] PropertyName { Top , Right , Bottom , Left } {
2022-05-23 15:22:14 +03:00
if size , ok := StringToSizeUnit ( values [ i ] ) ; ok && size . Type != Auto {
result . Set ( tag , size )
n ++
}
}
if n > 0 {
return result
}
return nil
default :
return nil
}
2021-09-07 17:36:50 +03:00
}
2022-05-23 15:22:14 +03:00
if size , ok := StringToSizeUnit ( value ) ; ok && size . Type != Auto {
return NewBoundsProperty ( Params {
Top : size ,
Right : size ,
Bottom : size ,
Left : size ,
} )
}
2021-09-07 17:36:50 +03:00
}
}
}
2022-05-23 15:22:14 +03:00
return nil
2021-09-07 17:36:50 +03:00
}
2023-05-14 17:53:26 +03:00
func ( table * tableViewData ) writeCellHtml ( adapter TableAdapter , row , column int , buffer * strings . Builder ) {
switch value := adapter . Cell ( row , column ) . ( type ) {
case string :
buffer . WriteString ( value )
case View :
viewHTML ( value , buffer )
table . cellViews = append ( table . cellViews , value )
case Color :
buffer . WriteString ( ` <div style="display: inline; height: 1em; background-color: ` )
buffer . WriteString ( value . cssString ( ) )
buffer . WriteString ( ` "> </div> ` )
buffer . WriteString ( value . String ( ) )
namedColors := NamedColors ( )
for _ , namedColor := range namedColors {
if namedColor . Color == value {
buffer . WriteString ( " (" )
buffer . WriteString ( namedColor . Name )
buffer . WriteRune ( ')' )
break
}
}
case fmt . Stringer :
buffer . WriteString ( value . String ( ) )
case rune :
buffer . WriteString ( string ( value ) )
case float32 :
buffer . WriteString ( fmt . Sprintf ( "%g" , float64 ( value ) ) )
case float64 :
buffer . WriteString ( fmt . Sprintf ( "%g" , value ) )
case bool :
2024-09-03 15:31:11 +03:00
accentColor := Color ( 0 )
if color := GetAccentColor ( table , "" ) ; color != 0 {
accentColor = color
}
2023-05-14 17:53:26 +03:00
if value {
2024-09-03 15:31:11 +03:00
buffer . WriteString ( table . Session ( ) . checkboxOnImage ( accentColor ) )
2023-05-14 17:53:26 +03:00
} else {
2024-09-03 15:31:11 +03:00
buffer . WriteString ( table . Session ( ) . checkboxOffImage ( accentColor ) )
2023-05-14 17:53:26 +03:00
}
default :
if n , ok := isInt ( value ) ; ok {
buffer . WriteString ( fmt . Sprintf ( "%d" , n ) )
} else {
buffer . WriteString ( "<Unsupported value>" )
}
}
}
2021-09-07 17:36:50 +03:00
func ( table * tableViewData ) cellBorderFromStyle ( style string ) BorderProperty {
2022-05-23 15:22:14 +03:00
if value := table . Session ( ) . styleProperty ( style , CellBorder ) ; value != nil {
if border , ok := value . ( BorderProperty ) ; ok {
return border
2021-09-07 17:36:50 +03:00
}
}
2022-05-23 15:22:14 +03:00
return nil
2021-09-07 17:36:50 +03:00
}
func ( table * tableViewData ) getCellBorder ( ) BorderProperty {
if value := table . getRaw ( CellBorder ) ; value != nil {
if border , ok := value . ( BorderProperty ) ; ok {
return border
}
}
if style , ok := stringProperty ( table , Style , table . Session ( ) ) ; ok {
if style , ok := table . Session ( ) . resolveConstants ( style ) ; ok {
return table . cellBorderFromStyle ( style )
}
}
return nil
}
2024-11-13 12:56:39 +03:00
func tableViewCurrent ( view View ) CellIndex {
if value := view . getRaw ( Current ) ; value != nil {
if current , ok := value . ( CellIndex ) ; ok {
return current
}
}
return CellIndex { Row : - 1 , Column : - 1 }
2022-01-15 01:20:04 +03:00
}
2021-09-07 17:36:50 +03:00
func ( table * tableViewData ) cssStyle ( self View , builder cssBuilder ) {
2022-09-05 14:00:07 +03:00
session := table . Session ( )
table . viewData . cssViewStyle ( builder , session )
2021-09-07 17:36:50 +03:00
2022-09-05 14:00:07 +03:00
gap , ok := sizeProperty ( table , Gap , session )
2021-09-07 17:36:50 +03:00
if ! ok || gap . Type == Auto || gap . Value <= 0 {
builder . add ( "border-spacing" , "0" )
builder . add ( "border-collapse" , "collapse" )
} else {
2022-09-05 14:00:07 +03:00
builder . add ( "border-spacing" , gap . cssString ( "0" , session ) )
2021-09-07 17:36:50 +03:00
builder . add ( "border-collapse" , "separate" )
}
}
func ( table * tableViewData ) ReloadTableData ( ) {
2022-09-05 14:00:07 +03:00
session := table . Session ( )
2022-10-30 17:22:33 +03:00
htmlID := table . htmlID ( )
2024-11-13 12:56:39 +03:00
if content := GetTableContent ( table ) ; content != nil {
2022-10-30 17:22:33 +03:00
session . updateProperty ( htmlID , "data-rows" , strconv . Itoa ( content . RowCount ( ) ) )
session . updateProperty ( htmlID , "data-columns" , strconv . Itoa ( content . ColumnCount ( ) ) )
2022-01-15 01:20:04 +03:00
}
2022-10-30 17:22:33 +03:00
updateInnerHTML ( htmlID , session )
2021-09-07 17:36:50 +03:00
}
2022-01-15 01:20:04 +03:00
func ( table * tableViewData ) onItemResize ( self View , index string , x , y , width , height float64 ) {
if n := strings . IndexRune ( index , '-' ) ; n > 0 {
if row , err := strconv . Atoi ( index [ : n ] ) ; err == nil {
if column , err := strconv . Atoi ( index [ n + 1 : ] ) ; err == nil {
2024-11-13 12:56:39 +03:00
if content := GetTableContent ( table ) ; content != nil {
2022-01-15 01:20:04 +03:00
i := row * content . ColumnCount ( ) + column
if i < len ( table . cellFrame ) {
table . cellFrame [ i ] . Left = x
table . cellFrame [ i ] . Top = y
table . cellFrame [ i ] . Width = width
table . cellFrame [ i ] . Height = height
}
}
} else {
ErrorLog ( err . Error ( ) )
}
} else {
ErrorLog ( err . Error ( ) )
}
} else {
ErrorLogF ( ` Invalid cell index: %s ` , index )
2021-09-07 17:36:50 +03:00
}
}
2022-01-15 01:20:04 +03:00
func ( table * tableViewData ) CellFrame ( row , column int ) Frame {
2024-11-13 12:56:39 +03:00
if content := GetTableContent ( table ) ; content != nil {
2022-01-15 01:20:04 +03:00
i := row * content . ColumnCount ( ) + column
if i < len ( table . cellFrame ) {
return table . cellFrame [ i ]
}
2021-09-07 17:36:50 +03:00
}
2022-01-15 01:20:04 +03:00
return Frame { }
2021-09-07 17:36:50 +03:00
}
2022-01-05 18:33:18 +03:00
2023-05-14 17:53:26 +03:00
func ( table * tableViewData ) ReloadCell ( row , column int ) {
2024-11-13 12:56:39 +03:00
if adapter := GetTableContent ( table ) ; adapter != nil {
buffer := allocStringBuilder ( )
defer freeStringBuilder ( buffer )
2023-05-14 17:53:26 +03:00
2024-11-13 12:56:39 +03:00
table . writeCellHtml ( adapter , row , column , buffer )
table . session . updateInnerHTML ( tableViewCellID ( table , row , column ) , buffer . String ( ) )
}
2023-05-14 17:53:26 +03:00
}
2022-01-05 18:33:18 +03:00
func ( table * tableViewData ) Views ( ) [ ] View {
return table . cellViews
}
2022-01-15 01:20:04 +03:00
2024-11-13 12:56:39 +03:00
func ( table * tableViewData ) handleCommand ( self View , command PropertyName , data DataObject ) bool {
2022-01-15 01:20:04 +03:00
switch command {
case "currentRow" :
2024-11-13 12:56:39 +03:00
current := tableViewCurrent ( table )
if row , ok := dataIntProperty ( data , "row" ) ; ok && row != current . Row {
current . Row = row
table . setRaw ( Current , current . Row )
if listener , ok := table . changeListener [ Current ] ; ok {
listener ( table , Current )
}
for _ , listener := range GetTableRowSelectedListeners ( table ) {
2022-01-15 01:20:04 +03:00
listener ( table , row )
}
}
case "currentCell" :
if row , ok := dataIntProperty ( data , "row" ) ; ok {
if column , ok := dataIntProperty ( data , "column" ) ; ok {
2024-11-13 12:56:39 +03:00
current := tableViewCurrent ( table )
if row != current . Row || column != current . Column {
current . Row = row
current . Column = column
table . setRaw ( Current , current . Row )
if listener , ok := table . changeListener [ Current ] ; ok {
listener ( table , Current )
}
for _ , listener := range GetTableCellSelectedListeners ( table ) {
2022-01-15 01:20:04 +03:00
listener ( table , row , column )
}
}
}
}
case "rowClick" :
if row , ok := dataIntProperty ( data , "row" ) ; ok {
2024-11-13 12:56:39 +03:00
for _ , listener := range GetTableRowClickedListeners ( table ) {
2022-01-15 01:20:04 +03:00
listener ( table , row )
}
}
case "cellClick" :
if row , ok := dataIntProperty ( data , "row" ) ; ok {
if column , ok := dataIntProperty ( data , "column" ) ; ok {
2024-11-13 12:56:39 +03:00
for _ , listener := range GetTableCellClickedListeners ( table ) {
2022-01-15 01:20:04 +03:00
listener ( table , row , column )
}
}
}
default :
return table . viewData . handleCommand ( self , command , data )
}
return true
}