View Single Post
12-18-13, 08:28 AM   #9
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
This is what I used in oUF_Donut just to play around with templates:
Lua Code:
  1. --get the addon namespace
  2.   local addon, ns = ...
  3.  
  4.   --object container
  5.   local tmp = CreateFrame("Frame")
  6.   ns.tmp = tmp
  7.  
  8.   ---------------------------------------------
  9.   -- variables
  10.   ---------------------------------------------
  11.  
  12.   tmp.styles = {}
  13.  
  14.   ---------------------------------------------
  15.   -- template functions
  16.   ---------------------------------------------
  17.  
  18.   --template RegisterTemplateByName
  19.   function tmp:RegisterTemplateByName(name,data)
  20.     tmp.styles[name] = data
  21.   end
  22.  
  23.   --template UnregisterTemplateByName
  24.   function tmp:UnregisterTemplateByName(name)
  25.     tmp.styles[name] = nil
  26.   end
  27.  
  28.   --template GetTemplateByName
  29.   function tmp:GetTemplateByName(name)
  30.     return tmp.styles[name]
  31.   end

If you make your templating object global any addon could use them.

Another way is adding new templating or skinning functions to specific frame meta tables. !BeautyCase does this for example. That way you add functions to the default wow api via progressive enhancement. http://code.google.com/p/rothui/sour...ore/lib.lua#84
Lua Code:
  1. local frame = FRAME_BY_GLOBALNAME or CreateFrame("Frame")
  2. local mt = getmetatable(frame).__index
  3. mt.SkinFrame = function(self,name,data)
  4.   --do stuff
  5. end
  6. frame:SkinFrame("name", {})

I'm in no way an expert on that topic but it got the job done for what I needed.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 12-18-13 at 08:37 AM.
  Reply With Quote