Page 1 of 1

SplitterGadget: Odd behaviour when resizing

Posted: Sat Mar 22, 2014 5:44 pm
by Fenix
Hi @ all,

I was looking for a possibility to have three gadgets combined by two splitter (http://www.purebasic.fr/english/viewtop ... 13&t=58809). Thanks to skywalk, I found the solution.

When I resize the window (I check for WM_EXITSIZEMOVE ) they get drawn just fine. When I MOVE the window (which will also fire WM_EXITSIZEMOVE) the get mixed up (drawn with different width and height). I can't figure out why, as it is the same procedure used to resize. If I have only one splitter active than moving the window won't mess up the resizing.

While browsing for an answer I found an old post (2007) saying it's best to resize the splitter gadgets and not the gadgets combined by them (http://www.purebasic.fr/english/viewtop ... ttergadget). I took that advice but it's still not working as it should.

Has someone encountered that problem too?

Thanx,
Fenix

Re: SplitterGadget: Odd behaviour when resizing

Posted: Sat Mar 22, 2014 6:03 pm
by Fenix
Found some very old post (http://www.purebasic.fr/english/viewtop ... ttergadget).
When I just resize the splitter gadget that holds the second splitter, all works fine. That's really odd :shock:

Is there any chance to size the gadgets within a splitter? I really like to save the positions so the user doesn't have to size again when he starts the program.

Thanx,
Fenix

Re: SplitterGadget: Odd behaviour when resizing

Posted: Sat Mar 22, 2014 7:14 pm
by IdeasVacuum
Ditch the splitters and control the gadget resizing with a little bit of math - once you get the hang of it, easy to do.

Re: SplitterGadget: Odd behaviour when resizing

Posted: Sat Mar 22, 2014 11:11 pm
by Danilo
Fenix wrote:Is there any chance to size the gadgets within a splitter? I really like to save the positions so the user doesn't have to size again when he starts the program.
SetGadgetState(splitter, size) to set the splitter position, GetGadgetState(splitter) to get the position for saving.

Re: SplitterGadget: Odd behaviour when resizing

Posted: Sun Mar 23, 2014 3:34 pm
by skywalk
IdeasVacuum wrote:Ditch the splitters and control the gadget resizing with a little bit of math - once you get the hang of it, easy to do.
Splitters are also the target of user click and drag. If you have several, that is a lot of extra code to duplicate. :idea:

Re: SplitterGadget: Odd behaviour when resizing

Posted: Sat May 24, 2014 5:28 am
by mestnyi
Is not this what you want? :D

Code: Select all

Procedure WindowProc(hWnd,Msg,wParam,lParam) 
  result = #PB_ProcessPureBasicEvents 
  If Msg = #WM_SIZE And hWnd = WindowID(10) 
    ResizeGadget(5,0,0,lParam&$FFFF,(lParam>>16)&$FFFF) 
    result = 0 
  EndIf 
  ProcedureReturn result 
EndProcedure 


 Procedure ResizeSplitter()
  Protected SplitterGadget=EventGadget()
   If IsGadget(SplitterGadget) And GadgetType(SplitterGadget)=#PB_GadgetType_Splitter
     Static OldState,OldStateX,OldStateY
      Protected Gadget,FirstGadget,SecondGadget,State,StateX,StateY
      FirstGadget= GetGadgetAttribute(SplitterGadget,#PB_Splitter_FirstGadget)
      SecondGadget= GetGadgetAttribute(SplitterGadget,#PB_Splitter_SecondGadget)
      If IsGadget(FirstGadget) And IsGadget(SecondGadget)
       If DesktopMouseX()>=GadgetX(FirstGadget,#PB_Gadget_ScreenCoordinate)+GadgetWidth(FirstGadget) And DesktopMouseX()<=GadgetX(SecondGadget,#PB_Gadget_ScreenCoordinate)
        Gadget=SplitterGadget
       EndIf  
       If DesktopMouseY()>=GadgetY(FirstGadget,#PB_Gadget_ScreenCoordinate)+GadgetHeight(FirstGadget) And DesktopMouseY()<=GadgetY(SecondGadget,#PB_Gadget_ScreenCoordinate)
        Gadget=SplitterGadget
       EndIf 
       If IsGadget(Gadget)
        State = GetGadgetState(Gadget) 
        If OldState <> State :OldState = State 
         If OldState 
           PostEvent(#PB_Event_Gadget,EventWindow(),EventGadget(),#PB_EventType_SizeItem)
          ProcedureReturn #True 
         EndIf 
        EndIf
       EndIf 
      EndIf   
    EndIf   
   EndProcedure
   
 
OpenWindow(10,0,0,500,400,"Split",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget) 

  SetWindowCallback(@WindowProc()) 
ButtonGadget(0,0,0,0,0,"")
  ListIconGadget(1,0,0,0,0,"Title",200,#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection) 
  EditorGadget(2,0,0,0,0) 
  EditorGadget(3,0,0,0,0) 

  ; splitter1: listicon and editor1 
  SplitterGadget(4,0,0,500,300,1,2,#PB_Splitter_Vertical);|#PB_Splitter_Separator) 
    SetGadgetState(4,150) ; Set splitter width 
BindGadgetEvent(4,@ResizeSplitter())
  
  ; splitter2: splitter1 and editor2 
  SplitterGadget(5,0,0,500,400,4,3);,#PB_Splitter_Separator) 
    SetGadgetState(5,300) ; Set splitter width 
  BindGadgetEvent(5,@ResizeSplitter())
  ;OpenWindow(11,0,0,500,400,"Split",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget) 
  
      
  
   Procedure WaitWindowEvent2()
     Event=WaitWindowEvent() 
     If Event = #PB_Event_Gadget
      Gadget=EventGadget() 
      If IsGadget(Gadget) And GadgetType(Gadget)=#PB_GadgetType_Splitter And EventType()=#PB_EventType_SizeItem
       Debug Gadget
      EndIf  
     EndIf
     ProcedureReturn Event
    EndProcedure
    
    Macro WaitWindowEvent()
      WaitWindowEvent2()
    EndMacro
    
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow