Hi there
I wanted to dynamically append a widget to a group as in the Dynamics2.hws example. I failed and found out it's because my group hasn't got a frame. I didn't find anything in the docs mentioning that a group would need a frame to be able to add widgets to it.
This can easily be reproduced by removing frame="true" in the Dynamics2.xml of the "Dynamics2" example. You'll get the following error:
Object "container" is no valid parent!
I hope this is a bug and not some limitation of the group class...
Cheers, Michael
Appending a widget to a frameless group doesn't work
Re: Appending a widget to a frameless group doesn't work
This is mentioned in the documentation:
"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."
"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."
Re: Appending a widget to a frameless group doesn't work
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?
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
I think this needs some attention by Andreas...
Cheers, Michael
- airsoftsoftwair
- Posts: 5446
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: Appending a widget to a frameless group doesn't work
Yes, looks like an issue. I'll see what's wrong there.
- airsoftsoftwair
- Posts: 5446
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: Appending a widget to a frameless group doesn't work
Code: Select all
- Fix [Windows/macOS/Linux]: Group.Remove() didn't work correctly for colgroups
- Fix: moai.CreateObject() didn't accept framed colgroups as the parent
This is because of a bug in your code. As mentioned in the doc, you need to pass the framed group next in the z-hierarchy as the parent, i.e. "colgroup" in your example. Of course, RapaGUI didn't allow that because of the bug but now that the bug is fixed, I've just tested it and the layout problem is gone when passing "colgroup" as the parent.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>:
Re: Appending a widget to a frameless group doesn't work
i'm facing the same problem when adding an image to a vgroup. Do you plan to release and update?
And also.
I didn't find a way to download an image using DefineVirtualFileFromString and display it into an <image> or <icon> object. Do you have a working example how to do this? It seems if an image has already a brush and i try to reuse the same brush with the downloaded image it doesn't work but also using a different brush
And also.
I didn't find a way to download an image using DefineVirtualFileFromString and display it into an <image> or <icon> object. Do you have a working example how to do this? It seems if an image has already a brush and i try to reuse the same brush with the downloaded image it doesn't work but also using a different brush
Re: Appending a widget to a frameless group doesn't work
I've found the problem. If you add useicons="true" on Application also "image" expects an icon instead of a brush.
The documentation says:
This attribute can be used to globally change the default image type for attributes
such as Button.Icon or Toolbarbutton.Icon to icon instead of brush
Is this a normal behaviour?
The documentation says:
This attribute can be used to globally change the default image type for attributes
such as Button.Icon or Toolbarbutton.Icon to icon instead of brush
Is this a normal behaviour?
- airsoftsoftwair
- Posts: 5446
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: Appending a widget to a frameless group doesn't work
Yes, but you can set Image.BrushType to "Brush" to override the global default set using Application.UseIcons.
- airsoftsoftwair
- Posts: 5446
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact: