[Gambas-user] Custom controls, Non-String arrays in the IDE

Benoit Minisini benoit.minisini at gambas-basic.org
Wed Aug 10 16:25:17 CEST 2022


Le 10/08/2022 à 15:46, Bruce Steers a écrit :
> 
> 
> On Wed, 10 Aug 2022 at 14:08, Benoit Minisini 
> <benoit.minisini at gambas-basic.org 
> <mailto:benoit.minisini at gambas-basic.org>> wrote:
> 
>     Le 10/08/2022 à 14:49, bb a écrit :
>      > On Wed, 2022-08-10 at 13:13 +0100, Bruce Steers wrote:
>      >> On Wed, 10 Aug 2022 at 11:53, Bruce Steers <bsteers4 at gmail.com
>     <mailto:bsteers4 at gmail.com>>
>      >> wrote:
>      >>
>      >>> You know how you can put the following in a custom control..
>      >>>
>      >>> *Public Const _Properties As String = "*,StringArray"*
>      >>>
>      >>> *Property StringArray As String[] Use $aStringArray*
>      >>>
>      >>> Then in the IDE form designer you'll get the StringArray property
>      >>> and get
>      >>> an editor to insert strings to the list.
>      >>>
>      >>> If i use ANY other type like Integer[] or Float[] then it does not
>      >>> work
>      >>> the same. i just get a combobox with "none" to select, and if i do
>      >>> select
>      >>> none i then have to manually edit the .form file to remove the def
>      >>> as it
>      >>> raises an error.
>      >>>
>      >>> Could the form designer also handle other types?
>      >>> Integer[] and Float[] shouldn't be too hard to handle.
>      >>> The existing string[] editor could be used then the items converted
>      >>> to
>      >>> their respective type array.
>      >>>
>      >>> Would open up a few things for me.
>      >>>
>      >>> I'm trying to add gradients to a control and want to handle the
>      >>> Colors[]
>      >>> and StopPoints[] in the IDE
>      >>>
>      >>> Can some method be added to a Custom control class that the IDE can
>      >>> use to
>      >>> pop up our own editor window ?
>      >>> Something like this maybe?..
>      >>>
>      >>> *Public Const _Properties As String = "*,IntegerArray{IntList()}"*
>      >>>
>      >>> *Private Sub IntList() As Integer[]*
>      >>>
>      >>> *  FGetIntegers.ShowModal()*
>      >>>
>      >>> *  Return FGetIntegers.List*
>      >>>
>      >>> *End*
>      >>>
>      >>> then FIntegers pops open my own list editor
>      >>>
>      >>> Is something like this already possible ?
>      >>>
>      >>> Respects
>      >>> BruceS
>      >>>
>      >>
>      >> I'm thinking my second idea of letting us create a custom property
>      >> editor
>      >> window that could return any type required would be a lot more
>     useful
>      >> than
>      >> just making Integer[] Float[] also work in the form designer.
>      >> Possibly even less code as you'd just have to check for () in the
>      >> _Properties def "*, MyPropertyName{type_is_method()}" then set the
>      >> property
>      >> edit button in the IDE to run the method and pass it's return data
>      >> straight
>      >> to the property.
>      >>
>      >> Hmm, When i put it that way it does sound like a fairly simple
>      >> addition.  I
>      >> might just have a browse through the IDE code and see if i can find
>      >> the way.
>      >>
>      >> Respects
>      >> BruceS
>      >>
>      >> ----[ http://gambaswiki.org/wiki/doc/netiquette
>     <http://gambaswiki.org/wiki/doc/netiquette> ]----
>      > Have a look at the "special" property editors used in the Report
>      > designer. Although they are implemented inside the IDE, it could give
>      > you the points at which you'd need to apply some surgery to the IDE.
>      >
>      > I did something like this years ago that let me design the property
>      > editor inside the component rather than imposing changes on the IDE.
>      > I just had a look at where I knew that I had used it in one component
>      > and unfortunately I have disabled the said code and removed the
>      > necessary changes to the IDE - sad as it did work a treat.
>      >
>      > My use was far above what you are trying but I bit on the "custom
>      > property editor".
>      >
>      >  From memory the changes in the IDE were not that extravagant, the
>      > tricky bit is getting the IDE to load the component and look for the
>      > property editor in there.
>      >
>      > hth
>      > b
>      >
> 
>     Mmm... No, thanks. I didn't want the IDE to load arbitrary components,
>     and I still have the same opinion (for security reasons at least).
> 
>     This is why all property types are directly handled by the IDE form
>     editor.
> 
>     As for the type of property you want to implement, are you sure that
>     defining a gradient from the form editor is really worth it in your
>     context?
> 
>     A brush property type has been implemented for the Report forms, but
>     it's because having a visual representation of what you are printing
>     may
>     be useful. It handles all brush types (and so gradients), even if
>     printing gradients should be forbidden by the law of good taste.
> 
>     Regards,
> 
>     -- 
>     Benoît Minisini.
> 
> 
> Yes it handles all types but not all array types just String[], making 
> it a bit limited.
> 
> For my context it is kinda really wanted,
> After my recent education in gradients i'm upgrading my 
> GradientButton.class to handle multiple gradient points not just 2 and 
> use the Paint.LinearGradient() method not the one i made before i 
> discovered the Paint version..
> https://forum.gambas.one/download/file.php?id=1128 
> <https://forum.gambas.one/download/file.php?id=1128>
> 
> In the above image I am Implementing multiple colourstops by using 
> String[] then converting gambas Color names (using color integer strings 
> was not really possible to use color selector gui so i kept it simple 
> and use existing color names)  and working out the StopPoint float value 
> automatically by division of the number of values.
> eg.
> GradientButton5.ColorNames = ["Green", "Blue", "Yellow"]
> 
> then in the _Draw() event...
>    Dim Cols As Integer[] = [], Points As Float[] = []
> 
>    If $aColorNames Then
>      Dim fOnePos As Float = 1 / $aColorNames.Max
>      Dim fPos As Float = 0, iCol As Integer
> 
>      For i As Integer = 0 To $aColorNames.Max
>        Try iCol = Object.GetProperty(Color, $aColorNames[i])
>        If Error Then
>         Dim sErr As String = Error.Text
>         Dim sCols As String[] = GetGambasColourNames()
>         Error.Raise($aColorNames[i] & "\n" & sErr & "\nUse only gambas 
> color names\n" & sCols.Sort().Join(", "))
>        Endif
> 
>        Cols.Add(iCol)
>        Points.Add(fPos)
>        fPos += fOnePos
>      Next
>    Else  ' use defaults
>      Cols = [Col1, Col2]
>      Points = [0, 1]
>    Endif
> 
> Because in the IDE String[] is all i really have to work with for an 
> array type property so i can set the string list.
> 
> Looking at the ide code i'm wondering if Field,Fields type could be used 
> for my needs?
> 
> Could you implement Array type? like my first idea of using the existing 
> String[] editor to edit then converting the strings to respective types?
> And possibly a more complicated Color[] type to set multiple colors?
> Dang, in my head this just got a lot more complicated :-\
> 
> 
> Many thanks
> BruceS
> 

Let's put the usefullness of flashy gradient buttons aside. What you 
would need is actually a brush, not a gradient. The gradient is just a 
particular case of a brush.

And editing a brush (or any other complex property) in the form editor 
needs:

1) An IDE internal string representation of the property.

2) A method in the Gambas component that converts that string into the 
real object, making that internal string representation part of the 
public API.

3) The corresponding property editor in the IDE.

4) The code that deals with the property kind in the form loading 
routine, saving routine, setting and getting property routines.

If you don't understand, look how the Font property kind is handled.

Implementing all that is not a five minutes job (hopefully the brush 
editor already exists in some way for the Report forms), and I usually 
do it when it's really useful. Anyway I can't do it now.

Regards,

-- 
Benoît Minisini.


More information about the User mailing list