Resizing woes - editorgadget, panel and splitter

Just starting out? Need help? Post your questions and find answers here.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Resizing woes - editorgadget, panel and splitter

Post by rsts »

I have a window (with a statusbar) containing a listviewgadget on the left and a panel containing an editorgadget on the right, separated by a splittergadget.

Upon resizing the window.

1 - The statusbar is immediately 'lost'.
2 - If the window is resized by simply making it wider, the editorgadget will 'lose' it's scrollbar while it is still required.

I've been at this for a while, trying various combinations until I'm repeating myself, without success.

freak mentioned in a post that you should not resize gadgets in a splitter only the splitter, but simply resizing the splitter leaves the editor gadget it's original size - not the behavior I desire.

I know this should be possible. What am I missing?

Code: Select all

Enumeration
  #statusBar
EndEnumeration


Global Window_0 
Global Panel_0 
Global ListIcon_0 
Global Splitter_0 
Global Gadget_Editor
Global text.s
Global stBar
text = "eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"THIS IS THE END OF THE TEXT LINE - THE LAST LINE" 
      
 
Procedure WindowCallback(hwnd.l,uMsg.l,wParam.l,lParam.l) 
  Result = #PB_ProcessPureBasicEvents 
  
  Select uMsg 
    Case #WM_SIZE 
      ResizeGadget(Splitter_0,#PB_Ignore,#PB_Ignore,WindowWidth(Window_0),WindowHeight(Window_0)) 
      ;   Have attempted various combinations of resizing the editorgadget without success :(  
      ResizeGadget(Gadget_Editor,#PB_Ignore,#PB_Ignore,WindowWidth(Window_0)-260 ,WindowHeight(Window_0)-40)  
      EndSelect 
  
  ProcedureReturn Result 
EndProcedure 

Procedure Open_Window_0() 
 
  Window_0 = OpenWindow(#PB_Any, 5, 5, 482, 310, "Split",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar ) 
  If Window_0 
    stBar = CreateStatusBar(#statusBar, WindowID(Window_0))
    AddStatusBarField(100)
    AddStatusBarField(100)
    AddStatusBarField(100)
    
    If CreateGadgetList(WindowID(Window_0)) 
            ListIcon_0 = ListViewGadget(#PB_Any, 10, 10, 140, 50) 
           Panel_0 = PanelGadget(#PB_Any, 10, 10,160,210) 
      AddGadgetItem(Panel_0, 1, "Tab 1")
      Gadget_Editor=EditorGadget(#PB_Any,10,10,250,220)
      CloseGadgetList()

 ;     CloseGadgetList() 
      Splitter_0 = SplitterGadget(#PB_Any, 0, 0, 450, 280,  ListIcon_0,Panel_0,#PB_Splitter_Separator|#PB_Splitter_Vertical);|#PB_Splitter_SecondFixed) 
        SetGadgetState(Splitter_0, 160)
      SendMessage_(GadgetID(Gadget_Editor),#EM_SETTARGETDEVICE, #Null, 0)
    EndIf 
  EndIf 
EndProcedure 

Open_Window_0() 
SetWindowCallback(@WindowCallback()) 

For i=1 To 50 
  AddGadgetItem(ListIcon_0,-1,"List item number "+Str(i)) 
Next i 
  SetGadgetText(Gadget_Editor,text)
Repeat 
  
  Event = WaitWindowEvent() 
  
  WindowID = EventWindow()  

  GadgetID = EventGadget() 
  
  If Event = #PB_Event_Gadget 
    
  EndIf 
  
Until Event = #PB_Event_CloseWindow 

End 
 
Thanks for looking.

cheers
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Hi,

there were quite a few problems with the code. For one, you should set the ListIcon and Panel gadgets to have dimensions of zero since the splitter handles the placement and size of these two gadgets.

You'll notice I've also set the editor gadget to have dimensions of zero. I do this to avoid repetition and get the #WM_SIZE handler to sort out all of the dimensions etc. For this I send an initial #WM_SIZE message.

Finally, you didn't take the status bar height into account when the window was being resized.

Code: Select all

Enumeration 
  #statusBar 
EndEnumeration 


Global Window_0 
Global Panel_0 
Global ListIcon_0 
Global Splitter_0 
Global Gadget_Editor 
Global text.s 
Global stBar 
text = "eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"THIS IS THE END OF THE TEXT LINE - THE LAST LINE" 
      
  
Procedure WindowCallback(hwnd.l,uMsg.l,wParam.l,lParam.l) 
  Result = #PB_ProcessPureBasicEvents 
  
  Select uMsg 
    Case #WM_SIZE 
;***
      ResizeGadget(Splitter_0,#PB_Ignore,#PB_Ignore,WindowWidth(Window_0),WindowHeight(Window_0)-StatusBarHeight(#statusBar)) 
;***
      ;   Have attempted various combinations of resizing the editorgadget without success :(  
;***
      ResizeGadget(Gadget_Editor,#PB_Ignore,#PB_Ignore,GetGadgetAttribute(Panel_0, #PB_Panel_ItemWidth)-10,GetGadgetAttribute(Panel_0, #PB_Panel_ItemHeight)-10)
;***      

      EndSelect 
  
  ProcedureReturn Result 
EndProcedure 

Procedure Open_Window_0() 
  
  Window_0 = OpenWindow(#PB_Any, 5, 5, 482, 310, "Split",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar ) 
  If Window_0 
    stBar = CreateStatusBar(#statusBar, WindowID(Window_0)) 
    AddStatusBarField(100) 
    AddStatusBarField(100) 
    AddStatusBarField(100) 
    
    If CreateGadgetList(WindowID(Window_0)) 
;***
      ListIcon_0 = ListViewGadget(#PB_Any, 0, 0, 0, 0) 
;***
      Panel_0 = PanelGadget(#PB_Any, 0, 0,0,0) 
;***
      AddGadgetItem(Panel_0, 1, "Tab 1") 
;***
      Gadget_Editor=EditorGadget(#PB_Any,5,5,0,0) 
;***
      CloseGadgetList() 

 ;     CloseGadgetList() 
;***
      Splitter_0 = SplitterGadget(#PB_Any, 0, 0, WindowWidth(Window_0), WindowHeight(Window_0)-StatusBarHeight(#statusBar),  ListIcon_0,Panel_0,#PB_Splitter_Separator|#PB_Splitter_Vertical);|#PB_Splitter_SecondFixed) 
;***
        SetGadgetState(Splitter_0, 160) 
      SendMessage_(GadgetID(Gadget_Editor),#EM_SETTARGETDEVICE, #Null, 0) 
    EndIf 
  EndIf 
EndProcedure 

Open_Window_0() 
SetWindowCallback(@WindowCallback()) 
;Force a resize
;***
  SendMessage_(WindowID(Window_0), #WM_SIZE, 0, 0)
;***


For i=1 To 50 
  AddGadgetItem(ListIcon_0,-1,"List item number "+Str(i)) 
Next i 
  SetGadgetText(Gadget_Editor,text) 
Repeat 
  
  Event = WaitWindowEvent() 
  
  WindowID = EventWindow()  

  GadgetID = EventGadget() 
  
  If Event = #PB_Event_Gadget 
    
  EndIf 
  
Until Event = #PB_Event_CloseWindow 

End 
Tip : WindowHeight() and WindowWidth() will return the size of the 'client area' of the window but include the area occupied by a menu. Use GetClientRect_() instead which excludes any menus.
I may look like a mule, but I'm not a complete ass.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

30 minutes! Man, you're slipping :)

If you ever offer a subscription for support services, put me on the charter subscriber list.

Now, to see if I can understand what you've done well enough to apply it to my real program.

Many, many thanks.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

You're welcome.

I must admit that I use EasyVENT for this kind of thing; it makes dynamically resizing gadgets much easier and very flexible. Attach an #OnResize handler to a container and you can resize all of it's child controls as appropriate and in a nicely self-contained manner. :wink:
I may look like a mule, but I'm not a complete ass.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

Guess I'll be studying easyvent then, because upon attempting to apply the lessons above to my real code (which has toolbars as well as a statusbar), I encounter another problem which I have been unable to overcome. I can get the toolbar OK but I've lost the statusbar again, and can't seem to come up with a way to have both.

EasyVent should keep me busy and out of your hair for a while :D

cheers
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

With toolbar :

Code: Select all

Enumeration 
  #statusBar 
EndEnumeration 


Global Window_0 
Global Panel_0 
Global ListIcon_0 
Global Splitter_0 
Global Gadget_Editor 
Global text.s 
Global stBar 
text = "eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam " 
text+"THIS IS THE END OF THE TEXT LINE - THE LAST LINE" 
      
  
Procedure WindowCallback(hwnd.l,uMsg.l,wParam.l,lParam.l) 
  Result = #PB_ProcessPureBasicEvents 
  
  Select uMsg 
    Case #WM_SIZE 
;*** 
      ResizeGadget(Splitter_0,#PB_Ignore,#PB_Ignore,WindowWidth(Window_0),WindowHeight(Window_0)-StatusBarHeight(#statusBar)-ToolBarHeight(0)) 
;*** 
      ;   Have attempted various combinations of resizing the editorgadget without success :(  
;*** 
      ResizeGadget(Gadget_Editor,#PB_Ignore,#PB_Ignore,GetGadgetAttribute(Panel_0, #PB_Panel_ItemWidth)-10,GetGadgetAttribute(Panel_0, #PB_Panel_ItemHeight)-10) 
;***      

      EndSelect 
  
  ProcedureReturn Result 
EndProcedure 

Procedure Open_Window_0() 
  
  Window_0 = OpenWindow(#PB_Any, 5, 5, 482, 310, "Split",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar ) 
  If Window_0 
    stBar = CreateStatusBar(#statusBar, WindowID(Window_0)) 
    AddStatusBarField(100) 
    AddStatusBarField(100) 
    AddStatusBarField(100) 
    
    CreateToolBar(0, WindowID(Window_0))
    ToolBarStandardButton(0, #PB_ToolBarIcon_New)
    ToolBarStandardButton(1, #PB_ToolBarIcon_Open)
    ToolBarStandardButton(2, #PB_ToolBarIcon_Save)

    If CreateGadgetList(WindowID(Window_0)) 
;*** 
      ListIcon_0 = ListViewGadget(#PB_Any, 0, 0, 0, 0) 
;*** 
      Panel_0 = PanelGadget(#PB_Any, 0, 0,0,0) 
;*** 
      AddGadgetItem(Panel_0, 1, "Tab 1") 
;*** 
      Gadget_Editor=EditorGadget(#PB_Any,5,5,0,0) 
;*** 
      CloseGadgetList() 

 ;     CloseGadgetList() 
;*** 
      Splitter_0 = SplitterGadget(#PB_Any, 0, ToolBarHeight(0), WindowWidth(Window_0), WindowHeight(Window_0)-StatusBarHeight(#statusBar)-ToolBarHeight(0),  ListIcon_0,Panel_0,#PB_Splitter_Separator|#PB_Splitter_Vertical);|#PB_Splitter_SecondFixed) 
;*** 
        SetGadgetState(Splitter_0, 160) 
      SendMessage_(GadgetID(Gadget_Editor),#EM_SETTARGETDEVICE, #Null, 0) 
    EndIf 
  EndIf 
EndProcedure 

Open_Window_0() 
SetWindowCallback(@WindowCallback()) 
;Force a resize 
;*** 
  SendMessage_(WindowID(Window_0), #WM_SIZE, 0, 0) 
;*** 


For i=1 To 50 
  AddGadgetItem(ListIcon_0,-1,"List item number "+Str(i)) 
Next i 
  SetGadgetText(Gadget_Editor,text) 
Repeat 
  
  Event = WaitWindowEvent() 
  
  WindowID = EventWindow()  

  GadgetID = EventGadget() 
  
  If Event = #PB_Event_Gadget 
    
  EndIf 
  
Until Event = #PB_Event_CloseWindow 

End 
A toolbar sits in the Window's client area so you need to take it's height into account. You'll see the ammnendments to the lines :

Code: Select all

ResizeGadget(Splitter_0,...)
and

Code: Select all

Splitter_0 = SplitterGadget(...)
I may look like a mule, but I'm not a complete ass.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

Well, at least I was close. I had exactly what you submitted EXCEPT for the -ToolBarHeight(0) in the resizegadget.

Now that I see the solution, I don't know how I missed that, but I sure did.

If I wasn't well past my 'fathering' years (youngest is 11 now), I'd have to name the next one Steven.

Gratitude - don't know what else to say.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

rsts wrote:If I wasn't well past my 'fathering' years (youngest is 11 now), I'd have to name the next one Steven.
Even if it was a girl? :wink:

If you add a menu then you'll need to consider MenuHeight() as well; unless you switch WindowHeight() for the height of the true client area obtained from GetClientRect_() etc.
I may look like a mule, but I'm not a complete ass.
Post Reply