View Single Post
05-22-11, 02:41 PM   #1
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
Enabling and disabling oUF elements

I need some help to understand how this actually works or what exactly is self:DisableElement supposed to do and where and how should we use it.

Say I have a custom DebuffHighlight element. Do I have a way to disable other DebuffHighlight elements provided I know theirs names?

I'll just start with what I think I know so far (I'll take the default oUF threat element as example):

An element registers itself with oUF through oUF:AddElement("name", update_func, enable_func, disable_func)

An element enables itself when its prerequisites are met (i.e. self.Threat is not nil)

oUF:AddElement creates an entry in a table called elements for every registered element that looks like this:
Code:
["element name"] = {
	update = update function of the element
	enable = enable function of the element
	disable = disable function of the element
}
We have another table self.__elements which contains the update functions of the enabled elements for the current unit frame(self). This gets populated by initObject() by calling self:EnableElement with every element name from the elements table.

Well when I run
Code:
print(self:IsElementEnabled("Health"))
from within my layout (at the end of the style function as I think that is the point where all element are enabled and applied), I expect it to return true and the index in the table where the update function is found. It returns nothing.

When I run
Code:
print(#self.__elements)
I expect it to return the number of update function, thus the number of used elements for the current frame. When ran from the layout this always returns 1.

I thought then that I should run this from an element itself. print(#self.__elements) then returns another number so I suppose that's the way to go, but how do I know in what order the element are loaded. By the numbers it returns a can tell that not all elements used in the layout are loaded before my print call.

I kinda lost myself, hope someone could shed some light on it for me :)

Last edited by Rainrider : 05-22-11 at 02:42 PM. Reason: Damn smilies
  Reply With Quote