Skip to content
João Cardoso edited this page Dec 16, 2019 · 6 revisions

In a sense, Poncho-2.0 is implemented as a class itself, from which all others can derive from. Therefore, Poncho provides multiple methods by default to generated classes. These methods can be defined into three categories:

  • Static, which should only be called by class objects.
  • Instance, which should only be called by frame objects.
  • Flexible, which can be called by both.

Classes can then be implemented by adding new methods or overwriting existing ones. In fact, some functionality is purposely divided into smaller methods, to allow for easier overwriting of default behavior.

Static Methods

class:NewClass([frameType] [,name] [,template])

Creates a new class that inherits class, with the given frameType and xml template. If name is a string, constructed frames will be given global names with increasing IDs. The class will be abstract if no frameType is provided.

class:New([parent])

Retrieves an inactive frame or constructs a new one based on this class.

class:Construct()

Generates a new frame based on this class. Called by class:New.

class:Bind(frame)

Gives any existing frame the proprieties of belonging to class. Called by class:Construct.

class:IsAbstract()

Returns whether the class is abstract (incapable of constructing frames, only defined for inheritance).

Instance Methods

frame:GetClass()

Returns the class object for this frame.

frame:Release()

As frames cannot be deallocated in World of Warcraft, this resets the frame state and assigns it to the inactive frame pool. Do not make further calls to a frame after releasing it.

frame:Reset()

Resets the frame state. Called by frame:Release.

frame:IsActive()

Returns whether the frame is currently in use or in the inactive pool.

frame:Super(class)

Utility metamagic method for making object oriented clean code while extending inherited functionality. For example, consider this extension of the :Reset method:

local class = LibStub('Poncho-2.0'):NewClass()

function class:Reset()
 class:GetSuper().Reset(self) -- calls the inherited method
 self:SetSize(200, 200) -- resets size
end

This code is equivalent to:

local class = LibStub('Poncho-2.0'):NewClass()

function class:Reset()
 self:Super(class):Reset() -- calls the inherited method
 self:SetSize(200, 200) -- resets size
end

Flexible Methods

any:GetClassName()

Returns the class name of the given class or frame object.

any:GetTemplate()

Returns the xml template of the given class or frame object.

any:GetFrameType()

Returns the frame type of the given class or frame object.

any:GetSuper()

Returns the class that the given class or frame object was inherited from. For example:

frame:GetClass():GetSuper() == frame:GetSuper() -- always returns true

any:NumFrames()

Returns the total number of constructed frames for the given class, or for the class that frame belongs to.

any:NumInactive()

Returns the number of frames in the inactive pool for the given class, or for the class that frame belongs to.

any:NumActive()

Returns the number of currently active frames for the given class, or for the class that frame belongs to.