calculator: shorter name and bump up the version number
[nit.git] / examples / calculator / src / calculator.nit
index 76c3a0a..6cfb1aa 100644 (file)
@@ -14,8 +14,8 @@
 
 # Portable calculator UI
 module calculator is
-app_name "app.nit Calc."
-       app_version(0, 1, git_revision)
+       app_name "app.nit Calc"
+       app_version(0, 2, git_revision)
        app_namespace "org.nitlanguage.calculator"
 
        # Lock in portrait mode
@@ -38,7 +38,7 @@ redef class App
                if debug then print "App::on_create"
 
                # Create the main window
-               window = new CalculatorWindow
+               push_window new CalculatorWindow
                super
        end
 end
@@ -51,13 +51,13 @@ class CalculatorWindow
        private var context = new CalculatorContext
 
        # Main window layout
-       private var layout = new VerticalLayout(parent=self)
+       var layout = new VerticalLayout(parent=self)
 
        # Main display, at the top of the screen
        private var display = new TextInput(parent=layout)
 
        # Maps operators as `String` to their `Button`
-       private var buttons = new HashMap[String, Button]
+       var buttons = new HashMap[String, Button]
 
        init
        do
@@ -66,8 +66,8 @@ class CalculatorWindow
                # All the button labels, row by row
                var rows = [["7", "8", "9", "+"],
                            ["4", "5", "6", "-"],
-                           ["1", "2", "3", "*"],
-                           ["0", ".", "C", "/"],
+                           ["1", "2", "3", "×"],
+                           ["0", ".", "C", "÷"],
                            ["="]]
 
                for row in rows do
@@ -75,7 +75,6 @@ class CalculatorWindow
 
                        for op in row do
                                var but = new Button(parent=row_layout, text=op)
-                               but.observers.add self
                                buttons[op] = but
                        end
                end
@@ -94,9 +93,9 @@ class CalculatorWindow
                        else if op.is_numeric then
                                var n = op.to_i
                                context.push_digit n
-                       else
+                       else if op != null then
                                buttons["."].enabled = true
-                               context.push_op op.chars.first
+                               context.push_op op
                        end
 
                        display.text = context.display_text