WIITD / raylib-freebasic

FreeBasic bindings for raylib
MIT License
27 stars 8 forks source link

Can't pass pointer to array of string to GuiListViewEx() raygui.bi #8

Closed Axle-Ozz-i-sofT closed 1 year ago

Axle-Ozz-i-sofT commented 2 years ago

Hi I have been attempting to get the FB array and variations of ZString Ptr array to pass to the GuiListViewEx() used in "raygui_controls_test_suite.bas" converted from ./raygui/examples/raygui_controls_test_suite.c I have tried multiple variations of the listViewExList and GuiListViewEx( ... ) as well as the raygui.bi "byval text as const zstring ptr ptr", "byref text as const zstring ptr ptr", "text as const zstring ptr ptr".

From raygui.bi v2.6 (fb-raylib v3.5) ./example/raygui_controls_test_suite.bas:

dim as string listViewExList( ... ) = { "This", "is", "a", "list view", "with", "disable", "elements", "amazing!" }

listViewExActive = GuiListViewEx( Rectangle( 165, 180, 140, 200 ), listViewExList(), 8, @listViewExFocus, @listViewExScrollIndex, listViewExActive )

raygui.bi
RAYGUIDEF Function GuiListView(bounds As Rectangle, text0 As Const zstring Ptr, scrollIndex as long ptr, active as long) As long            ' List View control, returns selected list item index
RAYGUIDEF Function GuiListViewEx overload(bounds As Rectangle, text0 As Const zstring ptr ptr, count as long , focus as long ptr, scrollIndex as long Ptr, active as long) As long   ' List View with extended parameters
RAYGUIDEF Function GuiListViewEx(bounds As Rectangle, text0() as string, count as long , focus as long ptr, scrollIndex as long Ptr, active as long) As long   ' List View with extended parameters

WIITD/raylib 4.1.x

declare function GuiListView(byval bounds as Rectangle, byval text as const zstring ptr, byval scrollIndex as long ptr, byval active as long) as long
declare function GuiListViewEx(byval bounds as Rectangle, byval text as const zstring ptr ptr, byval count as long, byval focus as long ptr, byval scrollIndex as long ptr, byval active as long) as long

What I have tried + many more random variations:

dim as string listViewExList( ... ) = { "This", "is", "a", "list view", "with", "disable", "elements", "amazing!" }
dim as string listViewExList( 7 ) = { "This", "is", "a", "list view", "with", "disable", "elements", "amazing!" }
dim as zstring ptr listViewExList( 7 ) = { @"This", @"is", @"a", @"list view", @"with", @"disable", @"elements", @"amazing!" }

listViewExActive = GuiListViewEx((Rectangle){ 165, 180, 140, 200 }, listViewExList, 8, &listViewExFocus, &listViewExScrollIndex, listViewExActive);
, listViewExList()
, listViewExList(7)
, @listViewExList(7)
, !"This;is;a;list view;with;disable;elements;amazing!"
++

I notice in the glasyalabolasfb-raylib v 2.6 uses overloading. Any thoughts? I may try swapping out/altering the header to use overloading see what happens when I get time. Axle

P.S. I tried using the overloaded function definition from fb-raylib/gui_2.6, but that failed. Prob the only other thing I can do at this stage is re-build the raylib.dll with a bebug routine to see what is being passed. That being said, GuiListView() is just a wrapper for GuiListViewEx(), so I can prob just leave it out.. But, looking at the pointer sent to GuiListViewEx() from GuiListView() it seams to be formated by GuiTextSplit() as a single string delimited by '\n'. result[len] = "Item-one\nItem-two\nItem-three", ''\0' or to put it another way GuiListView takes "Charmander;Bulbasaur;#18#Squirtel;Pikachu;Eevee;Pidgey" and is converted to "Charmander\nBulbasaur\n#18#Squirtel\nPikachu\nEevee\nPidgey" for GuiListViewEx Axle does self face palm. I'll let you know.

Axle-Ozz-i-sofT commented 2 years ago

Hi This is solved thanks to the help from FreeBASIC forum.

Use the following format replacing (4) with the number of string elements in the array: dim as zstring ptr TextArray( 4 ) = { @"This", @"is", @"a", @"text", @"array" } mycfunction( @TextArray( 0 ) )

Remember to use the "Address of" '@' when passing the array "@TextArray( 0 )" to the C function in the dll/so.

C array and function definition: const char TextArray[5] = { "This", "is", "a", "text", "array", }; int MyCFunction( const char **text);

dim as zstring ptr listViewExList( 7 ) = { @"This", @"is", @"a", @"list view", @"with", @"disable", @"elements", @"amazing!" }
listViewExActive = GuiListViewEx((Rectangle){ 165, 180, 140, 200 }, @listViewExList(0), 8, &listViewExFocus, &listViewExScrollIndex, listViewExActive);

Axle