Is there any way to hide and show any widget like Fl_Menu_Bar and Fl_Check_Button?

349 views
Skip to first unread message

Furqan Ullah

unread,
Jul 15, 2013, 9:25:13 PM7/15/13
to fltkg...@googlegroups.com
Is there anyway to hide any widget in FLTK 1.3.2?
For example i was to hide Fl_Menu_Bar in run time and also Fl_Check_Button.
By pressing button, main menu and some buttons should hide and then again by pressing button all show up?
Can I do that? Thanks.

Greg Ercolano

unread,
Jul 16, 2013, 1:05:13 AM7/16/13
to fltkg...@googlegroups.com
On 07/15/13 18:25, Furqan Ullah wrote:
> Is there anyway to hide any widget in FLTK 1.3.2?
> For example i was to hide Fl_Menu_Bar in run time and also Fl_Check_Button.

w->hide(); should work for widgets like the menubar itself,
and widgets like check buttons.

> By pressing button, main menu and some buttons should hide and then [again
> by pressing button all show up?

Yes, toggling hide() and show() for widgets should make them appear/disappear.
I'd tell the whole window to redraw() though after making such a change, ie.

your_app_win->redraw();

Similarly you can deactivate ('grey out') widgets using
w->deactivate(), and return them to normal with w->activate()

For menu items (such as in a main menu), those items are not really widgets,
so they are manipulated a bit differently.. they have a 'flags' value that
is a collection of bit flags. From Fl_Menu_Item.H:

enum { // values for flags:
FL_MENU_INACTIVE = 1, ///< Deactivate menu item (gray out)
FL_MENU_TOGGLE= 2, ///< Item is a checkbox toggle (shows checkbox for on/off state)
FL_MENU_VALUE = 4, ///< The on/off state for checkbox/radio buttons (if set, state is 'on')
FL_MENU_RADIO = 8, ///< Item is a radio button (one checkbox of many can be on)
FL_MENU_INVISIBLE = 0x10, ///< Item will not show up (shortcut will work)
FL_SUBMENU_POINTER = 0x20, ///< Indicates user_data() is a pointer to another menu array
FL_SUBMENU = 0x40, ///< This item is a submenu to other items
FL_MENU_DIVIDER = 0x80, ///< Creates divider line below this item. Also ends a group of radio buttons.
FL_MENU_HORIZONTAL = 0x100 ///< ??? -- reserved
};

So to toggle invisibility, you'd want to toggle the FL_MENU_INVISIBLE flag,
and to toggle activation (grey out), toggle the FL_MENU_INACTIVE flag.

So if you want to selectively make the File/Quit menu item inactive
from a button's callback, in your callback's code you'd do something like:

Fl_Menu_Item *item = menubar->find_item("File/Quit");
item->flags |= FL_MENU_INACTIVE;

Here's a complete program that shows that:

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Menu_Bar.H>
#include <FL/Fl_Button.H>
//
// Demonstrate toggling the File -> Quit menu item (toggle 'graying it out')
//
void Button_CB(Fl_Widget *w, void *data) {
Fl_Menu_Bar *menubar = (Fl_Menu_Bar*)data;
Fl_Menu_Item *item = (Fl_Menu_Item*)menubar->find_item("File/Quit");
if ( !item ) { fprintf(stderr, "ITEM NOT FOUND!\n"); return; }
item->flags ^= FL_MENU_INACTIVE;
}
int main() {
// Make the window
Fl_Window *win = new Fl_Window(400,200);
// Make the menubar with a few menu items
Fl_Menu_Bar *menubar = new Fl_Menu_Bar(0,0,400,25);
menubar->add("File/Open", 0,0,0);
menubar->add("File/Preferences", 0,0,0);
menubar->add("File/Quit", 0,0,0);
// Make a button to toggle the File/Quit menu item's activation state
Fl_Button *butt = new Fl_Button(30,50,100,25,"Toggle");
butt->callback(Button_CB, (void*)menubar);
win->end();
win->show();
return(Fl::run());
}

When you push the 'Toggle' button, the File -> Quit menu should gray out,
or return to normal each time you push it.

MacArthur, Ian (Selex ES, UK)

unread,
Jul 16, 2013, 8:37:38 AM7/16/13
to fltkg...@googlegroups.com

> Is there anyway to hide any widget in FLTK 1.3.2?

Just calling widget->hide(); and then redrawing the parent window ought to work.

Does it not work for you?




Selex ES Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 3EL
A company registered in England & Wales. Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************

Furqan Ullah

unread,
Jul 18, 2013, 9:02:10 AM7/18/13
to fltkg...@googlegroups.com, ian.ma...@selex-es.com
apologies..

its funny.. :)
I did it with hide(), it gave me error, i do not remind the error now. So i posted this question. My mistake, I should have tested it before posting.
But now its working fine.
Thanks.

Reply all
Reply to author
Forward
0 new messages