View Feature Request
Tag Field for everyone
Feature #: 482
File: LibAddonMenu-2.0
Date: 07/13/14 12:52 PM
By: zgrssd
Status: Feature already added
Practically every UI Framework has somewhere deep in it's Control Inheritances a property/field called "Tag" or something similar:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.tag.aspx
It allows you to put arbitrary data to the control element:
A common use for the Tag property is to store data that is closely associated with the control. For example, if you have a control that displays information about a customer, you might store a DataSet that contains the customer's order history in that control's Tag property so the data can be accessed quickly.
If you have to dynamically create controlls you sometimes want to hand it a single value along during the creation loops. You can just hand it in via the tag. Assign all controlls the same handlers.
And then just let the handler code find out wich control it is associated too by extracting the tag from his sender.

I would love to have a tag field for LibAddonMenu items. So I can dynamically create them (during OnLoaded), give them all the same handlers and let it run dynamically based on the tag.
It would be a bonus if the tag would just be handed in with the parameter list, so I do not have to go and exract it first.
In LAM1 I can make this externally (just making a table where [controlhandle/controlID] = [tagvalue] - and then looking up wich tag is assigned to this control).
But afaik I do not get any handles back from LAM 2 functions. So I would be at a loss at how to unambigiously identify wich dynamically created control raised the handler from inside the handler.

Any chances you could make Tag tag along for LibAddonMeu?

RSS 2.0 Feed for Favorite CommentsNotes Sort Options
By: zgrssd - 07/13/14 01:56 PM
It might be best to give an example:
The game only provides naitve Color Pickers/check boxes for a handfull of the 61 Chat Categories. While about 20 are in use and expose, and another 20 are (currently) unused and another 20 are in use but omited on the default Options panel. Those could be set via code.

If I wanted to provide Color Pickers for all 61 Chat Categories the way I see it now I would need:
61 versions of the exaclty same get/set function. Except for one integer constant being different (the chat category this setter writes to/getter retrieves from).

With LAM 1 I can just store each UI Element ID as they get generated by my for-loop.
But since the creation of the elements is held off as long as possible in LAM 2, this is not possible.
If I had the Tag I could just set that integer during creation/definition of the data table. I could use the same get/set functions for all 61. And just need to extract that one constant in the setter before doing the work (if it is not already handed in as argument into the callback).
By: Seerah - 07/13/14 04:27 PM
You can store whatever you want in the tables for the controlData. It's just a table, and it gets stored on that object. For example, in slider.lua:
Lua Code:
  1. control.data = sliderData
If you're not creating your controls manually, using the LAMCreateControl methods directly, and are instead allowing LAM2 to create your options panel for you, then use the 'reference' field in your data table to assign a global reference to the control.
reference = "string" - (optional) unique global reference to this control
By: Seerah - 07/13/14 04:28 PM
/edit: everything you want (I assume) is already here.