Thread Tools Display Modes
Prev Previous Post   Next Post Next
Unread 06-09-11, 03:16 AM   #1
alkazar
Zombie
Join Date: Jun 2011
Posts: 3
snippets/plugin

Hi,

Let's post here any snippet/improvements you've done so far

here is my UI.CreateButton function

Code:
-- UI.CreateButton by Alkazar@grimnir
function UI.CreateButton(parent, name, text, handler)
	-- create a host frame for our button
	local buttonFrame = UI.CreateFrame("Frame", name, parent)
	
	-- set default background color
	buttonFrame.BgColorR = 0
	buttonFrame.BgColorG = 0
	buttonFrame.BgColorB = 0
	buttonFrame.BgColorA = 1
	buttonFrame:SetBackgroundColor(0, 0, 0, 1)
	-- set focus background color
	buttonFrame.focusBgColorR = 0.2
	buttonFrame.focusBgColorG = 0.2
	buttonFrame.focusBgColorB = 0.2
	buttonFrame.focusBgColorA = 1
	
	-- label the button
	buttonFrame.text = UI.CreateFrame("Text", name.."Text", buttonFrame)
	buttonFrame.text:SetText(text)
	
	-- fit the stuff
	buttonFrame.text:SetHeight(buttonFrame.text:GetFullHeight())
	buttonFrame.text:SetWidth(buttonFrame.text:GetFullWidth())
	buttonFrame:SetHeight(buttonFrame.text:GetFullHeight())
	buttonFrame:SetWidth(buttonFrame.text:GetFullWidth())
    buttonFrame.text:SetPoint("CENTER", buttonFrame, "CENTER")
	
	-- set the handler
	buttonFrame.handler = handler
	
	function buttonFrame.Event:LeftDown()
		self:SetBackgroundColor(self.focusBgColorR, self.focusBgColorG, self.focusBgColorB, self.focusBgColorA)
	end
	
	function buttonFrame.Event:LeftUp()
		self:SetBackgroundColor(self.BgColorR, self.BgColorG, self.BgColorB, self.BgColorA)
		self:handler()
	end
	
	return buttonFrame
end
I guess it's self documented
You may be able to access members after the default setup

Please notice that our button will fire handler when left click is released, and only change the background when left click is pressed. Right now, even if the mouse get away, releasing the click will still trigger (which is not a bad thing from the API). But I couldn't figure out a way to check wether we're still focusing. Gonna update as soon as the API permits it.

You're free to use it anywhere you want, until you keep the heading commentary. No credit in readme (or whatever alike) needed. If you modify, you may put a heading line telling that this is not the original code.
alkazar is offline   Reply With Quote
 

Go BackRiftui » Developer Discussions » Tutorials & Other Helpful Info. » snippets/plugin


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off