Fl_Tree: How do I get an Fl_Tree with widgets without any left/bottom margins?

10 views
Skip to first unread message

Gonzalo Garramuno

unread,
Jan 21, 2023, 4:50:10 AM1/21/23
to fltkg...@googlegroups.com
I cannot get this to work. I have:

tree = new Fl_Tree( 0, g->y()+20, g->w(), 68 );
tree->showroot(0);
tree->showcollapse(0);
tree->selectmode(FL_TREE_SELECT_SINGLE_DRAGGABLE);
tree->item_draw_mode(FL_TREE_ITEM_HEIGHT_FROM_WIDGET);
tree->item_reselect_mode( FL_TREE_SELECTABLE_ALWAYS );
tree->connectorstyle( FL_TREE_CONNECTOR_NONE );
tree->connectorwidth( 0 );
tree->widgetmarginleft( 0 );
tree->marginleft(0);
tree->margintop(0);
tree->marginbottom(0);
tree->openchild_marginbottom(0);
tree->labelmarginleft(0);
tree->linespacing(0);
tree->usericonmarginleft( 0 );
tree->labelmarginleft( 0 );
tree->linespacing(3);
tree->box( FL_FLAT_BOX );
tree->color( FL_RED );
tree->begin();


ClipButton* b = new ClipButton( 0, g->y()+20+i*68, g->w(), 68 );
char buf[32];
sprintf( buf, "%zu", i );
Fl_Tree_Item* item = tree->add( buf );
item->widget( b );
...

And I still get a left/bottom margin (FL_RED) of the tree box. What’s the secret to get an Fl_Tree of widgets without margins?


Gonzalo Garramuno
ggar...@gmail.com




Greg Ercolano

unread,
Jan 21, 2023, 9:44:52 AM1/21/23
to fltkg...@googlegroups.com
    Can you provide a small standalone, compilable program showing what you're doing?

    I'm not sure what the g->y()+20+i*68 (blue) is about, or why the tree itself
    is only 68 pixels high(green), or if that has anything to do with it.

    A good place to start writing such a standalone would perhaps be the
    examples/tree-as-container.cxx (just set the MAX_ROWS smaller, lol.
    I don't know why that's set so large; it takes over 10 seconds just to
    open the app on my machine)

Gonzalo Garramuno

unread,
Jan 21, 2023, 10:06:16 AM1/21/23
to fltkg...@googlegroups.com

>>
> Can you provide a small standalone, compilable program showing what you're doing?

Here you go:



#include "FL/Fl.H"
#include "FL/Fl_Tree.H"
#include "FL/Fl_Double_Window.H"
#include "FL/Fl_Button.H"

namespace mrv
{
class PlaylistClip : public Fl_Button
{
public:
PlaylistClip( int X, int Y, int W, int H, const char* L = 0 ) :
Fl_Button( X, Y, W, H, L )
{
box( FL_ENGRAVED_BOX );
color( FL_BLUE );
selection_color( FL_YELLOW );
align( FL_ALIGN_LEFT | FL_ALIGN_INSIDE |
FL_ALIGN_IMAGE_NEXT_TO_TEXT );
labelsize( 12 );
}

void draw()
{
if ( value() ) labelcolor( FL_BLACK );
else labelcolor( FL_WHITE );
Fl_Color col = value() ? selection_color() : color();
draw_box(value() ? (down_box()?down_box():fl_down(box())) : box(), col);
draw_backdrop();
draw_label();
}

int handle( int e )
{
Fl_Button::handle( e );
return 0;
}


inline void drawAt( int X, int Y )
{
int xsave = x(), ysave = y();
// Temporarily move widget to mouse position
position(X,Y);
redraw();

// Draw widget at mouse position
draw(); // draw widget's group
// ..now move widget back to where it was
position(xsave,ysave);
redraw();
}
};

}

int main( const int argc, const char** argv )
{
using namespace mrv;
Fl_Double_Window win( 640, 480 );
win.begin();
Fl_Tree* tree = new Fl_Tree( 10, 10, 620, 400 );
tree->showroot(0);
tree->showcollapse(0);
tree->selectmode(FL_TREE_SELECT_SINGLE_DRAGGABLE);
tree->item_draw_mode(FL_TREE_ITEM_HEIGHT_FROM_WIDGET);
tree->item_reselect_mode( FL_TREE_SELECTABLE_ALWAYS );
tree->connectorstyle( FL_TREE_CONNECTOR_NONE );
tree->connectorwidth( 0 );
tree->widgetmarginleft( 0 );
tree->marginleft(0);
tree->margintop(0);
tree->marginbottom(0);
tree->openchild_marginbottom(0);
tree->labelmarginleft(0);
tree->linespacing(0);
tree->usericonmarginleft( 0 );
tree->labelmarginleft( 0 );
tree->linespacing(3);
tree->box( FL_FLAT_BOX );
tree->color( FL_RED );
tree->begin();
PlaylistClip* b = new PlaylistClip( 10, 10, tree->w(), 68 );
char buf[32];
size_t i = 0;
sprintf( buf, "%zu", i );
Fl_Tree_Item* item = tree->add( buf );
item->widget( b );
tree->end();
win.end();
win.show();
return Fl::run();
}

The tree background is red, the button widget is blue.
On my Mac, there’s a 5 pixel or so gap on the left of the button, which belongs to the tree.


Gonzalo Garramuno
ggar...@gmail.com




Greg Ercolano

unread,
Jan 21, 2023, 11:21:30 AM1/21/23
to fltkg...@googlegroups.com

On 1/21/23 07:06, Gonzalo Garramuno wrote:

    Can you provide a small standalone, compilable program showing what you're doing?
Here you go:

    Just so I understand what you're going for, is it something like this..? (from other toolkits):

Quick Qt: 6] How to
        add QPushButton or widgets to a QTreeWidget as QTreeWidgetItem |
        by Manash Kumar Mandal | Manash's blog  qtreewidget python - You.com | The AI Search Engine You
        Control
python - How to make QTreeWIdgetItems editable
        selectively - Stack Overflow

    When I'd designed Fl_Tree I hadn't considered that type of thing really,
    as Fl_Browser seemed to cover it. But I guess in today's world
    that is also a tree.

    To solve, I'll likely have to tweak the Fl_Tree code, as the extra red area
    you're talking about I think has less to do with the widget margins
    and more to do with the tree's branch-drawing code doing a residual offset
    for some reason.

    Should be possible to have the root not be indented at all.

Gonzalo Garramuño

unread,
Jan 21, 2023, 12:01:18 PM1/21/23
to fltkg...@googlegroups.com

El 21/01/2023 a las 01:21 p. m., Greg Ercolano escribió:
>
> On 1/21/23 07:06, Gonzalo Garramuno wrote:
>
>>> Can you provide a small standalone, compilable program showing what you're doing?
>> Here you go:
>
>     Just so I understand what you're going for, is it something like
> this..? (from other toolkits):
>
Yes, I may need that in the future.  For now, I just need a single list
of buttons placed packed tightly to the left, top, right and bottom.  I
am not sure if Fl_Browser can do it.

--
Gonzalo Garramuño
ggar...@gmail.com

Gonzalo Garramuño

unread,
Jan 21, 2023, 12:06:18 PM1/21/23
to fltkg...@googlegroups.com
And I need to be able to Drag and Drop the buttons (as they contain
images of video clips for a playlist).  That's why I went with Fl_Tree.

--
Gonzalo Garramuño
ggar...@gmail.com

Reply all
Reply to author
Forward
0 new messages