PDA

View Full Version : Resize window based on input



nickdigital
07-05-2011, 12:45 PM
Is it possible to resize a window based on what a user selects in lscript? I want to add options to a box but depending on what the user selects the number of options will change.

evenflcw
07-05-2011, 03:03 PM
Yes, you can.

But you'll have to close the panel because reqsize doesnt seem to work from within a button callback. Likely the requester size is set in reqpost, which also send the panel to the screen. Atleast in Modeler for modal panels. Layouts non-modal panels might work differently (reqopen()).

Anyway, have the requesters size in some global variables, like reqw and reqh. Have the gui creation code in a separate function, like options() (imho you should always have it so), so you can call it easily. Place a reqend() at the top of that function to close any previously opened panels from this script. Then just set reqw and reqh, and call options() from any callback to reopen the panel. Obviously store any values already set by the user so you can restore them in the newly opened panel.

One would think that you could place reqend() in the callback already, but this does not work. Lscript is really picky where it likes to have its req*() and ctl*() functions. They must usually be within the same block/function that reqbegin() is in for some odd and often annoying reason. I think perhaps lscript gets a panel id (not exposed in lscript) of sorts from the block/function that reqbegin is called within.


@version 2.2
@warnings
@script modeler

main
{
options();
}
w=100;
y=100;
options {
if(reqisopen()) reqend();
reqbegin("<Requester Title>");
reqsize(w,y);
ctl_button = ctlbutton("Reopen Panel", 40, "Reopen");
return if !reqpost();
reqend();
}
Reopen {
w+=5;
y+=5;
options();
}

nickdigital
07-05-2011, 04:32 PM
Thx!

nickdigital
07-05-2011, 05:38 PM
Is there a way to get this to work through ctlrefresh and a popup window selection? Your example is based on a button execution. Doing a condition check on the popup selection doesn't work as nothing is being returned that I can test against.

evenflcw
07-05-2011, 08:24 PM
This seems to work.
LW didn't quite like the last reqend this time. So simply skip it. Seems to work.

Btw please always refer to all lscript controls by their function name, ie ctlpopup to avoid confusion. I'm not sure if "popup window" refers to an lscript control or if you actually made another lscript requester/panel display along side the original. (Despite many things in MS Windows being a Window object, one should not always refer to them as that).


@version 2.2
@warnings
@script modeler

ctl_sizes;
size = 1;
sizes = @<200,200,0>, <300,300,0>, <400,400,0>@;
sizes_choices = @""+sizes[1].x+"x"+sizes[1].y, ""+sizes[2].x+"x"+sizes[2].y, ""+sizes[3].x+"x"+sizes[3][email protected];
result;

ctl_string;
validation_string="";

main
{
options();
info( (result?"OK":"Cancel"), " ", sizes_choices[size], " ", validation_string );
}

options {
if(reqisopen()) reqend();

reqbegin("Testing");
reqsize(sizes[size].x, sizes[size].y);
ctl_sizes = ctlpopup("Sizes", size, sizes_choices);
ctl_string = ctlstring("Validate", validation_string);
ctlrefresh(ctl_sizes, "size_change_event");

result=reqpost(); //if you want the return value, make it a global variable. LW seems to get confused as the options() function is indirectly calling itself, sortof recursing.
validation_string = ctl_string.value;
//reqabort(); //screws reqpost return value. probably clears that memory before function returns. I suggest to call this though, in lieu of reqend, if you dont need the reqpost return value.
//reqend(); //reqend crashed LW if size_change_event has been called previously. Likely LW has trouble handling all the panels. If only NT would have provided panel ids as in SDK there would be no such confusion. *Sigh*. Seems like you can skip it anyway since LW takes care of destroying the panel when you press either OK or Cancel. There might be some small memory still tied up. But when script ends, it should be returned.
}

size_change_event: val {
size = ctl_sizes.value; //or just val
validation_string = ctl_string.value; //store since we want to reopen panel with this value not default
options();
}

evenflcw
07-05-2011, 09:16 PM
Basically when you start combining things you try whatever might work or give up trying. Like LW in general.

nickdigital
07-05-2011, 09:42 PM
Basically when you start combining things you try whatever might work or give up trying. Like LW in general.

lol

I'll make sure my terminology is clearer. Thanks for the descriptive help.

nickdigital
07-06-2011, 09:34 AM
[Edit] Removed.