ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Move a control from lua (https://www.esoui.com/forums/showthread.php?t=1581)

Tar000un 05/21/14 04:55 PM

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.

thelegendaryof 05/21/14 06:36 PM

Quote:

Originally Posted by Tar000un (Post 8196)
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)

Stormknight 05/21/14 07:26 PM

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.

Tar000un 05/22/14 01:50 AM

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)

Quote:

Originally Posted by thelegendaryof (Post 8201)
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.

Garkin 05/22/14 04:09 AM

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.

Tar000un 05/22/14 07:18 AM

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>


Garkin 05/22/14 07:34 AM

Quote:

Originally Posted by Tar000un (Post 8227)
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)

Tar000un 05/22/14 08:16 AM

Quote:

Originally Posted by Garkin (Post 8229)
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.


Quote:

Originally Posted by Garkin (Post 8229)
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. :/

thelegendaryof 05/22/14 09:08 AM

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 ...

Garkin 05/22/14 09:14 AM

Quote:

Originally Posted by thelegendaryof (Post 8234)
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...

Quote:

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?

thelegendaryof 05/22/14 09:22 AM

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 ...

Tar000un 05/22/14 11:22 AM

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()

ingeniousclown 05/22/14 11:51 AM

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".

Tar000un 05/22/14 12:21 PM

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...).

ingeniousclown 05/22/14 12:35 PM

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).


All times are GMT -6. The time now is 10:47 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI