參考資料 › 函式參考 › UI

UI.checkbox.constructor

相依項目

呼叫方式

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.

參數

無。

傳回值

1RMConditionWidgetThe new check box widget, registered with the condition widget system.

版本

內建輔助函式在每個版本上都會註冊。不同的是它們讀取的遊戲 API;某個 API 不存在時,輔助函式會改用備用方式,或傳回 nil 並附上原因。

  • 該版本無法使用(原因請見提示)
  • 僅在暴雪的棄用相容層開啟時
遊戲 API經典時代TBC 週年版經典進程永久正式版
CreateFrame經典時代TBC 週年版經典進程永久正式版
UIParent經典時代TBC 週年版經典進程永久正式版

範例

-- 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)

返回函式參考