This is how TreeGadget's should work.

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Inner
PureBasic Expert
PureBasic Expert
Posts: 714
Joined: Fri Apr 25, 2003 4:47 pm
Location: New Zealand

This is how TreeGadget's should work.

Post by Inner »

** Section of code from B+ **


AddTreeViewNode( name$, perant_node )

Code: Select all

window=CreateWindow( "Simple TreeView demo",0,0,640,480 )

treeview=CreateTreeView( 0,0,ClientWidth(window),ClientHeight(window),window )
SetGadgetLayout treeview,1,1,1,1

root=TreeViewRoot( treeview )

hello=AddTreeViewNode( "Hello!",root )
	test1=AddTreeViewNode( "Test1",hello )
	test2=AddTreeViewNode( "Test2",hello )
	test3=AddTreeViewNode( "Test3",hello )
	test4=AddTreeViewNode( "Test4",hello)
		test5=AddTreeViewNode( "Test5",test4 )
		test6=AddTreeViewNode( "Test6",test4 )
		test7=AddTreeViewNode( "Test7",test4 )
		
While WaitEvent()<>$803

	If EventID()=$401 And EventSource()=treeview
		Select SelectedTreeViewNode( treeview )
		Case hello Notify "Hello hit"
		Case test1 Notify "Test1 hit"
		Case test2 Notify "Test2 hit"
		Case test3 Notify "Test3 hit"
		Case test4 Notify "Test4 hit"
		Case test5 Notify "Test5 hit"
		Case test6 Notify "Test6 hit"
		Case test7 Notify "Test7 hit"
		End Select
	EndIf

Wend

End
It's less confusing.
Searhin
User
User
Posts: 41
Joined: Mon May 26, 2003 10:53 am
Location: Germany

Post by Searhin »

i agree, this would be a more elegant (and less confusing) way to handle TreeGadget items. However, to determine the layout at the beginning may be a drawback as i learned that large trees are VERY slow. Trees with many entries should be handled dynamically, i.e. loading the entries of a node only if it was selected by the user.

a propos: is there a simple function which returns the selected tree item's level (e.g. root node, sub-node or lowest level entry)?
User avatar
Inner
PureBasic Expert
PureBasic Expert
Posts: 714
Joined: Fri Apr 25, 2003 4:47 pm
Location: New Zealand

Post by Inner »

indeed.

I don't know why exactally but the current implymentation doesn't work with the way I need to fill the list out.
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Where is the difference?

Code: Select all

OpenWindow(0, 0, 0, 640, 480, #PB_Window_SystemMenu, "Simple TreeView demo")
CreateGadgetList(WindowID())

TreeGadget(1, 0, 0, WindowWidth(), WindowHeight())

AddGadgetItem(1, -1, "Hello")
  OpenTreeGadgetNode(1)
    AddGadgetItem(1, -1, "Test1")
    AddGadgetItem(1, -1, "Test2")
    AddGadgetItem(1, -1, "Test3")
    AddGadgetItem(1, -1, "Test4")
      OpenTreeGadgetNode(1)
        AddGadgetItem(1, -1, "Test5")
        AddGadgetItem(1, -1, "Test6")
        AddGadgetItem(1, -1, "Test7")
      CloseTreeGadgetNode(1)
  CloseTreeGadgetNode(1)
  
Repeat
  Event = WaitWindowEvent()
  If Event = #PB_EventGadget And EventGadgetID() = 1 And EventType() = #PB_Eventtype_LEftClick
    Select GetGadgetState(1)
      Case 0: Debug "Hello hit"
      Case 1: Debug "Test1 hit"
      Case 2: Debug "Test2 hit"
      Case 3: Debug "Test3 hit"
      Case 4: Debug "Test4 hit"
      Case 5: Debug "Test5 hit"
      Case 6: Debug "Test6 hit"
      Case 7: Debug "Test7 hit"
    EndSelect
  EndIf
Until Event = #PB_EventCloseWindow

End
btw: "While WaitEvent()<>$803 " looks ugly, don't they have constants in b+? :lol:

Timo
quidquid Latine dictum sit altum videtur
User avatar
Inner
PureBasic Expert
PureBasic Expert
Posts: 714
Joined: Fri Apr 25, 2003 4:47 pm
Location: New Zealand

Post by Inner »

no idea if they do or don't :)

the diferents is that it's using a pointer from the previous item inserted to add the next one after it, the other diferents is you can tell it too instantly return to the root tree below the current items and add new fields.
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Yeah, $803 is a constant if I remember correctly :)
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Post Reply