forked from c0re100/go-tdlib
/
pageBlockTableCell.go
79 lines (67 loc) · 2.76 KB
/
pageBlockTableCell.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package tdlib
import (
"encoding/json"
)
// PageBlockTableCell Represents a cell of a table
type PageBlockTableCell struct {
tdCommon
Text RichText `json:"text"` // Cell text; may be null. If the text is null, then the cell must be invisible
IsHeader bool `json:"is_header"` // True, if it is a header cell
Colspan int32 `json:"colspan"` // The number of columns the cell spans
Rowspan int32 `json:"rowspan"` // The number of rows the cell spans
Align PageBlockHorizontalAlignment `json:"align"` // Horizontal cell content alignment
Valign PageBlockVerticalAlignment `json:"valign"` // Vertical cell content alignment
}
// MessageType return the string telegram-type of PageBlockTableCell
func (pageBlockTableCell *PageBlockTableCell) MessageType() string {
return "pageBlockTableCell"
}
// NewPageBlockTableCell creates a new PageBlockTableCell
//
// @param text Cell text; may be null. If the text is null, then the cell must be invisible
// @param isHeader True, if it is a header cell
// @param colspan The number of columns the cell spans
// @param rowspan The number of rows the cell spans
// @param align Horizontal cell content alignment
// @param valign Vertical cell content alignment
func NewPageBlockTableCell(text RichText, isHeader bool, colspan int32, rowspan int32, align PageBlockHorizontalAlignment, valign PageBlockVerticalAlignment) *PageBlockTableCell {
pageBlockTableCellTemp := PageBlockTableCell{
tdCommon: tdCommon{Type: "pageBlockTableCell"},
Text: text,
IsHeader: isHeader,
Colspan: colspan,
Rowspan: rowspan,
Align: align,
Valign: valign,
}
return &pageBlockTableCellTemp
}
// UnmarshalJSON unmarshal to json
func (pageBlockTableCell *PageBlockTableCell) UnmarshalJSON(b []byte) error {
var objMap map[string]*json.RawMessage
err := json.Unmarshal(b, &objMap)
if err != nil {
return err
}
tempObj := struct {
tdCommon
IsHeader bool `json:"is_header"` // True, if it is a header cell
Colspan int32 `json:"colspan"` // The number of columns the cell spans
Rowspan int32 `json:"rowspan"` // The number of rows the cell spans
}{}
err = json.Unmarshal(b, &tempObj)
if err != nil {
return err
}
pageBlockTableCell.tdCommon = tempObj.tdCommon
pageBlockTableCell.IsHeader = tempObj.IsHeader
pageBlockTableCell.Colspan = tempObj.Colspan
pageBlockTableCell.Rowspan = tempObj.Rowspan
fieldText, _ := unmarshalRichText(objMap["text"])
pageBlockTableCell.Text = fieldText
fieldAlign, _ := unmarshalPageBlockHorizontalAlignment(objMap["align"])
pageBlockTableCell.Align = fieldAlign
fieldValign, _ := unmarshalPageBlockVerticalAlignment(objMap["valign"])
pageBlockTableCell.Valign = fieldValign
return nil
}