Page 1 of 1

Modern Splitter Gadget with PureBasic

Posted: Thu Nov 18, 2021 6:09 pm
by RASHAD
The title say it all :D

Code: Select all

Procedure sizeCB()
  wwidth = GadgetWidth(1)+GadgetWidth(2)+26
  y4 = GadgetHeight(4)
  y5 = GadgetHeight(3)-y4+8
  ResizeGadget(10,#PB_Ignore,#PB_Ignore,WindowWidth(0)-18,WindowHeight(0,#PB_Window_InnerCoordinate)-38)
  ResizeGadget(0,#PB_Ignore,#PB_Ignore,WindowWidth(0)-20,WindowHeight(0,#PB_Window_InnerCoordinate)-40)
  ResizeGadget(1,#PB_Ignore,#PB_Ignore,#PB_Ignore,WindowHeight(0,#PB_Window_InnerCoordinate)-40)
  ResizeGadget(2,#PB_Ignore,#PB_Ignore,#PB_Ignore,WindowHeight(0,#PB_Window_InnerCoordinate)-40)
  ResizeGadget(3,#PB_Ignore,#PB_Ignore,WindowWidth(0)-340,WindowHeight(0,#PB_Window_InnerCoordinate)-40)                       
  ResizeGadget(4,#PB_Ignore,#PB_Ignore,WindowWidth(0)-wwidth,y4+(cy-inity))
  ResizeGadget(5,#PB_Ignore,#PB_Ignore,WindowWidth(0)-wwidth,y5+(inity-cy))
EndProcedure

sgcolor = $67DBF7

flags = #PB_Window_SystemMenu| #PB_Window_Invisible | #PB_Window_MaximizeGadget| #PB_Window_MinimizeGadget| #PB_Window_ScreenCentered | #PB_Window_SizeGadget
OpenWindow(0,0,0,800,600,"Test",Flags)
SmartWindowRefresh(0,1)

If CreateStatusBar(0, WindowID(0))
  AddStatusBarField(100)
  AddStatusBarField(50)
  AddStatusBarField(100)
EndIf

StatusBarText(0, 0, "Area 1")
StatusBarText(0, 1, "Area 2", #PB_StatusBar_BorderLess)
StatusBarText(0, 2, "Area 3", #PB_StatusBar_Right | #PB_StatusBar_Raised) 

FrameGadget(10,9,9,784,562,"",#PB_Frame_Flat)
CanvasGadget(0,10,10,780,560,#PB_Canvas_Container)
SetGadgetColor(0,#PB_Gadget_BackColor,$67DBF7)

ListIconGadget(1,0,0,184,560,"Column 0",100,#PB_ListIcon_FullRowSelect|#PB_ListIcon_GridLines)
ExplorerListGadget(2,188,0,188,560,"c:\")

wwidth = GadgetWidth(1)+GadgetWidth(2)+30
CanvasGadget(3,380,0,800,560,#PB_Canvas_Container)
SetGadgetColor(3,#PB_Gadget_BackColor,$8FFE9B)
ExplorerListGadget(4,0,0,wwidth,282,"c:\")
EditorGadget(5,0,288,wwidth,1000)
CloseGadgetList()

CloseGadgetList()
While WindowEvent() : Wend
HideWindow(0,0) 
BindEvent(#PB_Event_SizeWindow,@sizeCB())
BindEvent(#PB_Event_MaximizeWindow,@sizeCB())
Repeat
  
  Select WaitWindowEvent()
      
    Case #PB_Event_CloseWindow
      Quit = 1
      
      ;Case #PB_Event_MaximizeWindow
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          Select EventType()
            Case #PB_EventType_MouseEnter
              SetGadgetAttribute(0,#PB_Canvas_Cursor,#PB_Cursor_LeftRight)
              
            Case #PB_EventType_MouseLeave
              SetGadgetAttribute(0,#PB_Canvas_Cursor,#PB_Cursor_Default)
              Downflag = 0
              
            Case #PB_EventType_LeftButtonDown            
              cx = GetGadgetAttribute(0,#PB_Canvas_MouseX)               
              Downflag = 1
              If cx > GadgetX(2)
                split = 2
                ww = GadgetWidth(2)+GadgetWidth(3)+4
              Else
                split = 1
                ww = GadgetWidth(1)+GadgetWidth(2)+4
              EndIf
              
            Case #PB_EventType_LeftButtonUp
              Downflag = 0
              Downflag2 = 0              
              
            Case #PB_EventType_MouseMove
              If Downflag = 1
                cx = GetGadgetAttribute(0,#PB_Canvas_MouseX)
                wwidth = GadgetWidth(0)-GadgetWidth(1)-GadgetWidth(2)-4  
                If (cx < GadgetX(3)-12 And split = 1) Or (cx > GadgetX(2)+4 And split = 2)
                  If split = 1 
                    If cx < GadgetWidth(0)-6
                      ResizeGadget(1,#PB_Ignore,#PB_Ignore,cx,#PB_Ignore)                      
                      ResizeGadget(2,cx+5,#PB_Ignore,ww-cx-5,#PB_Ignore)
                    EndIf
                  Else
                    If cx < GadgetWidth(0)-6           
                      ResizeGadget(2,#PB_Ignore,#PB_Ignore,cx-GadgetWidth(1)-4,#PB_Ignore)
                      While WindowEvent() : Wend    
                      ResizeGadget(3,cx+5,#PB_Ignore,ww-GadgetWidth(2)-4,#PB_Ignore)
                    EndIf
                  EndIf
                  While WindowEvent() : Wend                               
                  ResizeGadget(4,#PB_Ignore,#PB_Ignore,wwidth,#PB_Ignore)                  
                  ResizeGadget(5,#PB_Ignore,#PB_Ignore,wwidth,#PB_Ignore)
                EndIf
              EndIf              
              
          EndSelect
          
        Case 3
          Select EventType()
            Case #PB_EventType_MouseEnter
              SetGadgetAttribute(3,#PB_Canvas_Cursor,#PB_Cursor_UpDown)
              
            Case #PB_EventType_MouseLeave
              SetGadgetAttribute(3,#PB_Canvas_Cursor,#PB_Cursor_Default)
              Downflag2 = 0
              
            Case #PB_EventType_LeftButtonDown
              Downflag2 = 1
              inity = GetGadgetAttribute(3,#PB_Canvas_MouseY)           
              y4 = GadgetHeight(4)
              y5 = GadgetHeight(3)-y4
              
            Case #PB_EventType_LeftButtonUp
              Downflag = 0
              Downflag2 = 0   
              
            Case #PB_EventType_MouseMove
              If Downflag2 = 1
                cy = GetGadgetAttribute(3,#PB_Canvas_MouseY)
                If cy < GadgetHeight(3)-6
                  ResizeGadget(4,#PB_Ignore,#PB_Ignore,#PB_Ignore,y4+(cy-inity))
                  While WindowEvent() : Wend                       
                  ResizeGadget(5,#PB_Ignore,GadgetHeight(4)+6,#PB_Ignore,y5+(inity-cy)) 
                EndIf
              EndIf
              
          EndSelect                       
      EndSelect         
      
  EndSelect 
  
Until Quit = 1
End
Edit : Bug fixed
Edit : Updated (Logically improved)
Edit : Updated again for KCC :D

Re: Modern Splitter Gadget with PureBasic

Posted: Thu Nov 18, 2021 6:25 pm
by skywalk
Looks nice!
There is weird behavior at the extremes. Like pulling the splitter to the bottom.
The splitter disappears and cannot recover.

Re: Modern Splitter Gadget with PureBasic

Posted: Thu Nov 18, 2021 7:09 pm
by RASHAD
@ skywalk
Thanks for the head up :)
Previous post updated

Re: Modern Splitter Gadget with PureBasic

Posted: Thu Nov 18, 2021 8:24 pm
by Kwai chang caine
Hello RASHAD :D
Don't know if it's the good behavior, but when i maximize the window, a green part appears in the right side :shock:
Else, it's a great usefull code and thanks for sharing it 8)

Re: Modern Splitter Gadget with PureBasic

Posted: Fri Nov 19, 2021 12:55 am
by RASHAD
Hi KCC
Previous post updated

Re: Modern Splitter Gadget with PureBasic

Posted: Fri Nov 19, 2021 1:37 am
by Paul
Should mention it doesn't work when compiled as "DPI aware" with scaling >100%

Re: Modern Splitter Gadget with PureBasic

Posted: Sat Nov 20, 2021 9:31 pm
by Kwai chang caine
RASHAD wrote: Fri Nov 19, 2021 12:55 am Hi KCC
Previous post updated
Thanks RASHAD 8)
But i have always two problems here :oops:

At the opening i have a little green line

Image

And when i maximize a big green area

Image

And this time i have try also with XP effect :mrgreen:

Re: Modern Splitter Gadget with PureBasic

Posted: Sat Nov 20, 2021 10:14 pm
by RASHAD
Hi KCC
Previous post updated
Now you will need moving the splitter by command when it is out of sight
You do it :P

Hi Paul
It needs calculating every movement to take DPI into consideration
That depends on the scheme which will be different for each user(If there any of them :mrgreen: )

Re: Modern Splitter Gadget with PureBasic

Posted: Sun Nov 21, 2021 12:01 am
by RASHAD
Added trick to compensate the bad effect of moving the Hal Splitter #2
The rest is yours :)

Code: Select all

Procedure sizeCB()
  wwidth = GadgetWidth(1)+GadgetWidth(2)+26
  cy = GetGadgetAttribute(3,#PB_Canvas_MouseX)  
  y4 = GadgetHeight(4)
  y5 = GadgetHeight(3)-y4+8
  ResizeGadget(10,#PB_Ignore,#PB_Ignore,WindowWidth(0)-18,WindowHeight(0,#PB_Window_InnerCoordinate)-38)
  ResizeGadget(0,#PB_Ignore,#PB_Ignore,WindowWidth(0)-20,WindowHeight(0,#PB_Window_InnerCoordinate)-40)
  ResizeGadget(1,#PB_Ignore,#PB_Ignore,#PB_Ignore,WindowHeight(0,#PB_Window_InnerCoordinate)-40)
  ResizeGadget(2,#PB_Ignore,#PB_Ignore,#PB_Ignore,WindowHeight(0,#PB_Window_InnerCoordinate)-40)
  ResizeGadget(3,#PB_Ignore,#PB_Ignore,WindowWidth(0)-340,WindowHeight(0,#PB_Window_InnerCoordinate)-40)                       
  ResizeGadget(4,#PB_Ignore,#PB_Ignore,WindowWidth(0)-wwidth,y4+(cy-inity))
  ResizeGadget(5,#PB_Ignore,#PB_Ignore,WindowWidth(0)-wwidth,y5+(inity-cy))
EndProcedure

sgcolor = $67DBF7

flags = #PB_Window_SystemMenu| #PB_Window_Invisible | #PB_Window_MaximizeGadget| #PB_Window_MinimizeGadget| #PB_Window_ScreenCentered | #PB_Window_SizeGadget
OpenWindow(0,0,0,800,600,"Test",Flags)
SmartWindowRefresh(0,1)

If CreateStatusBar(0, WindowID(0))
  AddStatusBarField(100)
  AddStatusBarField(50)
  AddStatusBarField(100)
EndIf

StatusBarText(0, 0, "Area 1")
StatusBarText(0, 1, "Area 2", #PB_StatusBar_BorderLess)
StatusBarText(0, 2, "Area 3", #PB_StatusBar_Right | #PB_StatusBar_Raised) 

FrameGadget(10,9,9,784,562,"",#PB_Frame_Flat)
CanvasGadget(0,10,10,780,560,#PB_Canvas_Container)
SetGadgetColor(0,#PB_Gadget_BackColor,$67DBF7)

ListIconGadget(1,0,0,184,560,"Column 0",100,#PB_ListIcon_FullRowSelect|#PB_ListIcon_GridLines)
ExplorerListGadget(2,188,0,188,560,"c:\")

wwidth = GadgetWidth(1)+GadgetWidth(2)+30
CanvasGadget(3,380,0,800,560,#PB_Canvas_Container)
SetGadgetColor(3,#PB_Gadget_BackColor,$8FFE9B)
ExplorerListGadget(4,0,0,wwidth,282,"c:\")
EditorGadget(5,0,288,wwidth,1000)
CloseGadgetList()

CloseGadgetList()
While WindowEvent() : Wend
HideWindow(0,0) 
BindEvent(#PB_Event_SizeWindow,@sizeCB())
BindEvent(#PB_Event_MaximizeWindow,@sizeCB())
Repeat
  
  Select WaitWindowEvent()
      
    Case #PB_Event_CloseWindow
      Quit = 1
      
      ;Case #PB_Event_MaximizeWindow
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          Select EventType()
            Case #PB_EventType_MouseEnter
              SetGadgetAttribute(0,#PB_Canvas_Cursor,#PB_Cursor_LeftRight)
              
            Case #PB_EventType_MouseLeave
              SetGadgetAttribute(0,#PB_Canvas_Cursor,#PB_Cursor_Default)
              downflag = 0
              
            Case #PB_EventType_LeftButtonDown                           
              Downflag = 1            
              cx = GetGadgetAttribute(0,#PB_Canvas_MouseX)
              If cx > GadgetX(2)
                split = 2
                ww = GadgetWidth(2)+GadgetWidth(3)+4
              Else
                split = 1
                ww = GadgetWidth(1)+GadgetWidth(2)+4
              EndIf
              inity = GetGadgetAttribute(3,#PB_Canvas_MouseY)
              cy = GetGadgetAttribute(3,#PB_Canvas_MouseX)           
              y4 = GadgetHeight(4)
              y5 = GadgetHeight(3)-y4
              
            Case #PB_EventType_LeftButtonUp
              wwidth = GadgetWidth(1)+GadgetWidth(2)+26               
              ResizeGadget(4,#PB_Ignore,#PB_Ignore,WindowWidth(0)-wwidth,y4+(cy-inity))
              ResizeGadget(5,#PB_Ignore,#PB_Ignore,WindowWidth(0)-wwidth,y5+(inity-cy))
              Downflag = 0
              Downflag2 = 0              
              
            Case #PB_EventType_MouseMove
              If Downflag = 1                                              
                ResizeGadget(4,#PB_Ignore,#PB_Ignore,WindowWidth(0),#PB_Ignore)                  
                ResizeGadget(5,#PB_Ignore,#PB_Ignore,WindowWidth(0),#PB_Ignore)
                cx = GetGadgetAttribute(0,#PB_Canvas_MouseX)
                wwidth = GadgetWidth(0)-GadgetWidth(1)-GadgetWidth(2)-4  
                If (cx < GadgetX(3)-12 And split = 1) Or (cx > GadgetX(2)+4 And split = 2)
                  If split = 1 
                    If cx < GadgetWidth(0)-6
                      ResizeGadget(1,#PB_Ignore,#PB_Ignore,cx,#PB_Ignore)                      
                      ResizeGadget(2,cx+5,#PB_Ignore,ww-cx-5,#PB_Ignore)
                    EndIf
                  Else
                    If cx < GadgetWidth(0)-6           
                      ResizeGadget(2,#PB_Ignore,#PB_Ignore,cx-GadgetWidth(1)-4,#PB_Ignore)
                      ResizeGadget(3,cx+5,#PB_Ignore,ww-GadgetWidth(2)-4,#PB_Ignore)                      
                    EndIf
                  EndIf
                EndIf
              EndIf              
              While WindowEvent() : Wend                  
              
          EndSelect
          
        Case 3
          Select EventType()
            Case #PB_EventType_MouseEnter
              SetGadgetAttribute(3,#PB_Canvas_Cursor,#PB_Cursor_UpDown)
              
            Case #PB_EventType_MouseLeave
              SetGadgetAttribute(3,#PB_Canvas_Cursor,#PB_Cursor_Default)
              
            Case #PB_EventType_LeftButtonDown
              inity = GetGadgetAttribute(3,#PB_Canvas_MouseY)           
              y4 = GadgetHeight(4)
              y5 = GadgetHeight(3)-y4
              Downflag2 = 1 
              
            Case #PB_EventType_LeftButtonUp
              Downflag = 0
              Downflag2 = 0   
              
            Case #PB_EventType_MouseMove
              If Downflag2 = 1
                cy = GetGadgetAttribute(3,#PB_Canvas_MouseY)
                If cy < GadgetHeight(3)-6
                  ResizeGadget(4,#PB_Ignore,#PB_Ignore,#PB_Ignore,y4+(cy-inity))
                  ResizeGadget(5,#PB_Ignore,GadgetHeight(4)+6,#PB_Ignore,y5+(inity-cy)) 
                EndIf
              EndIf              
              While WindowEvent() : Wend                       
              
          EndSelect                       
      EndSelect         
      
  EndSelect 
  
Until Quit = 1
End


Re: Modern Splitter Gadget with PureBasic

Posted: Mon Nov 22, 2021 8:25 am
by Joris
I asked this before, ... no answer, so :

How does this ResizeGadget differ with the splittergadget ?
Why isn't the ResizeGadget summed up in the gadgets list (PB help) ?

Re: Modern Splitter Gadget with PureBasic

Posted: Mon Nov 22, 2021 9:56 am
by BarryG
Joris wrote: Mon Nov 22, 2021 8:25 amWhy isn't the ResizeGadget summed up in the gadgets list (PB help) ?
It is (scroll down) -> https://www.purebasic.com/documentation/gadget/

Same area in the offline Help manual, underneath the images of all gadgets.

Re: Modern Splitter Gadget with PureBasic

Posted: Mon Nov 22, 2021 10:47 pm
by AZJIO
I also played a little with the code. I was doing an example on AutoIt3 and I didn't have a smeared line. But I used the "Static" element (text) as a splitter. And also MoveWindow_(), GetCursorInfo_(), WS_EX_COMPOSITED. Nothing new.

Code: Select all

EnableExplicit

Global iWidth = 800, iHeight = 630
Global CursorMove.b = 0, PosSplitterX, d
Global dd.f = 300 / iWidth
Define hGUI

#Window = 0

Enumeration
	#nEdit1
	#nEdit2
	#nSplitter
EndEnumeration


Procedure WinCallback(hWnd, Msg, wParam, lParam)
	Protected w
	Select Msg
		Case #WM_SIZE
			iWidth = WindowWidth(#Window, #PB_Window_InnerCoordinate)
			iHeight = WindowHeight(#Window, #PB_Window_InnerCoordinate) - 20
			w = iWidth * dd
			ResizeGadget(#nEdit1, #PB_Ignore, #PB_Ignore, w - 10, iHeight)
			ResizeGadget(#nEdit2, w + 9, #PB_Ignore, iWidth - w - 20, iHeight)
			ResizeGadget(#nSplitter, w, #PB_Ignore, #PB_Ignore, iHeight)
	EndSelect
	ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure


hGUI = OpenWindow(#Window, 0, 0, iWidth, iHeight + 20, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget| #PB_Window_MinimizeGadget)
If hGUI
; 	SetWindowLongPtr_(hGUI, #GWL_EXSTYLE,GetWindowLongPtr_(hGUI,#GWL_EXSTYLE) | #WS_EX_COMPOSITED)
	SetWindowLongPtr_(hGUI, #GWL_STYLE,GetWindowLongPtr_(hGUI,#GWL_STYLE) | #WS_CLIPCHILDREN)
	PosSplitterX = 300
	ExplorerListGadget(#nEdit1, 10, 10, PosSplitterX - 10, iHeight,"c:\")
	ExplorerListGadget(#nEdit2, PosSplitterX + 9, 10, iWidth - PosSplitterX - 20, iHeight,"c:\")
	CanvasGadget(#nSplitter, PosSplitterX, 10, 9, iHeight)
	SetGadgetColor(#nSplitter, #PB_Gadget_BackColor, $d7d7ff)
	
	SetWindowCallback(@WinCallback())
	
	Repeat
		Select WaitWindowEvent()
			Case #PB_Event_Gadget
				Select EventGadget()
					Case #nSplitter
						Select EventType()
							Case #PB_EventType_MouseEnter
								SetGadgetAttribute(#nSplitter,#PB_Canvas_Cursor,#PB_Cursor_LeftRight)
							Case #PB_EventType_MouseMove
								If CursorMove
; 									HideGadget(#nSplitter, 1)
									PosSplitterX = WindowMouseX(#Window) - d
									ResizeGadget(#nEdit1, #PB_Ignore, #PB_Ignore, PosSplitterX - 10, iHeight)
									ResizeGadget(#nEdit2, PosSplitterX + 9, #PB_Ignore, iWidth - PosSplitterX - 20, iHeight)
									ResizeGadget(#nSplitter, PosSplitterX, #PB_Ignore, #PB_Ignore, iHeight)
								EndIf
							Case #PB_EventType_LeftButtonUp
								CursorMove = 0
; 								HideGadget(#nSplitter, 0)
								dd.f = GadgetX(#nSplitter, #PB_Gadget_ContainerCoordinate) / iWidth
							Case #PB_EventType_LeftButtonDown
								CursorMove = 1
								d = WindowMouseX(#Window) - GadgetX(#nSplitter, #PB_Gadget_ContainerCoordinate)
						EndSelect
				EndSelect
			Case #PB_Event_CloseWindow
				CloseWindow(0)
				End
		EndSelect
	ForEver
EndIf

Re: Modern Splitter Gadget with PureBasic

Posted: Fri Nov 26, 2021 9:41 pm
by Kwai chang caine
RASHAD wrote: Sat Nov 20, 2021 10:14 pm Hi KCC
Previous post updated
Now you will need moving the splitter by command when it is out of sight
You do it :P
Works better i have always the little green line but i can maximize now
Thanks for all 8)