如何在 BrightScript 中使用 replaceChild 替换 PanelSet

How to replace a PanelSet using replaceChild in BrightScript

我正在使用 PanelSet class 创建一个由两个面板组成的设置屏幕:

当用户在 panelA 上更改焦点项目时,如何替换右侧显示的 Panel

Roku's documentation 声明您必须使用方法 replaceChild,但我无法弄清楚它应该如何工作,或任何示例。这是我正在尝试的方法,但它不起作用:

function showPanelInfo()
    if m.panelA.list.itemFocused = 0
        m.panelset.replaceChild(m.panelB, 3)
    else
        m.panelset.replaceChild(m.panelC, 3)
    end if
end function

Function init()
    m.panelset = createObject("roSGNode", "PanelSet")

    ' Left-hand side panel with two items list
    m.panelA = m.panelset.createChild("OptionsListPanel")

    ' Right-hand side panels with different lists for each item on left-hand side panel
    m.panelB = m.panelset.createChild("OptionsBPanel")
    m.panelC = createObject("roSGNode", "OptionsCPanel")

    m.panelA.list.observeField("itemFocused", "showPanelInfo")
...
end function

如果您使用 GridPanelListPanel,您应该观察其 createNextPanelIndex 字段并简单地在观察者中将新面板设置为其 nextPanel 字段。所以,通常你不应该手动 insert/replace/create children of PanelSet。检查它是如何工作的 here and here。如果你使用普通的面板节点,它可能会更复杂一点,但我相信情况并非如此。

示例代码:

Function showPanelInfo()
  if m.panelA.list.itemFocused = 0
    m.panelset.nextPanel = m.panelB
  else
    m.panelset.nextPanel = m.panelC
  end if
end function

Function init()
  m.panelset = createObject("roSGNode", "PanelSet")

  ' Left-hand side panel with two items list
  m.panelA = m.panelset.createChild("OptionsListPanel")

  ' Right-hand side panels with different lists for each item on left-hand side panel
  m.panelB = m.panelset.createChild("OptionsBPanel")
  m.panelC = createObject("roSGNode", "OptionsCPanel")

  m.panelA.observeField("createNextPanelIndex", "showPanelInfo")
  ...
end function

面板集没有nextPanel。只有列表面板和网格面板有nextPanel。所以,

m.panelA.nextPanel = m.panelB