Attaching objects to tabbers and updating.

BlitzMax Forums/BlitzMax GUI Programming/Attaching objects to tabbers and updating.

You can have different canvas for each tabs...
I used the basic example that comes with MaxGUI
' createtabber.bmx
Import MaxGui.Drivers
Strict 
Local window:TGadget
Local tabber:TGadget
Local document:TGadget[3],pa:tgadget[3]
Local currentdocument:TGadget

' CreateDocument creates a hidden panel that fills entire tabber client area 

Function CreateDocument:TGadget(tabber:TGadget)
	Local	panel:TGadget
	panel=CreatePanel(0,0,ClientWidth(tabber),ClientHeight(tabber),tabber)
	SetGadgetLayout panel,1,1,1,1
	HideGadget panel
	Return panel
End Function

' create a default window with a tabber gadget that fills entire client area

window=CreateWindow("My Window",30,20,400,300)

tabber=CreateTabber(0,0,ClientWidth(window),ClientHeight(window),window)
SetGadgetLayout tabber,1,1,1,1 

' add three items and corresponding document panels to the tabber

AddGadgetItem tabber,"Document 0",False,-1,""
AddGadgetItem tabber,"Document 1",False,-1,"Tabber Tip 1"
AddGadgetItem tabber,"Document 2",False,-1,"tips 4 2"

document[0]=CreateDocument(tabber)
document[1]=CreateDocument(tabber)
document[2]=CreateDocument(tabber)

SetPanelColor document[0],255,200,200
SetPanelColor document[1],200,255,200
SetPanelColor document[2] , 200 , 200 , 255

'to keep track of the canvases associated each to one tab (document[])


pa[0]=CreateCanvas(10 , 10 , 100 , 100 , document[0])
pa[1]=CreateCanvas(10 , 10 , 200 , 100 , document[1])
pa[2]=CreateCanvas(10 , 10 , 100 , 200 , document[2])


' our documents start off hidden so make first one current and show

currentdocument=document[0]
ShowGadget currentdocument


Global grfx:tgraphics = CanvasGraphics(pa[0])
SetGraphics grfx 

' standard message loop with special tabber GADGET_ACTION handling
Global text$ = "Red Canvas"
Global what_canvas:Int=0
While WaitEvent()
	Select EventID() 
	
		Case EVENT_TIMERTICK
			'redraw ONLY the current document-canvas
			RedrawGadget pa[what_canvas]
			
		Case EVENT_GADGETPAINT
			Cls
			DrawText text,0,0
			Flip()

	
		Case EVENT_GADGETACTION
			If EventSource()=tabber
				HideGadget currentdocument
				currentdocument = document[EventData()]
				'choose what canvas uses
				what_canvas = EventData()
				'setup graphics for that one
				grfx:tgraphics = CanvasGraphics(pa[what_canvas])
				SetGraphics grfx
				ShowGadget currentdocument
			EndIf
		Case EVENT_WINDOWCLOSE
			End
	End Select
Wend