SplitterGadget: Odd behaviour when resizing

Just starting out? Need help? Post your questions and find answers here.
Fenix
Enthusiast
Enthusiast
Posts: 102
Joined: Wed May 07, 2003 1:45 am
Location: Germany

SplitterGadget: Odd behaviour when resizing

Post 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
Fenix
Enthusiast
Enthusiast
Posts: 102
Joined: Wed May 07, 2003 1:45 am
Location: Germany

Re: SplitterGadget: Odd behaviour when resizing

Post 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
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: SplitterGadget: Odd behaviour when resizing

Post 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.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: SplitterGadget: Odd behaviour when resizing

Post 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.
User avatar
skywalk
Addict
Addict
Posts: 4265
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: SplitterGadget: Odd behaviour when resizing

Post 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:
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
mestnyi
Addict
Addict
Posts: 1109
Joined: Mon Nov 25, 2013 6:41 am

Re: SplitterGadget: Odd behaviour when resizing

Post 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 
Post Reply