Control:SetAnchor

From ESOUI Wiki

Jump to: navigation, search

Contents

SetAnchor

(AnchorPosition myPoint, object anchorTargetControl, AnchorPosition anchorControlsPoint, number offsetX, number offsetY)

Description

The function creates an anchor and adds it to the calling control. It does not overwrite an existing anchor. In order to replace an anchor, it is necessary to call Control:ClearAnchors() before-hand. Also note that Control:GetAnchor() can return different values than those that were set previously with Control:SetAnchor(), i.e. offsets relative to point CENTER can be internally converted to offsets relative to TOPLEFT with a new point value set.

Arguments

AnchorPosition   point The position of the anchor on the control that is set.
object anchorTargetControl   The control this control shall anchor to.
AnchorPosition   relativePoint The position of the anchor on the anchorTargetControl.
number offsetX The horizontal offset relative to the point position.
number offsetY The vertical offset relative to the point position.

Constrains

With anchor constrains, you can limit an anchor to only one dimension (X or Y): LUA:

  ANCHOR_CONSTRAINS_X -- makes an anchor only effective in the horizontal direction
  ANCHOR_CONSTRAINS_Y -- makes an anchor only effective in the vertical direction

XML:

  constrains="X" <!-- makes an anchor only effective in the horizontal direction -->
  constrains="Y" <!-- makes an anchor only effective in the vertical direction -->

Examples

Dynamically sizing

Span a control into parent

myControl will fill up parentControl. The same effect can be achieved by setting <AnchorFill /> in the XML.

-- control (orange) / targetControl (blue)
control:SetAnchor(TOPLEFT, targetControl, TOPLEFT, 0, 0)
control:SetAnchor(BOTTOMRIGHT, targetControl, RIGHT, 0, 0)

Twoanchors.png

two controls into parent

Control 1 has the fixed width of control1Width. Control 2 will resize dynamically and use up the remaining space in parentControl.

control1:SetAnchor(TOPLEFT, parentControl, TOPLEFT, 0, 0)
control1:SetAnchor(BOTTOMRIGHT, parentControl, BOTTOMLEFT, control1Width, 0)
 
control2:SetAnchor(TOPLEFT, control1, TOPRIGHT, 0, 0)
control2:SetAnchor(BOTTOMRIGHT, parentControl, BOTTOMRIGHT, 0, 0)

one control to parent

AnchorPositions.png

LUA - XML

ACMETopLevelControl:SetAnchor(CENTER, GuiRoot, nil, -100, 0)

equals:

<GuiXml>
  <Controls>
    <TopLevelControl name="ACMETopLevelControl">
      <Anchor point="CENTER" offsetX="-100"/>

and positions the control 100 units to the left of the center of the GuiRoot control.


Did you know?

Numeric values

Numeric values of AnchorPosition global variables are:

3 1 9
2 128 8
6 4 12
=
TOPLEFT TOP TOPRIGHT
LEFT CENTER RIGHT
BOTTOMLEFT BOTTOM BOTTOMRIGHT
TOP + LEFT = TOPLEFT (1 + 2 = 3)
TOP + RIGHT = TOPRIGHT (1 + 8 = 9)
BOTTOM + LEFT = BOTTOMLEFT (4 + 2 = 6)
BOTTOM + RIGHT = BOTTOMRIGHT (4 + 8 = 12)
Personal tools
Namespaces
Variants
Actions
Menu
Wiki
Toolbox