Lua WoW-设置(和重置)帧锚

Lua WoW-设置(和重置)帧锚,lua,world-of-warcraft,Lua,World Of Warcraft,我有一个非常简单的附加组件,它以文本方式显示四条信息,而不是在各自的框架上用视觉表示。每一个都可以由用户自行决定打开或关闭 我希望这些框架都能水平地相互固定。很简单,对吧?将Frame2的左边缘锚定到Frame1的右边缘,以相同的方式将Frame3锚定到Frame2,等等。如果禁用Frame2,则Frame3需要锚定到Frame1 我试图在锚定帧上运行Frame:GetChildren()来计算子项,并将它们锚定到锚定帧本身,而不是彼此锚定,但是Frame:GetChildren()返回一个表表

我有一个非常简单的附加组件,它以文本方式显示四条信息,而不是在各自的框架上用视觉表示。每一个都可以由用户自行决定打开或关闭

我希望这些框架都能水平地相互固定。很简单,对吧?将Frame2的左边缘锚定到Frame1的右边缘,以相同的方式将Frame3锚定到Frame2,等等。如果禁用Frame2,则Frame3需要锚定到Frame1

我试图在锚定帧上运行
Frame:GetChildren()
来计算子项,并将它们锚定到锚定帧本身,而不是彼此锚定,但是
Frame:GetChildren()
返回一个表表,而
#
操作符不计算表数

作为奖励,我希望用户能够更改帧的顺序

如何做到这一点的问题今天困扰了我一整天。也许是因为缺乏睡眠,或者是因为缺乏Lua体验。无论如何,任何帮助都将不胜感激

第一部分:组织框架 为不需要的帧指定一个接近零的宽度,所有其他帧都将混洗。(不要将宽度设置为零,否则从宽度定位的任何内容也将隐藏。)

作为奖励,重新排序帧,相对于公共父帧锚定所有帧(反之亦然),并手动计算x偏移:

Frame1:SetPoint("LEFT", UIParent, "LEFT", 0, 0)
Frame2:SetPoint("LEFT", UIParent, "LEFT", 300, 0)
Frame3:SetPoint("LEFT", UIParent, "LEFT", 900, 0)  -- will be right of Frame4
Frame4:SetPoint("LEFT", UIParent, "LEFT", 600, 0)
第二部分:GetChildren()返回值 GetChildren()返回多个值,每个值都是表示单个子项(即帧)的表。如果有四个孩子,你可以这样做:

local child1, child2, child3, child4 = Frame:GetChildren()

如果你事先不知道有多少个孩子,考虑把所有的值打包到一个表中,这样你就可以迭代一遍< /P>

local children = { Frame:GetChildren() }

for __, child in ipairs(children) do
   --do something to each child
end
由于您的目标是将每个帧实际锚定到前一帧,除了将第一帧锚定到其他位置之外,因此您需要使用不同类型的循环:

local children = { Frame:GetChildren() }

-- anchor the first frame if it exists
if (children[1]) then
    children[1]:SetPoint("CENTER", UIParent)
end

-- anchor any remaining frames
for i=2, #children do
    children[i]:SetPoint("LEFT", children[i-1], "RIGHT")
end
“the#operator不计算表”是的,它不计算表(Frame:GetChildren())-->Table1,Table2,…,TableN print(#Frame:GetChildren())-->0我很可能只是因为缺乏Lua经验而做错了什么,但我不确定它是什么。
Frame:GetChildren()
确实返回了表还是字符串?如果它是一个表,
print()
ing它将显示类似于
table:0x12345678
,除非它有
\uu tostring
元方法。请尝试
print(类型(Frame:GetChildren())
以查找其实际类型;)
local children = { Frame:GetChildren() }

-- anchor the first frame if it exists
if (children[1]) then
    children[1]:SetPoint("CENTER", UIParent)
end

-- anchor any remaining frames
for i=2, #children do
    children[i]:SetPoint("LEFT", children[i-1], "RIGHT")
end