Thanks for pointing this out to me, how on earth could I miss this? It's really well documented, apparently I missed the most obvious place to look...
Still, some things seem to be odd if the next visible group in the hierarchy is of type
ColGroup. This time I really really couldn't find anything in the docs mentioning
ColGroup would need special attention or something.
Please have a look at the following example:
Code: Select all
@REQUIRE "RapaGUI", { Link = True }
/*
** Handles all incoming events
*/
Function p_EventFunc(msg)
Switch msg.action
Case "RapaGUI":
Switch msg.attribute
Case "Pressed":
If msg.id = "add"
moai.CreateObject("<text id=\"text" .. count .. "\">Text " .. count .. "</text>", "win")
moai.CreateObject("<button id=\"button" .. count .. "\">Button " .. count .. "</button>", "win")
moai.DoMethod("container", "initchange")
If count = 1
moai.DoMethod("container", "remove", "blankspace1")
moai.DoMethod("container", "remove", "blankspace2")
EndIf
moai.DoMethod("container", "append", "text" .. count)
moai.DoMethod("container", "append", "button" .. count)
moai.DoMethod("container", "exitchange", False) ; tried True as well, but to no account
count = count + 1
ElseIf (msg.id = "rem") And (count > 1)
count = count - 1
moai.DoMethod("container", "initchange")
moai.DoMethod("container", "remove", "text" .. count)
moai.DoMethod("container", "remove", "button" .. count)
If count = 1
moai.DoMethod("container", "append", "blankspace1")
moai.DoMethod("container", "append", "blankspace2")
EndIf
moai.DoMethod("container", "exitchange", False) ; tried True as well, but to no account
moai.FreeObject("text" .. count)
moai.FreeObject("button" .. count)
ElseIf LeftStr(msg.id, 6) = "button"
moai.Request("Dynamic 2.5", "You've pressed button " .. UnrightStr(msg.id, 6) .. "!", "OK")
EndIf
EndSwitch
EndSwitch
EndFunction
count = 1
moai.CreateApp([[
<?xml version="1.0" encoding="iso-8859-1"?>
<application id="app">
<window title="Dynamic 2.5" id="win">
<vgroup id="rootgroup">
<colgroup id="container" columns="2" frame="true" frametitle="Buttons">
<rectangle id="blankspace1"></rectangle>
<rectangle id="blankspace2"></rectangle>
</colgroup>
<hgroup frame="true" frametitle="Control">
<button id="add" notify="pressed">Add button</button>
<button id="rem" notify="pressed">Remove button</button>
</hgroup>
</vgroup>
</window>
</application>
]])
; listen to these events!
InstallEventHandler({RapaGUI = p_EventFunc})
; main loop!
Repeat
WaitEvent
Forever
- If moai.CreateObject() is used with parentId = "win", it works, although the next visible group in the hierarchy is actually "container".
- If moai.CreateObject() is used with parentId = "container", the error Object "container" is no valid parent! occurs.
- With MUI, adding and removing works perfectly fine! This is after adding 3 buttons and removing 2:

- On Windows, though, adding works fine, but when removing only the text widhgets are removed properly but the buttons stay visible, although they seem to be in some strange state:

Resizing the window doesn't and either does using "True" in "exitChange" for a forced redraw.
Maybe some wxWidget bug?
And here's another one where the hierarchy goes a bit deeper: There's a <vgroup> inside the <colgroup> and buttons are added to that <vgroup>:
Code: Select all
@REQUIRE "RapaGUI", { Link = True }
/*
** Handles all incoming events
*/
Function p_EventFunc(msg)
Switch msg.action
Case "RapaGUI":
Switch msg.attribute
Case "Pressed":
Local group$ = "group"
If msg.id = "add"
moai.CreateObject("<button id=\"button" .. count .. "\">Button " .. count .. "</button>", "win")
moai.DoMethod(group$, "initchange")
If count = 1
moai.DoMethod(group$, "remove", "blankspace1")
EndIf
moai.DoMethod(group$, "append", "button" .. count)
moai.DoMethod(group$, "exitchange", False) ; tried True as well, but to no account
count = count + 1
ElseIf (msg.id = "rem") And (count > 1)
count = count - 1
moai.DoMethod(group$, "initchange")
moai.DoMethod(group$, "remove", "button" .. count)
If count = 1
moai.DoMethod(group$, "append", "blankspace1")
EndIf
moai.DoMethod(group$, "exitchange", False) ; tried True as well, but to no account
moai.FreeObject("button" .. count)
ElseIf LeftStr(msg.id, 6) = "button"
moai.Request("Dynamic 2.6", "You've pressed button " .. UnrightStr(msg.id, 6) .. "!", "OK")
EndIf
EndSwitch
EndSwitch
EndFunction
count = 1
moai.CreateApp([[
<?xml version="1.0" encoding="iso-8859-1"?>
<application id="app">
<window title="Dynamic 2.6" id="win">
<vgroup spacing="8">
<textview>Some text</textview>
<colgroup id="colgroup" columns="2" frame="true" frameTitle="Buttons">
<text>Some text</text>
<vgroup id="group">
<rectangle id="blankspace1" />
</vgroup>
</colgroup>
<hgroup>
<button id="add">_Add Button</button>
<button id="rem">_Remove Button</button>
</hgroup>
</vgroup>
</window>
</application>
]])
; listen to these events!
InstallEventHandler({RapaGUI = p_EventFunc})
; main loop!
Repeat
WaitEvent
Forever
Again, this works perfectly with MUI, but again on Windows adding buttons is bit of a mess:
I think this needs some attention by Andreas...
Cheers, Michael