s c h e m a t i c s : c o o k b o o k

/ GUIChapterComments / Cookbook.LayoutMultiplePanelsInAFrame

This Web


WebHome 
WebChanges 
TOC (with recipes)
NewRecipe 
WebTopicList 
WebStatistics 

Other Webs


Chicken
Cookbook
Erlang
Know
Main
Plugins
Sandbox
Scm
TWiki  

Schematics


Schematics Home
Sourceforge Page
SchemeWiki.org
Original Cookbook
RSS

Scheme Links


Schemers.org
Scheme FAQ
R5RS
SRFIs
Scheme Cross Reference
PLT Scheme SISC
Scheme48 SCM
MIT Scheme scsh
JScheme Kawa
Chicken Guile
Bigloo Tiny
Gambit LispMe
GaucheChez

Lambda the Ultimate
TWiki.org

Laying out panels in a window

Problem

You want to make a specific layout of your panels

Solution

Laying out panels in DrScheme is simple,

Inside your frame you can have multiple panels (or panes), and these can contain other panels. The default behaviour is for panels to share space equally with siblings sharing the same parent.

This can be varied by using the min-width and stretchable-width arguments.

Have a play with the window generated by this code;

note: # you will have to make the frame bigger by dragging the handle on the bottom right corner # this example uses the 'framework' collection to add draggable functionality that is useful, and helps you get a better handle on how panels interact. (you can replace panel:horizontal-dragable% with horizontal-panel% for the plain vanilla version)

(require (lib "framework.ss" "framework")) ;; to add cool draggable functionality

(define topframe (make-object frame% "test" #f ))

(define hpanel 
  (instantiate panel:horizontal-dragable%  
    (topframe) 
    (stretchable-width #t) 
    (style '(border)) (border 1)))

(define content-panel 
  (instantiate horizontal-panel% 
    (hpanel) 
    (min-width 200) 
    (style '(border)) (border 1)
    ))
(define content-panel2 
  (instantiate horizontal-panel% 
    (hpanel) 
    (min-width 200) 
    (style '(border)) (border 1)
    ))

(define control/status-panel 
  (instantiate vertical-panel% 
    (hpanel) 
    (stretchable-width #f) 
    (min-width 200) 
    (style '(border)) (border 1)
    ))

(define a-button
  (new button%
       (label "Press Me")
       (parent control/status-panel)
       (callback void))) 
(define a-text-field
  (new text-field% 
       (label "Enter Text")
       (parent control/status-panel) 
       (callback void)))


(send topframe show #t)

Discussion

A GOTCHA: one thing that might be confusing the first time it happens is adding controls like text-fields; if you create a text field with a large initial value, the parent panel will expand, the parents siblings and the frame may also expand in unexpected ways. You can avoid this by creating the text-field% control, with stretchable-width as #t and setting its initial value with the set-value method.


Comments about this recipe

Contributors

-- StephenDeGabrielle - 10 Mar 2008

CookbookForm
TopicType: Recipe
ParentTopic: GUIChapter
TopicOrder: 2

 
 
Copyright © 2004 by the contributing authors. All material on the Schematics Cookbook web site is the property of the contributing authors.
The copyright for certain compilations of material taken from this website is held by the SchematicsEditorsGroup - see ContributorAgreement & LGPL.
Other than such compilations, this material can be redistributed and/or modified under the terms of the GNU Lesser General Public License (LGPL), version 2.1, as published by the Free Software Foundation.
Ideas, requests, problems regarding Schematics Cookbook? Send feedback.
/ You are Main.guest