我试图在按钮内绘制一个带有按钮的按钮和正确的文本。XML文件如下。
<?xml version="1.0" encoding="utf-8" ?>
<component name="settingsButtons" extends="Group">
<interface>
<field id="itemContent" type="node" onChange="itemContentChanged"/>
</interface>
<script type="text/brightscript" >
<![CDATA[
sub itemContentChanged()
itemData = m.top.itemContent
m.buttonRect.width = itemData.buttonWidth
m.buttonRect.height = itemData.buttonHeight
m.buttonRect.color = itemData.buttonColor
m.buttonText.text = itemData.titleText
m.buttonText.translation = m.defaultTextTranslation
m.buttonText.color = itemData.textColor
m.buttonRightText.text = itemData.rightText
m.buttonRightText.translation = m.defaultRightTextTranslation
m.buttonRightText.color = itemData.textColor
end sub
sub initCoordinates()
m.defaultTextTranslation = "[30, 20]"
m.defaultRightTextTranslation = "[790, 20]"
end sub
sub init()
initCoordinates()
m.buttonRect = m.top.findNode("buttonRect")
m.buttonText = m.top.findNode("buttonText")
m.buttonRightText = m.top.findNode("buttonRightText")
end sub
]]>
</script>
<children>
<Rectangle id="buttonRect" translation="[0, 0]" width="820" height="70">
<Label id="buttonText" height="29" horizAlign = "left" vertAlign = "center" translation="[0, 0]" >
<Font role="font" uri="pkg:/fonts/NHaasGroteskDSStd-75Bd.otf" size="24" />
</Label>
<Label id="buttonRightText" height="29" horizAlign = "right" vertAlign = "center" translation="[0, 0]" >
<Font role="font" uri="pkg:/fonts/NHaasGroteskTXStd-55Rg.otf" size="24" />
</Label>
</Rectangle>
</children>
</component>
即使我一直保持正确的视频,但ButtonRightText从显示的位置显示的位置显示(即显示为左侧对齐)。您能否让我知道如何解决此问题。
从SDK DOC中,您需要具有指定宽度(不等于零)才能工作。
一个选项是让所有两个标签与矩形共享相同的宽度,并将翻译保持为[0, 0]
。
sub itemContentChanged()
itemData = m.top.itemContent
m.buttonRect.width = itemData.buttonWidth
m.buttonRect.height = itemData.buttonHeight
m.buttonRect.color = itemData.buttonColor
m.buttonText.text = itemData.titleText
m.buttonText.width = itemData.buttonWidth
m.buttonText.color = itemData.textColor
m.buttonRightText.text = itemData.rightText
m.buttonRightText.width = itemData.buttonWidth
m.buttonRightText.color = itemData.textColor
end sub