Example #1
0
void Fl_Tool_Bar::layout()
{
    if(!opened()) {
        Fl_Widget::layout();
        return;
    }

    int X=0,Y=0,W=w(),H=h();
    box()->inset(X,Y,W,H);
    X+=glyph_size()+layout_spacing();

    H=0;
    int hoff = layout_spacing()*2 + box()->dh();

    int out=-1;

    for(int n=0; n<children(); n++)
    {
        Fl_Widget *w = child(n);
        if(w==m_menu || w==m_menubut || w==m_right) continue;

        w->show();

        int ww = w->w();
        int wh = h()-hoff;

        w->preferred_size(ww, wh);

        w->resize(X, box()->dy()+layout_spacing(), ww, wh);
        w->layout();

        if(H < w->h()+hoff)
            H = w->h()+hoff;

        X += w->w()+layout_spacing();

        if(X>W - (m_menubut->visible()?15:0) ) {
            out=n;
            //w->hide();
            break;
        }

    }

    if(m_menu->children())
        m_menu->clear();

    if(out>=0)
    {
        m_menubut->resize(W-15, Y+2, 14, H-box()->dh()-4);
        m_menu->resize(W-15, Y, 15, H-box()->dh());
        m_menubut->show();

        m_menu->begin();
        for(int n=out; n<children(); n++) {
            Fl_Widget *w = child(n);
            if(w==m_menu || w==m_menubut || w==m_right) continue;

            if(n>out) w->hide();
            if(w->is_group()) continue;

            if(w->type()==Fl_Divider::VERTICAL) {
                // Create divider, only if not first in menu
                if(n>out)
                    new Fl_Divider(1, 5);

            } else {

                Fl_Item *i = new Fl_Item();
                // Tooltip as a label, if theres one
                i->label(w->tooltip().empty() ? w->label() : w->tooltip());
                i->image(w->image());
                i->user_data(w);
                i->activate(w->active());
                i->type(w->type());
                if(w->value()) i->set_value();
                else i->clear_value();
            }
        }
        m_menu->end();

    } else {
        m_menubut->hide();
    }

    if(h() != H) {
        h(H);
    }
    Fl_Widget::layout();
}