Discussion:
[fltk.general] How to change menu's label at runtime?
(too old to reply)
Suja
2007-07-09 21:05:18 UTC
Permalink
Could someone direct me how to change the menu label at runtime?
I want to display the menu label as one of the submenu labels,
which is selected at that time.
Thanks.
Suja
2007-07-09 22:16:17 UTC
Permalink
I need to set the label in the submenu callbacks.
Post by Suja
Could someone direct me how to change the menu label at runtime?
I want to display the menu label as one of the submenu labels,
which is selected at that time.
Thanks.
Greg Ercolano
2007-07-09 23:52:37 UTC
Permalink
Post by Suja
Could someone direct me how to change the menu label at runtime?
I want to display the menu label as one of the submenu labels,
which is selected at that time.
A simple example here:
http://seriss.com/people/erco/fltk/#Menu_ChangeLabel
Suja
2007-07-10 22:34:19 UTC
Permalink
Thanks...But this example shows how to change submenu labels.
I need to change the menubar label itself...am not able to make it work
the same way described as submenu's...
please help.
Post by Greg Ercolano
Post by Suja
Could someone direct me how to change the menu label at runtime?
I want to display the menu label as one of the submenu labels,
which is selected at that time.
http://seriss.com/people/erco/fltk/#Menu_ChangeLabel
Greg Ercolano
2007-07-10 23:59:24 UTC
Permalink
Post by Suja
Thanks...But this example shows how to change submenu labels.
I need to change the menubar label itself...am not able to make it work
the same way described as submenu's...
please help.
Although menubars can have labels, I've never personally even
seen or needed a menubar with a label.. normally the menubar
has no label at all, just a bar with submenus in it.

That said, you should be able to change the menubar's label
by just calling menu->label("some new label");, and telling the
parent window to redraw, e.g. from the example:

void Change_CB(Fl_Widget *w, void *) {
Fl_Menu_Bar *menu = (Fl_Menu_Bar*)w;
menu->label("Some text"); // ***
menu->window()->redraw(); // ***
..
Greg Ercolano
2007-07-11 00:03:19 UTC
Permalink
Post by Suja
Thanks...But this example shows how to change submenu labels.
I need to change the menubar label itself...am not able to make it work
the same way described as submenu's...
Specifically:

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Menu_Bar.H>
#include <stdlib.h>
void Change_CB(Fl_Widget *w, void *) {
Fl_Menu_Bar *menu = (Fl_Menu_Bar*)w;
menu->label("Some New Label");
}
void Quit_CB(Fl_Widget *, void *) {
exit(0);
}
int main() {
Fl_Window *win = new Fl_Window(400,400);
Fl_Menu_Bar *menu = new Fl_Menu_Bar(0,0,400,25,"Menu Label");
menu->align(FL_ALIGN_BOTTOM|FL_ALIGN_CENTER);
menu->add("File/Quit", FL_CTRL+'q', Quit_CB);
menu->add("Edit/Change", FL_CTRL+'c', Change_CB);
win->end();
win->show();
return(Fl::run());
}
Suja
2007-07-11 00:25:50 UTC
Permalink
Hi,
Thanks so much...I think I wasn't clear when I said manubar label.
I meant the "Edit" in "Edit/Change".
I can change "Change" to "new change", but can't change "Edit" to "File"!


My application is where user selects different interpolation methods
like cubic, linear etc from the menu. And I would like the menu
to show which method was chosen by the user.

Thanks.
Suja.
Post by Greg Ercolano
Post by Suja
Thanks...But this example shows how to change submenu labels.
I need to change the menubar label itself...am not able to make it work
the same way described as submenu's...
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Menu_Bar.H>
#include <stdlib.h>
void Change_CB(Fl_Widget *w, void *) {
Fl_Menu_Bar *menu = (Fl_Menu_Bar*)w;
menu->label("Some New Label");
}
void Quit_CB(Fl_Widget *, void *) {
exit(0);
}
int main() {
Fl_Window *win = new Fl_Window(400,400);
Fl_Menu_Bar *menu = new Fl_Menu_Bar(0,0,400,25,"Menu Label");
menu->align(FL_ALIGN_BOTTOM|FL_ALIGN_CENTER);
menu->add("File/Quit", FL_CTRL+'q', Quit_CB);
menu->add("Edit/Change", FL_CTRL+'c', Change_CB);
win->end();
win->show();
return(Fl::run());
}
matthiasm
2007-07-11 00:45:20 UTC
Permalink
Post by Suja
Thanks...But this example shows how to change submenu labels.
I need to change the menubar label itself...am not able to make it work
the same way described as submenu's...
Top-level menue labels are basically the same at submenu labels. The
exception is, that you should call "redraw()" on the menu widget
after you changed one of the titles of the menu bar.

----
http://robowerk.com/
Greg Ercolano
2007-07-11 01:29:42 UTC
Permalink
Post by Suja
Thanks so much...I think I wasn't clear when I said manubar label.
I meant the "Edit" in "Edit/Change".
I can change "Change" to "new change", but can't change "Edit" to "File"!
Works for me.. same technique as the first example I included:

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Menu_Bar.H>
#include <stdlib.h>
void Change_CB(Fl_Widget *w, void *) {
Fl_Menu_Bar *menu = (Fl_Menu_Bar*)w;
Fl_Menu_Item *p;
// Change submenu name
p = (Fl_Menu_Item*)menu->find_item("Edit");
if ( p ) { p->label("File"); menu->redraw(); }
}
void Quit_CB(Fl_Widget *, void *) {
exit(0);
}
int main() {
Fl_Window *win = new Fl_Window(400,400);
Fl_Menu_Bar *menu = new Fl_Menu_Bar(0,0,400,25);
menu->add("File/Quit", FL_CTRL+'q', Quit_CB);
menu->add("Edit/Change", FL_CTRL+'c', Change_CB);
win->end();
win->show();
return(Fl::run());
}

Loading...