View Single Post
04/14/14, 05:19 AM   #7
Nogaruk
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 15
I'll try to give a short example. Since storm gave you one with xml, I'll give you one with just lua.

Code:
--	Variable to hold the window manager object
local wm = GetWindowManager()

function addonName:CreateWindowFrames()

	-- Lets create our TOPLEVELWINDOW first
	--		@param - CreateTopLevelWindow just takes a string for the name
	local mainWindow = wm:CreateTopLevelWindow("addonName_mainWindow")

        --	Give it a size
	mainWindow:SetDimensions(100,100)
	
        --	Give it constraints so it can't be bigger than what you tell it
	--		@param iirc it's (minimum width, minimum height, max width, max height)
	mainWindow:SetDimensionConstraints(-1,-1,200,200)
	
        mainWindow:SetMovable(true) -- This plus MouseEnabled let you move the window around
	mainWindow:SetMouseEnabled(true)
	mainWindow:SetClampedToScreen(true) -- Lets make sure the window can't go out of the screen
	mainWindow:SetDrawLayer(0) -- This helps ensure that the window stays behind any children frames
	
        --	Lets get rid of any anchors it might already have
	mainWindow:ClearAnchors()

	--	Now set the anchor to where we want it
	--		@param alignSelf - this is the point on the window itself that you want to align from
	--			anchorParent - the control you want this to be parented to
	--			alignTarget - this is the point on the parent you want to align this window from
	--			offsetX,offsetY - how far you want this window to be away from it's parent in 
        --                     the X and Y directions

	--		- By setting the offsets to 25,100 and the aligns to TOPLEFT the window will have its' 
        --                TOPLEFT corner as the point that attaches to the parents' TOPLEFT corner and then 
        --                it will be moved 25 units to the right and 100 units down.

	local alignSelf = TOPLEFT, anchorParent = GuiRoot, alignTarget = TOPLEFT, offsetX = 25, offsetY = 100
	mainWindow:SetAnchor(alignSelf, anchorParent, alignTarget, offsetX, offsetY)

	mainWindow:SetHandler("OnReceiveDrag",function(self) self:StartMoveing() end)
	mainWindow:SetHandler("OnMouseUp",function(self) self:StopMovingOrResizing() end)
	
	--	Lets make sure there's something to see with this window
	--		@param it takes a string for the name, control to parent to, and a string for the template to base it off
	mainWindow.bd = wm:CreateControlFromVirtual("addonName_mainWindow_bd",mainWindow,"ZO_DefaultBackdrop")
	mainWindow.bd:SetAnchorFill(mainWindow)
	
	--	Now lets create some labels
	local labelOne = wm:CreateControl("addonName_label1",mainWindow,CT_LABEL)
	labelOne:SetText("LEFT")
	labelOne:ClearAnchors()
	labelOne:SetAnchor(TOPLEFT,mainWindow,TOPLEFT,0,0)
	
	local labelTwo = wm:CreateControl("addonName_label2",mainWindow,CT_LABEL)
	labelOne:SetText("CENTER")
	labelOne:ClearAnchors()
	labelOne:SetAnchor(TOPLEFT,labelOne,TOPRIGHT,0,0)

	local labelThree = wm:CreateControl("addonName_label3",mainWindow,CT_LABEL)
	labelOne:SetText("RIGHT")
	labelOne:ClearAnchors()
	labelOne:SetAnchor(TOPLEFT,labelTwo,TOPRIGHT,0,0)
end
It's a very simple example of chaining controls or windows next to eachother. If you wanted to have them chain vertically you would just change their self align to TOP and the target aligns to BOTTOM. Keep in mind though that the first control being parented to the "main window" or "main control" would have its target align be TOP as well, otherwise the labels (or other controls) would start at the bottom of the main window outside of its background.

There are chain functions examples on here for creating things or you could make your own functions to simplify, lower code reuse, or even automate the window creations.

Ok I'm going to bed. I'll double check this tomorrow to see if it was useful for ya and in case I typed something wrong. Can't think...clowns will eat me...night.

Last edited by Nogaruk : 04/14/14 at 05:45 PM.
  Reply With Quote