-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathStandardGridItemComponent.brs
More file actions
116 lines (103 loc) · 4.04 KB
/
StandardGridItemComponent.brs
File metadata and controls
116 lines (103 loc) · 4.04 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
' Copyright (c) 2018 Roku, Inc. All rights reserved.
sub Init()
m.labelsLayout = m.top.findNode("labelsLayout")
m.labelsBackground = m.top.findNode("labelsBackground")
m.line1 = m.top.findNode("line1")
m.line2 = m.top.findNode("line2")
m.poster = m.top.findNode("poster")
m.durationBar = m.top.findNode("durationBar")
m.durationBar.height = 6
end sub
sub onContentSet()
content = m.top.itemContent
if content <> invalid
m.poster.uri = content.hdPosterUrl
' contentSetLine is field to check if text is set to label
setLabelDataOrHide(m.line1, content.shortDescriptionLine1)
setLabelDataOrHide(m.line2, content.shortDescriptionLine2)
setDurationBarData(content.length, content.playStart, content.hideItemDurationBar <> true)
updateLabelsLayout()
end if
end sub
sub onWidthChange()
m.durationBar.width = m.top.width
m.poster.width = m.top.width
m.poster.loadWidth = m.top.width
updateLabelsLayout()
end sub
sub onHeightChange()
m.poster.height = m.top.height
m.poster.loadHeight = m.top.height
m.durationBar.translation = [0,m.top.height - m.durationBar.height]
updateLabelsLayout()
end sub
sub updateLabelsLayout()
width = m.top.width
height = m.top.height
if width > 0 and height > 0
' set theme parametres
parent = Utils_getParentbyIndex(3, m.top)
if parent <> invalid
if parent.itemTextColorLine1 <> invalid
m.line1.color = parent.itemTextColorLine1
end if
if parent.itemTextColorLine2 <> invalid
m.line2.color = parent.itemTextColorLine2
end if
itemTextBgColor = parent.itemTextBackgroundColor
if itemTextBgColor <> invalid and itemTextBgColor <> "" ' when itemTextBackgroundColor field is set
if m.line1.visible Or m.line2.visible ' show background if there is text for atleast one label
m.labelsBackground.color = parent.itemTextBackgroundColor
m.labelsBackground.opacity = 1
end if
end if
end if
padding = 5
if height > 200 then padding = 10
setLabelStyle(m.line1, width, height, padding)
setLabelStyle(m.line2, width, height, padding)
' set rectangle background width and height
heightLayout = m.labelsLayout.boundingRect().height
m.labelsBackground.width = width + 1 ' background should fill whole item width
m.labelsBackground.height = heightLayout + 2 * padding
' translate layouts to the bottom of item
m.labelsBackground.translation = [0, height - m.labelsBackground.height]
if m.line1.visible and not m.line2.visible ' to centralize text on labelsLayout
m.labelsLayout.translation = [padding, height - padding + m.labelsLayout.itemSpacings[0]]
else
m.labelsLayout.translation = [padding, height - padding]
end if
end if
end sub
sub setLabelStyle(label as Object, width as Integer, height as Integer, padding as Integer)
if height > 0 and width > 0
font = "font:MediumSystemFont"
if height > 220 ' big size
font = "font:LargeSystemFont"
end if
label.width = width - padding * 2
label.font = font
end if
end sub
sub setLabelDataOrHide(label as Object, text as String)
if text.trim().len() > 0
label.text = text
label.visible = true
label.scale = [1,1]
else
label.text = ""
label.visible = false
label.scale = [0,0]
end if
end sub
sub setDurationBarData(length as Integer, playStart as Integer, showDurationBar as Boolean)
if showDurationBar and length > 0 and playStart > 0 and playStart < length
m.durationBar.length = length
m.durationBar.playStart = playStart
m.durationBar.visible = true
m.durationBar.scale = [1,1]
else
m.durationBar.visible = false
m.durationBar.scale = [0,0]
end if
end sub