How to properly resize a PanelGadget child, an EditorGadget in this case? The only thing that seems to work ok is using subsystem qt with handling the resize events in the manual event loop directly. Any other approach like unsing event handler functions and/or gtk2/3 does either not resize the editor at all or its size is somewhat 'delayed' (visible when enlarging the window, the editor is sometimes smaller than it should be, or larger when shrinking the window. Also try window focus switch in combination with resizing, sometimes the editor doesn't get resized)
Code: Select all
EnableExplicit
Global window, panel, editor
; Procedure.s size()
; ProcedureReturn "" + GetGadgetAttribute(panel, #PB_Panel_ItemWidth) + " x " + GetGadgetAttribute(panel, #PB_Panel_ItemHeight)
; EndProcedure
Procedure windowSizeHandler()
Protected ww = WindowWidth(window)
Protected wh = WindowHeight(window)
ResizeGadget(panel, 4, 4, ww-8, wh-8)
;ResizeGadget(panel, 10, 10, 400, 300+1)
;Debug #PB_Compiler_Procedure + ": " + size()
EndProcedure
Procedure panelSizeHandler()
;Debug #PB_Compiler_Procedure + ": " + size()
Protected pw = GetGadgetAttribute(panel, #PB_Panel_ItemWidth)
Protected ph = GetGadgetAttribute(panel, #PB_Panel_ItemHeight)
ResizeGadget(editor, 4, 4, pw-8, ph-8)
; Protected ww = WindowWidth(window)
; Protected wh = WindowHeight(window)
; ResizeGadget(editor, 40, 40, ww-80, wh-80)
EndProcedure
window = OpenWindow(#PB_Any, 50,100, 800, 600, "window", #PB_Window_SystemMenu | #PB_Window_SizeGadget)
panel = PanelGadget(#PB_Any, 1, 1, 200, 200)
AddGadgetItem(panel, -1, "panel")
editor = EditorGadget(#PB_Any, 1, 1, 100, 100)
CloseGadgetList()
; Debug "created: " + size()
AddKeyboardShortcut(window, #PB_Shortcut_Escape, 99)
; BindEvent(#PB_Event_SizeWindow, @ windowSizeHandler())
; BindGadgetEvent(panel, @ panelSizeHandler(), #PB_EventType_Resize)
;
; windowSizeHandler()
; panelSizeHandler()
Repeat
Select WaitWindowEvent()
Case #PB_Event_SizeWindow
windowSizeHandler()
Case #PB_Event_Gadget
Select EventType()
Case #PB_EventType_Resize
;Debug "resize: " + size()
panelSizeHandler()
EndSelect
EndSelect
Debug "eee"
Until Event() = #PB_Event_CloseWindow Or Event() = #PB_Event_Menu