Resize event in container gadgets

Just starting out? Need help? Post your questions and find answers here.
Webarion
Posts: 7
Joined: Mon Mar 04, 2024 10:47 pm

Resize event in container gadgets

Post by Webarion »

It is not clear to me why the #PB_EventType_Resize event was removed from ContainerGadget, PanelGadget, ScrollAreaGadget, CanvasGadget?
This is very necessary!

Code: Select all

Enumeration
  #Container1
  #Container2
  #Button
  #Splitter
EndEnumeration

Procedure _EventResizeContainer()
  Protected EvType = EventType()
  CompilerIf Defined(PB_EventType_Resize, #PB_Constant)
    If EvType = #PB_EventType_Resize
      ResizeGadget( #Button, 10, GadgetHeight(#Container1)-34, 80, 24 )
    EndIf
  CompilerEndIf
EndProcedure

If OpenWindow(0, 0, 0, 230, 180, "SplitterGadget for Container", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  ContainerGadget(#Container1, 10, 10, 220, 59, #PB_Container_Double ) : CloseGadgetList()
  ContainerGadget(#Container2, 0, 0, 0, 0, #PB_Container_Double ) : CloseGadgetList()
  
  SplitterGadget(#Splitter, 5, 5, 220, 160, #Container1, #Container2, #PB_Splitter_Separator)
  
  OpenGadgetList(#Container1)
  ButtonGadget(#Button, 10, GadgetHeight(#Container1)-34, 80, 24, "Button")
  CloseGadgetList()
  
  BindGadgetEvent(#Container1, @_EventResizeContainer())
  
EndIf
munfraid
Posts: 108
Joined: Sat Mar 24, 2018 1:33 pm

Re: Resize event in container gadgets

Post by munfraid »

Looks like a SB bug.
documentation wrote:
The following event is supported through EventType():

#PB_EventType_Resize: The gadget has been resized.
But the constant is missing:

Code: Select all

Debug #PB_EventType_Resize
Tested on SB 2.51 arm64
the.weavster
Posts: 222
Joined: Sat Mar 01, 2014 3:02 pm

Re: Resize event in container gadgets

Post by the.weavster »

@Webarion
You need to post a bug report ;)
Webarion
Posts: 7
Joined: Mon Mar 04, 2024 10:47 pm

Re: Resize event in container gadgets

Post by Webarion »

munfraid wrote: Tue Mar 05, 2024 10:26 am Looks like a SB bug.
documentation wrote:
The following event is supported through EventType():

#PB_EventType_Resize: The gadget has been resized.
But the constant is missing:

Code: Select all

Debug #PB_EventType_Resize
Tested on SB 2.51 arm64
In the SpiderBasic documentation, #PB_EventType_Resize only exists for ContainerGadget. for other container gadgets, PB_EventType_Resize does not exist in the documentation.
This event does not work at all for container gadgets. I made this request in Bugs Reports.
Webarion
Posts: 7
Joined: Mon Mar 04, 2024 10:47 pm

Re: Resize event in container gadgets

Post by Webarion »

After some thought, I managed to bind #PB_EventType_Resize to the container gadgets. Generic example:

Code: Select all

CompilerIf Not Defined(WBN_Handler_Canvas_Container, #PB_Constant) 
  #WBN_Handler_Canvas_Container = #True
  !window.spider_CanvasGadget = new Proxy( window.spider_CanvasGadget, {
  !  apply(target, that, args) {
  !    var gRet = target(...args);
  !    if( typeof args[5] !== "undefined" && args[5] & 32 ){ // #PB_Canvas_Container
  !      var gObj = (args[0] == -1) ? spider.gadget.objects.Get(gRet) : gRet;
  !      gObj.cContainer = true; 
  !    }
  !    return gRet;
  !  }
  !});
CompilerEndIf
CompilerIf Not Defined(PB_EventType_Resize, #PB_Constant) 
  #PB_EventType_Resize = 6
  !window.spider_BindGadgetEvent = new Proxy( window.spider_BindGadgetEvent, {
  !  apply(target, that, args) {
  !    target(...args); 
  !    "undefined" === typeof args[2] && (args[2] = -1);
  !    if( args[2] == 6 || args[2] == -1 ){
  !      var gObj = spider.gadget.objects.Get(args[0]);
  !      if(gObj.type == 11 || gObj.type == 28 || gObj.type == 16 || ( gObj.type == 33 && typeof gObj.cContainer !== "undefined" ) ){
  !        gObj.Resize = new Proxy( gObj.Resize, {
  !          apply(target, that, args){
  !            target(...args);
  !            gObj.isDisabled || spider.event.Send(1, gObj.windowId, gObj.id, 6);
  !          }
  !        });
  !      }
  !    }
  !  }
  !});
CompilerEndIf

;- EXAMPLE
CompilerIf #PB_Compiler_IsMainFile
  
  Enumeration
    #Container1
    #Container2
    #Button
    #Splitter
  EndEnumeration
  
  Procedure _EventResizeContainer()
    If EventType() = #PB_EventType_Resize
      ResizeGadget( #Button, #PB_Ignore, GadgetHeight(#Container1)-34, #PB_Ignore, #PB_Ignore )
    EndIf
  EndProcedure
  
  If OpenWindow(0, 0, 0, 400, 300, "SpiderBasic: #PB_EventType_Resize for container gadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    
    ContainerGadget(#Container1, 10, 10, 380, 59, #PB_Container_Double ) : CloseGadgetList()
    ContainerGadget(#Container2, 0, 0, 0, 0, #PB_Container_Double ) : CloseGadgetList()
    
    SplitterGadget(#Splitter, 10, 10, 380, 275, #Container1, #Container2, #PB_Splitter_Separator)
    
    OpenGadgetList(#Container1)
    ButtonGadget(#Button, 10, GadgetHeight(#Container1)-34, 80, 24, "Button")
    CloseGadgetList()
    
    BindGadgetEvent( #Container1, @_EventResizeContainer(), #PB_EventType_Resize )
    
  EndIf
  
CompilerEndIf
Post Reply