03/29/15, 05:19 PM | #1 |
|
Dynamic Anchors?
Hey everyone, I am currently trying to figure anchors out. I was wondering if its possible to dynamically anchor one item to the next.
I can anchor two things beside each other but the issue is if one changes size (example a clock ranging from 12:00 to 1:00 shrinks) there becomes a larger gap than wanted. Is it possible to always maintain a certain padding no matter what size the string is? |
03/29/15, 05:38 PM | #2 | |
|
If one control changes position, size, exc...the controls still stay anchored to each other, at the same point, the gap would not change. The other control just follows it staying attached at the same point. It sounds more to me like your not resizing the control when the "text" shrinks from 12:00 to 1:00. The control is still exactly the same size, but the text is smaller. So the gap that you see is actually between the text & the other control...its not really between the two controls, that gap would not change (if they were anchored together). Like in the example picture above, in the bottom picture the words: "Control A" and "Control B" are closer together, the gap between them has shrunk...but the gap (or lack of a gap) between the two controls has not changed at all. They are still connected by their TOPLEFT/BOTTOMRIGHT corners. There is still no gap between the controls, they are still touching. Last edited by circonian : 03/29/15 at 05:43 PM. |
|
03/29/15, 05:51 PM | #3 |
|
Ok so my problem is definitely the controls size not shrinking with the string. Is there a way to dynamically do that?
Something like X = GetStringWidth() X = X |
03/29/15, 06:37 PM | #4 |
|
Well its kind of hard to say without knowing exactly what your doing & what all controls are involved, but this will give you a start & some ideas. Do keep in mind if there are other controls involved or anchored to/around these controls it could cause other problems changing the sizes of these controls.
Lua Code:
Do note, there are several unknown factors here. For example if the lableControl is inside of other controls, resizing the labelControl alone would not (probably not) solve the problem. Because its parent or top level control would still remain the same size...and so anything anchored to its parent or top level control would still "appear" to be farther away or closer (look like the gaps size is changing). I could make a better suggestion if you post some of the code for the controls your talking about so i can see how they are laid out. |
03/29/15, 06:57 PM | #5 |
|
Sure thanks for the help I do appreciate it.
Here is my XML: XML Code:
Anchors are still a bit of an issue for me. Maybe I'm just not wrapping my head around it. Here is what I currently have. Basically what I'm going for is all the "modules" to be evenly spaced at all times no matter the situation. |
03/29/15, 08:31 PM | #6 |
|
It looks like you need something like this:
Whenever you update the clock, you could adjust the width of the control: Lua Code:
Whenever you update the fps, you could adjust the width of the control: Lua Code:
Whenever you update the latency, you could adjust the width of the control: Lua Code:
Lua Code:
Do note that since were resizing the controls to the exact width of the text, this means they wont have any space in between each of the controls. You will probably need to add some padding in between them somehow. We could do it by adding padding to the width of the control (like I wrote in my last reply), but then the labels would not be centered inside of its parent control and we would have to mess with the xml anchors offsetX to center it. So instead I would just handle the padding in the xml acnhors using offsetX. Before you had some negative values for your offsetX, but that was because you were keeping a static width for the controls (which was probably to big) so you were using a negative offsetX to overlap the controls to remove some of that gap. Since were resizing our controls to the exact size of its contents that would cause the icons/text to overlap. We need positive values now, probably somewhere between 10-20 for the offsetX value would be my guess. xml Code:
Lastly....although I said I would handle the padding (space for in between the controls) in the anchors offsetX. From writing my own clock I know that there are some other factors that can affect the width of the text, like the font. I "don't think" that GetTextWidth() takes that into account when calculating the width, because when I wrote my clock, with adjustable fonts/sizes, I had to actually vary the size of the control by adding padding based on what font/sizes I was using. The point is, you may still have to add a small amount of padding to those control widths, but it shouldn't take very much. Last edited by circonian : 03/29/15 at 08:41 PM. |
03/29/15, 08:40 PM | #7 |
|
Also, you should be able to put the resize functions inside the top level control instead of each sub control.
|
03/29/15, 08:51 PM | #8 |
|
Thanks a lot circonian. That's a big help. My goal with this addon is to learn so when you take the time to explain it helps greatly.
|
03/30/15, 05:20 PM | #9 |
|
Worked wonderfully. I have another quick question though. I want to have it so I set the backdrop size based on the size of all the modules added up. When I try this it returns them as nil. This is because I set them as local functions. How does this work? Do I have to redefine them in another function, make them not local or am I just ordering things incorrectly?
EDIT: Just a thought is it because I'm defining the local variables inside of local functions? Last edited by lightz39 : 03/30/15 at 05:46 PM. |
03/30/15, 05:53 PM | #10 |
Local variables inside local functions are only known to this function!
If you want to have the value of some variable inside your addon you need to define it local in your addon, outside functions. Otherwise you need to define it global inside or outside a function, and it will be known outside your addon as well then. To change the backdrop size you'll need to react on "when a module is added/removed": -Your backdrop control got a name so use it with WINDOW_MANAGER:GetControlByName("your backdrop's name", "") -Store this in a vraible like myBackdrop -use myBackdrop:SetWidth(myNewWidth) myNewWidth should be changed by the width of all the modules you have added |
|
03/30/15, 05:58 PM | #11 |
|
Ok I had a hunch that was the issue. Thank you. Question about that Get control name you have "" for the suffix. What exactly is that?
|
03/30/15, 08:07 PM | #12 |
This is a good question I've never used it so far. Maybe it is for controls where the start is always the same and the suffix is the name of a child.
Like the first part is the parent and the suffic is the child. The way that :GetChildByName("sChild") is working for a control where let's say the parent name is "ThisIsAParent" and a childs name is "ThisIsAParentsChild" But I'm not sure, this is only a guess |
|
03/30/15, 09:29 PM | #13 | |
|
Lua Code:
If you needed to get the child of a child of a parent control.... Lets use this as an example, I want to get the control: ZO_PlayerInventoryTabsButton6 "ZO_PlayerInventoryTabs" is a child control of ZO_PlayerInventoryYou could do something like: Lua Code:
But instead of making the intermediate call to get: ZO_PlayerInventoryTabs control...even though you don't care about it & are only going to use it to grab the: ZO_PlayerInventoryTabsButton6 control. Instead you can just use: Lua Code:
Note: The control your trying to get doesn't have to be the Child of a child of the parent...it was just a decent example of use for the function. You could grab a parents child by doing: Lua Code:
But since "Tabs" is a child of ZO_PlayerInventory, we could also just call: Lua Code:
Last edited by circonian : 03/30/15 at 09:37 PM. |
|
03/31/15, 01:57 AM | #14 |
Thanks for the explanation circonian. Again I've learned something :-) (And I wasn#t that wrong with my guess above )
|
|
03/31/15, 06:07 AM | #15 |
|
Thanks again as always very helpful.
|
ESOUI » Developer Discussions » Lua/XML Help » Dynamic Anchors? |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|