[Gambas-user] User Controls and Font resizing to fit content

Tobias Boege taboege at gmail.com
Tue May 1 15:16:00 CEST 2018


On Tue, 01 May 2018, KKing wrote:
> Sorry to repeat and if any is covered by wiki/doco but I didn't seem to find
> any recent info on easily.
> 
> 1. Does Gambas have a concept similar to the VB User Control concept
> (i.e. you build a control with the standard label/textbox/buttons save
> it and be able to reuse multiple times in another form)?
> 

I put an answer off the first time around, because this question actually
needs a whole tutorial to be answered.

I don't know VB but Gambas does have a UserControl class for creating
custom controls. This is usually a two-step process:

  1. Create a form FMyControl and use the form editor to place your
     Labels, Buttons and everything else, then write their functionality
     into FMyControl's code.

  2. Create a class MyControl which inherits UserControl. This class
     will create an instance of FMyControl and embed it into itself.
     This way, you get the widget FMyControl but don't inherit all the
     methods and properties of the Form class. You will have to proxy
     the interface parts of FMyControl which you do want to expose
     yourself.

This technique is used in Gambas a lot. You should look through the
source code of gb.form for examples, or ask followup questions.

The ListEditor [1] is a very good starting point, because it is small,
easy to read and does only the things mentioned above. You will find
some UserControls without a corresponding form; these build their
appearance by code only, without the help of the form editor.
This makes sense for ValueBox, for example, which switches between
multiple input controls.

A tutorial for this would be nice to have, along with how to use
Arrangement, Expand, Spacing and Margin -- something like
"Advanced GUI techniques" -- does the Gambas magazine still exist? :-)

> 2. Suggestions if convenient way to get the font size to automatically
> change to fit provided text in a (can be any of) label/textbox/or other
> control?
> 

I don't know. Something like that would be nice for translated projects,
where you can't estimate the content size of a Label at development time.
[ Not sure if reducing the font size or enlarging the label is the right way
to go, but I guess anything but cutting off excessive text can go horribly
wrong. ]

Regards,
Tobi

[1] https://gitlab.com/gambas/gambas/tree/master/comp/src/gb.form/.src/ListEditor

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk


More information about the User mailing list