lib/linux: implement back button
authorAlexis Laferrière <alexis.laf@xymus.net>
Fri, 18 Mar 2016 19:12:23 +0000 (15:12 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Tue, 17 May 2016 15:28:39 +0000 (11:28 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/linux/ui.nit

index ca004a0..7c56e22 100644 (file)
@@ -43,7 +43,7 @@ redef class App
                bar.title = "app.nit" # TODO offer a portable API to name windows
                bar.show_close_button = true
 
-               # TODO add back button
+               bar.add back_button.native
 
                return bar
        end
@@ -55,6 +55,9 @@ redef class App
                return stack
        end
 
+       # Button on the header bar to go back
+       var back_button = new BackButton is lazy
+
        # On GNU/Linux, we go through all the callbacks once,
        # there is no complex life-cycle.
        redef fun run
@@ -64,7 +67,6 @@ redef class App
                app.on_start
                app.on_resume
 
-               native_window.show_all
                gtk_main
 
                app.on_pause
@@ -88,7 +90,13 @@ redef class App
                # improved with GTK 3.18 and interpolate_size.
                native_window.resizable = false
 
+               native_window.show_all
+
                super
+
+               if window.enable_back_button then
+                       back_button.native.show
+               else back_button.native.hide
        end
 end
 
@@ -243,6 +251,21 @@ redef class Button
        init do native.signal_connect("clicked", self, null)
 end
 
+# Button to go back between windows
+class BackButton
+       super Button
+
+       # TODO i18n
+       redef fun text=(value) do super(value or else "Back")
+
+       redef fun signal(sender, data)
+       do
+               super
+
+               app.window.on_back_button
+       end
+end
+
 redef class Label
        redef type NATIVE: GtkLabel
        redef var native = new GtkLabel("")