|
rTree 2.0 Summer is here, the trees are in blossom. Today is a good day, as I have the opportunity to write about a superb add-on to the LiveCode development environment. Before I start I'd better introduce myself. My name is Malte Pfaff-Brill, I am the CEO of a IT-service agency in the most northern part of Germany. If you are a fellow LiveCode developer, you might think there is that Multimedia guy again, boasting about his library animationEngine. Well that is not the case this time. Today I want to take the pleasure to tell you about an add-on to LiveCode I did not write myself. The library I am writing about is rTree by TapirSoft. You might have stumbled upon it already in the LiveCode marketplace. However I am writing about a version you will not have seen before. It is the brand new version 2.0, due out next week*. Why does this one get me excited so much? I have been developing software for archaeologists, called archaeoDox. One of the crucial elements in this software is a tree control, which is constantly updated. For version one of archaeoDox, my company was using Data Tree, which covered our basic needs quite nicely. My company is pretty experienced with using tree controls in LiveCode, so we know the other libraries that are around too. We have also been consulting for a company using the iMedTree library, which seems no longer to be actively maintained. All of the projects we have been working on that need a tree control are pretty complex. They need to display many trees, each rendering thousands of nodes. And this is where it gets tricky. Yesterdays problems Starting the benchmark tests Nodes are controls! Sublines Badges How does that beast work?
create_rTree "myTree"
Simple as that. Not in the mood for scripting? What takes a little bit of getting used to is the behavior when you are resizing the tree control with the pointer tool. The first time you resize the tree using the pointer tool, it looks a little bit like there would be wonky things happening. It does not, as the tree control takes care of its geometry, even when resizing it in edit mode. No need to be scared. Clever, clever, clever! Handlers or array, the choice is up to you Here comes a recipe for creating 1100 nodes 3 levels deep and Windows style using commands and setting properties. on mouseUp lock messages # Clear all data from the Tree. dispatch "delete_treeData" to control "Tree" # Set icons at Tree level. set the firstIconCollapsed of control "Tree" to 2194 set the firstIconExpanded of control "Tree" to 2195 set the secondIconCollapsed of control "Tree" to 2198 set the secondIconExpanded of control "Tree" to 2197 # Create new Nodes via commands and setting Node properties. repeat 10 times dispatch "new_node" to control "Tree" get the lastNodeID of control "Tree" set the depth_of_node_ID_[it] of control "Tree" to 0 repeat 10 times dispatch "new_node" to control "Tree" get the lastNodeID of control "Tree" set the depth_of_node_ID_[it] of control "Tree" to 1 repeat 10 times dispatch "new_node" to control "Tree" get the lastNodeID of control "Tree" set the depth_of_node_ID_[it] of control "Tree" to 2 end repeat end repeat end repeat # Render the Tree. dispatch "renderTree" to control "Tree" unlock Messages end mouseUp However, if you work in more complex environments, your data might not lend its hand to work like that. Most of the time I tend to be using arrays to build the tree. A little demo Script using array notation looks like this:
local sTreeArray on mouseUp dispatch "delete_nodeData" to control "tree" set the rootNodeIDs of control "Tree" to 1 refreshtree set the nodeData of control "Tree" to sTreeArray -- tA dispatch "renderTree" to group "Tree" end mouseUp on refreshtree pNode put "Root" into sTreeArray[1]["label"] put "test1" into sTreeArray[2]["label"] put "test2" into sTreeArray[3]["label"] put "test3" into sTreeArray[4]["label"] put 2&cr&3&cr&4 into sTreeArray[1]["children"] put "childOf3-1" into sTreeArray[5]["label"] put "childOf3-2" into sTreeArray[6]["label"] put "childOf3-3" into sTreeArray[7]["label"] put 5&cr&6&cr&7 into sTreeArray[4]["children"] put "ChildOf1-1" into sTreeArray[8]["label"] put "ChildOf1-2" into sTreeArray[9]["label"] put "ChildOf1-3" into sTreeArray[10]["label"] put 8&cr&9&cr&10 into sTreeArray[2]["children"] put "childOf1-1-1" into sTreeArray[11]["label"] put "childOf1-1-2" into sTreeArray[12]["label"] put "childOf1-1-3" into sTreeArray[13]["label"] put 11&cr&12&cr&13 into sTreeArray[8]["children"] put "Sublines test" &cr& "Second line" into \ sTreeArray[1]["sublines"] put "red" into sTreeArray[1]["textColor of line 1 of the \ sublines"] put "blue" into sTreeArray[1]["textColor of line 2 of the \ sublines"] put true into sTreeArray[5]["visible of the badge"] put "Malte" into sTreeArray[5]["label of the badge"] end refreshtree Right now we are in a transitional stage where we move archaeoDox from dataTree to rTree. The transition is fun and the new feature set is well worth the effort. rTree 2.0 will be available soon. If you need a Tree control you should hurry, as there is a very interesting offer that can save you some pennies. *rTree 2.0 is expected out within a week or two. Any purchasers of this great marketplace addon before the release of 2.0 will automatically be upgraded to 2.0 for free. Version 2.0 will be increasing in price to $79, so this represents a substantial saving on getting this fabulous time and effort saving tree control. It is also a part of our 3 for 2 Marketplace offer during July. So buy early and save twice!
|
Tweet
|