Thread Tools Display Modes
03/30/14, 04:50 PM   #1
Dio
 
Dio's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 29
Absolute positioning and Custom Scale

I have a control centered horizontally on the screen. If possible, how would I vertically position this control at exactly 1/2 distance between the top of the screen and the center, and have this control stay there despite UI custom scale changes?

Last edited by Dio : 03/30/14 at 04:54 PM.
  Reply With Quote
03/30/14, 07:53 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
I would do
Lua Code:
  1. local height = GuiRoot:GetHeight()
  2. myFrame:SetAnchor(TOP, GuiRoot, TOP, 0, height/4)


/edit: if you want the center of your frame to be at that point, then do this instead:
Lua Code:
  1. local height = GuiRoot:GetHeight()
  2. myFrame:SetAnchor(CENTER, GuiRoot, TOP, 0, height/4)
  Reply With Quote
03/30/14, 08:20 PM   #3
Dio
 
Dio's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 29
Originally Posted by Seerah View Post
/edit: if you want the center of your frame to be at that point, then do this instead:
Lua Code:
  1. local height = GuiRoot:GetHeight()
  2. myFrame:SetAnchor(CENTER, GuiRoot, TOP, 0, height/4)

Thanks! I'm using that inside a EVENT_SCREEN_RESIZED event, and it does the trick for screen resizing or Custom Scale changes.

Code:
EVENT_MANAGER:RegisterForEvent(name, EVENT_SCREEN_RESIZED, function()
    myFrame:SetAnchor(CENTER, GuiRoot, TOP, 0, GuiRoot:GetHeight() / 4)
end)
  Reply With Quote
03/30/14, 08:24 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
Clear your frame's anchor before setting a new one.
  Reply With Quote
03/30/14, 08:41 PM   #5
Dio
 
Dio's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 29
Originally Posted by Seerah View Post
Clear your frame's anchor before setting a new one.
Ah, I just assumed it set over the old one. Thanks.

Last edited by Dio : 03/30/14 at 08:52 PM.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Absolute positioning and Custom Scale


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