Autogenerated brush ID incompatible with Listview.Insert?

Discuss GUI programming with the RapaGUI plugin here
Post Reply
User avatar
mrupp
Posts: 147
Joined: Sun Jan 31, 2021 7:44 pm
Location: Switzerland
Contact:

Autogenerated brush ID incompatible with Listview.Insert?

Post by mrupp »

I'm having a listview and would like to dynamically load brushes and add them to my list (don't worry about memory consumption, they are not that many, should be < 10).
Now, as long as I choose the brush IDs myself, this is working fine, but if I let LoadBrush() autogenerate the brush identifier, calling the Listview's "insert" method generates an error. According to the docs, passing Nil as first parameter to LoadBrush() should return the new id, shouldn't it?
Here's an example:

Code: Select all

@REQUIRE "RapaGUI", { Link = True }

Function p_EventFunc(msg)
	Switch msg.id
	Case "btn1":
		Local id = 1
		LoadBrush(id, "ok.png", { LoadAlpha = True })
		moai.DoMethod("myListview", "insert", "bottom", id, "myValue")
	Case "btn2":
		Local autoid = LoadBrush(Nil, "ok.png", { LoadAlpha = True })
		DebugPrint("autoid", autoid)
		moai.DoMethod("myListview", "insert", "bottom", autoid, "myValue")
	EndSwitch
EndFunction

InstallEventHandler({RapaGUI = p_EventFunc})

moai.CreateApp([[<?xml version="1.0" encoding="iso-8859-1"?>
<application id="app">
	<window id="mainWindow" title="LoadBrush-Test">
		<vgroup>
			<button id="btn1">Add entry with fixed brush ID</button>
			<button id="btn2">Add entry with autogenerated ID</button>
			<listview id="myListview">
				<column icon="true" />
			</listview>
		</vgroup>
	</window>
</application>
]])

Repeat
	WaitEvent
Forever
Please note that you need to copy "ok.png" from the RapaGUI-Demo-script into the same directory for the example to work.

This is the error I get:
Error in line 12 (LoadBrush.hws): Number expected in argument 4!

And this is the output from DebugPrint("autoid", autoid):
autoid UserData: 00000000031EC840

Is this a bug or what am I missing?

Doing the same thing on a normal Hollywood window using DisplayBrush() works fine, so this seems a Listview.insert issue, I guess...

Code: Select all

Local autoid = LoadBrush(Nil, "ok.png", { LoadAlpha = True })
DebugPrint("autoid", autoid)
DisplayBrush(autoid, "100", "100")

Repeat
	WaitEvent
Forever
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Autogenerated brush ID incompatible with Listview.Insert?

Post by airsoftsoftwair »

Yes, this is a known limitation of RapaGUI and MUI Royale. Your brushes must use numeric identifiers because it's impossible to use the auto-IDs in XML files because they are essentially pointers. Also, RapaGUI and MUI Royale cache images which is described here.
User avatar
mrupp
Posts: 147
Joined: Sun Jan 31, 2021 7:44 pm
Location: Switzerland
Contact:

Re: Autogenerated brush ID incompatible with Listview.Insert?

Post by mrupp »

airsoftsoftwair wrote: Sun May 23, 2021 9:16 pm Yes, this is a known limitation of RapaGUI and MUI Royale. Your brushes must use numeric identifiers because it's impossible to use the auto-IDs in XML files because they are essentially pointers. Also, RapaGUI and MUI Royale cache images which is described here.
Thanks for clarifying this. Maybe you could change the doc entry for "Listview.Insert" to mention this. Maybe something like this:

The entry data consists of a text string and, if the column has the Listviewcolumn.Icon attribute set, an icon for each column. The icon has to be passed before the text string and it has to be an identifier of a Hollywood brush which should be used as the icon for the entry. If Listviewcolumn.Icon isn't set, then you must omit the icon parameter and only pass text data for the listview entry. If you've set Listviewcolumn.Icon to True and you don't want to show an icon in this particular row and column, you can also pass the special value -1. In that case, RapaGUI won't show an icon even though Listviewcolumn.Icon has been set to True. Please note that auto-generated IDs cannot be used. Please also read about RapaGUI's image cache to learn more about icon support in RapaGUI. See Image cache for details.

(...)

INPUTS
icon1
optional: icon for the first column; this must only be passed if the column has the icon attribute set. Note that this must be a numeric identifier and auto-generated IDs are not valid in this case.
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Autogenerated brush ID incompatible with Listview.Insert?

Post by airsoftsoftwair »

Ok, I'll update the doc!
Post Reply