Re: [Fxruby-users] controlling a FXComboBox size
Status: Inactive
Brought to you by:
lyle
From: Lyle J. <ly...@kn...> - 2003-12-04 02:15:29
|
On Dec 3, 2003, at 4:09 PM, Brett S Hallett wrote: > Find attached a few (small :-) example programs that I generated , the > only > one that produces a "correct" combobox is the one (testfox.rb) which > explicitly uses the coordinate AND size parameters, in every other > case I get > a VERY narrow displayed field ( and drop down field). > > I suspect that I am simply not using the correct opts= parameters to > get the > desired effect, which is : > > a) let the user define the width & height of the combobox field > b) let the field fall into its 'natural' position depending upon the > frame > type declared. When you specify an explicit (a.k.a. fixed) width for the combo-box, there is obviously no question as to which size the layout manager should assign to that combo-box. But if you don't specify a fixed width, the layout manager needs some other way to determine an appropriate default size for it. (This is of course true for any child widget, but today we're talking about combo-boxes ;) For the combo-box (as well as text fields, and some other widgets) the default size depends on the number of columns passed in as an argument to the constructor. In the case of your examples, you're passing in 1 as the number of columns, e.g. postcode = FXComboBox.new(combo, 1, 10, nil, 0, FRAME_SUNKEN|FRAME_THICK|COMBOBOX_NORMAL) which causes the combo-box to report a very small default width, since it thinks it only needs to be wide enough to display a string that is one character long. To quickly prove this to yourself, simply change the above line (from testfox1.rb) to read something like: postcode = FXComboBox.new(combo, 8, 10, nil, 0, FRAME_SUNKEN|FRAME_THICK|COMBOBOX_NORMAL) and you should like the result better. Of course, the "right" number of columns is going to depend on the lengths of the items' text, which you don't know in advance. Some people get around this by adjusting the number of columns after all of the items have been added, e.g. comboBox = FXComboBox.new(p, 1, ...) maxStringLen = 0 itemStrings.each do |itemString| comboBox.appendItem(itemString) maxStringLen = [maxStringLen, itemString.length].max end comboBox.numColumns = maxStringLen > Also note the file "testfox.fxs" which is FOX Script Language I am > developing > to see if this shorthand technique of describing forms is a viable > technique. > Although I've had plenty of experience with DELPHI, et al, I'm not > convinced > that a GUI IDE is necessarly the most efficient method for describing > forms > when the developers Language (Ruby) is using a independent GUI tool. > Delphi > works well because of the very tight intergration of Form/Language. I've never used Delphi itself, but have used Borland C++ Builder which is closely related, and yes, it is very nice. A lot of people are interested in "GUI building" tools for FOX and FXRuby (see for example http://fox-tool.rubyforge.org) and so I'm glad you're investigating this alternative approach. |