Thread Tools Display Modes
07/24/14, 09:10 AM   #1
zgrssd
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 280
Lua XML Basics

I am trying to get the hang of UI XML and so far I am not getting good. So I think need to start with a lot more basic stuff.

The top element of all XML files must be the "<GuiXml>" Tag
The second tier must tbe the "<Controls>" Tag under wich you can define your actuall elements.

There seem to be at least 3 Container Elements (elements with a Controls child element):
GuiXML - the root of all XML files
TopLevelControl - For Windows. Is automatically added to the UI upon execution without needing to call it.
Control - for templates in particular. It also seems to be the only "Container" you can use at any level.


Data like the Dimensions, anchoring or fill mode are not listed as Atributes of the Element. Instead they are assigned via child elements called "Anchoring" or "Dimensions". Not sure how to call those class, "Child Atributes" perhaps?
Data like Backdrops (the background to be used) must be assigned as a Child of the Controls object that is itself asigned as child of the container. So the most basic Window XML looks somewhat like this:
xml Code:
  1. <GuiXml>
  2.     <Controls>
  3.         <TopLevelControl name="testbedWindow">
  4.             <Dimensions x="400" y="400" />
  5.             <Anchor point="CENTER" />
  6.             <Controls>
  7.                 <--Other Child elements like labels would go here too-->
  8.                 <Backdrop name="$(parent)BG" inherits="ZO_DefaultBackdrop" />
  9.             </Controls>
  10.         </TopLevelControl>
  11.     </Controls>
  12. </GuiXml>

Know Atributes:
name - (optional) a Reference to this element will be stored in the Global Variables with this name. This is nessesary if you want to access it from code behind directly. The '$(parent)[suffix]' Syntax allows you to name a Child based on the name of it's parent and a suffix.
inherits - Seems to allow high level behavior changes. A Control type Container where 'inherits="ZO_ScrollContainer"' is written, behaves as a Scroll Container (if the Content is bigger then the Containers dimension, a Scroll Bar appears).
hidden - boolean value. Determines if the element is hidden by default. Usefull in particular for TopLevelControls that should be initialised automatically, but not shown automatically (there but hidden)
font, text - common for Elements that show Text, be it labels, Editboxes.
virtual - if true, this is a virtual Element. It is used as template for teh "CreateFromVirtual" function. Is not put into the global namespace, but instead used as String Indentifier for the "CreateFromVirtual" function.


Questions:
Wich Elements can all have a "Controls" child element?
Wich common GUI Values must be assigned as atributes, wich as Direct level child element and wich as Controls Child Element?
  Reply With Quote
07/24/14, 11:16 AM   #2
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Backdrop is a type of control, that's why it goes under <Controls>.

These are all control type constants, each has corresponding XML element:
Lua Code:
  1. ControlTypes
  2.     CT_CONTROL = 0,
  3.     CT_LABEL = 1,
  4.     CT_DEBUGTEXT = 2,
  5.     CT_TEXTURE = 3,
  6.     CT_TOPLEVELCONTROL = 4,
  7.     CT_ROOT_WINDOW = 5,
  8.     CT_TEXTBUFFER = 6,
  9.     CT_BUTTON = 7,
  10.     CT_STATUSBAR = 8,
  11.     CT_EDITBOX = 9,
  12.     CT_COOLDOWN = 10,
  13.     CT_TOOLTIP = 11,
  14.     CT_SCROLL = 12,
  15.     CT_SLIDER = 13,
  16.     CT_BACKDROP = 14,
  17.     CT_MAPDISPLAY = 15,
  18.     CT_COLORSELECT = 16,
  19.     CT_LINE = 17,
  20.     CT_BROWSER = 18,
  21.     CT_COMPASS = 19,
  22.     CT_TEXTURECOMPOSITE = 20,
  Reply With Quote
07/24/14, 01:11 PM   #3
zgrssd
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 280
So iriterating what I said before on teh other thread, there are three basic types of UI XML Elements:

Property Children:
XML Child Elementes with the sole purpose of defining stuff about thier parent. They don't inherit from control, and are mostly structure like things. But they can have short inheritance chains and functions as well.
The Property Children every Control can have is preset.

Controls
Consisting of Control and every UI Element that inherits it.
They are all containers on top of being stand alone controls, having a "Controls" Property Child with the purpose of containing further Controls.

Atributes:
There are also conventinal XML atributes. They are always of type string.
Overall Property Children seem a lot more common then classical Atributes.

inherits & virtual:
A control can inherit values from every virtual control that was defined in xml.
Virtual controls do not appear in the global table, but propably are defined/listed in some subtable.
Only virtual controls can be inherited, but every control can be made virtual. There might be limitations that only elemenst of the same base type can inherit (a Label can only inherit from a virtual Label), but that is not confirmed.
  Reply With Quote
07/24/14, 01:36 PM   #4
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Originally Posted by zgrssd View Post
Atributes:
There are also conventinal XML atributes. They are always of type string.
In XML it always looks like a string, but interpretation may vary depending on the attribute. Some examples:

offsetX="-5" ... used in <Anchor>, this attribute probably undergoes ivalue = tonumber(value) before being passed to control:SetAnchor(...)

point="LEFT" ... named constant, not sure whether point="2" (since LEFT == 2) would work; but I still think it's converted to integer at some point, ivalue = _G[value]

color="3a6b9c" ... hex color code, may be parsed by a, r, g, b = ConvertHTMLColorToFloatValues(value)

color="INTERFACE_COLOR_TYPE_ALLIANCE:ALLIANCE_DAGGERFALL_COVENANT" ... another way of specifying color; the conversion would look something like:
Lua Code:
  1. local colorType, colorIndex = value:match("(%w+):(%w+)")
  2. local r, g, b, a = GetInterfaceColor(colorType, colorIndex)
I'm not saying these conversions are done in Lua code, I only tried to illustrate how they'd be done in Lua.

Last edited by merlight : 07/24/14 at 06:03 PM.
  Reply With Quote
07/24/14, 03:24 PM   #5
farangkao
 
farangkao's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 59
Maybe not very well known is the "Virtual/Inherits" Mechanism.

Basically it's used to create a template and use that one instead of repeating the same xml over and over

Here an example:

Lua Code:
  1. <!-- Virtual Controls -->
  2.     <Button alpha="0.7" name="MB_Virtual_Button" virtual="true">
  3.         <Anchor point="TOPRIGHT" relativeTo="MBUI_Container" relativePoint="TOPRIGHT" offsetX="-40" offsetY="0" />
  4.         <Dimensions x="32" y="32" />  
  5.         <OnMouseExit>
  6.              ClearTooltip(InformationTooltip)
  7.         </OnMouseExit>
  8.     </Button>

This declares a virtual Control (means which is not used by itself) ,which already
predefines certain aspects ,even incl. programming logic ,as you can see on the "OnMouseExit" part.

Now later on in the XML i make use of the virtual template like this:

Lua Code:
  1. <Button name="$(parent)Close" inherits="MB_Virtual_Button">
  2.                 <OnMouseEnter>
  3.                     InitializeTooltip(InformationTooltip, self, TOPRIGHT)
  4.                     SetTooltipText(InformationTooltip, "Close")
  5.                 </OnMouseEnter>
  6.        
  7.                  <OnClicked>
  8.                      MBUI_Container:SetHidden(true)
  9.                      MB.PreviousButtonClicked=nil
  10.                      MB.LastButtonClicked=nil
  11.                  </OnClicked>
  12.                  <Textures normal="EsoUI/Art/Buttons/decline_down.dds"                          
  13.                    mouseOver="EsoUI/Art/Buttons/decline_over.dds" />
  14.    </Button>

it then takes over the definition of "Alpha" ,"Dimensions" and "OnMouseExit" .
Meaning that the Button created has all the properties inherited by it's template.

By the way on the Wiki is clearly defined which Child are allowed for the Element "Control":
http://wiki.esoui.com/UI_XML#Control

Also i might add, if you use ZBS with my Plugin, there is some support for GuiXML build in:

  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Lua XML Basics


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