调用方式
UI.checkbox.constructor()
记录依赖项 UI.checkbox.constructor,然后按该名称调用。带命名空间的调用不会传入 self:请使用冒号调用,或自行传入该对象。
作用
Constructs a new RM-CheckBox condition widget: a 180 by 24 frame holding a workbench check box, with SetLabel, SetValue, GetValue and SetDisabled, firing OnValueChanged when clicked. It returns the registered but not yet acquired widget; addon:CreateConditionCheckBox passes it to addon:AcquireConditionWidget, which reuses pooled instances.
参数
无。
返回值
| 1 | RMConditionWidget | The new check box widget, registered with the condition widget system. |
|---|
版本
内置辅助函数在每个版本上都会注册。不同的是它们读取的游戏 API;某个 API 缺失时,辅助函数会改用后备方案,或返回 nil 并附上原因。
- 该版本不可用(原因见提示)
- 仅在暴雪的弃用兼容层开启时
| 游戏 API | |||||
|---|---|---|---|---|---|
CreateFrame | |||||
UIParent |
示例
-- needs the dependency UI.checkbox.constructor
local box = addon:AcquireConditionWidget("RM-CheckBox", UI.checkbox.constructor)
box:SetLabel(L["Only in combat"])
box:SetValue(value.combat == true)
box:SetCallback("OnValueChanged", function(_, _, checked) value.combat = checked end)
parent:AddChild(box)源码
UI/checkbox.lua,第 24 行。在游戏中为只读;“复制”会生成一份可编辑的副本。
UI.checkbox.constructor()
local w={type='RM-CheckBox',alive=false,disabled=false}
local frame=CreateFrame('Frame',nil,UIParent);w.frame=frame;frame:SetSize(180,24)
local button=addon:CreateWorkbenchCheckBox(frame,'',180);w.button=button;button:SetAllPoints(frame)
function w:OnAcquire() self.alive=true;button.tooltip=nil;self:SetLabel('');self:SetValue(false);self:SetDisabled(false);self:SetWidth(180);self:SetHeight(24) end
function w:OnRelease() self.alive=false;self:SetValue(false) end
function w:SetLabel(text) button:SetText(text or '') end
function w:SetValue(value) button:SetChecked(value==true) end
function w:GetValue() return button:GetChecked() end
function w:SetDisabled(value) self.disabled=value==true;if self.disabled then button:Disable();button:SetAlpha(.45) else button:Enable();button:SetAlpha(1) end end
function w:OnWidthSet(width) button:GetFontString():SetWidth(math.max(1,width-22)) end
addon:SetUIScript(button,'OnClick',function()
if not w.alive or w.disabled then return end
w:SetValue(not w:GetValue());w:Fire('OnValueChanged',w:GetValue())
end)
---@cast w RMConditionWidget
return addon:RegisterConditionWidget(w)




