1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # User interface example using `app::ui`
18 app_namespace
"org.nitlanguage.ui_example"
23 import app
::data_store
24 import android
::aware
# for android_api_target
26 # Window showing off some the available controls
31 var layout
= new ListLayout(parent
=self)
34 var some_label
= new Label(parent
=layout
, text
="This Window uses a ListLayout.")
37 var checkbox
= new CheckBox(parent
=layout
, text
="A CheckBox")
39 # Horizontal organization
40 var h_layout
= new HorizontalLayout(parent
=layout
)
42 # Description for the `user_input`
43 var user_input_label
= new Label(parent
=h_layout
, text
="Input some text:", align
=0.5)
45 # Field for the user to enter data
46 var user_input
= new TextInput(parent
=h_layout
, text
="Default text")
48 # Button to open a new window with a ListLayout
49 var button_window
= new Button(parent
=layout
, text
="Open a new window")
52 var example_url
= "http://nitlanguage.org/"
54 # Button to open the browser
55 var button_browser
= new Button(parent
=layout
, text
="Open {example_url}")
57 redef fun on_event
(event
)
59 if event
isa ButtonPressEvent then
60 if event
.sender
== button_browser
then
61 example_url
.open_in_browser
62 else if event
.sender
== button_window
then
63 app
.push_window
new SecondWindow
65 else if event
isa ToggleEvent then
66 if event
.sender
== checkbox
then checkbox
.text
= if checkbox
.is_checked
then "Checked" else "Unchecked"
71 # Another window with a small `VerticalLayout`
76 var layout
= new VerticalLayout(parent
=self)
79 var a_label
= new Label(parent
=layout
, text
="This window uses a VerticalLayout.")
82 var another_label
= new Label(parent
=layout
, text
="Close it by tapping the back button.")
88 # Create the main window
89 push_window
new UiExampleWindow