app: intro `root_window` to select the first visible window
authorAlexis Laferrière <alexis.laf@xymus.net>
Wed, 6 Sep 2017 13:37:15 +0000 (09:37 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Fri, 8 Sep 2017 21:18:55 +0000 (17:18 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/app/examples/ui_example.nit
lib/app/ui.nit

index f7dca44..5d01592 100644 (file)
@@ -84,11 +84,4 @@ class SecondWindow
        var another_label = new Label(parent=layout, text="Close it by tapping the back button.")
 end
 
-redef class App
-       redef fun on_create
-       do
-               # Create the main window
-               push_window new UiExampleWindow
-               super
-       end
-end
+redef fun root_window do return new UiExampleWindow
index 1fdf801..e426383 100644 (file)
@@ -38,6 +38,7 @@ redef class App
        do
                window_stack.add window
                self.window = window
+               window.on_create
        end
 
        # Pop the current `window` from the stack and show the previous one
@@ -54,7 +55,11 @@ redef class App
        # Stack of active windows
        var window_stack = new Array[Window]
 
-       redef fun on_create do window.on_create
+       redef fun on_create
+       do
+               var window = root_window
+               push_window window
+       end
 
        redef fun on_resume do window.on_resume
 
@@ -67,6 +72,13 @@ redef class App
        redef fun on_save_state do window.on_save_state
 end
 
+# Hook to create the first window shown to the user
+#
+# By default, a `Window` is created, which can be refined to customize it.
+# However, most apps should refine this method to return a different window,
+# this way the app can have more than one window.
+fun root_window: Window do return new Window
+
 # An event created by an `AppComponent` and sent to `AppObserver`s
 interface AppEvent
 end