Today I take a quit from the job – I really need to stop for a moment… – and after some going cycling I decided to ‘make clear’ on my hard disk.
So I discovered an experiment I was working months ago (I suppose… I didnt’ remember it!)
Local btn:tgadget=CreateButtonX("Hallo{!pos:;size:50%,25%;title:I'm special!;fcolor:200,50,50;bcolor:255,200,125;layout:2,2,2,2!}",10,10,100,20,window)
Local btn2:tgadget=CreatebuttonX("My{!pos:100,100;layout:2,2,2,2!}",,,80,30 ,window)
Local btn3:tgadget=CreateListBoxX("{!size:50%;fcolor:200,250,50;bcolor:128,128,128;layout:2,2,2,2;items:One,Two,Three,Four,Five;select:2!}",10,150,100,180,window)
SendMessage(btn2,"fcolor:20,20,200;bcolor:164,170,176;pos:,100;size:,30")
The idea was to create ‘gadget’ on the fly, reading a sort-of CSS style code. The ‘string’ passed usually as title of the gadget in MaxGUI contains other info (the marker are {! and !}) and all the ‘commands’ are defined as ‘command:parameters;’ and the separation mark is ‘;’
So the first command (Hallo!{!pos:;size:50%,25%;title:I’m special!;fcolor:200,50,50;bcolor:255,200,125;layout:2,2,2,2!}
is ‘interpreted’ as
- create a button of width size 50% of parent and 25% height;
- set as title ‘I’m special‘
- foreground color is 200,50,50
- background color is 255,200,125
- layout is 2,2,2,2
Other keywords are
- items:One,Two,Three,Four,Five;
- select:2!
- enable
- disable
and they are quite self-explaining.
Keywords pos: and size: can take parameters both as expressed in pixel or in percentage (like in HTML/CSS).
The good points of a such ‘programming GUI’ are:
- you can change it on-the-fly if you save the description in a .txt file
- you can define in a very fast way the style of a gadget
The ‘cost’ for a GUI program is quite low: it takes only some more time at the GUI creation, and of course the incompatibility with other BlitzMax/MaxGUI users without the ‘interface-translator module’
However I would need to create an ‘interface’ for every MaxGUI gadget (in my example I made only for GadgetButton and ListBox)
Another ‘experiment’ I found is related to auto-alignment of gadgets.
When you create a GUI application in MaxGUI you need to place every gadgets ‘manually’ – placing the exact pixel coords, width and heigth.
It is a quite boring work.
SetGadgetAlignment(parent,MAXGUI_HORIZONTAL,10)
Local G1:TGADGET=CreateButtonX("test button 1",0,0,0,0,parent)
Local G2:TGADGET=CreateButtonX("test button 2",0,0,0,0,parent)
Local G3:TGADGET=CreateTextfieldX(0,0,0,0,parent)
DoAlignment()
parent:tgadget=CreatePanel(10,150,270,100,window)
SetGadgetColor parent,200,250,250
SetGadgetAlignment(parent,MAXGUI_VERTICAL)
G1:TGADGET=CreateButtonX("test button 1",0,0,0,0,parent)
G2:TGADGET=CreateButtonX("test button 2",0,0,0,0,parent)
G3:TGADGET=CreateButtonX("test button 3",0,0,0,0,parent)
DoAlignment()
In the above example the command SetGadgetAlignment() setup for the next gadgets that will be created some ‘instruction’.
They have no position or dimensions: it will MaxGUI (well, the behind-the-curtain function I wrote) to take care of these aspects: automatically – when DoAlignment() is called – the gadgets (stored in a list) are ‘reshaped’ to be adapted to the parent and alignment settings.
It is possible to have an HORIZONTAL or a VERTICAL alignment and choose a distance from the borders.
It works.
I’m quite sure I’ve changed MaxGUI-module to adapt this features, so gadget creation and alignment were completely transparent (I’ve added default parameters to all the gadgets, as you need to indicate a x,y,w,h parameters…)
So it was possible to code something like
SetGadgetAlignment(parent,MAXGUI_VERTICAL,10)
gad1=CreateLabel("Hallo")
gad2=CreateButton("Press this button",,,100)
(the actual target-parent gadget is – if not specified – the one expressed in SetGadgetAlignment, handy!)
Of course as that was an intenal work, I suspect I’ve lost my work, but I can guarantee it worked well.