| 1 | = Gtk Static Widgets = |
| 2 | |
| 3 | Static widgets provide information to the user, either about the state of the program or to help understand the display. |
| 4 | |
| 5 | == Labels == |
| 6 | |
| 7 | == Separators == |
| 8 | |
| 9 | == Frame == |
| 10 | |
| 11 | 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. |
| 12 | |
| 13 | 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: |
| 14 | {{{ |
| 15 | #!cobra |
| 16 | frame1 = Frame("Widgets label") |
| 17 | frame1.add(box) |
| 18 | }}} |
| 19 | |
| 20 | There are two display elements of the frame which can be changed. |
| 21 | |
| 22 | 1. The '''position''' of the label can be changed with respect to the top line using two attributes: |
| 23 | |
| 24 | * frame.labelXAlign: 0.0 is left, 1.0 is right. |
| 25 | * frame.labelYAlign: 0.0 is below the line, 0.5 on the line, and 1.0 above the line. |
| 26 | |
| 27 | 2. The '''style''' of the line can be changed, using the 'shadowType' attribute, which has the following values: |
| 28 | |
| 29 | * !ShadowType.None |
| 30 | * !ShadowType.In: bevelled inwards |
| 31 | * !ShadowType.Out: bevelled outwards |
| 32 | * !ShadowType.!EtchedIn: (the default) |
| 33 | * !ShadowType.!EtchedOut |
| 34 | |
| 35 | The following program illustrates using frames to label some radiobuttons. The frame on the left uses the default alignment and style. |
| 36 | |
| 37 | [[Image(gtk-frames.png)]] |
| 38 | |
| 39 | {{{ |
| 40 | #!cobra |
| 41 | # @args -pkg:gtk-sharp-2.0 # remove initial '#' |
| 42 | |
| 43 | use Gtk |
| 44 | |
| 45 | class ExampleWindow inherits Window |
| 46 | cue init |
| 47 | base.init("Example of Frames") |
| 48 | listen .deleteEvent, do(obj, e as DeleteEventArgs) |
| 49 | Application.quit |
| 50 | .createWidgets |
| 51 | .setDefaultSize(300, 100) |
| 52 | |
| 53 | def createRadios as VBox |
| 54 | radio1 = RadioButton("Cobra") |
| 55 | radio2 = RadioButton(radio1, "Java") |
| 56 | radio3 = RadioButton(radio2, "Python") |
| 57 | box = VBox(false, 10) |
| 58 | box.packStart(radio1, false, false, 0) |
| 59 | box.packStart(radio2, false, false, 0) |
| 60 | box.packStart(radio3, false, false, 0) |
| 61 | return box |
| 62 | |
| 63 | def createWidgets |
| 64 | frame1 = Frame("Select Language") |
| 65 | frame1.add(.createRadios) |
| 66 | |
| 67 | frame2 = Frame("Select Language") |
| 68 | frame2.labelXalign = 0.5 to float32 |
| 69 | frame2.labelYalign = 0 to float32 |
| 70 | frame2.shadowType = ShadowType.In |
| 71 | frame2.add(.createRadios) |
| 72 | |
| 73 | box = HBox(true, 20) |
| 74 | box.borderWidth = 20 |
| 75 | box.packStart(frame1, true, true, 0) |
| 76 | box.packStart(frame2, true, true, 0) |
| 77 | .add(box) |
| 78 | |
| 79 | class RunProgram |
| 80 | def main |
| 81 | Application.init |
| 82 | window = ExampleWindow() |
| 83 | window.showAll |
| 84 | Application.run |
| 85 | }}} |