ReneMiner
22-09-2014, 14:11
there's often in a project a way needed to enumerate certain things globally which are all somehow unique properties or settings.
For example in my current GUI-project i save loads of ini-settings classified to be either measurements or colors (see GUI.tBasicU if nosy) but to make it short i like the way to abuse an UDT for enumerations
-just to give an example of what i talk about- i do this:
' "abuse" this udt a little bit
Type t_Defaultcolorscheme
DisabledBack As TBGL_TRGBA
DisabledFront As TBGL_TRGBA
DisabledText As TBGL_TRGBA
'... lots more...
ListHeaders As TBGL_TRGBA
ListHeaderFont As TBGL_TRGBA
End Type
Global Colors As t_Defaultcolorscheme
'access like
Colors.DisabledBack.R = 123
' another type...
Type t_Measurements
' these are mostly for setting up sizes as
MenubarHeight As Long
ScrollsClient As Long ' these is thickness of scrolls at t_Client-structure
ScrollsThick As Long ' default-scroll-thickness for controls
BorderWidth As Long ' border-width for controls - boxes have always 4!
' other user-defineables
KeyRepeatTime As Long ' default timeout for a key to repeat .OnKeyDown() when hold
TabKeySpaces As Long
TooltipDistance As Long
TooltipTime As Long
CursorBlinkTime As Long
CheckBoxOffset As Long ' add to text-width of checkeables
End Type
Global Measurements As t_Measurements
' access like:
Measurements.Menubarheight = 42 '...
but i don't like that it's possible to create another variable of that UDT - since it's supposed to be unique. But in general this way is much faster when coding in thinAir since one just have to look for the udt in codebrowser to get the full list of properties
There's another way too, pretty simple, just use a global array
' alternative:
Begin Const
%MenubarHeight = 1
%ScrollsClient
%ScrollsThick
%BorderWidth
' other user-defineables
%KeyRepeatTime
%TabKeySpaces
%TooltipDistance
%TooltipTime
%CursorBlinkTime
%CheckBoxOffset
%Last
End Const
Global Measurements(%Last-1) As Long
' access like
Measurements(%Menubarheight) = 42
but i don't like the parenthesis-stuff and neither the idea that each single const is a global variable on its own which not does even store the value but just is an index that makes it necessary for the interpreter to jump around just to get the needed values together...
now i dreamt of another way. Syntax just an idea... could name it Enumerate/End Enumerate instead of Begin Enum/End Enum too
Begin Enum Measurements As Long
MenubarHeight
ScrollsClient
ScrollsThick
BorderWidth
' other user-defineables
KeyRepeatTime
TabKeySpaces
TooltipDistance
TooltipTime
CursorBlinkTime
CheckBoxOffset
End Enum
Begin Enum Colors As TBGL_TRGBA
DisabledBack
'...
End Enum
to access as if it were an udt in the first example but of course an "Enumeration" can not have functions and they are somewhat like a fixed array (size) where each member has a name.
if thinAir get's some makeover some day the enumerations could be listed in codebrowser too.
I give that request a very low priority by not posting it in support yet - just to get the thought rollin'...
For example in my current GUI-project i save loads of ini-settings classified to be either measurements or colors (see GUI.tBasicU if nosy) but to make it short i like the way to abuse an UDT for enumerations
-just to give an example of what i talk about- i do this:
' "abuse" this udt a little bit
Type t_Defaultcolorscheme
DisabledBack As TBGL_TRGBA
DisabledFront As TBGL_TRGBA
DisabledText As TBGL_TRGBA
'... lots more...
ListHeaders As TBGL_TRGBA
ListHeaderFont As TBGL_TRGBA
End Type
Global Colors As t_Defaultcolorscheme
'access like
Colors.DisabledBack.R = 123
' another type...
Type t_Measurements
' these are mostly for setting up sizes as
MenubarHeight As Long
ScrollsClient As Long ' these is thickness of scrolls at t_Client-structure
ScrollsThick As Long ' default-scroll-thickness for controls
BorderWidth As Long ' border-width for controls - boxes have always 4!
' other user-defineables
KeyRepeatTime As Long ' default timeout for a key to repeat .OnKeyDown() when hold
TabKeySpaces As Long
TooltipDistance As Long
TooltipTime As Long
CursorBlinkTime As Long
CheckBoxOffset As Long ' add to text-width of checkeables
End Type
Global Measurements As t_Measurements
' access like:
Measurements.Menubarheight = 42 '...
but i don't like that it's possible to create another variable of that UDT - since it's supposed to be unique. But in general this way is much faster when coding in thinAir since one just have to look for the udt in codebrowser to get the full list of properties
There's another way too, pretty simple, just use a global array
' alternative:
Begin Const
%MenubarHeight = 1
%ScrollsClient
%ScrollsThick
%BorderWidth
' other user-defineables
%KeyRepeatTime
%TabKeySpaces
%TooltipDistance
%TooltipTime
%CursorBlinkTime
%CheckBoxOffset
%Last
End Const
Global Measurements(%Last-1) As Long
' access like
Measurements(%Menubarheight) = 42
but i don't like the parenthesis-stuff and neither the idea that each single const is a global variable on its own which not does even store the value but just is an index that makes it necessary for the interpreter to jump around just to get the needed values together...
now i dreamt of another way. Syntax just an idea... could name it Enumerate/End Enumerate instead of Begin Enum/End Enum too
Begin Enum Measurements As Long
MenubarHeight
ScrollsClient
ScrollsThick
BorderWidth
' other user-defineables
KeyRepeatTime
TabKeySpaces
TooltipDistance
TooltipTime
CursorBlinkTime
CheckBoxOffset
End Enum
Begin Enum Colors As TBGL_TRGBA
DisabledBack
'...
End Enum
to access as if it were an udt in the first example but of course an "Enumeration" can not have functions and they are somewhat like a fixed array (size) where each member has a name.
if thinAir get's some makeover some day the enumerations could be listed in codebrowser too.
I give that request a very low priority by not posting it in support yet - just to get the thought rollin'...