Thread Tools Display Modes
05/21/14, 04:55 PM   #1
Tar000un
 
Tar000un's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 47
Move a control from lua

Hi,

from http://www.esoui.com/forums/showthread.php?t=1541

i ve a lua code like the Clear / SetAnchor,

Code:
AddOnUI:ClearAnchors();
AddOnUI:SetAnchor( TOPLEFT, GuiRoot, TOPLEFT, 0, 0);
I ve also other control in. A texture and a label, with and anchorfill in a backdrop. I tryed to clear / set the backdrop without any success.

As exemple, see 1.2.{3.1,3.2}. Where 2:SetAnchor( _, 1, _,_,_);
I clear from 3.2, then 3.1, then 2, then 1 and reset in the first order.

But that works once and after my UI get bad offset (typically, my label go to the cursor), and UI's position isnt reset.
  Reply With Quote
05/21/14, 06:36 PM   #2
thelegendaryof
 
thelegendaryof's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 161
Originally Posted by Tar000un View Post
Hi,

from http://www.esoui.com/forums/showthread.php?t=1541

i ve a lua code like the Clear / SetAnchor,

Code:
AddOnUI:ClearAnchors();
AddOnUI:SetAnchor( TOPLEFT, GuiRoot, TOPLEFT, 0, 0);
I ve also other control in. A texture and a label, with and anchorfill in a backdrop. I tryed to clear / set the backdrop without any success.

As exemple, see 1.2.{3.1,3.2}. Where 2:SetAnchor( _, 1, _,_,_);
I clear from 3.2, then 3.1, then 2, then 1 and reset in the first order.

But that works once and after my UI get bad offset (typically, my label go to the cursor), and UI's position isnt reset.
I'm not sure if I understand you correctly - however like I've posted the other thread (deleted it there now since it was OT)
just reapply your above code in OnUpdate for every Frame (and dont forget the Buffer)

Last edited by thelegendaryof : 05/21/14 at 06:39 PM.
  Reply With Quote
05/21/14, 07:26 PM   #3
Stormknight
 
Stormknight's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 128
I strongly advise against passing the variable _ to a function, unless you have declared it locally (assuming that's what you meant in the example).

It is commonly used as a "junk" variable so could contain any random value.
  Reply With Quote
05/22/14, 01:50 AM   #4
Tar000un
 
Tar000un's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 47
I used _ to exprim "any variable you want put here".
2:SetAnchor( _, 1, _,_,_) have to be read like 2:SetAnchor( pos1, 1, pos2,offx,offy)

Originally Posted by thelegendaryof View Post
I'm not sure if I understand you correctly - however like I've posted the other thread (deleted it there now since it was OT)
just reapply your above code in OnUpdate for every Frame (and dont forget the Buffer)
I apply the code on a reset slash command. My purpose isnt to show a move (with multiple reset), but to redefine a position. Which is correctly reset... only one time per reloadUI. All next command doesnt work.
  Reply With Quote
05/22/14, 04:09 AM   #5
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
This depends on how your controls are defined, if you can post a few lines of code maybe we can figure out why controls does not want to move.
  Reply With Quote
05/22/14, 07:18 AM   #6
Tar000un
 
Tar000un's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 47
The parts about the concerned code :

Lua Code:
  1. UI_Texture:ClearAnchors();
  2. UI_Label:ClearAnchors();
  3. UI_BG:ClearAnchors();
  4. UI:ClearAnchors();
  5.  
  6. UI:SetAnchor( TOPLEFT, GuiRoot, TOPLEFT, defaults.x, defaults.y );
  7. UI_BG:SetAnchor(TOPLEFT, UI, TOPLEFT, 0, 0);
  8. UI_Texture:SetAnchor(TOPLEFT, UI_BG, TOPLEFT, 0, 0);
  9. UI_Label:SetAnchor(BOTTOM, UI_BG, BOTTOM, 0, 0);



The XML:
Code:
<Controls>
	<Backdrop name="$(parent)_BGcompassTiny" 
			inherits="ZO_CenterlessBackdrop" edgeColor="000000" 
			centerColor="000000" alpha="0">
		<AnchorFill />
	</Backdrop>
	<Texture name="$(parent)_TextureCompassTiny" />
	<Label name="$(parent)_LabelCompassTiny" 
		verticalAlignment="BOTTOM" horizontalAlignment="CENTER" 
		text="Label" alpha="1" 
	/>
</Controls>
  Reply With Quote
05/22/14, 07:34 AM   #7
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by Tar000un View Post
The parts about the concerned code :

Lua Code:
  1. UI_Texture:ClearAnchors();
  2. UI_Label:ClearAnchors();
  3. UI_BG:ClearAnchors();
  4. UI:ClearAnchors();
  5.  
  6. UI:SetAnchor( TOPLEFT, GuiRoot, TOPLEFT, defaults.x, defaults.y );
  7. UI_BG:SetAnchor(TOPLEFT, UI, TOPLEFT, 0, 0);
  8. UI_Texture:SetAnchor(TOPLEFT, UI_BG, TOPLEFT, 0, 0);
  9. UI_Label:SetAnchor(BOTTOM, UI_BG, BOTTOM, 0, 0);



The XML:
Code:
<Controls>
	<Backdrop name="$(parent)_BGcompassTiny" 
			inherits="ZO_CenterlessBackdrop" edgeColor="000000" 
			centerColor="000000" alpha="0">
		<AnchorFill />
	</Backdrop>
	<Texture name="$(parent)_TextureCompassTiny" />
	<Label name="$(parent)_LabelCompassTiny" 
		verticalAlignment="BOTTOM" horizontalAlignment="CENTER" 
		text="Label" alpha="1" 
	/>
</Controls>
Everything is anchored to the UI (top level window), so it should be enough to move just UI.
Lua Code:
  1. UI:ClearAnchors()
  2. UI:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, defaults.x, defaults.y)

Also in my opinion both backdrop and texture needs two anchors:
Lua Code:
  1. UI:ClearAnchors()
  2. UI:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, defaults.x, defaults.y)
  3.  
  4. UI_BG:ClearAnchors()
  5. UI_BG:SetAnchor(TOPLEFT, UI, TOPLEFT, 0, 0)
  6. UI_BG:SetAnchor(BOTTOMRIGHT, UI, BOTTOMRIGHT, 0, 0)
  7. --or instead of two lines above use:
  8. --UI_BG:SetAnchorFill(UI)
  9.  
  10. UI_Texture:ClearAnchors()
  11. UI_Texture:SetAnchor(TOPLEFT, UI_BG, TOPLEFT, 0, 0)
  12. UI_Texture:SetAnchor(BOTTOMRIGHT, UI_BG, BOTTOMRIGHT, 0, 0)
  13. --or instead of two lines above use:
  14. --UI_Texture:SetAnchorFill(UI_BG)
  15.  
  16. UI_Label:ClearAnchors()
  17. UI_Label:SetAnchor(BOTTOM, UI_BG, BOTTOM, 0, 0)

Last edited by Garkin : 05/22/14 at 07:38 AM.
  Reply With Quote
05/22/14, 08:16 AM   #8
Tar000un
 
Tar000un's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 47
Originally Posted by Garkin View Post
Everything is anchored to the UI (top level window), so it should be enough to move just UI.
Lua Code:
  1. UI:ClearAnchors()
  2. UI:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, defaults.x, defaults.y)
I mind too, but in fact, per reloadui, the command replace the UI the first time, an do nothing after.


Originally Posted by Garkin View Post
Also in my opinion both backdrop and texture needs two anchors:
Lua Code:
  1. UI:ClearAnchors()
  2. UI:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, defaults.x, defaults.y)
  3.  
  4. UI_BG:ClearAnchors()
  5. UI_BG:SetAnchor(TOPLEFT, UI, TOPLEFT, 0, 0)
  6. UI_BG:SetAnchor(BOTTOMRIGHT, UI, BOTTOMRIGHT, 0, 0)
  7. --or instead of two lines above use:
  8. --UI_BG:SetAnchorFill(UI)
  9.  
  10. UI_Texture:ClearAnchors()
  11. UI_Texture:SetAnchor(TOPLEFT, UI_BG, TOPLEFT, 0, 0)
  12. UI_Texture:SetAnchor(BOTTOMRIGHT, UI_BG, BOTTOMRIGHT, 0, 0)
  13. --or instead of two lines above use:
  14. --UI_Texture:SetAnchorFill(UI_BG)
  15.  
  16. UI_Label:ClearAnchors()
  17. UI_Label:SetAnchor(BOTTOM, UI_BG, BOTTOM, 0, 0)
I tryed your code, but still with the no reset problem, when triggered more than once. :/
  Reply With Quote
05/22/14, 09:08 AM   #9
thelegendaryof
 
thelegendaryof's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 161
just reapply your above code in OnUpdate for every Frame (and dont forget the Buffer)
just reapply your above code in OnUpdate for every Frame (and dont forget the Buffer)
just reapply your above code in OnUpdate for every Frame (and dont forget the Buffer)
just reapply your above code in OnUpdate for every Frame (and dont forget the Buffer)
just reapply your above code in OnUpdate for every Frame (and dont forget the Buffer)
just reapply your above code in OnUpdate for every Frame (and dont forget the Buffer)
just reapply your above code in OnUpdate for every Frame (and dont forget the Buffer)
just reapply your above code in OnUpdate for every Frame (and dont forget the Buffer)
just reapply your above code in OnUpdate for every Frame (and dont forget the Buffer)
just reapply your above code in OnUpdate for every Frame (and dont forget the Buffer)

...

If there is NO specific event that 's the only thing you can do (well that and a timer)!
If for any reason you don't want to do that because the Player should be able to move the frames
then you have to think about a better solution with booleans n' stuff ...
  Reply With Quote
05/22/14, 09:14 AM   #10
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by thelegendaryof View Post
just reapply your above code in OnUpdate for every Frame (and dont forget the Buffer)
just reapply your above code in OnUpdate for every Frame (and dont forget the Buffer)
just reapply your above code in OnUpdate for every Frame (and dont forget the Buffer)
just reapply your above code in OnUpdate for every Frame (and dont forget the Buffer)
just reapply your above code in OnUpdate for every Frame (and dont forget the Buffer)
just reapply your above code in OnUpdate for every Frame (and dont forget the Buffer)
just reapply your above code in OnUpdate for every Frame (and dont forget the Buffer)
just reapply your above code in OnUpdate for every Frame (and dont forget the Buffer)
just reapply your above code in OnUpdate for every Frame (and dont forget the Buffer)
just reapply your above code in OnUpdate for every Frame (and dont forget the Buffer)

...
As Tar000un said a lots of times before, he can move frame just once an then it does not work. So if you add it to the OnUpdate, it will do nothing every update...

Originally Posted by Tar000un
I mind too, but in fact, per reloadui, the command replace the UI the first time, an do nothing after.
I can't find any other reason why this does not work -unless there is something wrong with offset values. Are sure that when you set new anchor, offset values are correct?
  Reply With Quote
05/22/14, 09:22 AM   #11
thelegendaryof
 
thelegendaryof's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 161
Oh guess it was language difficulties - he 's trying to MOVE it then afterwards after anchoring it to another position?
Ok OnUpdate is a bad idea then ...
  Reply With Quote
05/22/14, 11:22 AM   #12
Tar000un
 
Tar000un's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 47
It works better since i ve removed a lign :
Lua Code:
  1. settings = defaults;

This was causing me so many troubles... With your clue about offset, i saw on zgoo that my defaults were updated by the move.

From a
Lua Code:
  1. settings.x = UI:getLeft();
And do defaults.x = settings.x = UI:getLeft()...


***

I m using
Lua Code:
  1. UI:ClearAnchors()
  2. UI:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, defaults.x, defaults.y)
  3. AddOn.OnMoveStop()

Last edited by Tar000un : 05/22/14 at 11:29 AM.
  Reply With Quote
05/22/14, 11:51 AM   #13
ingeniousclown
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 122
Judging from your most recent reply, I'm guessing that you have something along the lines of this:

lua Code:
  1. defaults = {
  2.     x = someNumber,
  3.     y = someOtherNumber
  4. }
  5. settings = defaults
  6.  
  7. control:ClearAnchors()
  8. control:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, defaults.x, defaults.y)
  9.  
  10. --control is moved?
  11.  
  12. settings.x = newNumber
  13. settings.y = newOtherNumber
  14.  
  15. control:ClearAnchors()
  16. control:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, defaults.x, defaults.y)

Can you see the problem? Tables are not copied upon assignment, they are referenced.

So "settings = defaults" and then "settings.x = someNewNumber" in fact changes the value of your "defaults.x".
  Reply With Quote
05/22/14, 12:21 PM   #14
Tar000un
 
Tar000un's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 47
Not really the trace i imagine about my code, but we can resume like it.

On the one hand, you have to remind than I m new with Lua.
In the other hand, can you see i solved my problem ? What I did when I understand it.

My last post was just to inform than I solved my problem (which is a table's newb problem, I concede it...).

Last edited by Tar000un : 05/22/14 at 01:32 PM.
  Reply With Quote
05/22/14, 12:35 PM   #15
ingeniousclown
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 122
The point of my post was to inform you of something important that happens in lua, because like you said, you are new to it. It is a common mistake and worth mentioning, even if you did already solve your problem. Just trying to teach

Without learning this information about how tables are assigned, then you're likely to make the same mistake again in the future (if you DID make that mistake).
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Move a control from lua

Thread Tools
Display Modes

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