NkGenie - Anchors

From Riftui Wiki

Jump to: navigation, search

The library uses a very simply system on position frames. For all widgets the parameter anchors is supported. The paramter is always supplied in form of a LUA table using the folowing format:

anchors = {{ from = 'position', object = 'other ui element', to = 'position', x = pixel, y = pixel }}

The from position is always related to the widgt you are about to manipulate. Object is another UI element (or UIParent) vs which the widget will be positioned. Position is related to the other UI element.

The parameters x and y are optional. If supplied they will shift the object after positioning by the supplied number of pixels. You can supplied negative values.

For example if you want to position a nkGenie widget centered on the screen, you'd do it as folows:

anchors = {{ from = 'CENTER', object = UIParent, to = 'CENTER' }}

Maybe you have noted the double {} in the above example. The reason for this is that you can supply two anchoring definitions in one go. For example:

anchors = {{ from = 'TOPLEFT', object = UIParent, to = 'TOPLEFT' }, { from = 'BOTTOMLEFT', object = UIParent, to = 'BOTTOMLEFT' } }

This would draw a box (frame) which would cover the whole of the user screen (not that you'd really want to do this). The big advantage of anchoring like this you can make the size of a frame relative to another frame. If that 'parent' frame changes it's size so will do the anchored frame. For example:

local frame1 = UI.CreateFrame('nkExtFrame', 'frame1', UIParent, { width = 200, height = 200, anchors = {{ from = 'CENTER', object = UIParent, to = 'CENTER' }}, color = { body = '000000' } })
local frame2 = UI.CreateFrame('nkExtFrame', 'frame2', UIParent, { anchors = {{ from = 'TOPLEFT', object = frame1:getElement(), to = 'TOPLEFT', x = 1, y = 1 }, { from = 'BOTTOMRIGHT', object = frame1:getElement(), to = 'BOTTOMRIGHT', x = -1, y = -1 }}, color = { body = 'FFFFFF' } })
frame1:update ({ width = 300 })

The above example would lead to a 200x200 black frame centered on the screen filled with a white frame offseted by 1 pixel. The frame1:update({width = 300}) will then change the width of the frame1 object and frame2 will resize automatically to the new sizes. Actually that's not a nkGenie concept, but nkGenie makes it a lot easier to use.

Anchoring to nkGenie widgets

One very important thing is that you cannot supply nkGenie widgets as object parameter directly. This might change at some point, but for now you will have to use the getElement() method of the nkGenie widget you want to use as an anchoring object. The reason for this is, that nkGenie does not create internal objects but is rather a shell around Rift API ui elements. In order to access the underlying Rift API object which is needed for the anchoring process you have to use nkGenieWidget:getElement().

Preventing anchoring problems

If you supply x and y values for an anchor you cannot simply change the anchor through the update routine. This is not a problem of nkGenie but a problem of the Rift API. If you encounter error messages saying that you cannot specifiy duplicate SetPoint() entries, simply use the ClearAnchors() method before changing the anchoring of a widget. For example:

myFrame:ClearAnchors()
myFrame:update ({ anchors = {{ from = "CENTER", object = UIParent, to = "CENTER", x = -50, y = -50 }} })
Personal tools
Namespaces
Variants
Actions
Menu
Wiki
Toolbox