| 7 | A 'label' simply displays some text. The most straightforward construction is: |
| 8 | {{{ |
| 9 | #!cobra |
| 10 | label1 = Label("label") |
| 11 | }}} |
| 12 | |
| 13 | Labels can display larger blocks of text. Set 'lineWrap' to true if the text should be wrapped and displayed on multiple lines. Markup is supported to change the style of the text. If your label text contains markup you need to set the 'useMarkup' attribute of the label to true. |
| 14 | |
| 15 | The following image and program shows three different labels. |
| 16 | |
| 17 | [[Image(gtk-labels.png)]] |
| 18 | |
| 19 | {{{ |
| 20 | #!cobra |
| 21 | # @args -pkg:gtk-sharp-2.0 # remove initial '#' |
| 22 | |
| 23 | use Gtk |
| 24 | |
| 25 | class ExampleWindow inherits Window |
| 26 | cue init |
| 27 | base.init("Example of Labels") |
| 28 | listen .deleteEvent, do(obj, e as DeleteEventArgs) |
| 29 | Application.quit |
| 30 | .createWidgets |
| 31 | .setDefaultSize(300, 100) |
| 32 | |
| 33 | def createWidgets |
| 34 | label1 = Label("label") |
| 35 | label2 = Label("with _mnemonic") |
| 36 | label3 = Label("Right now, if you want software contracts in your language, |
| 37 | how can you get them? The answer is to use <tt>Eiffel</tt> or D. What if you want static and |
| 38 | dynamic binding? Use Objective-C or Boo. What if you want expressiveness and quick coding? |
| 39 | Use <b>Python, Ruby or Smalltalk</b>. What if you want runtime performance? Use C#, Java, C++, |
| 40 | etc. <i>What if you want first class language support for unit tests? Use D.</i>") |
| 41 | label3.lineWrap = true |
| 42 | label3.useMarkup = true |
| 43 | |
| 44 | box = HBox(false, 20) |
| 45 | box.borderWidth = 20 |
| 46 | box.packStart(label1, true, true, 0) |
| 47 | box.packStart(label2, true, true, 0) |
| 48 | box.packStart(label3, true, true, 0) |
| 49 | .add(box) |
| 50 | |
| 51 | class RunProgram |
| 52 | def main |
| 53 | Application.init |
| 54 | window = ExampleWindow() |
| 55 | window.showAll |
| 56 | Application.run |
| 57 | }}} |
| 58 | |