Exemple here with the Panel Locked at Left, Top and Bottom, the Container Locked at Right, Top and Bottom and the others, the 2 buttons and the editor are proportional.
It uses static variables to save the containers initial sizes. Let me know what you think, before I change my code ?
Code: Select all
EnableExplicit
Enumeration Window
#MainWindow
EndEnumeration
Enumeration Gadgets
#Panel
#Edit
#Cont
#Btn_OK
#Btn_Cancel
EndEnumeration
Declare Resize_MainWindow()
Declare Open_MainWindow(X = 0, Y = 0, Width = 650, Height = 440)
Procedure Resize_MainWindow()
Protected.f FactorX, FactorY
Static WinWidthIni, WinHeightIni
Static Panel_WidthIni, Panel_HeightIni
Static Cont_WidthIni, Cont_HeightIni
If WinWidthIni = 0
WinWidthIni = WindowWidth(#MainWindow) : WinHeightIni = WindowHeight(#MainWindow)
Panel_WidthIni = GadgetWidth(#Panel) : Panel_HeightIni = GetGadgetAttribute(#Panel, #PB_Panel_ItemHeight)
Cont_WidthIni = GadgetWidth(#Cont) : Cont_HeightIni = GadgetHeight(#Cont)
ProcedureReturn
EndIf
ResizeGadget(#Panel, 20, 20, WindowWidth(#MainWindow) - 230, WindowHeight(#MainWindow) - 40)
FactorX = GadgetWidth(#Panel) / Panel_WidthIni : FactorY = GetGadgetAttribute(#Panel, #PB_Panel_ItemHeight) / Panel_HeightIni
ResizeGadget(#Edit, FactorX * 10, FactorY * 10, FactorX * (Panel_WidthIni - 30), FactorY * (Panel_HeightIni - 16))
ResizeGadget(#Cont, WindowWidth(#MainWindow) - 200, 20, 190, WindowHeight(#MainWindow) - 40)
FactorX = GadgetWidth(#Cont) / Cont_WidthIni : FactorY = GadgetHeight(#Cont) / Cont_HeightIni
ResizeGadget(#Btn_OK, FactorX * 10, FactorY * 20, FactorX * (Cont_WidthIni - 30), FactorY * (Cont_HeightIni - 350))
ResizeGadget(#Btn_Cancel, FactorX * 10, FactorY * 90, FactorX * (Cont_WidthIni - 30), FactorY * (Cont_HeightIni - 350))
EndProcedure
Procedure Open_MainWindow(X = 0, Y = 0, Width = 650, Height = 440)
If OpenWindow(#MainWindow, X, Y, Width, Height, "Proportional Resize based on Containers", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
PanelGadget(#Panel, 20, 20, 420, 400) ; Lock Left, Top, Bottom
AddGadgetItem(#Panel, -1, "Tab_0")
EditorGadget(#Edit, 10, 10, 390, 355) ; Proportional
SetGadgetColor(#Edit, #PB_Gadget_BackColor, $D8FFFF)
AddGadgetItem(#Edit, -1, "Editor Line 1")
AddGadgetItem(#Panel, -1, "Tab_1")
CloseGadgetList() ; #Panel_1
ContainerGadget(#Cont, 450, 20, 190, 400, #PB_Container_Raised) ; Lock Right, Top, Bottom
SetGadgetColor(#Cont, #PB_Gadget_BackColor, $C0C0C0)
ButtonGadget(#Btn_OK, 10, 20, 160, 50, "OK") ; Proportional
ButtonGadget(#Btn_Cancel, 10, 90, 160, 50, "Cancel") ; Proportional
CloseGadgetList() ; #Cont
BindEvent(#PB_Event_SizeWindow, @Resize_MainWindow(), #MainWindow)
PostEvent(#PB_Event_SizeWindow, #MainWindow, 0)
WindowBounds(#MainWindow, 420, 200, #PB_Ignore, #PB_Ignore)
EndIf
EndProcedure
Open_MainWindow()
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow