Wiki
Version 1 (modified by callisto, 13 years ago)

added Gtk Frame description

Gtk Static Widgets

Static widgets provide information to the user, either about the state of the program or to help understand the display.

Labels

Separators

Frame

A 'frame' is a container class which holds one child widget, and displays that child with a surrounding border and title. That child can be another container, so frames can contain many other widgets.

A frame is easy to construct and use. Given a box containing widgets to display, the following two lines wrap the box in the frame class:

        frame1 = Frame("Widgets label")
        frame1.add(box)

There are two display elements of the frame which can be changed.

  1. The position of the label can be changed with respect to the top line using two attributes:
  • frame.labelXAlign: 0.0 is left, 1.0 is right.
  • frame.labelYAlign: 0.0 is below the line, 0.5 on the line, and 1.0 above the line.
  1. The style of the line can be changed, using the 'shadowType' attribute, which has the following values:
  • ShadowType.None
  • ShadowType.In: bevelled inwards
  • ShadowType.Out: bevelled outwards
  • ShadowType.EtchedIn: (the default)
  • ShadowType.EtchedOut

The following program illustrates using frames to label some radiobuttons. The frame on the left uses the default alignment and style.

# @args -pkg:gtk-sharp-2.0 # remove initial '#'

use Gtk

class ExampleWindow inherits Window
    cue init
        base.init("Example of Frames")
        listen .deleteEvent, do(obj, e as DeleteEventArgs)
            Application.quit
        .createWidgets
        .setDefaultSize(300, 100)

    def createRadios as VBox
        radio1 = RadioButton("Cobra")
        radio2 = RadioButton(radio1, "Java")
        radio3 = RadioButton(radio2, "Python")
        box = VBox(false, 10)
        box.packStart(radio1, false, false, 0)
        box.packStart(radio2, false, false, 0)
        box.packStart(radio3, false, false, 0)
        return box

    def createWidgets
        frame1 = Frame("Select Language")
        frame1.add(.createRadios)

        frame2 = Frame("Select Language")
        frame2.labelXalign = 0.5 to float32
        frame2.labelYalign = 0 to float32
        frame2.shadowType = ShadowType.In
        frame2.add(.createRadios)

        box = HBox(true, 20)
        box.borderWidth = 20
        box.packStart(frame1, true, true, 0)
        box.packStart(frame2, true, true, 0)
        .add(box)
    
class RunProgram
    def main
        Application.init
        window = ExampleWindow()
        window.showAll
        Application.run

Attachments