How to dynamically add Radio items, and a page.

Discuss GUI programming with the RapaGUI plugin here
Post Reply
Bugala
Posts: 1295
Joined: Sun Feb 14, 2010 7:11 pm

How to dynamically add Radio items, and a page.

Post by Bugala »

I am trying out RapaGUI for the first time, and while from manual these things sound simple, and there are even examples "Dynamic 1 - 5" which don't look that hard, I just cant get them to work at all. I cant add a single page nor item, therefore turning to you people to find out what I am missing here.

I took "pages" example and was planning to modify it for my own purpose, hence you can recognise lot of code from that one:

Code: Select all

@VERSION 9,0
@OPTIONS {DPIAware = True}
@REQUIRE "RapaGUI"

/*
** Our XML GUI definition
*/
@FILE 1, "RapaGuiPart.xml"

; dynamically create GUI from an external *.xml file definition
moai.CreateApp(ReadString(1))

moai.CreateObject("<menuitem id=\"single1\">Item 1</menuitem>")
moai.CreateObject("<menuitem id=\"single2\">Item 2</menuitem>")


moai.DoMethod("Screenmode", "initchange")

amigapage$ = [[
<vgroup title="Amigatesti id="Amigapage" padding="16">
</vgroup>
]]

moai.CreateObject(amigapage$, "mainpages")
moai.DoMethod("register", "append", "page" .. count, True)


moai.DoMethod("testi", "insert", "single1")
moai.DoMethod("testi", "exitchange")
; main loop!
Repeat
	WaitEvent
Forever
And there XML-file (a modified pages.xml-file):

Code: Select all

<?xml version="1.0" encoding="iso-8859-1"?>
<application id="app">
	<window title="Rogue Football Cardgame" id="window" width="400">
		<vgroup>
			<vspace height="2"/>

			<pageview id = "mainpages">
				
				<hgroup title="testi">
					<rectangle/>
					<radio>
						<item>Warrior</item>
						<item>Rogue</item>
						<item>Bard</item>
						<item>Monk</item>
						<item>Magician</item>
						<item>Archmage</item>
					</radio>
					<rectangle/>
				</hgroup>
				<hgroup title="Screenmode">
					<rectangle/>
					<radio>
						<item>Human</item>
						<item>Elf</item>
						<item>Dwarf</item>
						<item>Fairy</item>
						<item>Gnome</item>
					</radio>
					<rectangle/>
				</hgroup>

				<hgroup title="Volume">
					<colgroup columns="2">
						<label>Sounds:</label>
						<slider min="0" max="100" level="50"/>

						<label>Music:</label>
						<slider min="0" max="100" level="50"/>
					</colgroup>
				</hgroup>

				<hgroup title="Class">
					<rectangle/>
					<radio>
						<item>Warrior</item>
						<item>Rogue</item>
						<item>Bard</item>
						<item>Monk</item>
						<item>Magician</item>
						<item>Archmage</item>
					</radio>
					<rectangle/>
				</hgroup>

				<hgroup title="Amiga Specific">
					<colgroup columns="2">
						<label>Cloak:</label>
						<checkbox selected="true"/>

						<label>Shield:</label>
						<checkbox selected="true"/>

						<label>Gloves:</label>
						<checkbox selected="true"/>

						<label>Helmet:</label>
						<checkbox selected="true"/>
					</colgroup>
				</hgroup>

			</pageview>
		</vgroup>
	</window>
</application>

Couple of notices about changes to original "pages" example:
I have made one more Hgroup with title "testi", and changed names and items of some.

what comes to the Hollywood part, after using "moai.CreateApp(ReadString(1))" I have couple of lines where I am trying to add an item and a new page, but I cant get either to work.

The ultimate goal is that I want to generate a radio button which would show all the screenmode options, but I am first starting by simply trying to add an item.

What comes to the page, the idea is that Amiga versions would have an extra Page compared to other versions. Therefore it would check if software is ran on Amiga, then it would add that "amiga" page.


So why am I not getting item or page added. More specifically, why does it keep complaining "can find MOAI object Screenmode" when I try to run this, should group title "Screenmode" in the xml-file had made it so that this object is existing after the line " "moai.CreateApp(ReadString(1))" has been executed?
plouf
Posts: 604
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: How to dynamically add Radio items, and a page.

Post by plouf »

1) can't find "Screenmode" because you have no id, only title="Screenmoe" add id="Screenmode" (object identify by id not title)
2) amigapages$ title lacks closing " -> title="Amigatesti (")
3) a group need at least 1 object, if there are no objects ATM, use <rectangle/> , is for filling empty areas

your code again noed not run because some more object missing like "register" and "testi"
Christos
Bugala
Posts: 1295
Joined: Sun Feb 14, 2010 7:11 pm

Re: How to dynamically add Radio items, and a page.

Post by Bugala »

Thanks a dozen!

I now see the error finally. I unluckily picked the example that was using TITLE instead of ID as the basis of my code, and failed to notice difference between those two. Figured there was some fundamental issue I had missed, and this was it. Now I can finally get forward figuring thing out.
Bugala
Posts: 1295
Joined: Sun Feb 14, 2010 7:11 pm

Re: How to dynamically add Radio items, and a page.

Post by Bugala »

Got forward, I am now able to add a page dynamically based upon IF condition.

However, I stumbled upon another problem where I suppose I am missing some fundamental thing again as I cant find a solution from the manual to it.

Here is how this currently looks like:

xml-file:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1"?>
<application id="app">
	<window title="Rogue Football Cardgame" id="window" width="400">
		<vgroup>
			<vspace height="2"/>

			<pageview id = "mainpages">
				
				<hgroup title="testi" id="testi">
					<rectangle/>
					<rectangle/>
				</hgroup>
				<hgroup title="Screenmode" id="Screenmode">
					<rectangle/>
					<radio>
						<item>Human</item>
						<item>Elf</item>
						<item>Dwarf</item>
						<item>Fairy</item>
						<item>Gnome</item>
					</radio>
					<rectangle/>
				</hgroup>

				<hgroup title="Volume">
					<colgroup columns="2">
						<label>Sounds:</label>
						<slider min="0" max="100" level="50"/>

						<label>Music:</label>
						<slider min="0" max="100" level="50"/>
					</colgroup>
				</hgroup>

				<hgroup title="Class">
					<rectangle/>
					<radio>
						<item>Warrior</item>
						<item>Rogue</item>
						<item>Bard</item>
						<item>Monk</item>
						<item>Magician</item>
						<item>Archmage</item>
					</radio>
					<rectangle/>
				</hgroup>

			</pageview>
		</vgroup>
	</window>
</application>
And the Hollywood-code part:

Code: Select all

@VERSION 9,0
@OPTIONS {DPIAware = True}
@REQUIRE "RapaGUI"
@FILE 1, "RapaGuiPart.xml"

; dynamically create GUI from an external *.xml file definition


moai.CreateApp(ReadString(1))
Version = "AMIGA"
If Version="AMIGA"
	moai.CreateObject("<menuitem id=\"single1\">Item 1</menuitem>")
	moai.CreateObject("<menuitem id=\"single2\">Item 2</menuitem>")

	amigapage$ = [[
	<vgroup title="Amiga Specific" id="Amigapage" padding="16">
	<rectangle/>
	<rectangle/>
	</vgroup>
	]]

	moai.CreateObject(amigapage$, "mainpages")
	moai.DoMethod("mainpages", "append", "Amigapage", True)

EndIf



RadioStart$ = [[
<radio id="printer">
<item>HP Deskjet</item>
<item>NEC P6</item>
<item>Okimate 20</item>
</radio>
]]

moai.CreateObject(RadioStart$, "testi")



; main loop!

Repeat
	WaitEvent
Forever
Problem is that when I am trying to execute the "moai.CreateObject(RadioStart$, "testi")" trying to create radio buttons to "testi" page, it keeps telling me that "testi" is not a valid parent.

I don't know how to make it a valid parent.
User avatar
airsoftsoftwair
Posts: 5644
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: How to dynamically add Radio items, and a page.

Post by airsoftsoftwair »

Which platform are you running that on?
User avatar
airsoftsoftwair
Posts: 5644
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: How to dynamically add Radio items, and a page.

Post by airsoftsoftwair »

Oh actually, it's a case of RTFM, here's what the moai.CreateObject() manual says about the parent parameter:
Normally, you just have to pass the identifier of the window that you want to attach the MOAI object to as the parent. There is one exception: If you plan to add the MOAI object to a group with a frame, i.e. an instance of Group class with Group.Frame set to True, then you have to pass this group object as the parent. Note that this only applies to groups with a frame. If you plan to add the MOAI object to a normal group that doesn't have a frame, you just have to pass the identifier of the window to moai.CreateObject(). Note, though, that in case the normal group is itself just a child embedded somewhere in the hierarchy of a framed group, then you have to pass the identifier of the framed group. Also, when adding objects to scrollgroups, you need to pass the scrollgroup as the parent.
Since your "testi" group doesn't have a frame, you mustn't use it but the window as a parent if I understand my manual correctly ;)
Bugala
Posts: 1295
Joined: Sun Feb 14, 2010 7:11 pm

Re: How to dynamically add Radio items, and a page.

Post by Bugala »

Thanks, this cleared the parent issue, and thought I finally understood what I read, but now I am however still confused as to how to add the radio object under the "testi" tab.

For I thought it would be something like:

Code: Select all

moai.DoMethod("testi", "initchange")
moai.DoMethod("testi", "prepend", "printer")
moai.DoMethod("testi", "exitchange")
But not working. and mentioning this is windows 11 since you asked earlier.

"If your newly allocated MOAI object is a window object... ...To attach menu objects... ...All other objects can be attached by using the group methods
Group.Prepend, Group.Append and Group.Insert."

"moai.DoMethod(id, "Prepend", obj)
id id of the group object
obj id of the object to attach"

Tried the append and insert as well just in case, although I assume Prepend is the way to go.
User avatar
airsoftsoftwair
Posts: 5644
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: How to dynamically add Radio items, and a page.

Post by airsoftsoftwair »

Can you post an updated MCVE so that I can try the code here and see if it's a RapaGUI bug or a bug in your code? Thanks!
Bugala
Posts: 1295
Joined: Sun Feb 14, 2010 7:11 pm

Re: How to dynamically add Radio items, and a page.

Post by Bugala »

Here is close to MCV of one of my tries:
RapaGuiPart.XML-file:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1"?>
<application id="app">
	<window title="Rogue Football Cardgame" id="window" width="400">
		<vgroup>
			<vspace height="2"/>

			<pageview id = "mainpages">
				
				

				<hgroup title="Volume">
					<colgroup columns="2">
						<label>Sounds:</label>
						<slider min="0" max="100" level="50"/>

						<label>Music:</label>
						<slider min="0" max="100" level="50"/>
					</colgroup>
				</hgroup>
				
				<hgroup title="Test" id="test">
					<rectangle/>
					<rectangle/>
				</hgroup>
			</pageview>
			<hgroup>
				<button id="button_start">START</button>
			</hgroup>
		</vgroup>
	</window>
</application>
Hollywood Code:

Code: Select all

@VERSION 9,0
@OPTIONS {DPIAware = True}
@REQUIRE "RapaGUI"

@FILE 1, "RapaGuiPart.xml"


moai.CreateApp(ReadString(1))
amigaresolutions = {}



RadioStart$ = [[
<hgroup id="printteri" frame="true">
<radio id="printer">
<item>HP Deskjet</item>
<item>NEC P6</item>
<item>Okimate 20</item>
</radio>
</hgroup>
]]

moai.CreateObject(RadioStart$, "mainpages")

moai.DoMethod("test", "initchange")
moai.DoMethod("test", "append", "printteri")
moai.DoMethod("test", "exitchange")


Repeat
	WaitEvent
Forever

I have also tried changing following parts:

Code: Select all

RadioStart$ = [[
<hgroup id="printteri" frame="true">
<radio id="printer">
<item>HP Deskjet</item>
<item>NEC P6</item>
<item>Okimate 20</item>
</radio>
</hgroup>
]]
into

Code: Select all

RadioStart$ = [[
<radio id="printer">
<item>HP Deskjet</item>
<item>NEC P6</item>
<item>Okimate 20</item>
</radio>
]]
by otherwords, leaving only the Radio Button part in hopes it would work that way.

And therefore also changed:

Code: Select all

moai.DoMethod("testi", "initchange")
moai.DoMethod("testi", "prepend", "printteri")
moai.DoMethod("testi", "exitchange")
into

Code: Select all

moai.DoMethod("testi", "initchange")
moai.DoMethod("testi", "prepend", "printer")
moai.DoMethod("testi", "exitchange")
as in trying to just add the radio button to the tab.

That point is that I have tried both to add another tab with a radio button, as well as just a radio button to an existing tab, but succeeded in neither this way, although it seemed to me like moai.DoMethod with InitChange, Append, Exitchange would be the way to do it.

Anyway, I don't need an answer to this anymore myself, as, as you pointed out too, RapaGUI isn't the solution to giving users an option to choose how to open the display for a game, as it slows it down, although, good to know that in Amigas it could be used.
Bugala
Posts: 1295
Joined: Sun Feb 14, 2010 7:11 pm

Re: How to dynamically add Radio items, and a page.

Post by Bugala »

One mistake there in the code. I forgot to change the "testi" to "test" before I copy-pasted it here. so change the "testi" to "test".
Post Reply