View Single Post
04/07/14, 12:55 PM   #7
Errc
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 30
Personally I use Lua for everything. It is just significantly easier to create and modify when all of the code is written in Lua. You can find a chaining function in Zgoo that makes assigning properties and setting up UI even easier, discussed here as well.

The only advantage I have seen to writing in xml is it is slightly easier to identify the hierarchy, but templates and UI creation are easier to do in Lua and provide you with more functionality.

To replace templates I usually just make a new "class" in Lua and use that.

Example toplevel frame class.
Code:
 function Frame:New(parent,name)
  local frame = CHAIN(ui:CreateControl(name,parent,CT_TOPLEVELCONTROL,Frame))
   :SetClampedToScreen(true)
  .__END

  frame.bd = ui:Create("Backdrop",frame,name and name.."_BD")

  return frame
 end

 function Frame:SetCanDrag(drag)
  if drag then
   self:SetMovable(true)
   self:SetMouseEnabled(true)
  else
   self:SetMovable(false)
   self:SetMouseEnabled(false)
  end
 end
So this class just creates a simple top level frame with a backdrop, and has a custom function for making it draggable.

To use this you just
Code:
 local newFrame = CHAIN(Frame:New(GuiRoot,"MyNewFrameName"))
  :SetAnchor(CENTER)
  :SetCanDrag(true)
 .__END
There are some implementation details to getting it set up correctly to inherit custom functions and the rest of that jazz, but that is my experience.
  Reply With Quote