Thread Tools Display Modes
01-23-12, 05:20 PM   #1
killerpet1986
A Fallenroot Satyr
 
killerpet1986's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 22
UIDropDownMenu_AddButton font

Hi I was wondering if anyone knew how to set the font with UIDropDownMenu_AddButton similar to this:



Here is what I have so far:

Code:
table.foreach(Notepad.Lib.SharedMedia.MediaList.font, function(ID, text) 
	local info = UIDropDownMenu_CreateInfo();
	info.hasArrow = false;	-- no arrow (for sub menus)
	info.notCheckable = true;	-- not checkable (dot)
	info.keepShownOnClick = false;	-- keep showing the menu when this is clicked
	info.text = text;		-- set the text (name of the file)	
	info.func       = function(self)	--function called on click			
		local FontName = self:GetText()	-- get the text
		local FontPath = Notepad.Lib.SharedMedia:Fetch("font", FontName);				
		local font, size = Notepad.Name_TitleFrame:GetFont();
		
		Notepad.Name_TitleFrame:SetFont(FontPath, size)
	end; 
	UIDropDownMenu_AddButton(info, level);	-- add that button to the menu
end)

Last edited by killerpet1986 : 01-23-12 at 05:23 PM.
  Reply With Quote
01-23-12, 05:34 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Your screenshot is showing a dropdown created by AceGUI-3.0 by way of AceConfig-3.0 by way of an AceOptions table; it isn't using any part of the regular UIDropDownMenu.

If you'd rather use the UIDropDownMenu, you can look at my addon ShieldsUp for an example of how to build a scrolling dropdown menu that's based on the UIDropDownMenu API, along with a few custom elements. Most of this code is factored out into a pair of portable libraries (PhanxConfig-Dropdown and PhanxConfig-ScrollingDropdown), and then you can see in ShieldsUp how I use the libraries to create a dropdown and change the font of the buttons on the font selection dropdown (and also add a background texture for the statusbar selector). Feel free to use the libraries in your own addon, and reuse any code.

It's probably best to not try to change the fonts of buttons in the default UIDropDownMenu, unless you are extremely careful about resetting them, as the buttons are reused whenever any addon or the default UI shows a UIDropDownMenu, and your changes will affect everyone else.
  Reply With Quote
01-23-12, 05:38 PM   #3
killerpet1986
A Fallenroot Satyr
 
killerpet1986's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 22
Thanks for that

I was thinking it was an Ace thing. I had a look at http://wowprogramming.com/utils/xmlb...opDownMenu.lua and couldn't find anything unless I use a fontObject.

I think I will just leave it as the default font.
  Reply With Quote
01-23-12, 05:38 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Note: in addition to using AceConfig/AceGUI, that menu is also using AceGUI-3.0-SharedMediaWidgets to get the previews.
__________________
"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
01-23-12, 05:50 PM   #5
killerpet1986
A Fallenroot Satyr
 
killerpet1986's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 22
Looking at phanx's code it does seem a lot better than UIDropDownMenu. I might *cough* borrow *cough* some code
  Reply With Quote
01-23-12, 06:46 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I tried to add some helpful API functions, as well as reduce the amount of global namespace clutter, compared to the Blizzard templates/functions, while still keeping the look and feel of the Blizzard widgets, and being able to use normal frame-related functions like SetPoint, SetWidth, etc.

If you do use the libraries though, keep in mind that I don't make any effort to keep new versions backwards compatible, so you may want to rename them unless you want to have to always update your addon immediately every time I update one of mine that includes a newer version of the library.

The SVN repo is here if you want to browse:
svn://svn.wowinterface.com/PhanxConfigWidgets-486
  Reply With Quote
01-24-12, 05:59 AM   #7
Animor
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Mar 2011
Posts: 136
I'm a beginner programmer, but I just did something like that in my addon "hebChat". I wasn't aware of Ace3 or other libs, so I did it as a standalone code. In my addon I divided the code into XML and LUA.
This is how it looks like:


XML:
Code:
<Frame name="$parent_dropDownList" parentKey="dropDownList" inherits="UIDropDownMenuTemplate">
	<Anchors>
		<Anchor point="LEFT" relativePoint="RIGHT" relativeTo="$parent_dropDownFont">
			<Offset x="-3" y="-3"/>
		</Anchor>
	</Anchors>
	<Size x="250"/>				
	<Scripts>
		<OnLoad>
			hebChatDropDownList_OnLoad(self)
			UIDropDownMenu_SetWidth(self, 150)
			UIDropDownMenu_SetButtonWidth(self, 174)						
			UIDropDownMenu_JustifyText(self, "CENTER")
		</OnLoad>				
	</Scripts>
</Frame>
LUA:
Code:
-- Fonts table
hebChat.fonts = {
	["Default Font"] 		= {"No Hebrew", "Fonts\\ARIALN.TTF"},
	["Arial"] 				= {"תירבע", "Interface\\AddOns\\hebChat\\Fonts\\arial.ttf"},
	["Tahoma"] 				= {"תירבע", "Interface\\AddOns\\hebChat\\Fonts\\tahoma.ttf"},
	["Times New Roman"] 	= {"תירבע", "Interface\\AddOns\\hebChat\\Fonts\\times.ttf"},
	["Sans Serif"] 			= {"תירבע", "Interface\\AddOns\\hebChat\\Fonts\\micross.ttf"},
	["Miriam"] 				= {"תירבע", "Interface\\AddOns\\hebChat\\Fonts\\mriam.ttf"},
	["Courier"]				= {"תירבע", "Interface\\AddOns\\hebChat\\Fonts\\courbd.ttf"},
	["David"]				= {"תירבע", "Interface\\AddOns\\hebChat\\Fonts\\david.ttf"},
	["David Bold"]			= {"תירבע", "Interface\\AddOns\\hebChat\\Fonts\\davidbd.ttf"},
	["FrankRuehl"]			= {"תירבע", "Interface\\AddOns\\hebChat\\Fonts\\frank.ttf"},
	["Levenim"]				= {"תירבע", "Interface\\AddOns\\hebChat\\Fonts\\lvnm.ttf"},
	["Narkisim"]			= {"תירבע", "Interface\\AddOns\\hebChat\\Fonts\\nrkis.ttf"},
	["Gisha"]				= {"תירבע", "Interface\\AddOns\\hebChat\\Fonts\\gisha.ttf"},	
}

-- Font Objects table
hebChat.fObjects = {}

-- Create font objects
function hebChat:createFontObjects()
	local fObject = nil
	for k, v in pairs(self.fonts) do
		fObject  = CreateFont(k)
		fObject:SetFont(v[2], 13)
		self.fObjects[k] = fObject
	end
end

-- Selecting a font from dropdown list
local function hebChatDropDownList_OnClick(self, arg1)

	if (hebChatDB.globalEn) then
		hebChatDB.hebFont		= arg1
		hebChatDB.currentFont	= arg1
	else
		hebChatDB.defaultFont	= arg1
		hebChatDB.currentFont	= arg1	
	end
		
	hebChat:setChatFont()	
	UIDropDownMenu_SetText(hebChatConfigPanel.dropDownList, hebChatDB.currentFont)
end

-- Initialize fonts dropdown list
local function hebChatInitializeDropDown(self, level)	
	local info = UIDropDownMenu_CreateInfo()	
	for k, v in pairs(hebChat.fonts) do
		wipe (info)
		info.text = k.."   "..v[1]
		--info.keepShownOnClick = true
		--info.isNotRadio = true
		info.arg1 = k
		info.func = hebChatDropDownList_OnClick
		info.checked = hebChatIsCurrentFont(k)
		info.fontObject = hebChat.fObjects[k]		
		UIDropDownMenu_AddButton(info)
	end
end

function hebChatDropDownList_OnLoad(self)
	UIDropDownMenu_Initialize(self, hebChatInitializeDropDown)
end
  Reply With Quote
01-24-12, 12:07 PM   #8
killerpet1986
A Fallenroot Satyr
 
killerpet1986's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 22
Thats a good way of doing it, i wasnt sure about making them into fontObjects myself. However I will have to stick with phanx's code. The thing I noticed about it is that I can register an onenter and onleave script to give a preview of the changing in font and text size
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » UIDropDownMenu_AddButton font


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