components_config_JRServer.bs

import "pkg:/source/utils/misc.bs"

sub init() as void
  m.focusBorder = m.top.findNode("focusBorder")
  m.poster = m.top.findNode("poster")
  m.name = m.top.findNode("name")
  m.baseUrl = m.top.findNode("baseUrl")
  m.labels = m.top.findNode("labels")

  ' Set focus border color to primary color and size it to cover the entire component
  if isValid(m.focusBorder)
    m.focusBorder.blendColor = m.global.constants.colors.primary
    ' Size the border to cover the entire component with some padding
    ' get the itemSize of the parent MarkupList
    parentList = m.top.getParent()
    if isValid(parentList) and parentList.hasField("itemSize")
      itemSize = parentList.itemSize
      if isValid(itemSize) and itemSize.Count() = 2
        m.focusBorder.width = itemSize[0]
        m.focusBorder.height = itemSize[1]
      end if
    end if
    ' m.focusBorder.translation = [-10, -5]
  end if
end sub

sub itemContentChanged() as void
  server = m.top.itemContent

  m.poster.uri = server.iconUrl
  m.name.text = server.name
  m.baseUrl.text = server.baseUrl
end sub

sub onFocusPercentChange()
  ' Show focus border when item is focused (above 40% focus)
  if isValid(m.focusBorder)
    if m.top.focusPercent > 0.4
      m.focusBorder.visible = true
    else
      m.focusBorder.visible = false
    end if
  end if
end sub