An array of ID's

Discuss GUI programming with the MUI Royale plugin here
Post Reply
User avatar
r-tea
Posts: 80
Joined: Wed Feb 17, 2016 12:48 am
Location: Zdzieszowice, Poland
Contact:

An array of ID's

Post by r-tea » Wed Aug 08, 2018 11:36 pm

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?

User avatar
airsoftsoftwair
Posts: 2570
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany
Contact:

Re: An array of ID's

Post by airsoftsoftwair » Thu Aug 09, 2018 6:12 pm

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.

User avatar
r-tea
Posts: 80
Joined: Wed Feb 17, 2016 12:48 am
Location: Zdzieszowice, Poland
Contact:

Re: An array of ID's

Post by r-tea » Sun Aug 12, 2018 7:06 pm

But XML ID's must be predeterminated?

User avatar
airsoftsoftwair
Posts: 2570
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany
Contact:

Re: An array of ID's

Post by airsoftsoftwair » Mon Aug 13, 2018 10:27 pm

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...

User avatar
r-tea
Posts: 80
Joined: Wed Feb 17, 2016 12:48 am
Location: Zdzieszowice, Poland
Contact:

Re: An array of ID's

Post by r-tea » Mon Aug 20, 2018 7:40 pm

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

User avatar
jPV
Posts: 155
Joined: Sat Mar 26, 2016 11:44 am
Location: RNO
Contact:

Re: An array of ID's

Post by jPV » Tue Aug 21, 2018 8:40 am

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.

User avatar
r-tea
Posts: 80
Joined: Wed Feb 17, 2016 12:48 am
Location: Zdzieszowice, Poland
Contact:

Re: An array of ID's

Post by r-tea » Tue Sep 04, 2018 10:23 pm

I need it only while the initialization time.
It works! Thanks jPV :D

Post Reply