2022-01-05 18:33:18 +03:00
|
|
|
package rui
|
|
|
|
|
2024-11-13 12:56:39 +03:00
|
|
|
func newTableCellView(session Session) *tableCellView {
|
|
|
|
view := new(tableCellView)
|
|
|
|
view.init(session)
|
|
|
|
return view
|
2022-01-15 01:20:04 +03:00
|
|
|
}
|
|
|
|
|
2024-11-13 12:56:39 +03:00
|
|
|
func (cell *tableCellView) init(session Session) {
|
|
|
|
cell.viewData.init(session)
|
|
|
|
cell.normalize = func(tag PropertyName) PropertyName {
|
|
|
|
if tag == VerticalAlign {
|
|
|
|
return TableVerticalAlign
|
|
|
|
}
|
|
|
|
return tag
|
2022-01-15 01:20:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cell *tableCellView) cssStyle(self View, builder cssBuilder) {
|
|
|
|
session := cell.Session()
|
|
|
|
cell.viewData.cssViewStyle(builder, session)
|
|
|
|
|
|
|
|
if value, ok := enumProperty(cell, TableVerticalAlign, session, 0); ok {
|
|
|
|
builder.add("vertical-align", enumProperties[TableVerticalAlign].values[value])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-16 20:25:45 +03:00
|
|
|
// GetTableContent returns a TableAdapter which defines the TableView content.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetTableContent(view View, subviewID ...string) TableAdapter {
|
2024-11-24 16:43:31 +03:00
|
|
|
if view = getSubview(view, subviewID); view != nil {
|
2024-11-13 12:56:39 +03:00
|
|
|
if content := view.getRaw(Content); content != nil {
|
|
|
|
if adapter, ok := content.(TableAdapter); ok {
|
|
|
|
return adapter
|
|
|
|
}
|
2022-01-16 20:25:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetTableRowStyle returns a TableRowStyle which defines styles of TableView rows.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetTableRowStyle(view View, subviewID ...string) TableRowStyle {
|
2024-11-24 16:43:31 +03:00
|
|
|
if view = getSubview(view, subviewID); view != nil {
|
2024-11-13 12:56:39 +03:00
|
|
|
for _, tag := range []PropertyName{RowStyle, Content} {
|
|
|
|
if value := view.getRaw(tag); value != nil {
|
|
|
|
if style, ok := value.(TableRowStyle); ok {
|
|
|
|
return style
|
|
|
|
}
|
|
|
|
}
|
2022-01-16 20:25:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetTableColumnStyle returns a TableColumnStyle which defines styles of TableView columns.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetTableColumnStyle(view View, subviewID ...string) TableColumnStyle {
|
2024-11-24 16:43:31 +03:00
|
|
|
if view = getSubview(view, subviewID); view != nil {
|
2024-11-13 12:56:39 +03:00
|
|
|
for _, tag := range []PropertyName{ColumnStyle, Content} {
|
|
|
|
if value := view.getRaw(tag); value != nil {
|
|
|
|
if style, ok := value.(TableColumnStyle); ok {
|
|
|
|
return style
|
|
|
|
}
|
|
|
|
}
|
2022-01-16 20:25:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetTableCellStyle returns a TableCellStyle which defines styles of TableView cells.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetTableCellStyle(view View, subviewID ...string) TableCellStyle {
|
2024-11-24 16:43:31 +03:00
|
|
|
if view = getSubview(view, subviewID); view != nil {
|
2024-11-13 12:56:39 +03:00
|
|
|
for _, tag := range []PropertyName{CellStyle, Content} {
|
|
|
|
if value := view.getRaw(tag); value != nil {
|
|
|
|
if style, ok := value.(TableCellStyle); ok {
|
|
|
|
return style
|
|
|
|
}
|
|
|
|
}
|
2022-01-16 20:25:45 +03:00
|
|
|
}
|
2024-11-13 12:56:39 +03:00
|
|
|
return nil
|
2022-01-16 20:25:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-01-17 03:11:23 +03:00
|
|
|
// GetTableSelectionMode returns the mode of the TableView elements selection.
|
2022-01-05 18:33:18 +03:00
|
|
|
// Valid values are NoneSelection (0), CellSelection (1), and RowSelection (2).
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetTableSelectionMode(view View, subviewID ...string) int {
|
2022-07-28 12:41:50 +03:00
|
|
|
return enumStyledProperty(view, subviewID, SelectionMode, NoneSelection, false)
|
2022-01-05 18:33:18 +03:00
|
|
|
}
|
|
|
|
|
2022-11-23 15:10:29 +03:00
|
|
|
// GetTableVerticalAlign returns a vertical align in a TableView cell. Returns one of next values:
|
2022-01-16 20:25:45 +03:00
|
|
|
// TopAlign (0), BottomAlign (1), CenterAlign (2), and BaselineAlign (3)
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetTableVerticalAlign(view View, subviewID ...string) int {
|
2022-07-28 12:41:50 +03:00
|
|
|
return enumStyledProperty(view, subviewID, TableVerticalAlign, TopAlign, false)
|
2022-01-15 01:20:04 +03:00
|
|
|
}
|
|
|
|
|
2022-01-16 21:39:59 +03:00
|
|
|
// GetTableHeadHeight returns the number of rows in the table header.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetTableHeadHeight(view View, subviewID ...string) int {
|
2022-07-28 12:11:27 +03:00
|
|
|
return intStyledProperty(view, subviewID, HeadHeight, 0)
|
2022-01-16 21:39:59 +03:00
|
|
|
}
|
2022-01-16 20:25:45 +03:00
|
|
|
|
2022-01-16 21:39:59 +03:00
|
|
|
// GetTableFootHeight returns the number of rows in the table footer.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetTableFootHeight(view View, subviewID ...string) int {
|
2022-07-28 12:11:27 +03:00
|
|
|
return intStyledProperty(view, subviewID, FootHeight, 0)
|
2022-01-16 21:39:59 +03:00
|
|
|
}
|
2022-01-16 20:25:45 +03:00
|
|
|
|
|
|
|
// GetTableCurrent returns the row and column index of the TableView selected cell/row.
|
|
|
|
// If there is no selected cell/row or the selection mode is NoneSelection (0),
|
|
|
|
// then a value of the row and column index less than 0 is returned.
|
|
|
|
// If the selection mode is RowSelection (2) then the returned column index is less than 0.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetTableCurrent(view View, subviewID ...string) CellIndex {
|
2024-11-24 16:43:31 +03:00
|
|
|
if view = getSubview(view, subviewID); view != nil {
|
2022-08-31 22:17:46 +03:00
|
|
|
if selectionMode := GetTableSelectionMode(view); selectionMode != NoneSelection {
|
2024-11-13 12:56:39 +03:00
|
|
|
return tableViewCurrent(view)
|
2022-01-15 01:20:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return CellIndex{Row: -1, Column: -1}
|
|
|
|
}
|
|
|
|
|
2022-01-05 18:33:18 +03:00
|
|
|
// GetTableCellClickedListeners returns listeners of event which occurs when the user clicks on a table cell.
|
|
|
|
// If there are no listeners then the empty list is returned.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetTableCellClickedListeners(view View, subviewID ...string) []func(TableView, int, int) {
|
2024-11-18 17:20:25 +03:00
|
|
|
return getTwoArgEventListeners[TableView, int](view, subviewID, TableCellClickedEvent)
|
2022-01-05 18:33:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetTableCellSelectedListeners returns listeners of event which occurs when a table cell becomes selected.
|
|
|
|
// If there are no listeners then the empty list is returned.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetTableCellSelectedListeners(view View, subviewID ...string) []func(TableView, int, int) {
|
2024-11-18 17:20:25 +03:00
|
|
|
return getTwoArgEventListeners[TableView, int](view, subviewID, TableCellSelectedEvent)
|
2022-01-05 18:33:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetTableRowClickedListeners returns listeners of event which occurs when the user clicks on a table row.
|
|
|
|
// If there are no listeners then the empty list is returned.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetTableRowClickedListeners(view View, subviewID ...string) []func(TableView, int) {
|
2024-11-18 17:20:25 +03:00
|
|
|
return getOneArgEventListeners[TableView, int](view, subviewID, TableRowClickedEvent)
|
2022-01-05 18:33:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetTableRowSelectedListeners returns listeners of event which occurs when a table row becomes selected.
|
|
|
|
// If there are no listeners then the empty list is returned.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetTableRowSelectedListeners(view View, subviewID ...string) []func(TableView, int) {
|
2024-11-18 17:20:25 +03:00
|
|
|
return getOneArgEventListeners[TableView, int](view, subviewID, TableRowSelectedEvent)
|
2022-01-05 18:33:18 +03:00
|
|
|
}
|
2022-04-14 12:05:45 +03:00
|
|
|
|
|
|
|
// ReloadTableViewData updates TableView
|
2023-05-14 17:53:26 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then updates the first argument (TableView).
|
2022-08-31 22:17:46 +03:00
|
|
|
func ReloadTableViewData(view View, subviewID ...string) bool {
|
2024-11-24 16:43:31 +03:00
|
|
|
if view = getSubview(view, subviewID); view != nil {
|
|
|
|
if tableView, ok := view.(TableView); ok {
|
|
|
|
tableView.ReloadTableData()
|
|
|
|
return true
|
2022-04-14 12:05:45 +03:00
|
|
|
}
|
|
|
|
}
|
2024-11-24 16:43:31 +03:00
|
|
|
return false
|
2022-04-14 12:05:45 +03:00
|
|
|
}
|
2023-05-14 17:53:26 +03:00
|
|
|
|
|
|
|
// ReloadTableViewCell updates the given table cell.
|
|
|
|
// If the last argument (subviewID) is not specified or it is "" then updates the cell of the first argument (TableView).
|
|
|
|
func ReloadTableViewCell(row, column int, view View, subviewID ...string) bool {
|
2024-11-24 16:43:31 +03:00
|
|
|
if view = getSubview(view, subviewID); view != nil {
|
|
|
|
if tableView, ok := view.(TableView); ok {
|
|
|
|
tableView.ReloadCell(row, column)
|
|
|
|
return true
|
2023-05-14 17:53:26 +03:00
|
|
|
}
|
|
|
|
}
|
2024-11-24 16:43:31 +03:00
|
|
|
return false
|
2023-05-14 17:53:26 +03:00
|
|
|
}
|