ReparentGadget / MoveFromContainer
Posted: Sat Mar 15, 2014 12:19 am
Hi there,
I wish I could move a Gadget from one Container to another without deleting and recreate it.
This code works without problems, but in complexer situations it does not work very well:
I wish I could move a Gadget from one Container to another without deleting and recreate it.
This code works without problems, but in complexer situations it does not work very well:
Code: Select all
Define.i main, button, splitter
Global.i container1, container2
main = OpenWindow(#PB_Any, 0, 0, 800, 600, "test")
container1 = ContainerGadget(#PB_Any, 0, 0, 800, 300, #PB_Container_Raised)
button = ButtonGadget(#PB_Any, 5, 5, 100, 30, "Oben")
CloseGadgetList()
container2 = ContainerGadget(#PB_Any, 0, 300, 800, 300, #PB_Container_Raised)
CloseGadgetList()
splitter = SplitterGadget(#PB_Any, 0, 0, 800, 600, container1, container2, #PB_Splitter_SecondFixed)
Procedure SetGadgetParent(GadgetID.i, ContainerID.i)
If (GadgetType(ContainerID) = #PB_GadgetType_Container)
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
Protected x.i = GadgetX(GadgetID), y.i = GadgetY(GadgetID)
gtk_widget_reparent_(GadgetID(GadgetID), GadgetID(ContainerID))
ResizeGadget(GadgetID, x, y, #PB_Ignore, #PB_Ignore)
CompilerCase #PB_OS_Windows
SetParent_(GadgetID(GadgetID), GadgetID(ContainerID))
CompilerCase #PB_OS_MacOS
CompilerEndSelect
ProcedureReturn #True
EndIf
ProcedureReturn #False
EndProcedure
Procedure change()
Protected button.i = EventGadget()
If (GetGadgetText(button) = "Oben")
SetGadgetParent(button, container2)
SetGadgetText(button, "Unten")
Else
SetGadgetParent(button, container1)
SetGadgetText(button, "Oben")
EndIf
EndProcedure
BindGadgetEvent(button, @change())
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow