WoW:API Region SetPoint: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
m (reworded point arg description)
m (Move page script moved page API Region SetPoint to API Region SetPoint without leaving a redirect)
 
(19 intermediate revisions by 16 users not shown)
Line 1: Line 1:
<center>'''SetPoint''' ''-Documentation by [[Sarf]]-''</center>
{{widgetmethod}}
 
Sets an attachment point of an UI component.
Sets the current attachment point of an UI component.  Any of the following formats are valid
  obj:SetPoint(point, relativeFrame, relativePoint, ofsx, ofsy);
 
obj:SetPoint(point, relativeFrame, relativePoint);
obj:SetPoint(point, ofsx, ofsy);
  obj:SetPoint(point);
  obj:SetPoint(point);
obj:SetPoint(point, frame);
obj:SetPoint(point, frame, relativePoint);
obj:SetPoint(point, x, y);
obj:SetPoint(point, frame, relativePoint , x, y);


----
== Arguments ==
;''Arguments''
; point : String - Point of the object to adjust based on the anchor.
; relativeFrame : String/Widget - Name or reference to a frame to attach obj to. If omitted or nil, it typically defaults to the object's parent. However, if relativePoint is also not defined, relativeFrame will default to UIParent.
; relativePoint : String - point of the relativeFrame to attach point of obj to. If not specified, defaults to the value of point.
; ofsx : Number - x-offset (negative values will move ''obj'' left, positive values will move ''obj'' right), defaults to 0 if not specified.
; ofsy : Number - y-offset (negative values will move ''obj'' down, positive values will move ''obj'' up), defaults to 0 if not specified.


; point  
=== Points ===
: the point on your object to use for attaching the obj (see [[API Positions]])  (i.e. bind the left side of your frame)
There are nine valid point values:
* "TOP", "RIGHT" "BOTTOM" "LEFT": the center-points of the respective sides.
* "TOPRIGHT", "TOPLEFT", "BOTTOMLEFT", "BOTTOMRIGHT": corners of the frame rectangle.
* "CENTER": the center point of the frame rectangle.


; frame
== Examples ==
: the name of the frame to attach the obj to, an actual frame variable can also be used (can be "UIParent" to attach it to the screen itself)
: defaults to the parent of obj when not specified
 
; relativePoint
: the relative point to attach the obj to (see [[API Positions]])  (i.e. bind your frame to the left side of the parent)
: defaults to the value of point when not specified
 
; x
: the X offset (-5 means 5 units left, 5 means 5 units right)
: defaults to 0 when not specified
 
; y
: the Y offset (-5 means 5 units down, 5 means 5 units up)
: defaults to 0 when not specified
 
----
;''Returns''
 
:;nil
 
----
;''Examples''
The following are all equivalent.
The following are all equivalent.
  MainMenuBar:SetPoint("BOTTOMLEFT", "UIParent", "BOTTOMLEFT", 0, 0);
  MainMenuBar:SetPoint("BOTTOMLEFT", "UIParent", "BOTTOMLEFT", 0, 0);
Line 50: Line 30:
  MainMenuBar:SetPoint("BOTTOMLEFT", 0, 0);
  MainMenuBar:SetPoint("BOTTOMLEFT", 0, 0);


;''Result''
== Details ==
* Behavior of this function with multiple anchors is complex. Generally, you can override points by setting them again (so repeated assignment to the "TOPLEFT" point of a frame would move the frame, unless other anchor points interfere). If you're repositioning a frame, call <code>obj:[[API Region ClearAllPoints|ClearAllPoints]]()</code> to eliminate unwanted interactions.
* Offset units are relative to the screen's effective scale. WoW's screen always has a height of 768 units, while screen width varies with aspect ratio.
* <tt>ofsx</tt> and <tt>ofsy</tt> must both be passed as arguments for either to take effect; they default to 0 only when neither is given.  That is, <tt>foo:SetPoint(bar, 40)</tt> will ignore the 40 rather than treat it as (+40,+0).
* Secure frames will silently ignore calls to this function if the relative frame is a [[API FontString|FontString]].
 
=== Edge definitions ===
The edge "points" (TOP, RIGHT, BOTTOM, LEFT) are not actual points, but... edges. To fully define a region position using edges alone, you will need to define all four (as opposed to using corners, where you only need two) edges.


----
Therefore, defining an edge does not necessarily place a region relative to the center of that edge (For example, if you define TOP and RIGHT, the region will be placed at the TOPRIGHT corner). However, by default a region is "pulled" to the center if the number of points defined is insufficient.
;''Description''


: Attaches obj to the specified position.
Example:
----
Region:ClearAllPoints();
{{Template:WoW API}}
Region:SetPoint("TOP", relativeframe);
Region:SetWidth(100);
Region:SetHeight(100);
will place ''Region'' to the top center of the ''relativeframe'' while adding a
Region:SetPoint("RIGHT", relativeframe);
will place ''Region'' in the top right corner and now ''Region'' is fully defined.

Latest revision as of 04:47, 15 August 2023

Widget API ← Region < SetPoint

Sets an attachment point of an UI component.

obj:SetPoint(point, relativeFrame, relativePoint, ofsx, ofsy);
obj:SetPoint(point, relativeFrame, relativePoint);
obj:SetPoint(point, ofsx, ofsy);
obj:SetPoint(point);

Arguments[edit]

point
String - Point of the object to adjust based on the anchor.
relativeFrame
String/Widget - Name or reference to a frame to attach obj to. If omitted or nil, it typically defaults to the object's parent. However, if relativePoint is also not defined, relativeFrame will default to UIParent.
relativePoint
String - point of the relativeFrame to attach point of obj to. If not specified, defaults to the value of point.
ofsx
Number - x-offset (negative values will move obj left, positive values will move obj right), defaults to 0 if not specified.
ofsy
Number - y-offset (negative values will move obj down, positive values will move obj up), defaults to 0 if not specified.

Points[edit]

There are nine valid point values:

  • "TOP", "RIGHT" "BOTTOM" "LEFT": the center-points of the respective sides.
  • "TOPRIGHT", "TOPLEFT", "BOTTOMLEFT", "BOTTOMRIGHT": corners of the frame rectangle.
  • "CENTER": the center point of the frame rectangle.

Examples[edit]

The following are all equivalent.

MainMenuBar:SetPoint("BOTTOMLEFT", "UIParent", "BOTTOMLEFT", 0, 0);
MainMenuBar:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", 0, 0);
MainMenuBar:SetPoint("BOTTOMLEFT", "UIParent", "BOTTOMLEFT");
MainMenuBar:SetPoint("BOTTOMLEFT", "UIParent");

The following is equivalent to the above, given that the parent frame of MainMenuBar is UIParent.

MainMenuBar:SetPoint("BOTTOMLEFT");
MainMenuBar:SetPoint("BOTTOMLEFT", 0, 0);

Details[edit]

  • Behavior of this function with multiple anchors is complex. Generally, you can override points by setting them again (so repeated assignment to the "TOPLEFT" point of a frame would move the frame, unless other anchor points interfere). If you're repositioning a frame, call obj:ClearAllPoints() to eliminate unwanted interactions.
  • Offset units are relative to the screen's effective scale. WoW's screen always has a height of 768 units, while screen width varies with aspect ratio.
  • ofsx and ofsy must both be passed as arguments for either to take effect; they default to 0 only when neither is given. That is, foo:SetPoint(bar, 40) will ignore the 40 rather than treat it as (+40,+0).
  • Secure frames will silently ignore calls to this function if the relative frame is a FontString.

Edge definitions[edit]

The edge "points" (TOP, RIGHT, BOTTOM, LEFT) are not actual points, but... edges. To fully define a region position using edges alone, you will need to define all four (as opposed to using corners, where you only need two) edges.

Therefore, defining an edge does not necessarily place a region relative to the center of that edge (For example, if you define TOP and RIGHT, the region will be placed at the TOPRIGHT corner). However, by default a region is "pulled" to the center if the number of points defined is insufficient.

Example:

Region:ClearAllPoints();
Region:SetPoint("TOP", relativeframe);
Region:SetWidth(100);
Region:SetHeight(100);

will place Region to the top center of the relativeframe while adding a

Region:SetPoint("RIGHT", relativeframe);

will place Region in the top right corner and now Region is fully defined.