Page 1 of 2

An array of ID's

Posted: Wed Aug 08, 2018 11:36 pm
by r-tea
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?

Re: An array of ID's

Posted: Thu Aug 09, 2018 6:12 pm
by airsoftsoftwair
In Hollywood strings can be used as table indices, e.g.

Code: Select all

a["test"] = 5
a.test = 5
Both lines do exactly the same thing but the first line allows you to use a string as the index. More infos here.

Re: An array of ID's

Posted: Sun Aug 12, 2018 7:06 pm
by r-tea
But XML ID's must be predeterminated?

Re: An array of ID's

Posted: Mon Aug 13, 2018 10:27 pm
by airsoftsoftwair
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

Posted: Mon Aug 20, 2018 7:40 pm
by r-tea
Well, I need to create three arrays of tiny Colorfields in my GUI. It looks more or less like this:
Image
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"
			/>
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:

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,
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:

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

Posted: Tue Aug 21, 2018 8:40 am
by jPV
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:

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>
And Hollywood script:

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)       
But if you want it to be dynamic during the runtime too, then you could use Group.InitChange/AddHead/AddTail/Insert/Remove/ExitChange functions.

Re: An array of ID's

Posted: Tue Sep 04, 2018 10:23 pm
by r-tea
I need it only while the initialization time.
It works! Thanks jPV :D

Re: An array of ID's

Posted: Sat May 04, 2019 7:44 pm
by r-tea
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 "?

Re: An array of ID's

Posted: Sun May 05, 2019 1:39 am
by SamuraiCrow
I think the % macro definitions can be anywhere as long as you use the appropriate ReplaceString() commands.

Re: An array of ID's

Posted: Sun May 05, 2019 9:53 am
by jPV
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$)