Mark Volkmann wrote:> What''s the best way to specify the width of a TextCtrl in
characters
> instead of pixels?
>
There''s no way to specify a TextCtrl''s screen size directly in
characters (though you can constrain the maximum length of string
entered using Wx::TextCtrl.set_max_length).
Wx::Window#get_text_extent allows you to calculate the pixel dimensions
of a specified text displayed in a specified font. Something like
x, y = a_widget.get_text_extent(''a'' * 40)
would give you the pixel width and height of 40 characters which you can
then use to set the size of the TextCtrl
textctrl.set_size( Wx::Size.new(x, y) )
But ... unfortunately this function is currently only available in the
old 0.x series of wxruby.
It''s pending a SWIG solution for returning Ruby values that in C++ are
passed in as reference in-parameters. This is one of the last big SWIG
problems for wxruby2 to overcome, as it bedevils a fair number of useful
methods across WxWidgets. I''m sure a solution is possible, but
I''ve not
personally had any success with the techniques described in the SWIG
manual''s Ruby chapter ( http://www.swig.org/Doc1.3/Ruby.html#Ruby_nn32
)
hth
alex