An array of ID's
An array of ID's
Since the MUIRoyale's XML id's technically are static strings, is there a possibility to pass them to an indexed array?
I have lots of small Colorfields grouped into a single dimensional array. Doing it in E I created those Colorwields dynamically in a For loop. Each step passed a pointer of newly created Colorfield to another element of an array. For example: colorf[0], colorf[1], colorf[2] and so on.
How to obtain such things while we have static XML description?
I have lots of small Colorfields grouped into a single dimensional array. Doing it in E I created those Colorwields dynamically in a For loop. Each step passed a pointer of newly created Colorfield to another element of an array. For example: colorf[0], colorf[1], colorf[2] and so on.
How to obtain such things while we have static XML description?
- airsoftsoftwair
- Posts: 5446
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: An array of ID's
In Hollywood strings can be used as table indices, e.g.
Both lines do exactly the same thing but the first line allows you to use a string as the index. More infos here.
Code: Select all
a["test"] = 5
a.test = 5
Re: An array of ID's
But XML ID's must be predeterminated?
- airsoftsoftwair
- Posts: 5446
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: An array of ID's
Well, you can't use Hollywood variables directly in XML but of course you can use a template XML and replace certain tokens on-the-fly with things evaluated at script runtime. However, I haven't really understood what you want to do so you'd have to present a specific example in order for me to be able to help you here...
Re: An array of ID's
Well, I need to create three arrays of tiny Colorfields in my GUI. It looks more or less like this:
In the Hollywood's way it goes simply this way. It shows the XML of the very first three of them.:
And in AmigaE version of my program it's created dynamically in this way:
Part of GUI definition. Gr_lmp is the pointer to the group that gathers all the tiny Colourfields:
For loop that stuffs the Group (gr_lmp) with that Colorfields. Lmp_r is one of the arrays that spare me describing all of 24 Colorfields by hand:
In the Hollywood's way it goes simply this way. It shows the XML of the very first three of them.:
Code: Select all
<HGroup id="gr_bits" Spacing="0" InputMode="RelVerify" ShowSelState="0">
<Text FixWidthTxt="bits: ">bits:</Text>
<Colorfield id="lmp_r0"
RGB="#000000"
Frame="Gauge"
FixWidth="6"
InnerRight="0" InnerLeft="0" InnerTop="0" InnerBottom="0"
ShowSelState="0"
/>
<Colorfield id="lmp_r1"
RGB="#000000"
Frame="Gauge"
FixWidth="6"
InnerRight="0" InnerLeft="0" InnerTop="0" InnerBottom="0"
ShowSelState="0"
/>
<Colorfield id="lmp_r2"
RGB="#000000"
Frame="Gauge"
FixWidth="6"
InnerRight="0" InnerLeft="0" InnerTop="0" InnerBottom="0"
ShowSelState="0"
/>
Part of GUI definition. Gr_lmp is the pointer to the group that gathers all the tiny Colourfields:
Code: Select all
Child, gr_bits := HGroup,
Child, TextObject, MUIA_Text_Contents, 'bits:', MUIA_FixWidthTxt, 'www',End,
Child, gr_lmp:=HGroup,
MUIA_Group_Spacing, 0,
MUIA_InputMode, MUIV_InputMode_RelVerify,
MUIA_ShowSelState, FALSE, -> to avoid displaying the reverse image of the group
End,
End,
Code: Select all
FOR i:=0 TO 7
lmp_r[i] := ColorfieldObject,
MUIA_Frame, MUIV_Frame_Gauge,
MUIA_InnerRight, 0, MUIA_InnerLeft, 0, MUIA_InnerTop, 0, MUIA_InnerBottom, 0,
MUIA_Colorfield_RGB, col_off,
MUIA_FixWidth, 6,
MUIA_ShowSelState, FALSE, -> to prevent lamps group changing its look while clicking lamps
End
domethod(gr_lmp, [OM_ADDMEMBER, lmp_r[i]])
ENDFOR
Re: An array of ID's
If you only need to do it in init, you can edit the XML string from your Hollywood program before passing it to the mui.CreateGUI.
Like this for example....
lamp.xml:
And Hollywood script:
But if you want it to be dynamic during the runtime too, then you could use Group.InitChange/AddHead/AddTail/Insert/Remove/ExitChange functions.
Like this for example....
lamp.xml:
Code: Select all
<application base="LAMPTEST">
<window title="test" muiid="MAIN">
<hgroup id="gr_bits" Spacing="0" InputMode="RelVerify" ShowSelState="0">
<Text FixWidthTxt="bits: ">bits:</Text>
%lamps
</hgroup>
</window>
</application>
Code: Select all
@DISPLAY {Hidden=True}
@REQUIRE "muiroyale", {Version=1, Revision=7}
@FILE 1, "lamp.xml"
For Local i=0 To 7
lamps$=lamps$ .. [[
<Colorfield id="lmp_r]] .. i .. [["
RGB="#000000"
Frame="Gauge"
FixWidth="6"
InnerRight="0" InnerLeft="0" InnerTop="0" InnerBottom="0"
ShowSelState="0"
/>
]]
Next
mui.CreateGUI(ReplaceStr(ReadString(1),"%lamps",lamps$))
Wait(200)
Re: An array of ID's
I need it only while the initialization time.
It works! Thanks jPV
It works! Thanks jPV
Re: An array of ID's
I encountered an obstacle. This time I just need to control only a value between double quotes.
e.g "20"
Do I have to put %value between two pairs of xml tags in a separate line like this?
<>
%value
<>
Or can put %value between " and "?
e.g "20"
Do I have to put %value between two pairs of xml tags in a separate line like this?
<>
%value
<>
Or can put %value between " and "?
-
- Posts: 475
- Joined: Fri May 15, 2015 5:15 pm
- Location: Waterville, Minnesota USA
Re: An array of ID's
I think the % macro definitions can be anywhere as long as you use the appropriate ReplaceString() commands.
I'm on registered MorphOS using FlowStudio.
Re: An array of ID's
Yes, it can be put anywhere. You just replace all occurences of the "placeholder" string in the xml by something else. It isn't defined anywhere in what format the placeholder should be % in front of it just makes it less likely to accidently replace wrong words.
So, for example, you can have FixWidth="%value" in your xml data, and you can replace it with ReplaceStr(myxmldata, "%value", 6). Or as well you could have it like FixWidth="PLEASEREPLACEME" with ReplaceStr(myxmldata, "PLEASEREPLACEME", somevariablecontainingthevalue), etc. If the xml data contains the " characters, they'll stay there.
And of course you can have several placeholders to be replaced, just use different names and several ReplaceStr() lines before giving the argument to mui.CreateGUI().
If your xml data contains these lines:
Frame="%framevalue"
FixWidth="%widthvalue"
Then you can do like:
gui$=ReadString(1)
gui$=ReplaceStr(gui$, "%framevalue", "Gauge")
gui$=ReplaceStr(gui$, "%widthvalue", 6)
mui.CreateGUI(gui$)
So, for example, you can have FixWidth="%value" in your xml data, and you can replace it with ReplaceStr(myxmldata, "%value", 6). Or as well you could have it like FixWidth="PLEASEREPLACEME" with ReplaceStr(myxmldata, "PLEASEREPLACEME", somevariablecontainingthevalue), etc. If the xml data contains the " characters, they'll stay there.
And of course you can have several placeholders to be replaced, just use different names and several ReplaceStr() lines before giving the argument to mui.CreateGUI().
If your xml data contains these lines:
Frame="%framevalue"
FixWidth="%widthvalue"
Then you can do like:
gui$=ReadString(1)
gui$=ReplaceStr(gui$, "%framevalue", "Gauge")
gui$=ReplaceStr(gui$, "%widthvalue", 6)
mui.CreateGUI(gui$)