Référence › Référence des fonctions › UI

UI.selector.selectorWidget

dépendance

Appel

UI.selector.selectorWidget()

Enregistrez la dépendance UI.selector.selectorWidget, puis appelez-la sous ce nom. Un appel par espace de noms ne transmet pas self : utilisez un appel avec deux-points ou passez l'objet vous-même.

Ce qu'elle fait

Constructs a new RM-Selector dropdown widget: an optional caption over a button that opens the workbench selector popup. SetList takes a map of keys to text (or {text, icon}) and an optional order, sorting by text otherwise; choosing a different entry fires OnValueChanged. It returns the registered but not yet acquired widget; addon:CreateConditionDropdown acquires it.

Arguments

Aucun.

Retours

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

Éditions

Les fonctions utilitaires intégrées sont enregistrées sur toutes les éditions. Ce qui diffère, c'est l'API du jeu qu'elles lisent ; quand l'une manque, la fonction utilitaire se rabat sur une alternative ou renvoie nil avec une raison.

  • Indisponible sur cette édition (la raison figure dans l'infobulle)
  • Uniquement tant que les solutions de repli de Blizzard pour les fonctions obsolètes sont actives
API du jeuClassic EraTBC AnniversaryClassic ProgressionForeverRetail
CreateFrameClassic EraTBC AnniversaryClassic ProgressionForeverRetail
GameFontHighlightSmallClassic EraTBC AnniversaryClassic ProgressionForeverRetail
UIParentClassic EraTBC AnniversaryClassic ProgressionForeverRetail

Exemple

-- needs the dependency UI.selector.selectorWidget
local picker = addon:AcquireConditionWidget("RM-Selector", UI.selector.selectorWidget)
picker:SetLabel(L["Unit"])
picker:SetList({ player = L["Player"], target = L["Target"] }, { "player", "target" })
picker:SetValue(value.unit)
picker:SetCallback("OnValueChanged", function(_, _, unit) value.unit = unit end)
parent:AddChild(picker)

Source

UI/selector.lua, ligne 523. En lecture seule dans le jeu ; Dupliquer crée une copie modifiable.

UI.selector.selectorWidget()
    local w={type='RM-Selector',list={},order={},disabled=false}
    local frame=CreateFrame('Frame',nil,UIParent);w.frame=frame;frame:SetSize(220,44)
    local caption=frame:CreateFontString(nil,'OVERLAY','GameFontHighlightSmall');w.caption=caption;caption:SetPoint('TOPLEFT',0,0);caption:SetPoint('TOPRIGHT',0,0);caption:SetHeight(18);caption:SetJustifyH('LEFT')
    local button=addon:CreateWorkbenchLabeledIconButton(frame,'chevron-down','',220);w.button=button;button:SetPoint('TOPLEFT',0,-20);button:SetPoint('TOPRIGHT',0,-20)
    local popup=addon:CreateWorkbenchSelector();w.selector=popup
    function w:OnAcquire() self.alive=true;self.list={};self.order={};self:SetDisabled(false);self:SetLabel('');self:SetValue(nil);self:SetWidth(220);self:SetHeight(44) end
    function w:OnRelease() self.alive=false;popup:Release();self.list={};self.order={};self.value=nil end
    function w:SetLabel(text) caption:SetText(text or '');local has=text and text~='';if has then caption:Show() else caption:Hide() end;button:ClearAllPoints();button:SetPoint('TOPLEFT',0,has and -20 or 0);button:SetPoint('TOPRIGHT',0,has and -20 or 0);self:SetHeight(has and 44 or 24) end
    function w:SetText(text) button:SetText(text or L['Select']);addon:AlignWorkbenchTextLeft(button,26) end
    function w:SetValue(value) self.value=value;local entry=self.list[value];if type(entry)=='table' then addon:PaintSelectorSelection(button,entry,entry.text) else self:SetText(entry);if button.valueIcon then button.valueIcon:Hide() end end end
    function w:GetValue() return self.value end
    function w:SetList(values,order)
        self.list=values or {};self.order={};if order then for _,id in ipairs(order) do self.order[#self.order+1]=id end else for id in pairs(self.list) do self.order[#self.order+1]=id end;table.sort(self.order,function(a,b) return tostring(type(self.list[a])=='table' and self.list[a].text or self.list[a])<tostring(type(self.list[b])=='table' and self.list[b].text or self.list[b]) end) end;self:SetValue(self.value)
    end
    function w:SetDisabled(value) self.disabled=value==true;if self.disabled then button:Disable();popup:Hide() else button:Enable() end end
    function w:ClearFocus() popup:Hide() end
    addon:SetUIScript(button,'OnClick',function()
        if not w.alive or w.disabled then return end
        if popup.frame:IsShown() then popup:Hide();return end
        local entries={};for _,id in ipairs(w.order) do local item=w.list[id];local record=type(item)=='table' and item or nil;entries[#entries+1]={value=id,text=record and record.text or item,icon=record and record.icon or nil,disabled=record and record.disabled or nil,header=record and record.header or nil} end
        local lifetime=w.userdata
        popup:Open(button,entries,w.value,function(value) if value~=w.value then w:SetValue(value);w:Fire('OnValueChanged',value) end end,function() return w.alive and w.userdata==lifetime and not w.disabled end)
    end)
    addon:SetUIScript(frame,'OnHide',function() popup:Hide() end)
    ---@cast w RMConditionWidget
    return addon:RegisterConditionWidget(w)

Retour à Référence des fonctions