[MaxGUI] TreeView
BlitzMax Forums/BlitzMax Beginners Area/[MaxGUI] TreeView
| ||
InsertTreeViewNode:TGadget( index,text$,node:TGadget,icon=-1 ) My stupid daily question: is there a command to retrieve the 'index' of a gadget in the TreeView structure? At the moment I resolved scanning in the kids list of the parent of the gadget I'm looking for the position, but is there a direct-faster system/function/method to achieve this? Or I miss something? |
| ||
No one can respond or no one wants to respond? I'm know that this is maybe a stupid question, but I would like to know it there is a way to retrieve the index of a gadget in the treeview structure. I read the Tgadget type but I didn't find any variable that track the position as a index. So the basic question: what hell we need a command like InsertTreeViewNode() that requires a INDEX, if we don't know WHAT INDEX we need to use? |
| ||
Sorry, just got MAXGUI the other day. Haven't had a chance to fiddle around with it. :( I'm waiting for an answer to your question too! |
| ||
Good. I'm not the only one... |
| ||
AAARRRH! Please try this win_main:tgadget=CreateWindow("Test",50,50,400,400,,WINDOW_TITLEBAR|WINDOW_STATUS) tree_view:tgadget=CreateTreeView(10,10,200,320,win_main) SetGadgetLayout tree_view,1,0,1,1 but_up:tgadget=CreateButton(" UP ",220,20,60,20,win_main) but_down:tgadget=CreateButton("DOWN",220,40,60,20,win_main) but_add:tgadget=CreateButton("ADD",220,80,60,20,win_main) but_insert:tgadget=CreateButton("INSERT",220,100,60,20,win_main) tree_root:tgadget=TreeViewRoot(tree_view) tree_root:tgadget=AddTreeViewNode("Main",tree_root) tree_root.context="Root" tree_node_1:tgadget=AddTreeViewNode("Node 1",tree_root) tree_node_2:tgadget=AddTreeViewNode("Node 2",tree_root) tree_node_1.context="Node 1" tree_node_2.context="Node 2" For i=1 To 10 uno:tgadget=AddTreeViewNode("Test "+String(i),tree_node_1) due:tgadget=AddTreeViewNode("Test "+String(i),tree_node_2) uno.context="Test "+String(i) due.context="Test "+String(i) Next Global nodo_ultimo:tgadget,nodo_root:tgadget While True WaitEvent 'Print CurrentEvent.ToString() source:tgadget=tgadget(EventSource()) Select EventID() ' Rem Case EVENT_GADGETSELECT If source=tree_view ' Print "tree view" gad:tgadget=tgadget(EventExtra()) ' Print "> "+String(gad.context) nodo_ultimo:Tgadget = SelectedTreeViewNode(tree_view) nodo_root:tgadget=Tgadget(EventExtra()) Print "Last node "+String(nodo_ultimo.context) Print "Nodo root : "+String(nodo_root.context) SetStatusText win_main,"Select: "+String(nodo_ultimo.context) posizione=FindPosition(nodo_ultimo) Print "POS: "+posizione End If Case EVENT_GADGETACTION If source=but_insert If posizione<>-1 posizione=FindPosition(nodo_ultimo) InsertTreeViewNode(posizione+1,"New",nodo_root.parent) End If End If If source=but_add If nodo_root<>Null AddTreeViewNode "New",nodo_root End If If source=but_up If nodo_root<>Null MoveItem(-1) End If If source=but_down If nodo_root<>Null MoveItem(1) End If Case EVENT_WINDOWCLOSE End End Select Wend Function MoveItem(dx:Int=0) If dx=0 Return If nodo_ultimo=Null Return If nodo_root=Null Return pos=FindPosition(nodo_ultimo) parent:tgadget=nodo_ultimo.parent If parent<>Null Print "Parent "+String(parent.context) End If End Function Function FindPosition(e:tgadget) Local parent:tgadget=e.parent i=-1 Print "PARENT: ["+String(parent.context)+"]" If parent.kids=Null Return -1 For aa:tgadget=EachIn parent.kids i=i+1 If aa=e Exit;Return i 'Print "I: "+i Next Return i End Function The Function FINDPOSITION *should* find the position of an item in the list of each parent. Try to choose an element and press INSERT to watch what happens! Try many times because in the beginning seems it works perfectly, then... Can someone tell me where is the error? |
| ||
it works fine for me all the time (inserted 60 odd). if you mean its giving the wrong pos its because it amends the instert to the end. is this the poblem? |
| ||
Well I want to insert a specific item in the position I choose, not where Bmax wants! The command InsertTreeViewNode() requires an INDEX for the position, and this should be (or I think of) what I obtain by my FindPosition(). Try to add in node1 at the 5th position - press INSERT , then change to 2nd - press INSERT, then 10th and press INSERT: what do you obtain now? to me Bmax put a 'new' item between 8 and 9?!=!= Where the error is? It's more 2 hours that I'm looking for this damend thing!!! |
| ||
well i cant see how to fix it but i dont thinks its a problem with your code. The tree view doesnt problerly insert the items because the list (kids) isnt sorted out correctly and thus going through will get the wrong position. it works somtimes because the selected item is in the right position. the futher down you insert thhe more distored it gets (well of me). The only way i can think to solve this would be to create you own list with the correct positions for the items ( and also contains a pointer to the item so you can check agaist it ). |
| ||
ohhh sh*t! Thanks anyway! |
| ||
As Diablo said, and the way I solved the problem of knowing which node was where, is to have your own tree/list to track everything. It appears to be how the Max IDE works too for it navigator trees. The limiting factor for me with the treeview is that there's nowhere to stick on extra data (unlike lists with GadgetItems), so you kind of end up having to keep a separate model of the tree anyway. :-) |
| ||
yes it is the same solution for me too, but 'duplicating' things & works is not a good idea...I hope that in the future BRL make some changes to MaxGUI gadgets (or deleting unuseful commands...) |
| ||
Depends on what you class a duplication. With a Model / View you might say that is duplication, in that you have a structure for the model, and a similar structure to view the model. as far as I'm concerned, I need a model to describe the Tree of nodes, and happen to use the TreeView gadget to view that model. Anything I do to the "model" (like adding / moving nodes) I then reflect those changes in the TreeView... Seems to work ok? :-) (I'm sure there are better ways to do these things) |
| ||
...I'm lazy :P I know that there are many ways to do things, but the real (my) problem is that maybe a must restart some projects from the root as I find that 'my' idea doesn't works perfectly...and this is quite annoying... |
| ||
I completely understand ! :-) |
| ||
ps: good job the GED - I just tried the demo, go ahead! A little question: what are the min spec for running Bmax under Mac? I just made a search but I must be blind... |
| ||
thanks :-) According to the products page : MacOS Requirements: MacOS X 10.2.8 or higher; Project Builder or X-Code developer tools preinstalled. Tho that seems a little vague on the hardware side of things. I'm running a 867mhz laptop which is more than adequate for everything I've done in Max so far. There are probably people running it on less. |
| ||
I'm talking on the Mac hardware: someone I know what to sell me a Powerbook (I think - but I have no detail at the moment...) and I want to what are the min spec hardware to run Mac OS+devs applications+Bmax... |
| ||
Well. I have an G3 900mzh iBook with 256 mb ram and some ATI rage card and it runs fine :) |
| ||
Thanks, I just put my little hands on an used iBook G3@500Mhz, 192 Mb MacOs X 10.3.8 and it is a very good product compared on my very-old&crappy portable PC Acer Celeron800Mhz+128Mhz+WinME...another world! Now I'm happy like a child with a new toy! For this week I think I'm kidnapped by MacOs... byez |