Control
treeEach window should hold a single control, usually a CompositeControl
,
which in turn holds all the displayed controls.
app :: Window :: defaultinit
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
app :: AppObserver :: defaultinit
core :: Object :: defaultinit
app :: AppComponent :: defaultinit
gtk :: GtkCallable :: defaultinit
app :: Window :: defaultinit
core :: Finalizable :: defaultinit
app :: Control :: defaultinit
app :: CompositeControl :: defaultinit
core :: Finalizable :: finalize
Liberate any resources held byself
before the memory holding self
is freed
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
app :: AppComponent :: notify_observers
Propagateevent
to all observers
by calling AppObserver::on_event
app :: AppComponent :: observers
AllAppObserver
notified of events raised by self
app :: AppComponent :: observers=
AllAppObserver
notified of events raised by self
app :: AppComponent :: on_pause
The application leaves the active state but is still partially visibleapp :: AppComponent :: on_restart
The application returns to a visible state from a previouson_stop
app :: AppComponent :: on_restore_state
The application is launching, restore its state from a previouson_save_state
app :: AppComponent :: on_resume
The application enters the active state, it is in the foreground and interactiveapp :: AppComponent :: on_save_state
The application may be destroyed soon, save its state for a futureon_restore_state
app :: AppComponent :: on_start
The application is starting or restarting, it is visible to the usercore :: Object :: output_class_name
Display class name on stdout (debug only).Control
in the control tree
Control
in the control tree
app :: AppComponent
An element of an application that is notified of the application life cyclegtk :: GtkCallable
app :: HttpRequestClientWindow
Simple window with a label and a button
# A window, root of the `Control` tree
#
# Each window should hold a single control, usually a `CompositeControl`,
# which in turn holds all the displayed controls.
class Window
super CompositeControl
# Should the back button be shown and used to go back to a previous window?
fun enable_back_button: Bool do return app.window_stack.length > 1
# The back button has been pressed, usually to open the previous window
fun on_back_button do app.pop_window
end
lib/app/ui.nit:202,1--214,3
redef class Window
redef type NATIVE: NitViewController
redef var native = new NitViewController
# Title of this window
fun title: String do return native.title.to_s
# Set the title of this window
fun title=(title: String) do native.title = title.to_nsstring
redef fun add(view)
do
super
var native_view = view.native
assert native_view isa UIView
if view isa ListLayout then
native.view.add_subview native_view
else native.view = native_view
end
end
lib/ios/ui/ui.nit:206,1--228,3
# On GNU/Linux, a window is implemented by placing the `view` in a `GtkStack` in the single GTK window
redef class Window
# Root view of this window
var view: nullable View = null
redef fun add(view)
do
if view isa View then
self.view = view
view.native.valign = new GtkAlign.start
view.native.set_size_request(gtk_window_width_request, 0)
end
super
end
end
lib/linux/ui.nit:121,1--137,3
# On Android, a window is implemented with the fragment `native`
redef class Window
redef var native = (new Android_app_Fragment(self)).new_global_ref
redef type NATIVE: Android_app_Fragment
# Root high-level view of this window
var view: nullable View = null
redef fun add(item)
do
if item isa View then view = item
super
end
private fun on_create_fragment: NativeView
do
on_create
var view = view
assert view != null else print_error "{class_name} needs a `view` after `Window::on_create` returns"
return view.native
end
end
lib/android/ui/ui.nit:107,1--130,3
redef class Window
private var layout = new VerticalLayout(parent=self)
private var but_notif = new Button(parent=layout, text="Show Notification")
private var but_toast = new Button(parent=layout, text="Show Toast")
private var notif: nullable Notification = null
init
do
but_notif.observers.add self
but_toast.observers.add self
end
# Action when pressing `but_notif`
fun act_notif
do
var notif = self.notif
if notif == null then
notif = new Notification("From app.nit", "Some content...")
notif.ticker = "Ticker text..."
notif.show
self.notif = notif
else
notif.cancel
self.notif = null
end
end
# Action when pressing `but_toast`
fun act_toast
do
app.toast("Sample toast from app.nit at {get_time}", false)
end
redef fun on_event(event)
do
print "on_event {event}"
if event isa ButtonPressEvent then
var sender = event.sender
if sender == but_notif then
act_notif
else if sender == but_toast then
act_toast
end
end
end
end
lib/android/examples/src/ui_test.nit:39,1--87,3