Learn R Programming

gWidgets (version 0.0-27)

ggroup: Containers for packing in subsequent widgets

Description

A ggroup is the primary container for packing in subsequent widgets, either from left to right or top to bottom. Widgets are packed in using the add method and can be removed with the delete method.

The gframe and gexpandgroup widgets add a label to the group and in the latter case an arrow for hiding/showing the group.

Usage

ggroup(horizontal = TRUE, spacing = 5,  use.scrollwindow = FALSE, container = NULL, ..., toolkit = guiToolkit())

gframe(text = "", markup = FALSE, pos = 0, horizontal=TRUE, container = NULL, ..., toolkit = guiToolkit()) gexpandgroup(text = "", markup = FALSE, horizontal=TRUE, handler = NULL, action = NULL, container = NULL, ..., toolkit = guiToolkit())

Arguments

horizontal
Specifies if widgets are packed in left to right or top to bottom (FALSE)
spacing
Space in pixels around each widget. Can be changed with svalue
text
Text for label
markup
Optional markup. (See glabel for details.)
pos
Where to place label: 0 is to left, 1 to right, interpolates.
handler
Called when expand arrow is clicked
action
Passed to handler
use.scrollwindow
If TRUE then group is placed in a scrollwindow allowing panning with mouse.
container
Optional container to attach widget to. Not optional for gWidgetstcltk, or gWidgetsRwxwidgets
...
Passed to the add method of the container
toolkit
Which GUI toolkit to use

Details

The groups pack in widgets from either left to right (when horizontal=TRUE) or from top to bottom (when horizontal=FALSE).

The container argument is optional for gWidgetsRGtk2 and gWidgetsrJava, but not the other toolkits. It is suggested that it always be included for portability. When it is not included, widgets are added to the new group object through its add method. Otherwise, when a widget is created, the group is specified as the container and the add method is then called. The add method is used to place a child widget into a parent container. This method may be called directly in some cases, but often is called behind the scenes when a widget is constructed.

When the parent allocates space to a child widget is may be more than the space needed by the child widget. Different types of behavior are desirable for drawing the child. To have the widget grow to fill the space, use the argument expand=TRUE. (Growing is done in both x and y directions. To anchor the widget into a portion of the space provided, use the argument anchor=c(a,b) where a and b are values in -1,0,1 and specify the position using Cartesian coordinates.

The svalue<- method can be used to adjust the border width. By default it is 2 pixels. The spacing value determines the number of pixels of padding between each widget when packed in. This can be set when the group is constructed, or later using svalue.

To put space between just two widgets, the addSpace(obj, value, ...) method may be used where value is the number of pixels of padding between the just packed widget, and the next one to be packed.

The addSpring(obj,...) method will push the just packed widget and the next-to-be packed widget as far apart as possible.

In gWidgetsRGtk2 a few arguments add to the container. The argument raise.on.dragmotion = TRUE will cause the group to jump to the foreground when a drag action crosses it. The argument use.scrollwindow = TRUE will put the group For gframe and gexpandgroup the label name can be retrieved or adjusted with the names method.

Examples

Run this code
## basic group 
  group <- ggroup(horizontal=FALSE, container=gwindow())
  l <- glabel("widget 1")  ## not in gWidgetstcltk -- needs a container
  add(group, l)
  glabel("widget 2", container = group) ## style for all toolkits

  ## nested groups
  group <- ggroup(horizontal=FALSE, container=gwindow())
  innergroup <- ggroup(container = group)
  gtext("Text area", container=group)
  gbutton("button 1", container = innergroup)
  gbutton("button 2", container = innergroup)

  ## expand argument
  group <- ggroup(horizontal=FALSE, container=gwindow())
  gbutton("no expand", container=group)
  gbutton("expand=TRUE", container=group, expand=TRUE)

  ## anchor argument
  w <- gwindow("Anchor")
  size(w) <- c(500,500)
  group <- ggroup(container=w)
  glabel("upper left", container=group, anchor=c(-1,1))
  glabel("lower right", container=group, anchor=c(1,-1))

  ## add spring
  group <- ggroup(container=gwindow("menubar-like example"))
  gbutton("File",handler=function(h,...) print("file"), container=group)
  gbutton("Edit",handler=function(h,...) print("edit"), container=group)
  addSpring(group)				   
  gbutton("Help",handler=function(h,...) print("help"), container=group)

Run the code above in your browser using DataLab