About Store Forum Documentation Contact



Post Reply 
Tree view control
Author Message
Harton Offline
Member

Post: #1
Tree view control
Hello,

I would like ask about tree view control in gui. I didn't find a tutorial, which describe how to create it. However, in the Header Browser and the Code Editor, you created tree view control for files. I would ask you about tutorial, how create such a control in you gui.

Thanks and greetings!
Harton
05-02-2013 09:20 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Tree view control
Hello,

this should get you started:
Code:
/******************************************************************************/
class Elm // list element
{
   bool      opened=true; // if element is opened
   flt       offset=0;
   ImagePtr  arrow;
   Str       text;
   Memx<Elm> children;

   Elm& set(C Str &text) {T.text=text; return T;}
}
/******************************************************************************/
Region    region; // gui region
List<Elm> list  ; // gui list
Memx<Elm> elms  ; // elements
/******************************************************************************/
void InitPre()
{
   EE_INIT();
}
/******************************************************************************/
void SetVisible(Memt<bool> &elms_visible, Memx<Elm> &elms, bool visible, flt offset)
{
   flt children_offset=offset+0.05; // children will have bigger offset
   FREPA(elms) // process in order
   {
      Elm &elm=elms[i];
      elm.offset=offset;
      elm.arrow =(elm.children.elms() ? elm.opened ? "gui/arrow_down_big.gfx" : "gui/arrow_right_big.gfx" : ""); // set element arrow
      elms_visible.add(visible); // add visibility of this element to the list
      bool children_visible=(visible && elm.opened); // its children will be visible only if the element is visible and it's opened
      SetVisible(elms_visible, elm.children, children_visible, children_offset); // process recursively its children
   }
}
void SetListData()
{
   Memt<bool> elms_visible; // specifies which elements should be visible (array of bool's for all of the elements, including their children as well, recursively)
   SetVisible(elms_visible, elms, true, 0); // set true because root elements are visible by default, and with zero offset
   list.setDataNode(elms, elms_visible.data());
}
/******************************************************************************/
bool Init()
{
   DefaultTextStyle.color =BLACK;
   DefaultTextStyle.shadow=0;

   // setup sample elements
   Elm &a=elms.New().set("Root");
      Elm &b=a.children.New().set("Child" );
      Elm &c=a.children.New().set("Second");
         Elm &d=c.children.New().set("Inside");

   Elm &e=elms.New().set("Other");
      Elm &f=e.children.New().set("xxx");

   // create gui objects
   ListColumn list_column[]= // gui list column (stores information about class format)
   {
      ListColumn(MEMBER(Elm, arrow), 0.05, "Arrow"), // column displaying arrow
      ListColumn(MEMBER(Elm, text ), 0.40, "Text" ), // column displaying text
   };

   Gui   +=region.create(Rect_C(0, 0, 0.5, 0.5));               // create region
   region+=list  .create(list_column, Elms(list_column), true); // create list with 'list_column' columns but hidden
  
   list.setElmOffset(MEMBER(Elm, offset)); // set offset of each element to be taken from 'offset' member
   SetListData();

   return true;
}
/******************************************************************************/
void Shut()
{
}
/******************************************************************************/
bool Update()
{
   if(Kb.bp(KB_ESC))return false;
   Gui.update();

   // toggle list element on click
   if(Ms.bp(0))
      if(Gui.ms()==&list)
         if(Elm *elm=list())
   {
      elm.opened^=1; // toggle if opened
      SetListData(); // after changing data, set the list data again
   }

   return true;
}
/******************************************************************************/
void Draw()
{
   D  .clear(WHITE);
   Gui.draw ();
}
/******************************************************************************/

it will be available in next Esenthel 2.0 release as the "Gui/18 - Tree List" tutorial
05-17-2013 02:06 PM
Find all posts by this user Quote this message in a reply
gwald Offline
Member

Post: #3
RE: Tree view control
That's pretty cool smile
Just wondering how/where you would capture a selected item?

My Blog
http://www.esenthel.com/community/showthread.php?tid=6043

I hang out at Esenthel IRC Channel
http://webchat.freenode.net/?channels=#Esenthel
05-18-2013 12:00 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Harton Offline
Member

Post: #4
RE: Tree view control
Thanks!
05-18-2013 10:11 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply