I am trying to format my calculator that I made in FXRuby and right now all the buttons are in one column and so I was wondering how I could use the FXMatrix class so that I can format the buttons into a much more appealing setting. Heres what the program looks like right now:
require 'fox16'
include Fox class Calc 50, :padRight => 50, :padTop => 50, :padBottom => 50)
@calc_lbl = FXLabel.new(self, "Calculator")
@calc_txt = FXTextField.new(self, 10)
#Calc functions definitions
@calc_add = FXButton.new(self, "+")
@calc_sub = FXButton.new(self, "-")
@calc_div = FXButton.new(self, "/")
@calc_mul = FXButton.new(self, "*")
@calc_eq = FXButton.new(self, "=")
@calc_clr = FXButton.new(self, "Clr")
#Number button definitions
@calc_1 = FXButton.new(self, "1")
@calc_2 = FXButton.new(self, "2")
@calc_3 = FXButton.new(self, "3")
@calc_4 = FXButton.new(self, "4")
@calc_5 = FXButton.new(self, "5")
@calc_6 = FXButton.new(self, "6")
@calc_7 = FXButton.new(self, "7")
@calc_8 = FXButton.new(self, "8")
@calc_9 = FXButton.new(self, "9")
@calc_1.connect(SEL_COMMAND) do |sender, sel, event|
@calc_txt.text += "1"
end
@calc_2.connect(SEL_COMMAND) do |sender, sel, event|
@calc_txt.text += "2"
end
@calc_3.connect(SEL_COMMAND) do |sender, sel, event|
@calc_txt.text += "3"
end
@calc_4.connect(SEL_COMMAND) do |sender, sel, event|
@calc_txt.text += "4"
end
@calc_5.connect(SEL_COMMAND) do |sender, sel, event|
@calc_txt.text += "5"
end
@calc_6.connect(SEL_COMMAND) do |sender, sel, event|
@calc_txt.text += "6"
end
@calc_7.connect(SEL_COMMAND) do |sender, sel, event|
@calc_txt.text += "7"
end
@calc_8.connect(SEL_COMMAND) do |sender, sel, event|
@calc_txt.text += "8"
end
@calc_9.connect(SEL_COMMAND) do |sender, sel, event|
@calc_txt.text += "9"
end
@calc_add.connect(SEL_COMMAND) do |sender, sel, event|
@num1 = @calc_txt.text
@calc_txt.text = ""
@op = "+"
end
@calc_sub.connect(SEL_COMMAND) do |sender, sel, event|
@num1 = @calc_txt.text
@calc_txt.text = ""
@op = "-"
end
@calc_div.connect(SEL_COMMAND) do |sender, sel, event|
@num1 = @calc_txt.text
@calc_txt.text = ""
@op = "/"
end
@calc_mul.connect(SEL_COMMAND) do |sender, sel, event|
@num1 = @calc_txt.text
@calc_txt.text = ""
@op = "*"
end
@calc_eq.connect(SEL_COMMAND) do |sender, sel, event|
@num2 = @calc_txt.text
if @op == "+"
@calc_txt.text = (@num1.to_f + @num2.to_f).to_s
end
if @op == "-"
@calc_txt.text = (@num1.to_f - @num2.to_f).to_s
end
if @op == "/"
@calc_txt.text = (@num1.to_f / @num2.to_f).to_s
end
if @op == "*"
@calc_txt.text = (@num1.to_f * @num2.to_f).to_s
end
@calc_clr.connect(SEL_COMMAND) do |sender, sel, event|
@calc_txt.text = ""
end
end
end
def create super self.show(PLACEMENT_SCREEN)
end end
app = FXApp.new main_window = Calc.new(app) app.create app.run