using a treebox - Printable Version +- yab | yet another Basic for HAIKU (https://yab.orgfree.com/forum) +-- Forum: Programming in yab (https://yab.orgfree.com/forum/forumdisplay.php?fid=1) +--- Forum: Snippets (https://yab.orgfree.com/forum/forumdisplay.php?fid=3) +--- Thread: using a treebox (/showthread.php?tid=83) |
using a treebox - bbjimmy - 03-08-2017 Treeboxes are the yab version of the Outline List View. They allow the user to select an item like a listbox while allowing for sub items for each listed item. This takes some special handeling to set-up. First, add the treebox : TREEBOX 0,0 to 300,400, "TB", 1, View$ Next add all the top level items in the order to be shown: TREEBOX ADD "TB", "First Item" TREEBOX ADD "TB", "Second Item" TREEBOX ADD "TB", "Third Item" Now add the sub-items grouped together and in the reverse order: TREEBOX ADD "TB", "First Item", "Sub item2",0 TREEBOX ADD "TB", "First Item", "Sub item1",0 TREEBOX ADD "TB", "Sub item1", "Detail2", 0 TREEBOX ADD "TB", "Sub item1", "Detail1", 0 TREEBOX ADD "TB", "Second Item", "Sub item2,2",0 TREEBOX ADD "TB", "Second Item", "Sub item2,1",0 Haiku has issues with the outlinelistview therefore yab has the same issue. If one colapsed a menu and later expands the menu and attempts to make a selection, the wrong item is selected. The following is a work-around that will always make the proper selection, although it adds a minor visual glitch. In the program loop do the following: if left$(msg$(everyCommand),11)="TB:_Select:" then tmp=treebox get "TB" TREEBOX SELECT "TB", tmp // now process the selection endif It seems that treebox get was not included in the documentation. It makes one wonder how many other yab commands are missing from the docs. The magic here is: TREEBOX SELECT "TB", tmp this selects the item, but the loop will come around soon enough to re-select the sub-idem that was really intended. otherwise outlinelistview will continue to reurn the wrong message and the user will see his selection not take effect. Example program: Code: #!yab RE: using a treebox - clasqm - 03-09-2017 Very useful, thanks Jim. I must admit I've been avoiding this widget. Can I add this to the next edition of Programming with yab? RE: using a treebox - bbjimmy - 03-09-2017 Sure! |