Forum: Ruby wxruby and the use of sizers - Help, Please!

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
64a808c19ac542b14c4021dcb9484a37?d=identicon&s=25 Ruby Student (Guest)
on 2009-01-23 23:43
(Received via mailing list)
Hello all you happy people!
I am trying to learn wxruby and to that effect I played with the
tutorial,
which is very limited.
I am trying to draw a grid for a sudoku puzzle. I first tried using
GridSizer but then I did not know how to add each cell (button) to the
9x9
grid.
Then I thought that perhaps I should use GridBagSizer for flexibility or
something else.
I need to be able to change the caption of the button, which could have
a
number from 1 to 9, dynamically.
Which class should I use and where can I find examples of it uses?
I searched Google with different search keys but could not really find
any
example.

Your help will be greatly appreciated.

Thank you
669b7046f02e5dfc4bda4421f1069731?d=identicon&s=25 Alex Fenton (Guest)
on 2009-01-24 01:40
(Received via mailing list)
Ruby Student wrote:

> I am trying to learn wxruby and to that effect I played with the tutorial,
> which is very limited.


Questions about wxRuby are more appropriate to the wxruby-users mailing
list:
http://rubyforge.org/mailman/listinfo/wxruby-users
OR WEB ACCESS:
http://www.ruby-forum.com/forum/36

If possible, show some example code with what you've tried and you will
find people happy to advise.


> I am trying to draw a grid for a sudoku puzzle. I first tried using
> GridSizer but then I did not know how to add each cell (button) to the 9x9
> grid.


You create and add a button to a sizer with something like this:

sizer = Wx::GridSizer.new(9) # 9 column
button = Wx::Button.new(parent, :label => '3')
sizer.add(sudoku_button)


> Then I thought that perhaps I should use GridBagSizer for flexibility or
> something else.


Probably not GridBagSizer. It's offered b/c it's part of the wxWidgets
API, but there are almost always easier and simpler ways of doing the
same thing, IMHO.


> I need to be able to change the caption of the button, which could have a
> number from 1 to 9, dynamically.


No problem:

button.label = "4"


> Which class should I use and where can I find examples of it uses?


You could use GridSizer + Buttons, as you have been. Simple, but it
might look a bit strange.

You could use Wx::Grid, a spreadsheet-style widget.

A bit more work, but probably the most attractive solution: you could
draw your own grid lines and numbers using a DC (Device Context).

You will find examples of using all of these by looking in the samples
distributed with the wxRuby gem / source. Look in samples/grid,
samples/bigdemo/wxSizer and samples/drawing for help.

a
64a808c19ac542b14c4021dcb9484a37?d=identicon&s=25 Ruby Student (Guest)
on 2009-01-24 02:46
(Received via mailing list)
Alex, thank you for your quick and detailed reply.I will look at the
samples
distributed with wx.

Thank you

Ruby Student
This topic is locked and can not be replied to.