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

Share your advanced PureBasic knowledge/code with the community.
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

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

Post by infratec »

Hi,

it happens with the ResizeGadget().
Maybe that's a PB bug.

You can see this if you replace

Code: Select all

RS_Resize(Event, EventWindow())
with

Code: Select all

ResizeGadget(#Button_0, 5, 5, 80, 40)
It happens only for editable ComboBoxes.

Btw. if you use

Code: Select all

SetGadgetState(i, 0)
instead of

Code: Select all

SetGadgetText(i,"Hi")
The problem disappears

Bernd
User avatar
Michael Vogel
Addict
Addict
Posts: 2680
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

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

Post by Michael Vogel »

The problem is also seen, when the entered text (by using the keyboard) is identical with any combo gadget list entry. I have only used SetGadgetText to simulate this.

Code: Select all

; Define

	#WinW=720
	#WinH=552
	#WinZ=400

	Global WinID

	Enumeration
		#StrName;			0
		#StrExt;				1
		#StrOutput;			2
		#WinID
		#Frm01
		#Frm02
		#Frm03
		#TxtInfo
		#TxtName
		#TxtExt
		#TxtOutput
		#StrInfo
		#TxtSearch
		#TxtReplace
		#FlgOutCase
		#FlgFirst
		#FlgNameOnly
		#FlgCase
		#FlgAll
		#FlgDate
		#List
		#ButRename
		#ButClose
		#ButProfile
		#ButFilter
		#TxtWriteName
		#TxtWriteExt
		#StrSearch
		#StrReplace
		#StrWriteName;		\
		#StrWriteExt ;		/
	EndEnumeration

	Enumeration
		#ListPath
		#ListOldName
		#ListNewName
		#ListSize
		#ListDate
		#ListState
	EndEnumeration

; EndDefine

Procedure Events()

	Protected x,y,n,m

	If EventWindow()=#WinID
		x=WindowWidth(#WinID)
		y=WindowHeight(#WinID)
		If GadgetWidth(#TxtInfo)=x
			ResizeGadget(#List,#PB_Ignore,#PB_Ignore,#PB_Ignore,y-262)
			ResizeGadget(#TxtInfo,#PB_Ignore,y-22,#PB_Ignore,#PB_Ignore)
			ResizeGadget(#StrInfo,#PB_Ignore,y-18,#PB_Ignore,#PB_Ignore)
		Else

			SendMessage_(WindowID(#WinID),#WM_SETREDRAW,#False,0);		SPEEDUP (WINDOWS)

			n=(x-#WinW)/5
			ResizeGadget(#List,#PB_Ignore,#PB_Ignore,x-26,y-262)
			ResizeGadget(#TxtInfo,#PB_Ignore,y-22,x,#PB_Ignore)
			ResizeGadget(#StrInfo,#PB_Ignore,y-18,#PB_Ignore,#PB_Ignore)

			y=n<<1
			m=n<<2
			ResizeGadget(#Frm01,#PB_Ignore,#PB_Ignore,565+m,#PB_Ignore)
			ResizeGadget(#Frm02,#PB_Ignore,#PB_Ignore,565+m,#PB_Ignore)
			ResizeGadget(#Frm03,#PB_Ignore,#PB_Ignore,x-26,#PB_Ignore)

			x=y-n>>2
			ResizeGadget(#StrName,#PB_Ignore,#PB_Ignore,207+x,#PB_Ignore);
			ResizeGadget(#StrOutput,#PB_Ignore,#PB_Ignore,207+x,#PB_Ignore);
			ResizeGadget(#TxtExt,345+y,#PB_Ignore,#PB_Ignore,#PB_Ignore);
			ResizeGadget(#StrExt,430+y,#PB_Ignore,125+x,#PB_Ignore);
			ResizeGadget(#FlgOutCase,346+y,#PB_Ignore,#PB_Ignore,#PB_Ignore);

			ResizeGadget(#StrSearch,#PB_Ignore,#PB_Ignore,207+x,#PB_Ignore);
			ResizeGadget(#StrReplace,#PB_Ignore,#PB_Ignore,207+x,#PB_Ignore);
			ResizeGadget(#FlgFirst,346+y,#PB_Ignore,#PB_Ignore,#PB_Ignore);
			ResizeGadget(#FlgNameOnly,465+y+n,#PB_Ignore,#PB_Ignore,#PB_Ignore);
			ResizeGadget(#FlgCase,346+y,#PB_Ignore,#PB_Ignore,#PB_Ignore);
			ResizeGadget(#FlgAll,346+y,#PB_Ignore,#PB_Ignore,#PB_Ignore);

			ResizeGadget(#StrWriteName,#PB_Ignore,#PB_Ignore,135+n,#PB_Ignore);
			ResizeGadget(#TxtWriteExt,275+y,#PB_Ignore,#PB_Ignore,#PB_Ignore);
			ResizeGadget(#StrWriteExt,356+y,#PB_Ignore,135+n,#PB_Ignore);
			ResizeGadget(#FlgDate,550+x+y+n,#PB_Ignore,#PB_Ignore,#PB_Ignore);

			ResizeGadget(#ButRename,585+m,#PB_Ignore,115+n,#PB_Ignore);
			ResizeGadget(#ButClose,585+m,#PB_Ignore,115+n,#PB_Ignore);
			ResizeGadget(#ButProfile,585+m,#PB_Ignore,115+n,#PB_Ignore);
			ResizeGadget(#ButFilter,585+m,#PB_Ignore,115+n,#PB_Ignore) ;

			SetGadgetItemAttribute(#List,#PB_Ignore,#PB_ListIcon_ColumnWidth,210+y,#ListOldName)
			SetGadgetItemAttribute(#List,#PB_Ignore,#PB_ListIcon_ColumnWidth,210+y,#ListNewName)
			SetGadgetItemAttribute(#List,#PB_Ignore,#PB_ListIcon_ColumnWidth,78+n,#ListState)

			SendMessage_(WindowID(#WinID),#WM_SETREDRAW,#True,0);					SPEEDUP (WINDOWS)
			RedrawWindow_(WindowID(#WinID),#Null,#Null,#RDW_INVALIDATE|#RDW_ERASE);	SPEEDUP (WINDOWS)

		EndIf
	EndIf

EndProcedure
Procedure Init()

	Protected i
	WinID=OpenWindow(#WinID,0,0,#WinW,#WinH,"",#WS_SYSMENU|#PB_Window_ScreenCentered|#PB_Window_Invisible|#PB_Window_SizeGadget|#PB_Window_MaximizeGadget|#PB_Window_MinimizeGadget)

	FrameGadget(#Frm01,10,10,560,72,"A")
	TextGadget(#TxtName,20,30,60,20,"B:",#SS_CENTERIMAGE)
	ComboBoxGadget(#StrName,105,29,207,22,#PB_ComboBox_Editable)
	TextGadget(#TxtExt,345,30,75,20,"C:",#SS_CENTERIMAGE)
	ComboBoxGadget(#StrExt,430,29,125,22,#PB_ComboBox_Editable)
	TextGadget(#TxtOutput,20,55,60,20,"D:",#SS_CENTERIMAGE)
	ComboBoxGadget(#StrOutput,105,54,207,22,#PB_ComboBox_Editable)
	CheckBoxGadget(#FlgOutCase,346,55,175,22," E")

	FrameGadget(#Frm02,10,90,560,72,"F")
	TextGadget(#TxtSearch,20,110,100,20,"G:",#SS_CENTERIMAGE)
	ComboBoxGadget(#StrSearch,105,109,207,22,#PB_ComboBox_Editable)
	TextGadget(#TxtReplace,20,135,100,20,"H:",#SS_CENTERIMAGE)
	ComboBoxGadget(#StrReplace,105,134,207,22,#PB_ComboBox_Editable)
	CheckBoxGadget(#FlgFirst,346,104,109,18," I")
	CheckBoxGadget(#FlgNameOnly,465,104,100,18," J")
	CheckBoxGadget(#FlgCase,346,122,175,18," K")
	CheckBoxGadget(#FlgAll,346,140,175,18," L")

	FrameGadget(#Frm03,10,168,694,48,"M")
	TextGadget(#TxtWriteName,20,188,75,20,"N:",#SS_CENTERIMAGE)
	ComboBoxGadget(#StrWriteName,105,188,135,20)
	TextGadget(#TxtWriteExt,275,188,70,20,"O:",#SS_CENTERIMAGE)
	ComboBoxGadget(#StrWriteExt,346,188,135,20)
	CheckBoxGadget(#FlgDate,550,188,140,18," P")

	ListIconGadget(#List,10,230,694,285," ·",20,#PB_ListIcon_FullRowSelect|#PB_ListIcon_GridLines)
	AddGadgetColumn(#List,#ListOldName,"A",210)
	AddGadgetColumn(#List,#ListNewName,"B",210)
	AddGadgetColumn(#List,#ListSize,"C",52)
	AddGadgetColumn(#List,#ListDate,"D",102)
	AddGadgetColumn(#List,#ListState,"E",78)

	FrameGadget(#TxtInfo,0,530,#WinW,2,"",#PB_Frame_Single)
	TextGadget(#StrInfo,0,534,999,16,"",#SS_CENTERIMAGE)

	ButtonGadget(#ButRename,585,15,115,30,"Q",#PB_Button_Default)
	ButtonGadget(#ButClose,585,53,115,30,"R")
	ButtonGadget(#ButProfile,585,95,115,30,"S")
	ButtonGadget(#ButFilter,585,132,115,30,"T",#PB_Button_Toggle)

	For i=0 To 9
		AddGadgetItem(#StrName,i,"Number "+Str(i))
		AddGadgetItem(#StrExt,i,"Number "+Str(i))
		AddGadgetItem(#StrOutput,i,"Number "+Str(i))
	Next i

	SetGadgetText(#StrName,"Number 3")
	SetGadgetText(#StrExt,"Number 5")
	SetGadgetText(#StrOutput,"Number 7")

	AddKeyboardShortcut(#WinID,#PB_Shortcut_Escape,#ButClose)

	BindEvent(#PB_Event_SizeWindow,@Events(),#WinID)

	SetActiveWindow(#WinID)
	SetActiveGadget(#StrName)
	HideWindow(#WinID,#Null)

EndProcedure
Procedure Main()

	Protected quit

	Init()

	Repeat
		Select WaitWindowEvent()
		Case #PB_Event_Menu,#PB_Event_Gadget
			Select EventGadget()
			Case #ButClose
				quit=1
			EndSelect
		Case #PB_Event_CloseWindow
			quit=1
		EndSelect
	Until quit

EndProcedure

Main()
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4664
Joined: Sun Apr 12, 2009 6:27 am

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

Post by RASHAD »

Hi MV
Replace

#1 :

Code: Select all

        ResizeGadget(#StrName,#PB_Ignore,#PB_Ignore,207+x, #PB_Ignore)
         SendMessage_(GadgetID(#StrName), #CB_SETEDITSEL, 0,-1)
         ResizeGadget(#StrOutput,#PB_Ignore,#PB_Ignore,207+x, #PB_Ignore)
         SendMessage_(GadgetID(#StrOutput), #CB_SETEDITSEL, 0,-1)
         ResizeGadget(#TxtExt,345+y,#PB_Ignore,#PB_Ignore, #PB_Ignore);
         ResizeGadget(#StrExt,430+y,#PB_Ignore,125+x, #PB_Ignore)
         SendMessage_(GadgetID(#StrExt), #CB_SETEDITSEL, 0,-1)
         ResizeGadget(#FlgOutCase,346+y,#PB_Ignore,#PB_Ignore, #PB_Ignore);
#2 :

Code: Select all

Procedure Init()
.
.
.
  HideWindow(#WinID,#Null)

  SetGadgetState(#StrName,0)
  SetGadgetState(#StrExt,0)
  SetGadgetState(#StrOutput,0)

EndProcedure
Egypt my love
User avatar
Michael Vogel
Addict
Addict
Posts: 2680
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

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

Post by Michael Vogel »

Briliant, Rashad!

Don't need the SetGadgetState (would have to do it permanently when the uses edits one combo text), but the SendMessage does the trick - thank you!

Changed all 'ResizeGadget' calls for ComboBoxGadgets to 'ResizeComboGadget' :wink:

Code: Select all

Procedure ResizeComboGadget(gadget,x,y,width,height)

	ResizeGadget(gadget,x,y,width,height)
	If GetActiveGadget()<>gadget
		SendMessage_(GadgetID(gadget),#CB_SETEDITSEL,0,-1)
	EndIf

EndProcedure
mestnyi
Addict
Addict
Posts: 1001
Joined: Mon Nov 25, 2013 6:41 am

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

Post by mestnyi »

Code: Select all

EnableExplicit
;info: RS_Gadget (Automatically Resize PureBasic Gadgets)
;
; 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 Parent ID.
;

;DECLARATIONS
DeclareModule RS_gadget
  EnableExplicit
  ;  
  #PB_Align_Avto   =1<<0
  #PB_Align_Left   =1<<1
  #PB_Align_Top    =1<<2
  #PB_Align_Right  =1<<3
  #PB_Align_Bottom =1<<4
  #PB_Align_Full   =1<<5
  #PB_Align_Center =1<<6
  
  Declare RS_Resize(RS_ParentID)
  Declare RS_UnRegister(RS_gadget.l)
  Declare RS_Register(RS_gadget, Flags, gap_between_gadgets = #False, Rs_ParentID = #False)
EndDeclareModule

Module RS_gadget
  CompilerIf #PB_Compiler_OS = #PB_OS_Windows
    Import ""
    CompilerElse
      ImportC ""
      CompilerEndIf
      PB_Object_EnumerateStart( PB_Objects )
      PB_Object_EnumerateNext( PB_Objects, *ID.Integer )
      PB_Object_EnumerateAbort( PB_Objects )
      
      PB_Object_Count( PB_Objects )
      
      PB_Window_Objects.i
      PB_Gadget_Objects.i
    EndImport
    
    Procedure Parent( ParentID ) 
      Protected Window
      PB_Object_EnumerateStart( PB_Window_Objects )
      If PB_Window_Objects
        While PB_Object_EnumerateNext(PB_Window_Objects, @Window )
          If WindowID( Window ) = ParentID
            ProcedureReturn Window
          EndIf  
        Wend
        
        PB_Object_EnumerateAbort( PB_Window_Objects ) 
      EndIf
      
      Protected Gadget
      PB_Object_EnumerateStart( PB_Gadget_Objects )
      If PB_Gadget_Objects
        While PB_Object_EnumerateNext(PB_Gadget_Objects, @Gadget )
          If GadgetID( Gadget ) = ParentID
            ProcedureReturn Gadget
          EndIf  
        Wend
        
        PB_Object_EnumerateAbort( PB_Gadget_Objects ) 
      EndIf
      ProcedureReturn -1   
    EndProcedure
    
    
    Structure RS_struct
      ParentID.l     
      Gadget.l     
      Parent.l
      
      X.l
      Y.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_struct()
    
    ; RS_Resize - Resize all registered gadgets for the resizing window.
    ; Parameters: Parent ID (long).
    Procedure RS_Resize(RS_ParentID)
      If ListSize(RS_Gadgets())
        Protected Rs_Parent.l, RS_gadget.l, RS_x.l, RS_y.l, Rs_w.l, Rs_h.l
        
        ForEach RS_Gadgets()
          If RS_Gadgets()\ParentID = RS_ParentID
            RS_gadget = RS_Gadgets()\Gadget
            RS_Parent = RS_Gadgets()\Parent
            
            If (IsWindow(RS_Parent) And WindowID(RS_Parent) = RS_ParentID)
              RS_w = WindowWidth(RS_Parent)
              RS_h = WindowHeight(Rs_Parent)
              
            ElseIf (IsGadget(RS_Parent) And GadgetID(RS_Parent) = RS_ParentID)
              RS_w = GadgetWidth(RS_Parent)
              RS_h = GadgetHeight(RS_Parent)
              
            EndIf
            
            If (RS_Gadgets()\Lock_Left)   
              If (RS_Gadgets()\Lock_Right)
                RS_w = (RS_w - GadgetX(RS_gadget)) - RS_Gadgets()\Right
                ResizeGadget(RS_gadget, #PB_Ignore, #PB_Ignore, RS_w, #PB_Ignore)
              EndIf
              
            Else
              RS_x = (RS_w - RS_Gadgets()\Left)
              If (RS_Gadgets()\Lock_Right = #False) ; 
                RS_x = RS_Gadgets()\X + ((RS_x - RS_Gadgets()\X) /2)
              EndIf
              ResizeGadget(RS_gadget, RS_x, #PB_Ignore, #PB_Ignore, #PB_Ignore)
              
            EndIf
            
            If (RS_Gadgets()\Lock_Top)
              If (RS_Gadgets()\Lock_Bottom)
                RS_h = (RS_h - GadgetY(RS_gadget)) - RS_Gadgets()\Bottom
                ResizeGadget(RS_gadget, #PB_Ignore, #PB_Ignore, #PB_Ignore, RS_h)
              EndIf       
              
            Else
              RS_y = (RS_h - RS_Gadgets()\Top)
              If (RS_Gadgets()\Lock_Bottom = #False)
                RS_y = RS_Gadgets()\Y + ((RS_y - RS_Gadgets()\Y) /2)
              EndIf
              ResizeGadget(RS_gadget, #PB_Ignore, RS_y, #PB_Ignore, #PB_Ignore)
              
            EndIf       
            
            CompilerIf #PB_Compiler_OS = #PB_OS_Windows
              RedrawWindow_(RS_ParentID, 0, 0, #RDW_ALLCHILDREN|#RDW_UPDATENOW)
            CompilerEndIf
          EndIf
        Next
        
      EndIf
      
    EndProcedure
    
    ;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:  Window (long), Gadget (long), Left (boolean), Top (boolean), Right (boolean), Bottom (boolean).
    Procedure RS_Register(RS_gadget, Flags, gap_between_gadgets = #False, Rs_ParentID = #False) ;
      Protected RS_left.b, RS_top.b, RS_right.b, RS_bottom.b
      Protected RS_x.l, RS_y.l, Rs_w.l, Rs_h.l 
      
      If IsGadget(RS_gadget)
        AddElement(RS_Gadgets())
        If Rs_ParentID = #False
          Rs_ParentID = UseGadgetList(0)
        EndIf
        Protected Rs_Parent = Parent( Rs_ParentID ) 
        
        
        If (Flags & #PB_Align_Avto) = #PB_Align_Avto
          If (Flags & #PB_Align_Full) = #PB_Align_Full
            Flags = #PB_Align_Avto|#PB_Align_Left|#PB_Align_Top|#PB_Align_Right|#PB_Align_Bottom
          EndIf
          If (Flags & #PB_Align_Center) = #PB_Align_Center
            Flags = #PB_Align_Avto
          EndIf
        Else
          If (Flags & #PB_Align_Center) = #PB_Align_Center
            Flags = #False
          EndIf
          If (Flags & #PB_Align_Full) = #PB_Align_Full
            Flags = #PB_Align_Left|#PB_Align_Top|#PB_Align_Right|#PB_Align_Bottom
          EndIf
        EndIf
        
        If ((Flags & #PB_Align_Left) = #PB_Align_Left)  
          RS_left = #True
        EndIf  
        If ((Flags & #PB_Align_Top) = #PB_Align_Top)
          RS_top = #True
        EndIf
        If ((Flags & #PB_Align_Right) = #PB_Align_Right)
          RS_right  = #True
        EndIf
        If ((Flags & #PB_Align_Bottom) = #PB_Align_Bottom) 
          Rs_bottom = #True
        EndIf
        
        RS_Gadgets()\Gadget = RS_gadget
        RS_Gadgets()\Parent = Rs_Parent
        RS_Gadgets()\ParentID = Rs_ParentID
        
        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 IsWindow(Rs_Parent) And
           WindowID(Rs_Parent) = Rs_ParentID
          Rs_w = WindowWidth(Rs_Parent)
          Rs_h = WindowHeight(Rs_Parent)
        ElseIf IsGadget(Rs_Parent) And 
               GadgetID(Rs_Parent) = Rs_ParentID
          Rs_w = GadgetWidth(Rs_Parent)
          Rs_h = GadgetHeight(Rs_Parent)
        EndIf
        
        If (Flags & #PB_Align_Avto) = #PB_Align_Avto
          If RS_left = #False   
            RS_x = (Rs_w - GadgetWidth(RS_gadget))-gap_between_gadgets
            If RS_right = #False ; 
              RS_x = GadgetX(RS_gadget) + ((RS_x - (GadgetX(RS_gadget) - gap_between_gadgets)) /2) ; Середина по вертикали
            EndIf
            ResizeGadget(RS_gadget, RS_x, #PB_Ignore, #PB_Ignore, #PB_Ignore)
            If RS_top
              ResizeGadget(RS_gadget, #PB_Ignore, gap_between_gadgets, #PB_Ignore, #PB_Ignore)
            EndIf
          EndIf
          
          If RS_top = #False 
            RS_y = (Rs_h - GadgetHeight(RS_gadget))-gap_between_gadgets
            If Rs_bottom = #False
              RS_y = (GadgetY(RS_gadget) + ((RS_y - (GadgetY(RS_gadget) - gap_between_gadgets)) /2)) ; Середина по горизонтали
            EndIf
            ResizeGadget(RS_gadget, #PB_Ignore, RS_y, #PB_Ignore, #PB_Ignore)
            If RS_left
              ResizeGadget(RS_gadget, gap_between_gadgets, #PB_Ignore, #PB_Ignore, #PB_Ignore)
            EndIf
          EndIf       
          
          If (RS_left And RS_top) And (RS_right And RS_bottom)
            ResizeGadget(RS_gadget, gap_between_gadgets, gap_between_gadgets, Rs_w-gap_between_gadgets*2, Rs_h-gap_between_gadgets*2)
          Else
            If (RS_right And RS_left)
              If RS_top Or (RS_right And RS_bottom)
                ResizeGadget(RS_gadget, (Rs_w - GadgetWidth(RS_gadget)) /2, #PB_Ignore, #PB_Ignore, #PB_Ignore)
              EndIf
              ResizeGadget(RS_gadget, #PB_Ignore, #PB_Ignore, (Rs_w - GadgetX(RS_gadget)) - (Rs_w - (GadgetX(RS_gadget) + GadgetWidth(RS_gadget))), #PB_Ignore)
            Else
              If (RS_left And RS_top)
                ResizeGadget(RS_gadget, gap_between_gadgets, gap_between_gadgets, #PB_Ignore, #PB_Ignore)
              EndIf
            EndIf
            
            If (Rs_bottom And RS_top)
              If RS_left Or (Rs_bottom And RS_right)
                ResizeGadget(RS_gadget, #PB_Ignore, (Rs_h - GadgetHeight(RS_gadget)) /2, #PB_Ignore, #PB_Ignore)
              EndIf
              ResizeGadget(RS_gadget, #PB_Ignore, #PB_Ignore, #PB_Ignore, (Rs_h - GadgetY(RS_gadget)) - (Rs_h - (GadgetY(RS_gadget) + GadgetHeight(RS_gadget))))
            Else
              If (RS_left And RS_top)
                ResizeGadget(RS_gadget, gap_between_gadgets, gap_between_gadgets, #PB_Ignore, #PB_Ignore)
              EndIf
            EndIf       
          EndIf
        EndIf
        
        RS_x = GadgetX(RS_gadget)
        RS_y = GadgetY(RS_gadget)
        
        If RS_left = #False
          RS_Gadgets()\X = RS_x
          RS_Gadgets()\Left = Rs_w - RS_x
        EndIf
        If RS_top = #False
          RS_Gadgets()\Y = RS_y
          RS_Gadgets()\Top = Rs_h - RS_y
        EndIf
        If RS_right : RS_Gadgets()\Right = Rs_w - (RS_x + GadgetWidth(RS_gadget)) : EndIf
        If RS_bottom : RS_Gadgets()\Bottom = Rs_h - (RS_y + GadgetHeight(RS_gadget)) : EndIf
      EndIf
    EndProcedure
    
    
    ; RS_Unregister - Unregister gadget from resizing
    Procedure RS_UnRegister(RS_gadget.l)
      
      ForEach RS_Gadgets()
        
        If (RS_Gadgets()\Gadget = RS_gadget)
          DeleteElement(RS_Gadgets())
        EndIf
        
      Next 
      
    EndProcedure
    
    
  EndModule
  
 Procedure ClipGadgets( Window ) ;
      CompilerIf #PB_Compiler_OS = #PB_OS_Windows
        Protected WindowID
        Protected Dim EnumerateList.I(0)
        If IsWindow( Window ) 
          WindowID = WindowID( Window )
        Else
          WindowID = UseGadgetList(0)
        EndIf
        Protected GadgetID = FindWindowEx_( WindowID, 0,0,0 )
        
        While GadgetID
          If GadgetID
            If GetWindowLongPtr_( GadgetID, #GWL_STYLE ) & #WS_CLIPSIBLINGS = #False 
              Protected Gadget = GetProp_( GadgetID, "PB_ID" ) ; IDGadget( GadgetID )
              If ( IsGadget( Gadget ) And GadgetID( Gadget ) = GadgetID )
                Protected Height = GadgetHeight( Gadget ) 
                SetWindowLongPtr_( GadgetID, #GWL_STYLE, GetWindowLongPtr_( GadgetID, #GWL_STYLE )|#WS_CLIPSIBLINGS )
                ResizeGadget( Gadget, #PB_Ignore, #PB_Ignore, #PB_Ignore, Height )
              EndIf
            EndIf
            ReDim EnumerateList( ArraySize( EnumerateList() ) + (1) ) : EnumerateList( ArraySize( EnumerateList() ) ) = GadgetID
          EndIf
          GadgetID = GetWindow_( GadgetID, #GW_HWNDNEXT )  
        Wend
        
        While ArraySize( EnumerateList() ) 
          If ArraySize( EnumerateList() )
            GadgetID = EnumerateList( ArraySize( EnumerateList() ) ) : ReDim EnumerateList( ArraySize( EnumerateList() ) - (1) )
            SetWindowPos_( GadgetID, #GW_HWNDLAST, 0,0,0,0, #SWP_NOMOVE|#SWP_NOSIZE )
          EndIf 
        Wend
        
        FreeArray( EnumerateList() )
      CompilerEndIf
    EndProcedure
     
  UseModule RS_gadget
  
  Procedure Window_Resize()
    RS_Resize(WindowID(EventWindow()))
  EndProcedure
  
  Procedure Demo()
    Define RS_window = 50
    OpenWindow(RS_window,5,5,400,300,"",#PB_Window_SystemMenu|#PB_Window_SizeGadget)
    ;
    SmartWindowRefresh(RS_window, #True)
    WindowBounds(RS_window, WindowWidth(RS_window), WindowHeight(RS_window), #PB_Ignore, #PB_Ignore)
    
    BindEvent(#PB_Event_SizeWindow,@Window_Resize(),RS_window) 
    
    ButtonGadget(9, 135, 137,130,25,"Dock = client") :RS_Register(9,#PB_Align_Avto|#PB_Align_Full)
    ButtonGadget(19, 135, 137,130,25,"Dock = client") :RS_Register(19,#PB_Align_Full)
    
    
    ButtonGadget(15, 0, 0,130,25,"Dock = l_t_r") :RS_Register(15,#PB_Align_Avto|#PB_Align_Left|#PB_Align_Top|#PB_Align_Right)
    ButtonGadget(18, 0, 0,130,25,"Dock = t_l_b") :RS_Register(18,#PB_Align_Avto|#PB_Align_Left|#PB_Align_Top|#PB_Align_Bottom)
    ;             
    ButtonGadget(12, 0, 0,130,25,"Dock = t_r_b") :RS_Register(12,#PB_Align_Avto|#PB_Align_Top|#PB_Align_Right|#PB_Align_Bottom)
    ButtonGadget(13, 0, 0,130,25,"Dock = l_b_r") :RS_Register(13,#PB_Align_Avto|#PB_Align_Left|#PB_Align_Bottom|#PB_Align_Right)
    
    ButtonGadget(10, 0, 0,130,25,"Dock = l_r") :RS_Register(10,#PB_Align_Avto|#PB_Align_Left|#PB_Align_Right)
    ButtonGadget(11, 0, 0,130,25,"Dock = t_b") :RS_Register(11,#PB_Align_Avto|#PB_Align_Top|#PB_Align_Bottom)
    ButtonGadget(8, 0, 0,130,25,"Dock = lefttop") :RS_Register(8,#PB_Align_Avto|#PB_Align_Left|#PB_Align_Top)
    ButtonGadget(5, 0, 0,130,25,"Dock = righttop") :RS_Register(5,#PB_Align_Avto|#PB_Align_Right|#PB_Align_Top)
    ButtonGadget(6, 0, 0,130,25,"Dock = leftbottom") :RS_Register(6,#PB_Align_Avto|#PB_Align_Left|#PB_Align_Bottom)
    ButtonGadget(7, 0, 0,130,25,"Dock = rightbottom") :RS_Register(7,#PB_Align_Avto|#PB_Align_Right|#PB_Align_Bottom)
    
    
    
    ButtonGadget(20, 0, 0,130,25,"Dock = left") :RS_Register(20,#PB_Align_Avto|#PB_Align_Left)
    ButtonGadget(1, 0, 0,130,25,"Dock = top") :RS_Register(1,#PB_Align_Avto|#PB_Align_Top)
    ButtonGadget(2, 0, 0,130,25,"Dock = right") :RS_Register(2,#PB_Align_Avto|#PB_Align_Right)
    ButtonGadget(3, 0, 0,130,25,"Dock = bottom") :RS_Register(3,#PB_Align_Avto|#PB_Align_Bottom)
    ButtonGadget(4, 0, 0,130,25,"Dock = center") :RS_Register(4,#PB_Align_Avto|#PB_Align_Center)
    
    ClipGadgets(RS_window)
  EndProcedure   
  
  UnuseModule RS_gadget
  
  Demo()
  
  Repeat
    
    Select WaitWindowEvent() 
      Case #PB_Event_CloseWindow
        End
    EndSelect
    
  ForEver
What do you think?
Last edited by mestnyi on Fri Feb 12, 2016 2:14 pm, edited 1 time in total.
User avatar
Michael Vogel
Addict
Addict
Posts: 2680
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

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

Post by Michael Vogel »

mestnyi wrote:What do you think?
Looks fine, runs very smooth :)
Needs some minu..., oh, months to understand your redrawing technique, but I will try it :wink:
Post Reply