Resize PanelGadget Child (Linux)

Just starting out? Need help? Post your questions and find answers here.
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Resize PanelGadget Child (Linux)

Post by #NULL »

(Linux/Ubuntu18, pb570b2 x64)
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
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Resize PanelGadget Child (Linux)

Post by #NULL »

some correction..

Code: Select all

editor = PanelGadget(..)
should be

Code: Select all

editor = EditorGadget(..)
but the problems persist.
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Resize PanelGadget Child (Linux)

Post by #NULL »

And if I use multiple panel items (tabs) and play with resizing and switching the active panel, sometimes the panel/editor doesn't resize properly as well.
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Resize PanelGadget Child (Linux)

Post by Shardik »

Sorry, but on my Linux Mint 18.3 'Sylvia' x64 with Cinnamon I can't confirm your described problems running your code example with both PB 5.62 and PB 5.70 Beta 2. When using the default GTK3, the panel and EditorGadget are always correctly resized when resizing the window. When using subsystem GTK2 there is sometimes a small delay when quickly enlarging the window but afterwards the panel and EditorGadget are always perfectly resized inside the window.
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Resize PanelGadget Child (Linux)

Post by #NULL »

Sorry, I think it was slightly confusing. I was even confused myself right now for a moment. You might see it if you disable the event loop resize handling and use the event bindings instead:

Code: Select all

EnableExplicit

Global window, panel, editor

Procedure windowSizeHandler()
  Protected ww = WindowWidth(window)
  Protected wh = WindowHeight(window)
  ResizeGadget(panel, 4, 4, ww-8, wh-8)
EndProcedure

Procedure panelSizeHandler()
  Protected pw = GetGadgetAttribute(panel, #PB_Panel_ItemWidth)
  Protected ph = GetGadgetAttribute(panel, #PB_Panel_ItemHeight)
  ResizeGadget(editor, 4, 4, pw-8, ph-8)
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()

AddKeyboardShortcut(window, #PB_Shortcut_Escape, 99)

BindEvent(#PB_Event_SizeWindow, @ windowSizeHandler())
BindGadgetEvent(panel, @ panelSizeHandler(), #PB_EventType_Resize)

Repeat
  WaitWindowEvent()
Until Event() = #PB_Event_CloseWindow Or Event() = #PB_Event_Menu
here I get the delayed or uncomplete resizing with qt and gtk3. I don't mean the missing initial resize but during actual window resizing.
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Resize PanelGadget Child (Linux)

Post by #NULL »

With qt and multiple panel tabs:
alternate between the tabs and resize the window each time. It looks as if the tab that just became active before the resizing would have like a maximum size set and does not enlarge beyond that.

Code: Select all

EnableExplicit

Global window, panel, editor1, editor2

Procedure windowSizeHandler()
  Protected ww = WindowWidth(window)
  Protected wh = WindowHeight(window)
  ResizeGadget(panel, 4, 4, ww-8, wh-8)
EndProcedure

Procedure panelSizeHandler()
  Protected pw = GetGadgetAttribute(panel, #PB_Panel_ItemWidth)
  Protected ph = GetGadgetAttribute(panel, #PB_Panel_ItemHeight)
  ResizeGadget(editor1, 4, 4, pw-8, ph-8)
  ResizeGadget(editor2, 4, 4, pw-8, ph-8)
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, "panel1")
editor1 = EditorGadget(#PB_Any, 1, 1, 100, 100)
AddGadgetItem(panel, -1, "panel2")
editor2 = EditorGadget(#PB_Any, 1, 1, 100, 100)
CloseGadgetList()

AddKeyboardShortcut(window, #PB_Shortcut_Escape, 99)

BindEvent(#PB_Event_SizeWindow, @ windowSizeHandler())
BindGadgetEvent(panel, @ panelSizeHandler(), #PB_EventType_Resize)

Repeat
  WaitWindowEvent()
Until Event() = #PB_Event_CloseWindow Or Event() = #PB_Event_Menu
<edit>
It's actually not the tab that mis-resizes, but the child editor, i.e. the gagdet attribute / item width/height is incorrect.

There are other related threads:
viewtopic.php?f=23&t=68031
viewtopic.php?f=23&t=65863
but they only address the inital gadget attribute value before any event processing.
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Resize PanelGadget Child (Linux)

Post by mk-soft »

I once put an event cycle in between. So only in the second cycle the size of the gadgets will be adjusted.
It seems that only in the second event cycle the size of panel gadget is returned correctly.

I have a same problem with resize canvas gadget...

Update

Code: Select all

EnableExplicit

Global window, panel, editor1, editor2

Enumeration CustomEventType #PB_EventType_FirstCustomValue
  #MyEventType_Resize
EndEnumeration

Procedure windowSizeHandler()
  Protected ww = WindowWidth(window)
  Protected wh = WindowHeight(window)
  ResizeGadget(panel, 4, 4, ww-8, wh-8)
EndProcedure

Procedure ResizeGadgetHandler()
  If EventType() = #PB_EventType_Resize
    PostEvent(#PB_Event_Gadget, EventWindow(), EventGadget(), #MyEventType_Resize)
  EndIf
EndProcedure

Procedure panelSizeHandler()
  Protected pw = GetGadgetAttribute(panel, #PB_Panel_ItemWidth)
  Protected ph = GetGadgetAttribute(panel, #PB_Panel_ItemHeight)
  ResizeGadget(editor1, 4, 4, pw-8, ph-8)
  ResizeGadget(editor2, 4, 4, pw-8, ph-8)
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, "panel1")
editor1 = EditorGadget(#PB_Any, 1, 1, 100, 100)
AddGadgetItem(panel, -1, "panel2")
editor2 = EditorGadget(#PB_Any, 1, 1, 100, 100)
CloseGadgetList()

AddKeyboardShortcut(window, #PB_Shortcut_Escape, 99)

BindEvent(#PB_Event_SizeWindow, @windowSizeHandler())
BindEvent(#PB_Event_Gadget, @ResizeGadgetHandler())
BindGadgetEvent(panel, @panelSizeHandler(), #MyEventType_Resize)
;BindGadgetEvent(panel, @panelSizeHandler(), #PB_EventType_Resize)

windowSizeHandler()

Repeat
  WaitWindowEvent()
Until Event() = #PB_Event_CloseWindow Or Event() = #PB_Event_Menu
[/size]

P.S. Not work with MacOS!
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Resize PanelGadget Child (Linux)

Post by #NULL »

That works :)
I didn't even try that because I thought the custom events would cut in line before the necessary processing.
The issue with qt and switching tabs is still there though.
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Resize PanelGadget Child (Linux)

Post by mk-soft »

Its a Bug...

If the second panel is active, the size will not be adjusted.
I have outputted the sizes.

Edit: Workaround...

Code: Select all

EnableExplicit

Global window, panel, editor1, editor2

Enumeration CustomEventType #PB_EventType_FirstCustomValue
  #MyEventType_Resize
EndEnumeration

Procedure windowSizeHandler()
  Protected ww = WindowWidth(window)
  Protected wh = WindowHeight(window)
  ResizeGadget(panel, 4, 4, ww-8, wh-8)
EndProcedure

; Workaround #PB_EventType_Resize
Procedure ResizeGadgetHandler()
  If EventType() = #PB_EventType_Resize
    PostEvent(#PB_Event_Gadget, EventWindow(), EventGadget(), #MyEventType_Resize)
  EndIf
EndProcedure

; Workaround #PB_Panel_ItemWidth / Height
Procedure panelSizeHandler()
  Static delta_pw, delta_ph
  If delta_pw = 0
    delta_pw = GadgetWidth(panel) - GetGadgetAttribute(panel, #PB_Panel_ItemWidth)
    delta_ph = GadgetHeight(panel) - GetGadgetAttribute(panel, #PB_Panel_ItemHeight)
  EndIf
  ;Protected pw = GetGadgetAttribute(panel, #PB_Panel_ItemWidth)
  ;Protected ph = GetGadgetAttribute(panel, #PB_Panel_ItemHeight)
  Protected pw = GadgetWidth(panel) - delta_pw
  Protected ph = GadgetHeight(panel) - delta_ph
  
  Debug "Resize " + pw
  ResizeGadget(editor1, 4, 4, pw-8, ph-8)
  ResizeGadget(editor2, 4, 4, pw-8, ph-8)
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, "panel1")
editor1 = EditorGadget(#PB_Any, 1, 1, 100, 100)
SetGadgetColor(editor1, #PB_Gadget_BackColor, $808000)
AddGadgetItem(panel, -1, "panel2")
editor2 = EditorGadget(#PB_Any, 1, 1, 100, 100)
SetGadgetColor(editor2, #PB_Gadget_BackColor, $008080)
CloseGadgetList()

AddKeyboardShortcut(window, #PB_Shortcut_Escape, 99)

BindEvent(#PB_Event_SizeWindow, @windowSizeHandler())
BindEvent(#PB_Event_Gadget, @ResizeGadgetHandler())
BindGadgetEvent(panel, @panelSizeHandler(), #MyEventType_Resize)
;BindGadgetEvent(panel, @panelSizeHandler(), #PB_EventType_Resize)

windowSizeHandler()

Repeat
  WaitWindowEvent()
Until Event() = #PB_Event_CloseWindow Or Event() = #PB_Event_Menu
[/size]
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Resize PanelGadget Child (Linux)

Post by mk-soft »

I have reported the bug
See link: viewtopic.php?f=23&t=71638
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Resize PanelGadget Child (Linux)

Post by #NULL »

Thanks for the workarounds and the reporting.
Post Reply