Thread Tools Display Modes
12-05-10, 07:48 PM   #1
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Simplest Button Example?

Can anyone point me to a relatively simple button preferably in Lua vs XML.

I'm attempting to change the GuildRosterFrame's drop-down menu to buttons.

I'm not too familiar with using XML and using button templates.
  Reply With Quote
12-05-10, 07:59 PM   #2
Ailae
A Rage Talon Dragon Guard
 
Ailae's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 318
Code:
local b = CreateFrame("Button", "MyButton", UIParent, "UIPanelButtonTemplate")
b:SetSize(80 ,22) -- width, height
b:SetText("Button!")
b:SetPoint("CENTER")
b:SetScript("OnClick", function()
    print("I'm in your buttonz")
end)
This gives you the most basic interface-button, like "Okay" and "Cancel" that you see in the interface options.
__________________
Oh, the simulated horror!
  Reply With Quote
12-05-10, 08:03 PM   #3
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
lua Code:
  1. local button = CreateFrame('Button', 'MyButtonName', UIParent)
  2. button:SetPoint('CENTER')
  3. button:SetSize(16, 16)
  4. button:SetScript('OnClick', function()
  5.    -- do something
  6. end)

xml Code:
  1. <Ui>
  2.    <Button name='MyButtonName' parent='UIParent'>
  3.       <Size x='16' y='16' />
  4.       <Anchors>
  5.          <Anchor point='CENTER' />
  6.       </Anchors>
  7.       <Scripts>
  8.          <OnClick>
  9.             -- do something
  10.          </OnClick>
  11.       </Scripts>
  12.    </Button>
  13. </Ui>

Last edited by p3lim : 12-05-10 at 08:05 PM.
  Reply With Quote
12-05-10, 08:18 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Note (when trying the above examples) that p3lim's code snippets DO work, they're just invisible.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
12-05-10, 08:54 PM   #5
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Originally Posted by Seerah View Post
Note (when trying the above examples) that p3lim's code snippets DO work, they're just invisible.
Lol they'd have no textures.

Anyway result:

Code:
local f = CreateFrame("frame")
f:RegisterEvent("PLAYER_LOGIN")
f:SetScript("OnEvent", function(self,event,...)
	if event == "PLAYER_LOGIN" then
		LoadAddOn("Blizzard_GuildUI")
		GuildRosterViewDropdown:Hide()
	end
	local function Update()
		GuildRoster();
		GuildRoster_Update();
		SetCVar("guildRosterView", currentGuildView);
	end
	local b1 = CreateFrame("Button", "playerStatus", GuildRosterFrame, "UIPanelButtonTemplate")
	b1:SetSize(120 ,18)
	b1:SetText("Player Status")
	b1:SetPoint("TOPRIGHT",-25,-26)
	b1:SetScript("OnClick", function()
		GuildRoster_SetView("playerStatus");
		Update()
	end)
	local b2 = CreateFrame("Button", "guildStatus", b1, "UIPanelButtonTemplate")
	b2:SetSize(120 ,18)
	b2:SetText("Guild Status")
	b2:SetPoint("TOPRIGHT", b1, "TOPLEFT")
	b2:SetScript("OnClick", function()
		GuildRoster_SetView("guildStatus");
		Update()
	end)
	local b3 = CreateFrame("Button", "achievement", b1, "UIPanelButtonTemplate")
	b3:SetSize(120 ,18)
	b3:SetText("Achievements")
	b3:SetPoint("TOPRIGHT", b1, "BOTTOMRIGHT")
	b3:SetScript("OnClick", function()
		GuildRoster_SetView("achievement");
		Update()
	end)
	local b4 = CreateFrame("Button", "tradeskill", b3, "UIPanelButtonTemplate")
	b4:SetSize(120 ,18)
	b4:SetText("Professions")
	b4:SetPoint("TOPRIGHT", b3, "TOPLEFT")
	b4:SetScript("OnClick", function()
		GuildRoster_SetView("tradeskill");
		Update()
	end)
end)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Simplest Button Example?


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