ResizeGadgets: Auto-resize or auto-move your gadgets.

Share your advanced PureBasic knowledge/code with the community.
User avatar
USCode
Addict
Addict
Posts: 912
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle, USA

ResizeGadgets: Auto-resize or auto-move your gadgets.

Post by USCode »

* Occasionally I update this code in response to changes to PB. Look for the best version below that works for the version of PB you are currently using. See comments in this thread for other suggested improvements/changes, etc.

- RS_ResizeGadgets -
One of the things I really liked about Borland Delphi was the "anchor" feature which allows you to "lock" one side of a widget to that side of a resizable window. So in essence, when the window was resized by either the user or programmatically, you could get your widgets to react accordingly. Your widgets could stay in place, move, stretch, whatever you wanted the behavior to be. I missed having this automatic behavior in PureBasic...

I haven't been able to find any user or PB routines out there which gave me this functionality, so I wrote a couple of simple routines to take care of it for me and I'd like to share them with you here. I'm very new to PureBasic so I'm sure lots of you wizards out there could improve upon this or offer some helpful suggestions. Any feedback is appreciated.

Essentially, all you have to do is 3 simple changes: IncludeFile my RS_ResizeGadgets.pb source file, RS_Register your gadgets specifying which side(s) you want to lock and call RS_Resize in the Event Loop. See the example below for how to use the 2 resize procedures, the required parameters and various combinations of "locking" you can do.

When you run the example, grab the lower right corner of the window and move that corner around, resizing the window in all various directions. You'll see how you can get the gadgets to behave.

Be sure you have also saved the RS_ResizeGadgets.pb source file listed below as well.

RS_ResizeGadgets for PB 4.5+

Code: Select all

;
; RS_ResizeGadgets.pb
; Automatically Resize PureBasic Gadgets
; Author: USCode
;
; September 13, 2010 - Added With/ForEach statements, 'Window' Unregister, longs to integers
; February 19, 2006 - Updated for PureBasic 4.0.
; April 15, 2004 - Original version for 3.9x.
;
; To use:
; - Include this source file.
; - Call RS_Register ONCE for EACH Gadget to be resized, specifying side locks.
; - Call RS_Resize in the event loop, specifying Event ID and Event Window ID.
;

; DECLARATIONS

; Constants
#RS_All = -1

; Structures
Structure RS_gadget_struct
  Window.i      
  Gadget.i      
  Left.i   
  Top.i         
  Right.i       
  Bottom.i      
  Lock_left.b
  Lock_top.b
  Lock_right.b
  Lock_bottom.b  
EndStructure      

Global NewList RS_Gadgets.RS_gadget_struct()

; PROCEDURES

; RS_Register - Register gadget to be resized and how to resize.
; Specify #TRUE for each side of the gadget you want to LOCK, else #FALSE.
; Parameters:  WindowID (integer), GadgetID (integer), Left (boolean), Top (boolean), Right (boolean), Bottom (boolean).
Procedure RS_Register(RS_window.i, RS_gadget.i, RS_left.b, RS_top.b, RS_right.b, RS_bottom.b)

  AddElement(RS_Gadgets())
  
  With RS_Gadgets()
  
    \Gadget = RS_gadget
    \Window = RS_window
    \Lock_left = RS_left
    \Lock_top = RS_top
    \Lock_right = RS_right
    \Lock_bottom = RS_bottom
  
    If RS_left = #False
      \Left = WindowWidth(RS_window) - GadgetX(RS_gadget)
    EndIf
    
    If RS_top = #False
      \Top = WindowHeight(RS_window) - GadgetY(RS_gadget) 
    EndIf 
    
    If RS_right = #True
      \Right = WindowWidth(RS_window) - (GadgetX(RS_gadget) + GadgetWidth(RS_gadget))
    EndIf
    
    If RS_bottom = #True
      \Bottom = WindowHeight(RS_window) - (GadgetY(RS_gadget) + GadgetHeight(RS_gadget))
    EndIf
  
  EndWith

EndProcedure

; RS_Unregister - Unregister gadget from resizing.
; Parameters: Window ID (integer), Gadget ID (integer).  
; Gadget ID = #RS_All to unregister all gadgets for Window ID.
Procedure RS_Unregister(RS_window.i, RS_gadget.i)

  ResetList(RS_Gadgets())

  ForEach RS_Gadgets()

    If RS_Gadgets()\Window = RS_window And (RS_Gadgets()\Gadget = RS_gadget Or RS_gadget = #RS_All)
      DeleteElement(RS_Gadgets())
    EndIf
    
  Next
  
EndProcedure

; RS_Resize - Resize all registered gadgets for the resizing window.
; Parameters: Event ID (integer), Event Window ID (integer).
Procedure RS_Resize(RS_Event.i, RS_window.i)
  
  If RS_Event = #PB_Event_SizeWindow And ListSize(RS_Gadgets()) > 0
 
    Define.i RS_gadget, RS_size, RS_x, RS_y, RS_w, RS_h
    
    ForEach RS_Gadgets()
      
      If RS_Gadgets()\Window = RS_window
        
        With RS_Gadgets()
          
          RS_gadget = \Gadget
          
          RS_x = GadgetX(RS_gadget)
          RS_y = GadgetY(RS_gadget)
          RS_w = #PB_Ignore:RS_h = #PB_Ignore 
          
          If \Lock_left = #False   
            RS_x = (WindowWidth(RS_window) - \Left)
          EndIf
              
          If \Lock_top = #False
            RS_y = (WindowHeight(RS_window) - \Top)
          EndIf        
                  
          If \Lock_right = #True
            RS_w = (WindowWidth(RS_window) - RS_x) - \Right
          EndIf
        
          If \Lock_bottom = #True
            RS_h = (WindowHeight(RS_window) - RS_y) - \Bottom
          EndIf        
          
          ResizeGadget(RS_gadget, RS_x, RS_y, RS_w, RS_h)
        
        EndWith
        
      EndIf
      
    Next

  EndIf 

EndProcedure

; RS_ResizeGadgets.pb
RS_ResizeGadgets for PB 4.0:

Code: Select all

;
; RS_ResizeGadgets.pb
; Automatically Resize PureBasic Gadgets
; Author: USCode
; February 19, 2006 - Updated for PureBasic 4.0.
; April 15, 2004 - Original version for 3.9x.
;
; To use:
; - Include this source file.
; - Call RS_Register ONCE for EACH Gadget to be resized, specifying side locks.
; - Call RS_Resize in the event loop, specifying Event ID and Event Window ID.
;

;DECLARATIONS

Structure RS_gadget_struct
  Window.l      
  Gadget.l      
  Left.l   
  Top.l         
  Right.l       
  Bottom.l      
  Lock_left.b
  Lock_top.b
  Lock_right.b
  Lock_bottom.b  
EndStructure      

Global NewList RS_Gadgets.RS_gadget_struct()


;PROCEDURES

; RS_Register - Register gadget to be resized and how to resize.
; Specify #TRUE for each side of the gadget you want to LOCK, else #FALSE.
; Parameters:  WindowID (long), GadgetID (long), Left (boolean), Top (boolean), Right (boolean), Bottom (boolean).
Procedure RS_Register(RS_window.l, RS_gadget.l, RS_left.b, RS_top.b, RS_right.b, RS_bottom.b)

  AddElement(RS_Gadgets())

  RS_Gadgets()\Gadget = RS_gadget
  RS_Gadgets()\Window = RS_window
  RS_Gadgets()\Lock_left = RS_left
  RS_Gadgets()\Lock_top = RS_top
  RS_Gadgets()\Lock_right = RS_right
  RS_Gadgets()\Lock_bottom = RS_bottom

  If RS_left = #False
    RS_Gadgets()\Left = WindowWidth(RS_window) - GadgetX(RS_gadget)
  EndIf
  
  If RS_top = #False
    RS_Gadgets()\Top = WindowHeight(RS_window) - GadgetY(RS_gadget) 
  EndIf 
  
  If RS_right = #True
    RS_Gadgets()\Right = WindowWidth(RS_window) - (GadgetX(RS_gadget) + GadgetWidth(RS_gadget))
  EndIf
  
  If RS_bottom = #True
    RS_Gadgets()\Bottom = WindowHeight(RS_window) - (GadgetY(RS_gadget) + GadgetHeight(RS_gadget))
  EndIf

EndProcedure


; RS_Unregister - Unregister gadget from resizing
Procedure RS_Unregister(RS_window.l, RS_gadget.l)

  ResetList(RS_Gadgets())

  While NextElement(RS_Gadgets())

    If (RS_Gadgets()\Window = RS_window) And (RS_Gadgets()\Gadget = RS_gadget)
      DeleteElement(RS_Gadgets())
    EndIf

  Wend
  
EndProcedure


; RS_Resize - Resize all registered gadgets for the resizing window.
; Parameters: Event ID (long), Event Window ID (long).
Procedure RS_Resize(RS_Event.l, RS_window.l)
  
  If RS_Event = #PB_Event_SizeWindow And CountList(RS_Gadgets()) > 0
 
    RS_gadget.l:RS_size.l:RS_x.l:RS_y.l:RS_w.l:RS_h.l
    
    ResetList(RS_Gadgets())
    While NextElement(RS_Gadgets())
      If RS_Gadgets()\Window = RS_window
      
        RS_gadget = RS_Gadgets()\Gadget
        
        RS_x = GadgetX(RS_gadget)
        RS_y = GadgetY(RS_gadget)
        RS_w = #PB_Ignore:RS_h = #PB_Ignore 
        
        If RS_Gadgets()\Lock_left = #False   
          RS_x = (WindowWidth(RS_window) - RS_Gadgets()\Left)
        EndIf
            
        If RS_Gadgets()\Lock_top = #False
          RS_y = (WindowHeight(RS_window) - RS_Gadgets()\Top)
        EndIf        
                
        If RS_Gadgets()\Lock_right = #True
          RS_w = (WindowWidth(RS_window) - RS_x) - RS_Gadgets()\Right
        EndIf
      
        If RS_Gadgets()\Lock_bottom = #True
          RS_h = (WindowHeight(RS_window) - RS_y) - RS_Gadgets()\Bottom
        EndIf        
        
        ResizeGadget(RS_gadget, RS_x, RS_y, RS_w, RS_h)
        
      EndIf
    Wend  

  EndIf 

EndProcedure

; RS_ResizeGadgets.pb
ResizeTest.pb for PB 4.0

Code: Select all

;
; RS_ResizeGadgets test
;

;- Window Constants
;
Enumeration
  #Window_0
EndEnumeration

;- Gadget Constants
;
Enumeration
  #Button_0
  #Button_1
  #Button_2
  #Button_3
  #Listview_0
EndEnumeration

Procedure Open_Window_0()
  If OpenWindow(#Window_0, 358, 178, 300, 300, "Resize Test",  #PB_Window_SizeGadget | #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered )
    If CreateGadgetList(WindowID(#Window_0))
      ButtonGadget(#Button_0, 5, 5, 50, 25, "Button0")
      ButtonGadget(#Button_1, 245, 5, 50, 25, "Button1")
      ButtonGadget(#Button_2, 5, 270, 50, 25, "Button2")
      ButtonGadget(#Button_3, 245, 270, 50, 25, "Button3")
      ListViewGadget(#Listview_0, 55, 30, 190, 240)     
    EndIf
  EndIf
EndProcedure

Open_Window_0()

; (1) RESIZE INCLUDE
IncludeFile "C:\Backup\Software\PureBasic\RS_ResizeGadgets\RS_ResizeGadgets.pb"       
; (2) REGISTER RESIZE GADGETS   
; Parameters:  Parent WindowID, GadgetID, Lock Left, Lock Top, Lock Right, Lock Bottom)
RS_Register(#Window_0,#Button_0,#True,#True,#False,#False) 
RS_Register(#Window_0,#Button_1,#False,#True,#True,#False)
RS_Register(#Window_0,#Button_2,#True,#False,#False,#True)
RS_Register(#Window_0,#Button_3,#False,#False,#True,#True)
RS_Register(#Window_0,#Listview_0,#True,#True,#True,#True)
;

Repeat
 
  Event = WaitWindowEvent()

; (3) RESIZE GADGETS 
  RS_Resize(Event,EventWindow())                         

  If Event = #PB_Event_Gadget
   
    GadgetID = EventGadget()
   
    If GadgetID = #Button_0
      Debug "GadgetID: #Button_0"
     
    ElseIf GadgetID = #Button_1
      Debug "GadgetID: #Button_1"
     
    ElseIf GadgetID = #Button_2
      Debug "GadgetID: #Button_2"
     
    ElseIf GadgetID = #Button_3
      Debug "GadgetID: #Button_3"
     
    ElseIf GadgetID = #Listview_0
      Debug "GadgetID: #Listview_0"
     
    EndIf
   
  EndIf
 
Until Event = #PB_Event_CloseWindow

End
;
ResizeTest.pb for PB 3.9x

Code: Select all

;
; RS_ResizeGadgets test
;

;- Window Constants
;
Enumeration
  #Window_0
EndEnumeration

;- Gadget Constants
;
Enumeration
  #Button_0
  #Button_1
  #Button_2
  #Button_3
  #Listview_0
EndEnumeration

Procedure Open_Window_0()
  If OpenWindow(#Window_0, 358, 178, 300, 300,  #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered , "Resize Test")
    If CreateGadgetList(WindowID())
      ButtonGadget(#Button_0, 5, 5, 50, 25, "Button0")
      ButtonGadget(#Button_1, 245, 5, 50, 25, "Button1")
      ButtonGadget(#Button_2, 5, 270, 50, 25, "Button2")
      ButtonGadget(#Button_3, 245, 270, 50, 25, "Button3")
      ListViewGadget(#Listview_0, 55, 30, 190, 240)      
    EndIf
  EndIf
EndProcedure

Open_Window_0()

; (1) RESIZE INCLUDE
IncludeFile "RS_ResizeGadgets.pb"       
; (2) REGISTER RESIZE GADGETS    
; Parameters:  Parent WindowID, GadgetID, Lock Left, Lock Top, Lock Right, Lock Bottom)
RS_Register(#Window_0,#Button_0,#TRUE,#TRUE,#FALSE,#FALSE)  
RS_Register(#Window_0,#Button_1,#FALSE,#TRUE,#TRUE,#FALSE)
RS_Register(#Window_0,#Button_2,#TRUE,#FALSE,#FALSE,#TRUE)
RS_Register(#Window_0,#Button_3,#FALSE,#FALSE,#TRUE,#TRUE)
RS_Register(#Window_0,#Listview_0,#TRUE,#TRUE,#TRUE,#TRUE)
;

Repeat
  
  Event = WaitWindowEvent()

; (3) RESIZE GADGETS  
  RS_Resize(Event,EventWindowID())                          

  If Event = #PB_EventGadget
    
    GadgetID = EventGadgetID()
    
    If GadgetID = #Button_0
      Debug "GadgetID: #Button_0"
      
    ElseIf GadgetID = #Button_1
      Debug "GadgetID: #Button_1"
      
    ElseIf GadgetID = #Button_2
      Debug "GadgetID: #Button_2"
      
    ElseIf GadgetID = #Button_3
      Debug "GadgetID: #Button_3"
      
    ElseIf GadgetID = #Listview_0
      Debug "GadgetID: #Listview_0"
      
    EndIf
    
  EndIf
  
Until Event = #PB_EventCloseWindow

End
;

RS_ResizeGadgets.pb for PB 3.9x

Code: Select all

;
;
; RS_ResizeGadgets.pb
; Automatically Resize PureBasic Gadgets
; Author: USCode
; Date: April 15, 2004
;
; To use:
; - Include this source file.
; - Call RS_Register ONCE for EACH Gadget to be resized, specifiying side locks.
; - Call RS_Resize in the event loop, specifying EventID and EventWindowID.
;

;DECLARATIONS

Structure RS_gadget_struct
  Window.l      
  Gadget.l      
  Left.w        
  Top.w         
  Right.w       
  Bottom.w      
  Lock_left.b
  Lock_top.b
  Lock_right.b
  Lock_bottom.b  
EndStructure

NewList RS_Gadgets.RS_gadget_struct()


;PROCEDURES

; RS_Register - Register gadget to be resized and how to resize.
; Specify #TRUE for each side of the gadget you want to LOCK, else #FALSE.
; Parameters:  WindowID (long), GadgetID (long), Left (boolean), Top (boolean), Right (boolean), Bottom (boolean).
Procedure RS_Register(RS_window.l, RS_gadget.l, RS_left.b, RS_top.b, RS_right.b, RS_bottom.b)

  AddElement(RS_Gadgets())

  RS_Gadgets()\Gadget = RS_gadget
  RS_Gadgets()\Window = RS_window
  RS_Gadgets()\Lock_left = RS_left
  RS_Gadgets()\Lock_top = RS_top
  RS_Gadgets()\Lock_right = RS_right
  RS_Gadgets()\Lock_bottom = RS_bottom

  UseWindow(RS_window)

  If RS_left = #FALSE
    RS_Gadgets()\Left = WindowWidth() - GadgetX(RS_gadget)
  EndIf
  
  If RS_top = #FALSE
    RS_Gadgets()\Top = WindowHeight() - GadgetY(RS_gadget) 
  EndIf 
  
  If RS_right = #TRUE
    RS_Gadgets()\Right = WindowWidth() - (GadgetX(RS_gadget) + GadgetWidth(RS_gadget))
  EndIf
  
  If RS_bottom = #TRUE
    RS_Gadgets()\Bottom = WindowHeight() - (GadgetY(RS_gadget) + GadgetHeight(RS_gadget))
  EndIf

EndProcedure


; RS_Unregister - Contributed by "FloHimself". 
Procedure RS_Unregister(RS_window.l, RS_gadget.l)
  ResetList(RS_Gadgets())
  While NextElement(RS_Gadgets())
    If (RS_Gadgets()\Window = RS_window) And (RS_Gadgets()\Gadget = RS_gadget)
      DeleteElement(RS_Gadgets())
    EndIf
  Wend
EndProcedure


; RS_Resize - Resize all registered gadgets for the resizing window.
; Parameters: Event ID (long), Event Window ID (long).
Procedure RS_Resize(RS_Event.l, RS_window.l)
  
  If RS_Event = #PB_Event_SizeWindow And CountList(RS_Gadgets()) > 0
 
    RS_gadget.l:RS_size.w:RS_x.w:RS_y.w:RS_w.l:RS_h.w
    
    ResetList(RS_Gadgets())
    While NextElement(RS_Gadgets())
      If RS_Gadgets()\Window = RS_window
      
        UseWindow(RS_window)
        RS_gadget = RS_Gadgets()\Gadget
        
        RS_x = GadgetX(RS_gadget)
        RS_y = GadgetY(RS_gadget)
        RS_w = -1:RS_h = -1
        
        If RS_Gadgets()\Lock_left = #FALSE   
          RS_x = (WindowWidth() - RS_Gadgets()\Left)
        EndIf
            
        If RS_Gadgets()\Lock_top = #FALSE
          RS_y = (WindowHeight() - RS_Gadgets()\Top)
        EndIf        
                
        If RS_Gadgets()\Lock_right = #TRUE
          RS_w = (WindowWidth() - RS_x) - RS_Gadgets()\Right
        EndIf
      
        If RS_Gadgets()\Lock_bottom = #TRUE
          RS_h = (WindowHeight() - RS_y) - RS_Gadgets()\Bottom
        EndIf        
        
        ResizeGadget(RS_gadget, RS_x, RS_y, RS_w, RS_h)
        
      EndIf
    Wend  

  EndIf 

EndProcedure

; RS_ResizeGadgets.pb
This was written only in PureBasic code so it should run on all supported platforms.
I've run a test case with 100 gadgets on 1 window and it ran very fast.

Please let me know if you have any questions/suggestions/comments, etc.

Enjoy.

Thanks,
USCode
Last edited by USCode on Sat Nov 06, 2021 1:38 am, edited 24 times in total.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

i was considering something among the same lines, using a procedure that is called in a callback or event section to react on a resize event and then resize all gadgets depending on the new settings :-)

this saves me some thinking :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

@ USCode
8)
IMHO it's too neat to let it stay under GENERAL DISCUSSION :wink:
Thanks for sharing...

@ Admin
8O
Could somebody please move this topic to TIPS&TRICKS :?:
Thanks for moving...
User avatar
USCode
Addict
Addict
Posts: 912
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle, USA

Useful?

Post by USCode »

Thanks fsw, I hope folks find it useful. :D
I like to make most of my windows resizable so the user can customize a size that works for them and their screen resolution, etc. but that entails having controls resize/move themselves to take advantage of the additional space. These 2 routines make it easy AND automatic!
User avatar
USCode
Addict
Addict
Posts: 912
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle, USA

Updated - April 15, 2004

Post by USCode »

:arrow: Updated to handle gadgets initially placed directly up to the edges of the window, i.e. distance between gadget edge and window = 0.
Updated source RS_ResizeGagets.pb code placed above in original post.
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

PureVision has integrated sizing, moving and docking for some time - it's done with a userlib and is super fast..

Thanks for sharing!
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
User avatar
USCode
Addict
Addict
Posts: 912
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle, USA

Resizing

Post by USCode »

PureVision has integrated sizing, moving and docking for some time - it's done with a userlib and is super fast..
Yeah but this one is free! It's speed isn't too shabby either... :wink:
User avatar
cabaptista
User
User
Posts: 86
Joined: Sun Nov 30, 2003 11:42 pm
Location: Lisboa, Portugal

Thanks

Post by cabaptista »

USCode,

Thanks for sharing this code with us.

Many others should follow your example, starting by me. :D

Keep the good working.
User avatar
USCode
Addict
Addict
Posts: 912
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle, USA

Practical Example

Post by USCode »

:arrow: FYI - Thought I'd provide here another more practical example on using RS_ResizeGadgets, using a simplifed version of Fred's Mini Web Browser as an example. 3 easy steps and the rest is automatic.

Code: Select all

; WebBrowser

;RESIZE step 1
IncludeFile "RS_ResizeGadgets.pb"

If OpenWindow(0, 0, 0, 500, 300, #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget, "Mini-Browser")
      
  CreateGadgetList(WindowID())
    ButtonGadget(1,   0, 0, 50, 25, "Back")
    ButtonGadget(2,  50, 0, 50, 25, "Next")
    ButtonGadget(3, 100, 0, 50, 25, "Stop")
  
    StringGadget(4, 150, 3, 325, 20, "http://")
    
    ButtonGadget(5, 475, 0, 25 , 25, "Go")
    
    Frame3DGadget(6, 1, 30, 500, 2, "", 2) 
  
    If WebGadget(10, 5, 35, 490, 260, "") = 0 : MessageRequester("Error", "ATL.dll not found", 0) : End : EndIf
  
  AddKeyboardShortcut(0, #PB_Shortcut_Return, 0)
  
;RESIZE step 2
  RS_Register(0,4,#TRUE,#TRUE,#TRUE,#FALSE)
  RS_Register(0,5,#FALSE,#TRUE,#TRUE,#FALSE)
  RS_Register(0,6,#TRUE,#TRUE,#TRUE,#FALSE)
  RS_Register(0,10,#TRUE,#TRUE,#TRUE,#TRUE) 
  
  Repeat
    Event = WaitWindowEvent()
    
;RESIZE step 3 ... DONE!    
    RS_Resize(Event,EventWindowID())
    
    Select Event
      Case #PB_Event_Gadget
      
        Select EventGadgetID()
          Case 1
            SetGadgetState(10, #PB_Web_Back)
          
          Case 2
            SetGadgetState(10, #PB_Web_Forward)
          
          Case 3
            SetGadgetState(10, #PB_Web_Stop)
          
          Case 5
            SetGadgetText(10, GetGadgetText(4))
            
        EndSelect      
      
      Case #PB_Event_Menu 
        SetGadgetText(10, GetGadgetText(4))
      
    EndSelect
      
  Until Event = #PB_Event_CloseWindow
   
EndIf
Berikco
Administrator
Administrator
Posts: 1326
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Re: Auto-resize or auto-move your gadgets.

Post by Berikco »

USCode wrote: :idea: Ideally, it'd be nice if the Visual Designer gave each gadget 4 checkbox flags: lock left, lock top, lock right and lock bottom. Then it could easily autogenerate the necessary code to call these routines to do the Auto-resizing for us. ;-) ;-)
Very nice work USCode :)

With your permission, i'l include this in Visual Designer.
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

Indeed, it doesn't work under 3.81, even if it compiles without error. What is it, that makes this code 3.90 specific? I haven't yet installed my update....
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
Berikco
Administrator
Administrator
Posts: 1326
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post by Berikco »

The #PB_EventSizeWindow event is now working correct in 3.90

Code: Select all

If RS_Event = #PB_EventSizeWindow And CountList(RS_Gadgets()) > 0
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

Merci/bedankt(?) Berikco, for the clarification.

so, I've taken the plunge and installed the 3.90 update. After that, I used the 'smart update' to get the latest corrections as well. Works like a charm!

The gadget resizing code posted above works fine. I can see why you'd want to include that in VD...
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
User avatar
USCode
Addict
Addict
Posts: 912
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle, USA

Permission granted!

Post by USCode »

With your permission, i'l include this in Visual Designer.
Berikco,
Please do, that'd be great! :D
Thanks!
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

great!

(hey berikco, you have my premission to add toolbars as well :-))
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Post Reply