How to set image as background of TreeView widget item

  • Hi,
    I create an TreeView widget with nodes. I want to change TreeView Item images and set Text indent zero.
    When I use following code,

    Code
    TREEVIEW_SetImage(hItem,TREEVIEW_BI_OPEN,&bitmap200x20);
    
    
    TREEVIEW_SetTextIndent(hItem,0);

    TreeView item text disappears. So How can I bring TreeView item's text front of the TreeView item's bitmap ?

    P.S: I have reviewed all emWin User&Reference Guide. Document: UM03001. If I have miss related part of document. You can point document.

    Thanks in advance...

    Best Regards
    Emin ATEŞ

  • Hello,

    in case you set indentation of item text to 0 then text is covered by item images. I think it is because default drawing function first draws item text and after that it draws images.

    To change the order I think custom drawing function can be set where you should "do nothing" when handling text drawing command (WIDGET_ITEM_DRAW_TEXT) and sort of "repeat" text drawing after drawing item image when handling image drawing command (WIDGET_ITEM_DRAW_BITMAP). I think treeview items can be distinguished, say, by the y0 parameter of WIDGET_ITEM_DRAW_INFO structure passed to the custom drawing function.

    I'd do something like this:


    Works in my simulation (STemWin v5.32). Some parameters (item height, font, selection colors...) may vary depending on your code.

    Alex.

    Edited once, last by LexaGB (February 4, 2019 at 11:50 PM).

  • Hi Alex,
    I had tried to implement your code to my treeview but i could not succeed. I have a few questions. I will be appreciate if you answer me kindly. Before the questions i will inform you about my application;
    I use key reaction to control widget behavior.
    Treeview widget created in a dialogbox with a window by GuiBuilder.exe
    The treeview nodes and leafs create by file which located in sd card.
    Example file format in sd card is below;

    So According to the file item count ends with "#end" command. When I call create dialog function the treeview items created according to the file. After Treeview widged created, I want to add new leaf below selected leaf. It is easy to add sibling leaf. The new leaf must give some information about prev leaf(selected). But selected leaf and new leaf looks separate from each other. So I want to add frame images to them which looks like upper(selected item's background) part of frame and lower(new created item's background) part of frame. It will be more clear if you review "customTreeview.png" from attachments. So if user change selection, old selected item should seems normal and created item should deleted before creating new item and changing frame. It can be a bit confusing up here because my English is may not clear.


    It is possible to create treeview like attachments?
    if it is possible, how do I add a custom draw to the treeview created under dialog?
    Can you suggest more effective way to do this?

    If you want additional info please submit.

    Thanks in advance...

    Best Regards
    Emin ATEŞ

  • Hello,

    you can add new leaf below selected but its going to be a big difficult code to handle "main" leaf and its "info" leaf in conjunction.

    Instead of this I'd change the size of selected leaf then draw upper (for item) and lower (for info) rects and then add the info text in the lower rect. I attached the code and this code is also not to say simple. It works around with item coordinates, item hadlers array and makes up user data to pass when handling commands. Initial code created in GUIBulder and only for one node. If you add another nodes in GUIBuilder then you have to watch for item handlers to copy it to the list correctly.

    Alex.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!