Tabber help

BlitzPlus Forums/BlitzPlus Beginners Area/Tabber help

Ked(Posted 2007) [#1]
Can anyone give me an example of creating a new tab when the menu item new is selected and how to delete them when the menu item delete is selected? I've been working on figuring it out but I can't get it.

Thanks


kfprimm(Posted 2007) [#2]
Basically, when the user clicks New,
AddGadgetItem tabber,"New Tab"

And when they hit Delete,
If SelectedGadgetItem(tabber)>-1 RemoveGadgetItem tabber,SelectedGadgetItem(tabber)

Sorry I couldn't provide an example. That should be enough to get you going. If you need more help, let me know.


Ked(Posted 2007) [#3]
Why doesn't this work though?

Global window=CreateWindow("TAB TEST",0,0,640,480,Desktop(),1+2+4)
Dim tabtextareas(10)
Dim tabpanels(10)
Global tabcount=0

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

tabpanels(tabcount)=CreatePanel(0,0,ClientWidth(tabber),ClientHeight(tabber),tabber)
SetGadgetLayout tabpanels(tabcount),1,1,1,1
tabtextareas(tabcount)=CreateTextArea(0,0,ClientWidth(tabpanels(tabcount)),ClientHeight(tabpanels(tabcount)),tabpanels(tabcount))
SetGadgetLayout tabtextareas(tabcount),1,1,1,1
AddGadgetItem tabber,"New Tab",True
tabcount=tabcount+1

filemenu=CreateMenu("File",0,WindowMenu(window))
	CreateMenu("New Tab",1,filemenu)
	CreateMenu("Delete Tab",2,filemenu)
	CreateMenu("",0,filemenu)
	CreateMenu("Exit",3,filemenu)

UpdateWindowMenu window

Repeat
	Select WaitEvent()
		Case $803
			Select EventSource()
				Case window
					End
			End Select
		Case $1001
			Select EventData()
				Case 1
					tabpanels(tabcount)=CreatePanel(0,0,ClientWidth(tabber),ClientHeight(tabber),tabber)
					SetGadgetLayout tabpanels(tabcount),1,1,1,1
					tabtextareas(tabcount)=CreateTextArea(0,0,ClientWidth(tabpanels(tabcount)),ClientHeight(tabpanels(tabcount)),tabpanels(tabcount))
					SetGadgetLayout tabtextareas(tabcount),1,1,1,1
					AddGadgetItem tabber,"New Tab"
					tabcount=tabcount+1
				Case 2
					If SelectedGadgetItem(tabber)>-1
						RemoveGadgetItem tabber,SelectedGadgetItem(tabber)
						FreeGadget tabpanels(SelectedGadgetItem(tabber))
						tabcount=tabcount-1
					EndIf
			End Select
		Case $401
			Select EventSource()
				Case tabber
					For i=0 To tabcount-1
						If i=EventData()
							ShowGadget tabpanels(i)
						Else
							HideGadget tabpanels(i)
						EndIf
					Next
			End Select
	End Select
Forever
End



Siopses(Posted 2007) [#4]
Ked, I have a better idea over using the Global function. Here is an example of using banks, banks are much better then Globals.


;Combo Box example
;by Siopses
;Event List 
KEY_DOWN=$101 ;A key was pressed down-needs the keys scancode for EventData().
KEY_UP=$102 ;A key has been released on the keyboard-needs the keys scancode for EventData().
KEY_USED=$103 ;A key has been typed-needs keys ascii value.
MOUSE_BUTTON_DOWN=$201 ;self explanatory, needs one of the following values(1=left,2=middle,3=right).
MOUSE_OVER_CANVAS=$203 ;self explanatory, you need to use EventX() and EventY() along with the canvas handle.
GADGET_USED=$401 ;self explanatory, you need to be specific to what kind of gadget it is, and what the gadgets handle is as well.
MENU_SELECTED=$1001 ;something has been selected from a menu, needs the menu identifier
X_HIT=$803 ;The X was hit
APPLICATION_HALTED=$2001 ;Self explanatory, means that the program was suspended
APPLICATION_RESUMED=$2002 ;Self explanatory, means that the program was resumed

;GUI

;Window
window=CreateWindow("COMBO BOX EXAMPLE",250,350,350,400,window,15)

;Combo box
box=CreateComboBox(125,125,100,50,window)
AddGadgetItem box,"HELLO"
AddGadgetItem box,"BYE"

bank=CreateBank(12)
PokeInt bank,0,box
PokeInt bank,4,hello
PokeInt bank,8,bye
.begin
Repeat

	WaitEvent()
	
	ComboBox(bank)
	
Until EventID()=$803

	AppTitle("Quit?")
	
	blah=Confirm("Are you sure you want to quit?",1)
	
		If blah=1 Then
		
			End
			
				Else 
				
					If blah<>1 Then
					
						Gosub begin
						
					EndIf
					
		EndIf
		
Function ComboBox(bank)

	box=PeekInt(bank,0)
	
		Select EventID()
		
			Case $401 
			
				If SelectedGadgetItem(box)=0 Then
				
					AppTitle("Hello")
				
					Notify("HELLO")
					
						Else 
						
							If SelectedGadgetItem(box)=1 Then
							
								AppTitle("Bye")
							
								Notify("BYE")
								
							EndIf
							
				EndIf
				
		End Select
		
End Function 



I forgot why though, but a while back CS_TBL was helping
me get a grasp on programming, and banks was what he used to store GUI, and other stuff.


Ked(Posted 2007) [#5]
Thanks! I will use that from now on.

But what about my tabber problem?


Siopses(Posted 2007) [#6]
Sorry, I'm not quite sure how to fix this one. Particularly because I still don't understand the For/Next loop.


Ked(Posted 2007) [#7]
I got it. I ended up having to use types. If anyone is interested I'll post the code up here.