Thread Tools Display Modes
04/12/14, 10:27 AM   #1
Blackstorm
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 12
API : Controls and Offset

Hello,

I am currently writting my own extension, i have done a small code part ^^ but i am blocked with the UI style

I am trying to add some controls headers and controls lines one above the other on a constant background but without knowing the exact offset (or height) of each element, and each element can have one or more lignes and never the same height.

so is it possible please ? if it's possible can you help me to know how ?


I have actualy something like that :

Lua Code:
  1. MMQTbg = WM:CreateControl("MMQT_Background", MMQTmain, CT_STATUSBAR)
  2. MMQTbg:SetSimpleAnchorParent(0,0)
  3. MMQTbg:SetResizeToFitDescendents(true)
  4.  
  5. function AddNewTitle(qindex, qlevel, qname)
  6.     if not MMQTlabel[qindex] then
  7.         MMQTlabel[qindex] = WM:CreateControl("MMQT_Label_"..qindex, MMQTbg , CT_LABEL)
  8.         if qindex == 1 then
  9.             local offsetTitle = 0
  10.             MMQTlabel[qindex]:SetSimpleAnchorParent(0,offsetTitle)
  11.         else
  12.             local offsetTitle = (qindex -1) * 25
  13.             MMQTlabel[qindex]:SetSimpleAnchorParent(0,offsetTitle)
  14.         end
  15.     end
  16.     MMQTlabel[qindex]:SetFont("ZoFontAnnounceMessage")
  17.     MMQTlabel[qindex]:SetText("["..qlevel.."] - "..qname)
  18. end
  19.  
  20. for i=1, 6 do
  21.     AddNewTitle(qindex, qlevel, qname)
  22. end


this code work fine, but i'm looking for a way to automatically place the object

Thanks in advance ^^
  Reply With Quote
04/13/14, 04:30 AM   #2
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
What's wrong with GetDimensions() and GetAnchor() ?
  Reply With Quote
04/13/14, 01:31 PM   #3
Blackstorm
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 12
Originally Posted by Iyanga View Post
What's wrong with GetDimensions() and GetAnchor() ?
It's not realy documented, no example.. maybe it's doing what i want maybe not ^^

But thanks for info, i will try ^^
  Reply With Quote
04/13/14, 02:20 PM   #4
Nogaruk
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 15
I'd love to know if you manage to figure out SetResizeToFitDescendents(bool resize). I have only managed to get it to work with SetDimensionConstraints(number minWidth, number minHeight, number maxWidth, number maxHeight) and SetResizeToFitPadding(number width, number height).

Also, depending on what you want to achieve at the end, you could also use SetAnchor instead of SetSimple so you can have control over the objects alignment. I find it much easier to use the alignment with parenting windows to control how and where they show up in relation to other frames. Instead of trying to find specific offsets to use.

For a descending order for example, TOP alignment for the windows self alignment and BOTTOM for the windows target alignment would ensure that no matter how long (wide) a label's text is, it will always be centered underneath its parent frame.
  Reply With Quote
04/14/14, 02:55 AM   #5
Blackstorm
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 12
Hi ^^ thanks for your answers ^^

I tryed with GetDimension() and GetHeight() but nothing, the return give me a '0' value.

I will try today what Nogaruk said...


The problem is i have no examples...

Nogaruk can you give me an short example please, for placing automaticaly several child one above the other ? (I have only one parent, it's the background...) ?

Otherwise, i use SetResizeToFitDescendents() without argument and it auto resize width and height from is content -> set on my background (the background is the parent of all content)

I am looking for a way to use a constraint on the width value, to permit players to specify width in the menu settings ... but i don't know if it's possible to keep the 2 possibilities .. i need to do some tries ^^

Last edited by Blackstorm : 04/14/14 at 02:57 AM.
  Reply With Quote
04/14/14, 03:12 AM   #6
Stormknight
 
Stormknight's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 128
Something you can do, that I have working nicely in my main addon is to chain components together on the screen with anchor points.


Say you have two labels: LABELA & LABELB.

You set the position of LABELA as normal, within your top-level container.

You can then use SetAnchor to anchor the TOP of LABELB to the BOTTOM of LABELA.

If you change the height of LABELA, then the position of LABELB on the screen will automatically adjust without you having to do any additional scripting to move it.

Code:
<GuiXml>
    <Controls>
        <TopLevelControl name="MyAddon" mouseEnabled="true" movable="true" clampedToScreen="true">
            <Dimensions x="200" y="150" />
            <Controls>
                <Label name="$(parent)LabelA" font="ZoFontWinH1" color="FFFFFF" inheritAlpha="true" wrapMode="TRUNCATE" verticalAlignment="TOP" horizontalAlignment="CENTER" text="This is Label A" />
                <Label name="$(parent)LabelB" font="ZoFontWinH5" color="FFFFFF" inheritAlpha="true" wrapMode="TRUNCATE" verticalAlignment="TOP" horizontalAlignment="CENTER" text="This is Label B" />
            </Controls>
        </TopLevelControl>
    </Controls>
</GuiXml>
then in your LUA:
Code:
MyAddonLabelB:SetAnchor(TOP, MyAddonLabelA, BOTTOM, 0, 0)
This means set the anchor of LabelB. We are anchoring the TOP of label B to the BOTTOM of Label A, with zero offsets.

Now when you change the size or position of LabelA, you'll see LabelB adjusts as well.

Last edited by Stormknight : 04/14/14 at 03:23 AM.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » API : Controls and Offset


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