Chuck Brotman | 23 Jul 2012 01:44
Picon

Need a simple graphics interface/function for ruby

Hi,
 
I'd like to have an M x N array of characters which I can address (say, by Row and column) and update or read any spot (M,N).  This array would map directly to a window.  can anyone suggest the best/easiest way to implement this?  In other words, I'm looking for a way to display an array of characters to a Window.... 
 
Thanks,
Chuck
 
Ps.  I have FXRuby installed, I probably just need to be shown a sarting point maybe an FX Ruby function????
Jan E. | 23 Jul 2012 02:51

Re: Need a simple graphics interface/function for ruby

Hi,

I have no idea how FXRuby works, but I guess every GUI framework has 
some kind of table object. For example, in Ruby-GNOME2 you'd use a 
Gtk::Table and put a Gtk::Label with the corresponding character in 
every cell.

However, you won't be able to base this table on a normal array and have 
every update to the array directly update the GUI object. You'll need a 
custom object for that, which also updates the GUI object on change.

--

-- 
Posted via http://www.ruby-forum.com/.

Regis d'Aubarede | 24 Jul 2012 10:16

Re: Need a simple graphics interface/function for ruby

here a example with gtk by a littlr dsl
> ... install gtk2
> gem install Ruiby

and then :

require 'ruiby'
M=12
N=10
Ruiby.app width: 400, height:400 do
  <at> matrix=[]
 table(M,N) do
    M.times {
    line=[]
    row {
      N.times {
        line << label("   ")
        cell(line.last)
      }
    }
     <at> matrix << line
  }
 end
 anim(10) do
     <at> matrix[rand(M)][rand(N)].text = (Time.now.to_i%10).to_s
 end
end

--

-- 
Posted via http://www.ruby-forum.com/.

Chuck Brotman | 26 Jul 2012 07:13
Picon

Re: Need a simple graphics interface/function for ruby

Regis,
 
Thank you for your informative reply.   I'll give it a try!
 

On Tuesday, July 24, 2012 4:16:53 AM UTC-4, Regis d'Aubarede wrote:
here a example with gtk by a littlr dsl
> ... install gtk2
> gem install Ruiby

and then :


require 'ruiby'
M=12
N=10
Ruiby.app width: 400, height:400 do
  <at> matrix=[]
 table(M,N) do
    M.times {
    line=[]
    row {
      N.times {
        line << label("   ")
        cell(line.last)
      }
    }
    <at> matrix << line
  }
 end
 anim(10) do
    <at> matrix[rand(M)][rand(N)].text = (Time.now.to_i%10).to_s
 end
end

--
Posted via http://www.ruby-forum.com/.


Gmane