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 # Implementation of the app.nit UI module for GNU/Linux
24 redef fun setup
do gtk_init
26 # On GNU/Linux, we go through all the callbacks once,
27 # there is no complex life-cycle.
36 window
.native
.show_all
45 # Spacing between GTK controls, default at 2
46 var control_spacing
= 2 is writable
53 # The GTK element used to implement `self`
54 fun native
: NATIVE is abstract
57 type NATIVE: GtkWidget
62 if not native
.address_is_null
then native
.destroy
66 redef class CompositeControl
67 redef type NATIVE: GtkContainer
72 native
.add item
.native
77 redef type NATIVE: GtkWindow
79 var win
= new GtkWindow(new GtkWindowType.toplevel
)
80 win
.connect_destroy_signal_to_quit
88 redef fun enabled
do return native
.sensitive
89 redef fun enabled
=(enabled
) do native
.sensitive
= enabled
or else true
93 redef type NATIVE: GtkBox
94 redef fun remove
(view
)
97 native
.remove view
.native
101 redef class HorizontalLayout
102 redef var native
= new GtkBox(new GtkOrientation.horizontal
, app
.control_spacing
)
107 native
.homogeneous
= true
108 native
.set_child_packing
(item
.native
, true, true, 0, new GtkPackType.start
)
112 redef class VerticalLayout
113 redef var native
= new GtkBox(new GtkOrientation.vertical
, app
.control_spacing
)
119 # FIXME abstract the use either homogeneous or weight to balance views size in a layout
120 native
.homogeneous
= true
121 native
.set_child_packing
(item
.native
, true, true, 0, new GtkPackType.start
)
125 redef class ListLayout
126 redef type NATIVE: GtkListBox
127 redef var native
= new GtkListBox
129 init do native
.selection_mode
= new GtkSelectionMode.none
133 redef type NATIVE: GtkButton
134 redef var native
= new GtkButton
136 redef fun text
do return native
.text
137 redef fun text
=(value
) do native
.text
= (value
or else "").to_s
139 redef fun signal
(sender
, data
) do notify_observers
new ButtonPressEvent(self)
141 init do native
.signal_connect
("clicked", self, null)
145 redef type NATIVE: GtkLabel
146 redef var native
= new GtkLabel("")
148 redef fun text
do return native
.text
149 redef fun text
=(value
) do native
.text
= (value
or else "").to_s
152 redef class TextInput
153 redef type NATIVE: GtkEntry
154 redef var native
= new GtkEntry
156 redef fun text
do return native
.text
157 redef fun text
=(value
) do
158 if value
== null then value
= ""
159 native
.text
= value
.to_s