PDA

View Full Version : Using getSize() function on windowcontrol



bzjeurd
January 9th, 2014, 09:26
Hello,

I would like to use the getSize() function into the onInit() event function but the returned values are always 0,0.
If I use getSize(9 in other function (like onClickRelease() for example), the values are correctly filled for the control...

In fact, I would like to center (vertically or horizontally) a control (with a fixed width/height) to an edge of another control using setAnchor() function, but without the size of the second control, its impossible...
Maybe there is another way to achieve this "center" issue...

Thanx for your help.

Bz.

Trenloe
January 9th, 2014, 09:55
I've just done a quick test and it worked OK for me - in the onInit function of an image control:

local w, h = getSize();
Debug.console("control size = " .. w .. ", " .. h);


What kind of control is it? Can you show us the code you are using?

Trenloe
January 9th, 2014, 09:58
But, you may be able to do what you want in the control XML.

If you haven't looked into it already, the "control positioning" section of the ruleset modification guide gives info on anchoring controls to other controls: https://www.fantasygrounds.com/modguide/windowing.xcp

bzjeurd
January 9th, 2014, 10:56
Hello Trenloe,
Thanx for your quick answer...
I'm using a genericcontrol (to set frame where several other control type will be positionned).
I've just tested your script and the result is 0,0 for genericcontrol... maybe a bug or normal behavior for this kind of control?
I'm using the 3.0.2 version of FG.

edit: the result didn't change whatever I use bounds tag or anchored tag.

Bz
NB: I will have a look to the section you mentionned.

Trenloe
January 9th, 2014, 11:33
How is the control defined in the XML? That is, what is the XML you are using?

bzjeurd
January 9th, 2014, 12:23
This is an example:

<genericcontrol name="testframe">
<anchored position="insidetopleft" offset="225,210" width="200" height="80" />
<script>
function onInit()
local w, h = getSize();
Debug.console("control size = " .. w .. ", " .. h);
end
</script>
</genericcontrol>

If I replace the anchored tag with bounds tag, same behavior.

Bz

Moon Wizard
January 9th, 2014, 21:42
Only top-level window instance objects are laid out before onInit calls. Any embedded window instances (within windowlistcontrol or subwindow) are not. You can possibly use the windowinstance.onSizeChanged event to capture the window changes, and reset anchors based on that event.

Can you provide me with the XML of the two controls and what you are trying to do (i.e. centering)? I may be able to suggest another way that does not involve Lua code.

Regards,
JPG

bzjeurd
January 10th, 2014, 12:59
Hello Moon_wizard,

Actually, I tested my "testframe" control in a toplevel windowinstance and the getSize() function return the correct size of the control...
As you mentioned above, the problem arises when controls belong to a subwindow (my case) instance.

However I found a workaround. I set the genericcontrol size in a explicite way like this:
<anchored><size><height>100</height><width>200</width></size></anchored>
And I retrieve the control size values in the LUA code using the anchored table and setAnchor() function.
But it's not satisfactory for me as I can't use anymore a <bounds> tag with negative (relative) parameters to set size and position for my controls...

I'm very interested in any better way to achieve "center" positionning of control...

The first control is a genericcontrol as the "testframe" one above.
The second control is another genericcontrol that works like a buttoncontrol (to simplify) or more precisely like the buttongroup_tabs defined in the CoreRPG (but it's not a buttongroup_tabs control).

I would like to set the position of the second one centered on one of the edge of the first one (left, right, top or bottom).

This is an example with the bottom centered position using the workaround previoulsy described:

5851

bzjeurd
January 10th, 2014, 13:16
I have little question...
Why the onInit() event has a different behavior for controls within a subwindow instance as ones in a top level window instance?
This can reserve some bad surprise...
Is there somewhere a documentation that mentions this (or other) slight difference?

Thanx for any help.

Bz

Moon Wizard
January 10th, 2014, 21:36
It's not specifically documented, but it's more of an efficiency issue.

Whenever a window is laid out (i.e. all the controls positioned), all of the parent windows up the chain have to be laid out as well to allow for embedded windows to impact the size and layout of controls in which they are embedded and the parent windows.

When loading a record containing many child windows, the top-level window would have to go through that many layout events before even appearing on the screen. In some cases, such as spell lists in PFRPG, this would cause huge delays (several seconds).

You can set anchors based on position of the first control:
<top parent="first" />
Or you can set anchors based on the center of the window:
<top anchor="center" />

Can you use one of those anchor types?

Regards,
JPG

bzjeurd
January 12th, 2014, 11:10
Moon Wizard,
I tried your second option and it works fine!

In my script I translate this with setAnchor function as below:

setAnchor("top","firstcontrol","bottom", "absolute", -7);
setAnchor("left","firstcontrol","center", "absolute", -(secondcontrolwidth/2));

In your documentation, the parentanchor parameter doesn't mention the "center" as a possible value. It should be nice for other ruleset developpers, if you can add it to the setAnchor function description.

Bz.