Not sure if this has been asked before, but I'll post anyway..
How about the ability to scale/position a gadget by percentage of the parent window/element, or auto-aligned to one side, so that it auto-updates when you (the end-user) resize the window. Would be useful to be able to do this in the VD too.
I know this is something that can be hand-coded as a procedure, but making it part of the language would be even better.
Gadget position/scale by percentage of parent window
Gadget position/scale by percentage of parent window
Innesoft - The Software Marketplace - Innesoft Blog
» Applications, Educational Software, Casual Games
» Applications, Educational Software, Casual Games
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: Gadget position/scale by percentage of parent window
well I think ...
this would require a built-in callback, what definitely is not the way PureBasic is designed.
PureBasic is a procedural language and can handle events, but is not event-driven like OOP languages.
so, maybe that sounds like a nice feature, but it is completely off the philosophy of this language.
this would require a built-in callback, what definitely is not the way PureBasic is designed.
PureBasic is a procedural language and can handle events, but is not event-driven like OOP languages.
so, maybe that sounds like a nice feature, but it is completely off the philosophy of this language.
oh... and have a nice day.
Re: Gadget position/scale by percentage of parent window
You don't necessarily need callback for that. A layout library would be enough to handle that.
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: Gadget position/scale by percentage of parent window
oookaaaay.... 
that sounds as if you're already on it...

that sounds as if you're already on it...
oh... and have a nice day.
Re: Gadget position/scale by percentage of parent window
I understand where you're coming from, but I'm not sure I agree that it goes against what the language should be. It's just a way of handling a gadget property dynamically, however that would be handled behind the scenes. I mean, there's already a WindowEvent() for #PB_Event_SizeWindow. Not much of a deviation from the language, other than the way gadgets are handled, and this could be done with a flag like #PB_Position_Percentage (or something) and a command to update gadgets with that flag on a #PB_Event_SizeWindow event.Kaeru Gaman wrote:..so, maybe that sounds like a nice feature, but it is completely off the philosophy of this language.
Anyway, just a thought.
Innesoft - The Software Marketplace - Innesoft Blog
» Applications, Educational Software, Casual Games
» Applications, Educational Software, Casual Games
Re: Gadget position/scale by percentage of parent window
I appreciate this idea.
See: http://www.purebasic.fr/english/viewtop ... =3&t=35680
See: http://www.purebasic.fr/english/viewtop ... =3&t=35680
cheers,
bembulak
bembulak
Re: Gadget position/scale by percentage of parent window
I've knocked up a quick solution, which can probably be improved, but it's literally 5 minutes work thrown together. At least until Fred is kind enough to integrate a better solution into the language.
(Works with all gadgets)
Step 1. The Procedures...
Step 2. Make Your Gadgets Dynamic...
The initial x,y,w,h of the gadget is automatically the minimum it will be allowed when you resize. This allows you to design your layout at the minimum with scope for maximizing the window.
Step 3. Put This in Your Main Loop

(Works with all gadgets)
Step 1. The Procedures...
Code: Select all
Structure dyn_element
ID.i
PAR.i
lockwh.i
lockx.i
locky.i
min_x.i
min_y.i
x_perc.f
y_perc.f
min_w.i
min_h.i
w_perc.f
h_perc.f
EndStructure
Dim dyn.dyn_element(99)
Global dyn_cnt.i
Global dyn_statusbar_adjust.i = 24 ;adjust inner-height for status bar (set to zero to disable)
Procedure DynamicElement(parent,ID,lockx.i,locky.i,lockwh.i)
Shared dyn.dyn_element()
dyn_cnt.i=dyn_cnt.i+1
dyn(dyn_cnt.i)\ID.i=ID
dyn(dyn_cnt.i)\PAR.i=parent
dyn(dyn_cnt.i)\lockwh.i=lockwh.i
dyn(dyn_cnt.i)\lockx.i=lockx.i
dyn(dyn_cnt.i)\locky.i=locky.i
If dyn(dyn_cnt.i)\lockwh.i = 0
dyn(dyn_cnt.i)\min_w.i=GadgetWidth(ID)
dyn(dyn_cnt.i)\min_h.i=GadgetHeight(ID)
dyn(dyn_cnt.i)\w_perc.f=(dyn(dyn_cnt.i)\min_w.i/(WindowWidth(parent)-dyn_statusbar_adjust.i))*100
dyn(dyn_cnt.i)\h_perc.f=(dyn(dyn_cnt.i)\min_h.i/(WindowHeight(parent)-dyn_statusbar_adjust.i))*100
EndIf
dyn(dyn_cnt.i)\min_x.i=GadgetX(ID)
dyn(dyn_cnt.i)\min_y.i=GadgetY(ID)
dyn(dyn_cnt.i)\x_perc.f=(dyn(dyn_cnt.i)\min_x.i/(WindowWidth(parent)-dyn_statusbar_adjust.i))*100
dyn(dyn_cnt.i)\y_perc.f=(dyn(dyn_cnt.i)\min_y.i/(WindowHeight(parent)-dyn_statusbar_adjust.i))*100
EndProcedure
Procedure UpdateDynamicElements()
Shared dyn.dyn_element()
For a.i=1 To dyn_cnt.i
pw.f = WindowWidth(dyn(a.i)\PAR.i)-dyn_statusbar_adjust.i
ph.f = WindowHeight(dyn(a.i)\PAR.i)-dyn_statusbar_adjust.i
If dyn(dyn_cnt.i)\lockwh.i = 0
gw.f = ((pw.f/100) * dyn(a.i)\w_perc.f)
gh.f = ((ph.f/100) * dyn(a.i)\h_perc.f)
If gw.f < dyn(a.i)\min_w.i
gw.f = dyn(a.i)\min_w.i
EndIf
If gh.f < dyn(a.i)\min_h.i
gh.f = dyn(a.i)\min_h.i
EndIf
Else
gw.f = GadgetWidth(dyn(a.i)\ID.i)
gh.f = GadgetHeight(dyn(a.i)\ID.i)
EndIf
If dyn(dyn_cnt.i)\lockx.i = 0
gx.f = ((pw.f/100) * dyn(a.i)\x_perc.f)
If gx.f < dyn(a.i)\min_x.i
gx.f = dyn(a.i)\min_x.i
EndIf
Else
gx.f = dyn(a.i)\min_x.i
EndIf
If dyn(dyn_cnt.i)\locky.i = 0
gy.f = ((ph.f/100) * dyn(a.i)\y_perc.f)
If gy.f < dyn(a.i)\min_y.i
gy.f = dyn(a.i)\min_y.i
EndIf
Else
gy.f = dyn(a.i)\min_y.i
EndIf
ResizeGadget(dyn(a.i)\ID.i,gx.f,gy.f,gw.f,gh.f)
Next
EndProcedure
The initial x,y,w,h of the gadget is automatically the minimum it will be allowed when you resize. This allows you to design your layout at the minimum with scope for maximizing the window.
Code: Select all
;Usage: DynamicElement(parent_window,gadgetID,lockx,locky,lockscale)
DynamicElement(#Window_0,#Panel_0,1,0,0) ;dynamic but lock x position
DynamicElement(#Window_0,#Panel_1,0,1,0) ;dynamic but lock y position
DynamicElement(#Window_0,#Panel_2,0,0,1) ;dynamic but lock scale
Code: Select all
Event = WaitWindowEvent() ; you probably already have this line in your loop
If Event = #PB_Event_SizeWindow Or Event = #PB_Event_MaximizeWindow Or Event = #PB_Event_RestoreWindow
UpdateDynamicElements()
EndIf
Innesoft - The Software Marketplace - Innesoft Blog
» Applications, Educational Software, Casual Games
» Applications, Educational Software, Casual Games