This would make several things more comfortable:
- as that container is resized, its children can be automatically resized by the same procedure that first arranges them
- there is no need to define x, y, width and height for the children gadgets (just the order)
This is akin to the SplitterGadget, but:
- it can contain more than two children,
- it can be used when the user does not need to or simply should not change the internal proportions
You can find below the code an example for an AutosizeGadget()
But first, for the Feature Request
I would recommend the implementation of such gadget in the PB core, so that:
- the usage could be akin to the one in the example ( AutosizeGadget(), [children], CloseGadgetList() )
- there would be for the coder no need to call the "AutosizeGadget_Resize()" after the GUI definition, nor after the ResizeGadget(#myautosizegadget,...): calling the ResizeGadget on it should also resize its contents
Do you think this might be useful?
Code: Select all
Enumeration
#gadget_Autosize_Horizontal
#gadget_Autosize_Vertical
EndEnumeration
Structure sk_autosizegadget
num.l ; #mygadget
mode.l ; horizontal: children are side by side | vertical: children are stacked
children.l[8] ; #gadgets contained by #mygadget
EndStructure
Global NewList autosizegadgets.sk_autosizegadget()
Procedure AutosizeGadget( gadget_number, x, y, width, height, mode, g0, g1, g2=-1, g3=-1, g4=-1, g5=-1, g6=-1, g7=-1 )
ContainerGadget(gadget_number,x,y,width,height)
AddElement( autosizegadgets() )
autosizegadgets()\num = gadget_number
autosizegadgets()\mode = mode
autosizegadgets()\children[0]=g0
autosizegadgets()\children[1]=g1
autosizegadgets()\children[2]=g2
autosizegadgets()\children[3]=g3
autosizegadgets()\children[4]=g4
autosizegadgets()\children[5]=g5
autosizegadgets()\children[6]=g6
autosizegadgets()\children[7]=g7
EndProcedure
Procedure AutosizeGadget_Resize()
ForEach autosizegadgets()
mode = autosizegadgets()\mode
w = GadgetWidth(autosizegadgets()\num)-2
h = GadgetHeight(autosizegadgets()\num)-2
totchildren=0 : For a=0 To 7 : If autosizegadgets()\children[a]<>-1 : totchildren+1 : EndIf : Next
If mode=#gadget_Autosize_Vertical
childw.f = w*1.0/totchildren : childh.f = h
For a=0 To 7
If autosizegadgets()\children[a]<>-1
ResizeGadget(autosizegadgets()\children[a],Int(a*childw),0,Int(childw),childh)
EndIf
Next
Else
childh.f = h*1.0/totchildren : childw.f = w
For a=0 To 7
If autosizegadgets()\children[a]<>-1
ResizeGadget(autosizegadgets()\children[a],0,Int(a*childh),childw,Int(childh))
EndIf
Next
EndIf
Next
EndProcedure
; =======
; EXAMPLE
Enumeration
#g_toplabel
#g_autosize2
#g_autosize1 : #g_label0 : #g_label1
#g_autosize0 : #g_b0 : #g_b1 : #g_b2
EndEnumeration
If Not OpenWindow(0, 100, 200, 320, 240, "AutosizeGadget()", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget) : End : EndIf
TextGadget(#g_toplabel,0,0,320,20,"AutosizeGadget test")
AutosizeGadget(#g_autosize2,0,20,320,220,#gadget_autosize_vertical,#g_autosize0,#g_autosize1)
AutosizeGadget(#g_autosize0,0,0,0,0,#gadget_autosize_horizontal,#g_b0,#g_b1,#g_b2)
ButtonGadget(#g_b0,0,0,0,0,"1")
ButtonGadget(#g_b1,0,0,0,0,"22")
ButtonGadget(#g_b2,0,0,0,0,"333")
CloseGadgetList()
AutosizeGadget(#g_autosize1,0,0,0,0,#gadget_autosize_horizontal,#g_label0,#g_label1)
TextGadget(#g_label0,0,0,0,0,"Text 1",#PB_Text_Border)
TextGadget(#g_label1,0,0,0,0,"Text 2",#PB_Text_Border)
CloseGadgetList()
CloseGadgetList()
AutosizeGadget_Resize()
Repeat
EvID = WaitWindowEvent()
Select EvID
Case #PB_Event_SizeWindow
ResizeGadget(#g_autosize2,0,20,WindowWidth(0),WindowHeight(0)-20)
AutosizeGadget_Resize()
EndSelect
Until EvID = #PB_Event_CloseWindow