README: document nit_env.sh
[nit.git] / lib / app / app_base.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2011-2014 Alexis Laferrière <alexis.laf@xymus.net>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # Base of the _app.nit_ framework, defines `App`
18 module app_base is
19 new_annotation app_name
20 new_annotation app_namespace
21 new_annotation app_version
22 end
23
24 # App subclasses are cross-platform applications
25 #
26 # This class is refined by platform modules and so
27 # App can be specialized directly in the user application code.
28 class App
29 super AppComponent
30
31 protected init do end
32
33 # Starts the internal setup of graphical and other stuff
34 # Is called just before run
35 fun setup do end
36
37 # Main entry point of your application
38 fun run do end
39 end
40
41 # An element of an application that is notified of the application life cycle
42 #
43 # Most users of _app.nit_ need only to implement `on_create` to setup the application.
44 #
45 # On mobile devices, the application can be stopped a anytime when another application takes the foreground.
46 # Implement the callbacks `on_save_state` and `on_load_state` to keep the state of the application between execution,
47 # for an illusion of continuous execution.
48 abstract class AppComponent
49
50 # The application is being created
51 #
52 # You should build the UI at this time.
53 fun on_create do end
54
55 # The application is starting or restarting, it is visible to the user
56 fun on_start do end
57
58 # The application enters the active state, it is in the foreground and interactive
59 fun on_resume do end
60
61 # The application leaves the active state but is still partially visible
62 #
63 # It may still be visible in the background.
64 # It may then go back to `on_resume` or `on_stop`.
65 fun on_pause do end
66
67 # The application is completely hidden from the user
68 #
69 # It may then be destroyed (`on_destroy`) or go back to `on_start`.
70 fun on_stop do end
71
72 # The application is being destroyed
73 fun on_destroy do end
74
75 # The application may be destroyed soon, save its state for a future `on_restore_state`
76 fun on_save_state do end
77
78 # The application is launching, restore its state from a previous `on_save_state`
79 fun on_restore_state do end
80 end
81
82 # Print a warning
83 fun print_warning(object: Object)
84 do
85 sys.stderr.write object.to_s
86 sys.stderr.write "\n"
87 end
88
89 # The running `App`
90 fun app: App do return once new App
91
92 app.setup
93 app.run