View Full Version : resizing the character sheet
DNH
June 22nd, 2007, 15:47
my players would really like to be able to resize the character sheet to their liking (and not just the character sheet, pretty much anything in FG2) but i can't seem to get this working. i have added the following code to my charsheet_main windowclass ...
<windowclass name="charsheet_main">
<sizelimits>
<maximum>
<width>504</width>
<height>911</height>
</maximum>
<minimum>
<width>252</width>
<height>611</height>
</minimum>
<dynamic>
<resize>both</resize>
</dynamic>
</sizelimits>
... but to no avail. Am I doing something wrong here?
One thing occurs to me: do all subsequent controls then have to be "anchored", as opposed to having set "bounds"? That sounds like it makes sense.
Any thoughts?
Also, assuming the resizing thing works, how is it achieved? Do you simply grab the frame and drag? Hit control and drag? Is there a resize scroller?
Thanks.
joshuha
June 22nd, 2007, 15:55
Yes, you will need to make sure things are anchored as opposed to bound controls otherwise they will just get more blankspace.
Charsheet_main is only the main frame lying on top of the charsheet. Look at charsheet_toplevel.xml for the main windowclass that defines the whole sheet (its called "charsheet") and make your changes there first.
DNH
June 22nd, 2007, 16:03
aha! i thought there must be something like that when i couldn't find a <frame> definition for charsheet_main.
i shall try that tonight, thanks.
DNH
June 22nd, 2007, 18:18
ok, i have now tried this out with limited success. thanks.
i say limited because while i can indeed resize the character sheet, by "bounded" controls remain fixed, which rather defeats the object. i am now starting work on converting them all to "anchored" controls BUT i have fallen at the first hurdle ... sorry!
<windowclass name="charsheet_main">
<placement>
<size>
<width>252</width>
<height>611</height>
</size>
</placement>
<nodelete />
<sheetdata>
<!-- OVERVIEW -->
<genericcontrol name="overviewframe">
<anchored>
<left>
<parent>charsheet_main</parent>
<anchor>insideleft</anchor>
<offset>5</offset>
</left>
<top>
<parent>charsheet_main</parent>
<anchor>insidetop</anchor>
<offset>5</offset>
</top>
</anchored>
<!-- <bounds>15,20,480,108</bounds> -->
<frame>
<name>sheetgroup</name>
</frame>
</genericcontrol>
... fails, giving me an error such that
Ruleset Error: Control 'overviewframe' anchoring to an undefined control 'charsheet_main'
I have tried anchoring it to "main" (the subwindow of "charsheet") and to "charsheet" itself, but no luck. What am I doing wrong?
joshuha
June 22nd, 2007, 18:29
You can't anchor to the windowclass itself directly (its not really a control and you can only anchor to other controls). Just don't specify a parent tag and it will anchor to the window edges.
"The <parent> tag contains a string value identifying the name of the control to which the edge is being anchored. If this tag is omitted, the anchoring will be done to the window edges."
This is from the library ruleset modification guide. The windows and control section I still use all the time.
https://www.fantasygrounds.com/modguide/windowing.xcp
DNH
June 22nd, 2007, 18:36
hmm, well you see, that's what i thought (the windowclass thing, i mean) so i removed the parent tag but the overview control disappeared altogether!
hang on: i have it now! the anchor for left side was wrong!
thanks joshuha (again)
DNH
June 22nd, 2007, 19:08
ahem! sorry, me again. more problems i can't seem to fix.
1 - i want the frame to extend down as far as the next control (almost) but it won't. i tried setting the anchor of the bottom edge of the current one to the top edge of the next one but i get an error msg, videlicet
Ruleset Error: Control 'overviewframe' anchoring to uncalculated control 'abilityframe'
2 - i have three stringfields within the top line of this control (name, full name and player, for what it's worth). what i would really like is for them all to span across the top line, but what they currently do is anchor against each other. what i mean is, the controls are only as large as they need to be to contain the values. if i specify a width for them, isn't that going against the resizing/anchoring philosophy?
thanks
joshuha
June 22nd, 2007, 20:26
ahem! sorry, me again. more problems i can't seem to fix.
1 - i want the frame to extend down as far as the next control (almost) but it won't. i tried setting the anchor of the bottom edge of the current one to the top edge of the next one but i get an error msg, videlicet
Well the error you are getting is because I think you are trying to anchor to a control that is defined after the control. Not exactly sure what you are trying to do though, I might need a better explanation.
2 - i have three stringfields within the top line of this control (name, full name and player, for what it's worth). what i would really like is for them all to span across the top line, but what they currently do is anchor against each other. what i mean is, the controls are only as large as they need to be to contain the values. if i specify a width for them, isn't that going against the resizing/anchoring philosophy?
thanks
Have you looked at the <relation> tag and the relative value? This might accomplish what you are looking for.
Dachannien
June 22nd, 2007, 22:00
Also note that, in general, what you're trying to do won't work. You'll have to specify widths or bounds for at least some of the controls, in particular those which don't take up the entire width or height of a particular window (which would be pretty much all of them), except for one in any row or column of controls. I suspect that the "uncalculated" error means that there isn't enough information to determine where control A is placed, and so when control B is anchored to it, FG can't do anything with it.
The thing missing that would permit you to do what you want to do is percent widths. In HTML tables, for example, you can specify the width of a column based on a percentage of the entire table (whose width is either specified explicitly or is determined by whatever object contains it). If you make the table bigger, the columns get proportionally wider (which is what you're trying to do). Since FG doesn't do percent widths, you can't do this (at least, not the easy way).
What you do have access to is the same thing that's left with HTML tables if you take out percent widths: You can allow the controls to autosize based on the size of their content, with the next control over being anchored to the previous one (and moving around when the previous control gets bigger or smaller. The controls won't change size when you resize the window, though. You can specify the dimensions of all but one control. The remaining control then has its edges specified by anchoring them to the surrounding controls, and when you resize the sheet, that one control changes size by the same amount. You can use scripting to dynamically resize every control on a sheet whenever the sheet is resized (assuming there's some sort of event triggered by resizing it), similar to using Javascript to tinkering with elements on a web page, but for mental health reasons, I'd advise against it ;)
DNH
June 23rd, 2007, 15:41
i HAD hoped that fg2 would support % width values but i tried it and, of course, it wouldn't work.
what i was thinking was something like the following, using three controls - A, B and C - within a windowcontrol W:
the left edge of A is anchored to the insideleft edge of W the right edge of A is anchored to the left edge of B the left edge of B is anchored to the right edge of A the right edge of B is anchored to the left edge of C the left edge of C is anchored to the right edge of B the right edge of C is anchored to the insideright edge of W
which sounds to me as though it should expand the controls A, B and C accordingly ...
... BUT i can't do this of course, because i would be trying to anchor A to B when i haven't yet defined B, and so on.
does anyone know if % width support is in the offing?
joshuha
June 23rd, 2007, 20:04
This wouldn't be too hard I would think using templates and a bit of LUA. Just have a LUA funciton that gets the width of the parent container. Then a custom tag <percentwidth> that scales to a percent of that on the onInit of the control.
Don't have time to work on this right now but I think it woud be doable.
DNH
June 25th, 2007, 17:33
that's a very interesting idea, joshuha! i can see how that could be done. i too lack the time to try it out just now, but let me know if you are likely to have a go at this some time soon. if not, i shall give it a try myself.
DNH
June 27th, 2007, 14:23
You can allow the controls to autosize based on the size of their content, with the next control over being anchored to the previous one (and moving around when the previous control gets bigger or smaller.
how do you achieve that exactly? i have tried to avoid defining width and height but it just ends up messy. is it possible to define a minimum size? i mean, with this being a character sheet and all, most fields are blank until the players enter the values, so i have a bunch of "labelledstring" fields with the labels overlapping each other!
Dachannien
June 27th, 2007, 19:04
Doh, I didn't think of that. You might try inserting
<sizelimits>
<minimum>
<width> ... </width>
<height> ... </height>
</minimum>
</sizelimits>
into the control's definition, specifying the minimum width and height as appropriate, but I don't know whether that will work or not.
it doesn't, in short. i tried that myself at one point.
here is a code snippet:
<labeledstring name="fullname">
<anchored>
<left>
<parent>name</parent>
<anchor>right</anchor>
<offset>10</offset>
</left>
<top>
<parent>overviewframe</parent>
<anchor>top</anchor>
<offset>10</offset>
</top>
<sizelimits>
<minimum>
<width>100</width>
<height>20</height>
</minimum>
</sizelimits>
</anchored>
<label>fullname</label>
<tabtarget>
<next>player</next>
<prev>name</prev>
</tabtarget>
</labeledstring>
i have tried placing the <sizelimits> element both within and without the <anchored> element, but neither works.
isn't there a way i can achieve this through scripting? i have tried something like
function onInit()
local width = self.getSize().width;
if width < 120 then
setAnchoredWidth(120);
end
end
but no joy. i keep getting a zero result, which could be because i am calling this wrong but i am assuming it is rather because this is happening in the onInit phase and so the control has yet to be fully defined.
any thoughts?
of course, i would also have to add this code to any control for which i want to set a minimum size. i could certainly place the same in the template definition for a default size, but anything not default would have to have this initHandler added to it. hmm.
joshuha
July 2nd, 2007, 17:07
Look at the adventure_npcs.xml file. They have several templates there that set anchoring and width on the onInit() so it should work.
Look at the adventure_npcs.xml file. They have several templates there that set anchoring and width on the onInit() so it should work.
those templates relate to resizing though, which is good for something else i am trying to achieve but not this. they are not really onInit size and anchor settings.
i have pretty much given up no this for the moment. i can't seem to get what i want and i don't see why. it's more of a niggle than anything anyway, and i can get around things by using suitable tabtargets.
thanks anyway.
joshuha
July 3rd, 2007, 13:54
isn't there a way i can achieve this through scripting? i have tried something like
function onInit()
local width = self.getSize().width;
if width < 120 then
setAnchoredWidth(120);
end
end
but no joy. i keep getting a zero result, which could be because i am calling this wrong but i am assuming it is rather because this is happening in the onInit phase and so the control has yet to be fully defined.
any thoughts?
getSize() returns 2 values and not sure if its table indexed where width would work. Try this:
function onInit()
local width, height = self.getSize();
if width < 120 then
setAnchoredWidth(120);
end
end
this is exactly what i did try (following my quoted code above) but it doesn't work. that is, it appears that getSize() in onInit will always retrieve zeroes and therefore, my minimum default size code will always be processed.
hmm.
Dachannien
July 3rd, 2007, 15:35
We determined in this thread that controls don't have positions yet (or, presumably, sizes) during onInit. I conjectured that maybe another event, such as onMove or onSizeChanged, fires once the control has been placed, but this hasn't been tested.
ok, thanks to Joshuha's suggestion of looking at adventure_npcs.xml, i now have %-based resizing of character sheet fields! the script is as follows ...
<script>
function sizeChanged()
local winwidth, winheight = getSize();
local pcwidth = math.floor((winwidth - 47) / 100);
local pcheight = math.floor((winheight - 27) / 100);
name.setAnchoredWidth(pcwidth * 30);
fullname.setAnchoredWidth(pcwidth * 40);
player.setAnchoredWidth(pcwidth * 30);
class1.setAnchoredWidth(pcwidth * 14);
class2.setAnchoredWidth(pcwidth * 14);
class3.setAnchoredWidth(pcwidth * 14);
kit.setAnchoredWidth(pcwidth * 10);
level1.setAnchoredWidth(pcwidth * 5);
level2.setAnchoredWidth(pcwidth * 5);
level3.setAnchoredWidth(pcwidth * 5);
xpcurrent.setAnchoredWidth(pcwidth * 10);
xprequired.setAnchoredWidth(pcwidth * 10);
end
function onInit()
self.onSizeChanged = sizeChanged;
sizeChanged();
end
</script>
the "winwidth - 47" takes account of the offsets left and right, as "winheight -27" does for top and bottom.
you will have to add .setAnchoredWidth/Height method calls for each element of the character sheet you want resizing, of course. and you should also anchor the right edge of the rightmost element to the inside edge of your frame.
i have no doubt there is a more elegant and efficient way of doing this (using the template definition perhaps) but this works fine, looks rather cool and will satisfy my players. and i don't notice any performance hits just yet, not after the initial loading of the character sheet anyway.
Powered by vBulletin® Version 4.2.1 Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.