Creating the scaffold of the calculator
This commit is contained in:
@@ -1,39 +1,39 @@
|
||||
public class Main : Gtk.Application {
|
||||
public Main() {
|
||||
Object (application_id: "com.example.App");
|
||||
}
|
||||
public Main() {
|
||||
Object (application_id: "com.example.App");
|
||||
}
|
||||
|
||||
public override void activate () {
|
||||
var win = new Gtk.ApplicationWindow (this);
|
||||
win.set_title("Calculator");
|
||||
public override void activate () {
|
||||
var win = new Gtk.ApplicationWindow (this);
|
||||
win.set_title("Calculator");
|
||||
|
||||
var display = new Gtk.Label("Display");
|
||||
display.xalign = 1.0f;
|
||||
var grid = new Gtk.Grid();
|
||||
var display = new Gtk.Label("Display");
|
||||
display.xalign = 1.0f;
|
||||
var grid = new Gtk.Grid();
|
||||
|
||||
grid.attach(display, 0, 0, 3);
|
||||
// Procedurlly generating numbered buttons 1-9
|
||||
for (int col = 0; col < 3; col++) {
|
||||
for (int row = 0; row < 3; row++){
|
||||
// This math is need to orient the buttons in the correct order
|
||||
// starting from bottom left to top right
|
||||
var number = (3 - row - 1)*3 + col + 1;
|
||||
var btn = new Gtk.Button.with_label("%d".printf(number));
|
||||
grid.attach(btn, col, row+1);
|
||||
}
|
||||
}
|
||||
grid.attach(display, 0, 0, 3);
|
||||
// Procedurlly generating numbered buttons 1-9
|
||||
for (int col = 0; col < 3; col++) {
|
||||
for (int row = 0; row < 3; row++){
|
||||
// This math is need to orient the buttons in the correct order
|
||||
// starting from bottom left to top right
|
||||
var number = (3 - row - 1)*3 + col + 1;
|
||||
var btn = new Gtk.Button.with_label("%d".printf(number));
|
||||
grid.attach(btn, col, row+1);
|
||||
}
|
||||
}
|
||||
|
||||
var zero = new Gtk.Button.with_label("0");
|
||||
var equal = new Gtk.Button.with_label("=");
|
||||
grid.attach(zero, 0, 4);
|
||||
grid.attach(equal, 1, 4);
|
||||
var zero = new Gtk.Button.with_label("0");
|
||||
var equal = new Gtk.Button.with_label("=");
|
||||
grid.attach(zero, 0, 4);
|
||||
grid.attach(equal, 1, 4);
|
||||
|
||||
win.child = grid;
|
||||
win.present ();
|
||||
}
|
||||
win.child = grid;
|
||||
win.present ();
|
||||
}
|
||||
|
||||
public static int main (string[] args) {
|
||||
var app = new Main();
|
||||
return app.run (args);
|
||||
}
|
||||
public static int main (string[] args) {
|
||||
var app = new Main();
|
||||
return app.run (args);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user