Справочник › Справочник функций › UI

UI.condition_display.buttonConstructor

зависимость

Как вызывать

UI.condition_display.buttonConstructor()

Запишите зависимость UI.condition_display.buttonConstructor и вызывайте её по этому имени. Вызов через пространство имён не передаёт self: используйте вызов через двоеточие или передайте объект сами.

Что делает

Constructs a new RM-ConditionButton widget around a 200-pixel workbench button, with SetText, SetAutoWidth and SetDisabled, firing OnClick (with the mouse button), OnEnter and OnLeave only while its lease is live. It returns the registered but not yet acquired widget; addon:CreateConditionButton passes it to addon:AcquireConditionWidget.

Аргументы

Нет.

Возвращает

1RMConditionWidgetThe new button widget, registered with the condition widget system.

Издания

Встроенные помощники регистрируются во всех изданиях. Различается игровой API, который они читают; если нужного API нет, помощник использует запасной вариант или возвращает nil с причиной.

  • Недоступно в этом издании (причина — во всплывающей подсказке)
  • Только пока включены запасные реализации Blizzard для устаревших функций
Игровой APIClassic EraTBC AnniversaryClassic ProgressionForeverRetail
GameTooltipClassic EraTBC AnniversaryClassic ProgressionForeverRetail
UIParentClassic EraTBC AnniversaryClassic ProgressionForeverRetail

Пример

-- needs the dependency UI.condition_display.buttonConstructor
local button = addon:AcquireConditionWidget("RM-ConditionButton", UI.condition_display.buttonConstructor)
button:SetText(L["Clear"])
button:SetAutoWidth(true)
button:SetCallback("OnClick", function() value.spell = nil end)
parent:AddChild(button)

Зависимости

Исходный код

UI/condition_display.lua, строка 110. В игре только для чтения; «Дублировать» создаёт редактируемую копию.

UI.condition_display.buttonConstructor()
    local w={type='RM-ConditionButton',text='',disabled=false,autoWidth=false}
    local frame=addon:CreateWorkbenchButton(UIParent,'',200);w.frame=frame
    local label=frame:GetFontString();w.label=label;label:SetWordWrap(false)
    local enter,leave=frame:GetScript('OnEnter'),frame:GetScript('OnLeave')
    function w:OnWidthSet(width) label:SetWidth(math.max(1,width-12)) end
    function w:SetText(text)
        self.text=text==nil and '' or tostring(text);frame:SetText(self.text);label:SetText(self.text)
        if self.autoWidth then self:SetWidth(label:GetStringWidth()+30) end
    end
    function w:SetAutoWidth(value)
        self.autoWidth=value==true
        if self.autoWidth then self:SetWidth(label:GetStringWidth()+30) end
    end
    function w:SetDisabled(value) self.disabled=value==true;if self.disabled then frame:Disable() else frame:Enable() end end
    function w:OnAcquire()
        self:SetAutoWidth(false);self:SetWidth(200);self:SetHeight(24);self:SetDisabled(false);self:SetText('')
        label:SetFontObject(defaultFont());frame:SetSelected(false);frame.tooltip=nil;frame:RegisterForClicks('LeftButtonUp')
        local lease=self.rmLease
        local function live() return w.rmActive and w.rmLease==lease and not w:IsReleasing() end
        addon:SetUIScript(frame,'OnClick',function(_,button) if live() and not w.disabled then w:Fire('OnClick',button) end end)
        addon:SetUIScript(frame,'OnEnter',function() if live() then if enter then enter(frame) end;w:Fire('OnEnter') end end)
        addon:SetUIScript(frame,'OnLeave',function() if live() then if leave then leave(frame) end;w:Fire('OnLeave') end end)
    end
    function w:OnRelease()
        if GameTooltip and GameTooltip:IsOwned(frame) then GameTooltip:Hide() end
        self.text='';frame:SetText('');label:SetText('');frame.tooltip=nil
    end
    return addon:RegisterConditionWidget(w)

Назад: Справочник функций