]> gitweb.factorcode.org Git - factor.git/blob - extra/gtk-samples/hello-world/hello-world.factor
core, basis, extra: Remove DOS line endings from files.
[factor.git] / extra / gtk-samples / hello-world / hello-world.factor
1 ! Copyright (C) 2010 Anton Gorenko.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien.strings gobject.ffi gtk.ffi io.encodings.utf8
4 kernel locals ;
5 IN: gtk-samples.hello-world
6
7 : on-button-clicked ( button label-user-data -- )
8     nip "Hello! :)" utf8 string>alien gtk_label_set_text ;
9
10 :: hello-world-win ( -- window )
11     GTK_WINDOW_TOPLEVEL gtk_window_new :> window
12
13     window
14     [ "Hello world!" utf8 string>alien gtk_window_set_title ]
15     [ 300 200 gtk_window_set_default_size ]
16     [ GTK_WIN_POS_CENTER gtk_window_set_position ] tri
17
18     gtk_fixed_new :> frame
19     window frame gtk_container_add
20
21     "Say 'Hello!'" utf8 string>alien gtk_button_new_with_label :> button
22     button 140 30 gtk_widget_set_size_request
23     frame button 80 60 gtk_fixed_put
24
25     "" utf8 string>alien gtk_label_new :> label
26     frame label 120 110 gtk_fixed_put
27
28     button "clicked" utf8 string>alien
29     [ on-button-clicked ] GtkButton:clicked label
30     g_signal_connect drop
31
32     window ;
33
34 :: hello-world-main ( -- )
35     f f gtk_init
36     hello-world-win :> window
37
38     window "destroy" utf8 string>alien
39     [ 2drop gtk_main_quit ] GtkObject:destroy f
40     g_signal_connect drop
41
42     window gtk_widget_show_all
43
44     gtk_main ;
45
46 MAIN: hello-world-main