-
Notifications
You must be signed in to change notification settings - Fork 4
Home
axiles edited this page Jul 5, 2014
·
3 revisions
To write an Elementary app in Ocaml, you can get started with the following:
open Efl
let () =
Elm.init ();
(* create window(s) here and do any application init *)
Elm.run (); (* run main loop *)
Elm.shutdown (); (* after mainloop finished running, shutdown *)
To build this program you need the ocamlfind package efl.
Now let’s actually create an interactive “Hello World” gui that you can click
the ok button to exit. It’s more code because this now does something much more
significant, but it’s still very simple:
open Efl
let on_done obj =
Elm.exit () (* quit mainloop (Elm.run function will return *)
let () =
Elm.init ();
(* new window - do the usual and give it a name (hello) and a title (Hello)*)
let win = Elm_win.util_standard_add "hello" "Hello" in
(* when the user clicks "close" on a window there is a request to delete *)
Elm_connect.Win.delete_request win on_done;
(* add a box object - default is vertical. a box holds children in a row
* either horizontally or vertically. nothing more. *)
let box = Elm_box.add win in
(* make the box horizontal *)
Elm_box.horizontal_set box true;
(* add object as a resize object for the window (controls window minimum
* size as well as gets resized if window is resized) *)
Elm_win.resize_object_add win box;
Evas_object.show box;
(* add a label widget, set the text and put it in the pad frame *)
let lab = Elm_label.add win in
(* set default text of the label *)
Elm_object.text_set lab "Hello out there world!";
(* pack the label at the end of the box *)
Elm_box.pack_end box lab;
Evas_object.show lab;
(* add an ok button *)
let btn = Elm_button.add win in
(* set default text of button to "OK" *)
Elm_object.text_set btn "Ok";
(* pack the button at the end of the box *)
Elm_box.pack_end box btn;
Evas_object.show btn;
(* call on_done when the button is clicked *)
Elm_connect.Button.clicked btn on_done;
(* now we are done, show the window *)
Evas_object.show win;
(* run the mainloop and process events and callbacks *)
Elm.run ();
Elm.shutdown ()
It is also possible to use addx functions instead:
open Efl
let on_done obj = Elm.exit ()
let () =
Elm.init ();
let win = Elm_win.addx ~title:"Hello" "hello" in
Elm_connect.Win.delete_request win on_done;
let box = Elm_box.addx ~win win in
Elm_box.horizontal_set box true;
ignore (Elm_label.addx ~text:"Hello out there World!" ~box win);
let btn = Elm_button.addx ~text:"Ok" ~box win in
Elm_connect.Button.clicked btn on_done;
Evas_object.show win;
Elm.run ();
Elm.shutdown ()