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

UI.condition_display.labelConstructor

зависимость

Как вызывать

UI.condition_display.labelConstructor(interactive)

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

Что делает

Constructs a new condition text widget: a plain wrapping RM-ConditionLabel, or with interactive set an RM-ConditionLink button that adds a leading image and OnEnter, OnLeave and OnClick callbacks. Both measure their wrapped text height and ask the parent to lay out again when it changes.

Аргументы

ИмяТипЧто делает
interactiveboolean | nilTrue to build the interactive link variant with an image; false or nil builds a plain label.

Возвращает

1RMConditionWidgetThe new label or link widget, registered but not yet acquired.

Издания

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

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

Как его вызывает аддон

Зависимости

Исходный код

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

UI.condition_display.labelConstructor(interactive)
    local w={type=interactive and 'RM-ConditionLink' or 'RM-ConditionLabel',text=''}
    local frame=CreateFrame(interactive and 'Button' or 'Frame',nil,UIParent);w.frame=frame
    local image=interactive and frame:CreateTexture(nil,'ARTWORK');w.image=image
    local label=frame:CreateFontString(nil,'OVERLAY','GameFontHighlightSmall');w.label=label
    label:SetPoint('TOPLEFT');label:SetWordWrap(true);label:SetHeight(0)
    local function layoutText()
        local inset=image and w.imagePath and (w.imageWidth+4) or 0
        label:SetWidth(math.max(1,frame:GetWidth()-inset))
        local textHeight=math.max(1,label:GetStringHeight() or 0)
        local height=math.max(textHeight,image and w.imagePath and w.imageHeight or 0)
        label:ClearAllPoints();label:SetPoint('TOPLEFT',frame,'TOPLEFT',inset,-(height-textHeight)/2)
        if image then image:ClearAllPoints();image:SetPoint('TOPLEFT',frame,'TOPLEFT',0,-(height-w.imageHeight)/2) end
        -- Backing frame dimensions may be quantized. Compare text requests,
        -- not engine rounding, before notifying the parent layout.
        local changed=height~=w.measuredHeight
        w.measuredHeight=height;w:SetHeight(height)
        return changed
    end
    local function measure()
        if w.measuring then return end
        w.measuring=true
        local ok,changed=pcall(layoutText)
        w.measuring=false
        if not ok then error(changed,0) end
        if changed and w.parent and w.parent.DoLayout then w.parent:DoLayout() end
    end
    function w:OnWidthSet() measure() end
    function w:SetText(text) self.text=text==nil and '' or tostring(text);label:SetText(self.text);measure() end
    function w:SetFont(path,height,flags) label:SetFont(path,height,flags);measure() end
    function w:SetFontObject(font) label:SetFontObject(font or defaultFont());measure() end
    function w:SetColor(red,green,blue,alpha)
        if red==nil or green==nil or blue==nil then red,green,blue=1,1,1 end
        label:SetTextColor(red,green,blue,alpha or 1)
    end
    function w:SetJustifyH(value) label:SetJustifyH(value) end
    function w:SetJustifyV(value) label:SetJustifyV(value) end
    if interactive then
        function w:SetImage(path,...)
            self.imagePath=path;image:SetTexture(path)
            local count=select('#',...);if count==4 or count==8 then image:SetTexCoord(...) else image:SetTexCoord(0,1,0,1) end
            if path then image:Show() else image:Hide() end;measure()
        end
        function w:SetImageSize(width,height) self.imageWidth,self.imageHeight=width,height;image:SetSize(width,height);measure() end
        function w:SetDisabled(value) self.disabled=value==true;if self.disabled then frame:Disable() else frame:Enable() end end
    end
    function w:OnAcquire()
        self.measuring=false;self.measuredHeight=nil
        if interactive then self.imagePath=nil;self.imageWidth,self.imageHeight=24,24;image:SetTexture(nil);image:SetSize(24,24);image:Hide();self:SetDisabled(false) end
        self:SetText('');self:SetFontObject();self:SetColor();self:SetJustifyH('LEFT');self:SetJustifyV('TOP');self:SetWidth(200)
        if interactive then
            frame:RegisterForClicks('LeftButtonUp','RightButtonUp');local lease=self.rmLease
            local function live() return w.rmActive and w.rmLease==lease and not w:IsReleasing() end
            addon:SetUIScript(frame,'OnEnter',function() if live() then w:Fire('OnEnter') end end)
            addon:SetUIScript(frame,'OnLeave',function() if live() then w:Fire('OnLeave') end end)
            addon:SetUIScript(frame,'OnClick',function(_,button) if live() and not w.disabled then w:Fire('OnClick',button) end end)
        end
    end
    function w:OnRelease()
        self.text='';self.measuring=false;self.measuredHeight=nil;label:SetText('')
        if image then image:Hide();image:SetTexture(nil);self.imagePath=nil;if GameTooltip and GameTooltip:IsOwned(frame) then GameTooltip:Hide() end end
    end
    return addon:RegisterConditionWidget(w)

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