jf-roku/components/IconButton.brs

82 lines
2.1 KiB
Plaintext
Raw Normal View History

2022-07-19 02:28:06 +00:00
sub init()
m.buttonBackground = m.top.findNode("buttonBackground")
m.buttonIcon = m.top.findNode("buttonIcon")
m.buttonText = m.top.findNode("buttonText")
m.top.observeField("background", "onBackgroundChanged")
m.top.observeField("icon", "onIconChanged")
m.top.observeField("text", "onTextChanged")
m.top.observeField("height", "onHeightChanged")
m.top.observeField("width", "onWidthChanged")
m.top.observeField("padding", "onPaddingChanged")
2022-09-03 20:06:57 +00:00
m.top.observeField("focus", "onFocusChanged")
2022-07-19 02:28:06 +00:00
end sub
sub onFocusChanged()
2022-09-03 20:06:57 +00:00
if m.top.focus
2022-07-19 02:28:06 +00:00
m.buttonBackground.blendColor = m.top.focusBackground
else
m.buttonBackground.blendColor = m.top.background
end if
end sub
sub onBackgroundChanged()
m.buttonBackground.blendColor = m.top.background
m.top.unobserveField("background")
end sub
sub onIconChanged()
m.buttonIcon.uri = m.top.icon
end sub
sub onTextChanged()
m.buttonText.text = m.top.text
end sub
sub setIconSize()
height = m.buttonBackground.height
width = m.buttonBackground.width
if height > 0 and width > 0
' TODO: Use smallest number between them
m.buttonIcon.height = m.top.height
if m.top.padding > 0
m.buttonIcon.height = m.buttonIcon.height - m.top.padding
end if
m.buttonIcon.width = m.buttonIcon.height
m.buttonIcon.translation = [((width - m.buttonIcon.width) / 2), ((height - m.buttonIcon.height) / 2)]
m.buttonText.translation = [0, height + 10]
m.buttonText.width = width
end if
end sub
sub onHeightChanged()
m.buttonBackground.height = m.top.height
setIconSize()
end sub
sub onWidthChanged()
m.buttonBackground.width = m.top.width
setIconSize()
end sub
sub onPaddingChanged()
setIconSize()
end sub
function onKeyEvent(key as string, press as boolean) as boolean
if not press then return false
2022-09-27 01:26:17 +00:00
if key = "right" and m.top.focus
2022-09-03 20:06:57 +00:00
m.top.escape = "right"
end if
2022-09-27 01:26:17 +00:00
if key = "left" and m.top.focus
2022-09-03 20:06:57 +00:00
m.top.escape = "left"
end if
2022-07-19 02:28:06 +00:00
return false
end function