[Gambas-user] Inherit Button, looks bad in the IDE?
Tobias Boege
tobs at taboege.de
Wed Feb 17 17:06:20 CET 2021
On Wed, 17 Feb 2021, Bruce Steers wrote:
> On Wed, 17 Feb 2021 at 13:57, Tobias Boege <tobs at taboege.de> wrote:
>
> > On Wed, 17 Feb 2021, Bruce Steers wrote:
> > > --------------------------
> > > ' Gambas class file
> > >
> > > Export
> > > Inherits Button
> > >
> > > Public Const _Properties As String = "*,Delay=200"
> > > Public Const _Similar As String = "Button"
> > >
> > > '' Get or set Time between flash on/off in ms , default 500
> > > Property Delay As Integer
> > > Private $Delay As Integer
> > > '' Get or set default Time between flash on/off in ms , default 500
> > > Static Public Default_Delay As Integer = 500
> > >
> > > ----------------------------
> > >
> > > It works a treat in operation but the button in the IDE looks nothing
> > like
> > > the other buttons.
> > > It looks fine at runtime but any idea how to get it to look right in the
> > > IDE?
> > > (see attached snapshot, the button called FlashButton)
> > >
> >
> > _Similar is not related to appearance. I think you need the _DrawWith
> > constant. See http://gambaswiki.org/wiki/dev/gambas
> >
> > Best,
> > Tobias
> >
> > Brilliant , Thank you Tobias.
> _Similar i used so i could use the "Change into" function to quickly change
> a button to a flashbutton in the IDE
>
> It was almost perfect except for how it looked in the IDE.
> _DrawWith sorted it out a treat :)
>
> i have just recently discovered the power of using Inherit on controls in a
> class and getting into customizing them.
> Loving it, so far all i have is a flashy colour button and a GridView that
> has built in Sort and MoveRowUp and MoverowDown functions but feeling a new
> area of an awesomely handy library of custom controls ready for import into
> my projects in the making..
> :)
In addition to what Fabien said, let me give you two pieces of information
that may be useful to you in the future:
(1) Inheritance sounds fine for the kind of modifications you describe.
In the Gambas source code, another pattern that occurs, in my experience,
more often is encapsulation instead of inheritance. When you want to
modify an already existing control X (modify, extend or even constrain
aspects of its behavior instead of just adding new methods to it), it is
more common to write a class Y which Inherits UserControl and creates an
instance of X *on itself*. This way, you can build a completely new
interface around the X object. See the SpinBox or _TreeView classes in
gb.gui.base for one of many examples.
(2) The greatest thing ever in Gambas is making new "compound controls",
i.e. widgets composed of already existing controls (labels, buttons,
textareas) which are functioning as one unit. Turning them into a new
control class lets you drop many instances of the same GUI logic into
your forms easily, or create new instances at runtime. What is so great
about this is that you can design these compounds in the IDE form designer,
giving you a FZ.form and FZ.class, which you can then wrap under a neat
and tidy API in Z.class using the encapsulation (1). This works because
you can embed a Form in another container (which in turn lives on some
other Form) like any other control. Notable examples include the DataBrowser
in gb.db.form or the FileProperties widget in gb.form.
Best,
Tobias
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
More information about the User
mailing list