FLTK logo

Re: [fltk.general] Memory leakage after creating a new Fl_Tree

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: Memory leakage after creating a new Fl_Tree Greg Ercolano Jun 11, 2021  
 

On 6/11/21 8:03 AM, Greg Ercolano wrote:

    If you parented FLTK widgets to items using Fl_Tree_Item::widget(),
    to clear /those/, you can call: Fl_Tree::Fl_Group::clear(). So to clear the tree
    and all child FLTK widgets I think you'd need to use:

            tree->clear();
            tree->Fl_Group::clear();


    Actually, I take that back, that advice is bad as that clears Fl_Tree's
    child scrollbar widgets too, which Fl_Tree will not expect.

    To clear all the FLTK child widgets (without clearing the scrollbars),
    Fl_Tree should really provide a method to clear the FLTK child widgets
    along the lines of:

  // Clear all items and FLTK child widgets parented to the tree
  void Fl_Tree::clear_all() {
    clear(); // clears the items

    Fl_Group::remove(_vscroll);
    Fl_Group::remove(_hscroll);

    Fl_Group::clear(); // clears all child fltk widgets except scrollbars
    Fl_Group::add(_vscroll);
    Fl_Group::add(_hscroll);

  }

    You can derive your own class from Fl_Tree and implement that method.
    That's the only way you can access the protected scrollbar members.

    Arguably Fl_Tree::clear() should clear the FLTK child widgets too,
    though there was a desire to allow the items to be cleared separately
    from FLTK widgets, and I don't think that was ever rectified in the API.

    Perhaps it's easier is to simply delete and recreate the Fl_Tree widget,
    as the Fl_Group base class will handle clearing the FLTK children.

    Anyway, all this is /only/ an issue if your app creates FLTK widgets
    and attaches them to the tree with Fl_Tree_Item::widget(w).

--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/8af80549-8db0-76ab-0606-b02064619d47%40seriss.com.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.