I'm adding a symbol to an Fl_Menu_Item on an Fl_Menu_Bar using 
set_labeltype(). It's mostly working but when the menu is dropped down, 
the symbol moves to the left by about 12 units. (BTW, this approach 
solves the "Changing an Fl_Menu_Bar item colors" question)

Why does the symbol move and how can I keep it from moving?

#include <FL/Fl.H>
#include <FL/fl_draw.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Menu_Bar.H>
// In fl_labeltype.cxx
extern void fl_normal_label(const Fl_Label* o, int X, int Y, int W, int 
H, Fl_Align align);
extern void fl_normal_measure(const Fl_Label* o, int& W, int& H);

enum { EXTRA_MENU_WIDTH = 10, };

void menu_label(const Fl_Label* o, int X, int Y, int W, int H, Fl_Align a) {
     fl_normal_label(o, X, Y, W, H, a);
     // ***** Why does this move when the menu item is selected? *****
     fl_circle(X+W-12, Y+H/2, 5);
}
void menu_measure(const Fl_Label* o, int& W, int& H) {
     fl_normal_measure(o, W, H);
     W += EXTRA_MENU_WIDTH;
}

int main(int argc, char **argv) {
     Fl_Double_Window *win = new Fl_Double_Window(300,25);
     Fl_Menu_Bar* menubar  = new Fl_Menu_Bar(0,0,300,25);

     menubar->add("Menu1/one", 0, 0, 0, 0);
     menubar->add("Menu1/two", 0, 0, 0, 0);

Fl::set_labeltype(static_cast<Fl_Labeltype>(FL_FREE_LABELTYPE),
                       menu_label, menu_measure);

     const Fl_Menu_Item* m ;
     if ((m = menubar->find_item("Menu1")) != NULL) {
         const_cast<Fl_Menu_Item*>(m)->labeltype_ = FL_FREE_LABELTYPE;
     }

     win->end();
     win->show();

     return Fl::run();
}

_______________________________________________
fltk mailing list
fltk@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to