It is currently Mon Sep 23, 2019 4:42 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Resize PanelGadget Child (Linux)
PostPosted: Wed Oct 24, 2018 1:34 pm 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1052
Location: right here
(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:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Resize PanelGadget Child (Linux)
PostPosted: Wed Oct 24, 2018 2:58 pm 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1052
Location: right here
some correction..
Code:
editor = PanelGadget(..)

should be
Code:
editor = EditorGadget(..)

but the problems persist.


Top
 Profile  
Reply with quote  
 Post subject: Re: Resize PanelGadget Child (Linux)
PostPosted: Wed Oct 24, 2018 3:02 pm 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1052
Location: right here
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Resize PanelGadget Child (Linux)
PostPosted: Wed Oct 24, 2018 10:27 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1649
Location: Germany
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Resize PanelGadget Child (Linux)
PostPosted: Sat Oct 27, 2018 10:35 am 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1052
Location: right here
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:
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Resize PanelGadget Child (Linux)
PostPosted: Sat Oct 27, 2018 10:47 am 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1052
Location: right here
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:
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:
https://www.purebasic.fr/english/viewtopic.php?f=23&t=68031
https://www.purebasic.fr/english/viewtopic.php?f=23&t=65863
but they only address the inital gadget attribute value before any event processing.


Top
 Profile  
Reply with quote  
 Post subject: Re: Resize PanelGadget Child (Linux)
PostPosted: Sat Oct 27, 2018 2:34 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1915
Location: Germany
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:
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


P.S. Not work with MacOS!

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Resize PanelGadget Child (Linux)
PostPosted: Sat Oct 27, 2018 5:27 pm 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1052
Location: right here
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Resize PanelGadget Child (Linux)
PostPosted: Sun Oct 28, 2018 12:26 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1915
Location: Germany
Its a Bug...

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

Edit: Workaround...
Code:
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

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Resize PanelGadget Child (Linux)
PostPosted: Sun Oct 28, 2018 1:13 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1915
Location: Germany
I have reported the bug
See link: viewtopic.php?f=23&t=71638

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Resize PanelGadget Child (Linux)
PostPosted: Sun Nov 04, 2018 12:49 pm 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1052
Location: right here
Thanks for the workarounds and the reporting.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Denis and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye