Skip to content

Commit

Permalink
Add Scala example
Browse files Browse the repository at this point in the history
  • Loading branch information
jwharm committed Aug 26, 2024
1 parent f297515 commit 73a3b94
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,43 @@ An example Gtk application with a "Hello world" button can be created as follows
}
```

=== "Scala"

```scala
package my.example.helloapp
import org.gnome.gtk.*
import org.gnome.gio.ApplicationFlags
class HelloWorld {
def activate(app: Application) = {
var window = new ApplicationWindow(app)
window.setTitle("GTK from Scala")

var box = new Box(Orientation.VERTICAL, 1) {
setHalign(Align.CENTER)
setValign(Align.CENTER)
}

var button = Button.withLabel("Hello world!")
button.onClicked{() => window.close}

box.append(button)
window.setChild(box)
window.present()
}
}

object HelloWorld {
def main(args: Array[String]) = {
val app = Application("my.example.HelloApp", ApplicationFlags.DEFAULT_FLAGS)
app.onActivate(() => HelloWorld().activate(app))
app.run(args);
()
}
}
```

## Compile and run

Build and run the application using your IDE or build tool of choice. The following command-line parameters are useful:
Expand Down

0 comments on commit 73a3b94

Please sign in to comment.