Re: [fltk.general] How do you disable a button?

22 views
Skip to first unread message

Phil

unread,
Jan 13, 2022, 7:27:39 AM1/13/22
to fltkg...@googlegroups.com


On 13 Jan 2022 12:25, Phil <pvr...@btinternet.com> wrote:
Hi mark,

I don't have access to my code, but IIRC in the callback for each subitem, I keep track of the status of each subitem, and if there are none or no active ones, I mark the higher one inactive.




On 13 Jan 2022 11:38, "'Mark' via fltk.general" <fltkg...@googlegroups.com> wrote:
I have a "history" menubutton that I want to enable when the menu has items and disable when it doesn't. It will start out with no entries and gradually they'll be added depending on what the user does. Similarly, I have other buttons which should be enabled/disabled depending on context.

I've tried setting the trigger to none but that didn't do it. I also tried calling deactivate but that didn't stop clicking it from working.

Searching for 'enable' and 'disable' in the docs didn't help.

So maybe fltk has a way of doing this using terminology/functions I'm unfamiliar with? (I'm pretty new to fltk; I'm much more familiar with Tk, Qt, and wxWidgets.)

--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/7b3d977e-598e-4f74-a138-528cf4337fffn%40googlegroups.com.


Albrecht Schlosser

unread,
Jan 13, 2022, 8:14:08 AM1/13/22
to fltkg...@googlegroups.com
On 1/13/22 12:38 PM 'Mark' via fltk.general wrote:
> I have a "history" menubutton that I want to enable when the menu has
> items and disable when it doesn't.

Just to make sure we agree in what we're saying: In FLTK terminology
this would be a menu item (Fl_Menu_Item) and the "items" you're talking
about (the list of recent files, below) would be submenu items. There's
also a widget called Fl_Menu_Button but that's a button that can pop up
a menu when clicked.

I assume you're implementing a normal menu (Fl_Menu or Fl_Menu_Bar) with
a submenu of recent files.

> It will start out with no entries and gradually they'll be added
> depending on what the user does. Similarly, I have other buttons which
> should be enabled/disabled depending on context.

Again, "buttons" = Fl_Menu_Items?

> I've tried setting the trigger to none but that didn't do it. I also
> tried calling deactivate but that didn't stop clicking it from working.

"Setting the trigger" is not a FLTK term. What exactly did you try?
Exact code (statements, not full program) would be much more helpful so
we can better help you.

That said, you must disable the particular Fl_Menu_Item which is
described here:
https://fltk.gitlab.io/fltk/structFl__Menu__Item.html#a3d531242e84a7bf8ee27482052f673a5

> So maybe fltk has a way of doing this using terminology/functions I'm
> unfamiliar with? (I'm pretty new to fltk; I'm much more familiar with
> Tk, Qt, and wxWidgets.)

The terminology used in such cases is usually "activate" and
"deactivate" (widgets/buttons, menu items, whatever). Sometimes enable
and disable is used as well.

Greg Ercolano

unread,
Jan 13, 2022, 10:06:58 AM1/13/22
to fltkg...@googlegroups.com


On 1/13/22 3:38 AM, 'Mark' via fltk.general wrote:
I have a "history" menubutton that I want to enable when the menu has items and disable when it doesn't. It will start out with no entries and gradually they'll be added depending on what the user does. Similarly, I have other buttons which should be enabled/disabled depending on context.

    If it's a widget, e.g. Fl_Menu_Button, all widgets derive from Fl_Widget where you'll find
    methods like deactivate() (which disables and grays-out the widget), and activate().
    Also show() and hide() which can make a widget appear/disappear.
    That should affect the entire menu button, deactivating it from being pressed.

    If however you're trying to deactivate individual menu items or submenus,
    that's different; you might use e.g. menubutton->find_item("item name here")
    to find the Fl_Menu_Item, and then call item->deactivate() to deactivate it. e.g.

        Fl_Menu_Item *item = (Fl_Menu_Item*)menubutton->find_item("History..");
        item->deactivate();


I've tried setting the trigger to none but that didn't do it.

    Whether or not a widget (or menu item) has a callback() doesn't affect its visible attributes.
    At least not in FLTK, as some buttons/menu items have state that can be polled and not need
    a callback. Also with menus, individual items can leave their callbacks unset, and just set a
    callback for the whole menu, which can be used to determine which item was clicked.

   

I also tried calling deactivate but that didn't stop clicking it from working.

    Hmm, that should have worked. But see above.

    If that advice doesn't work, we might have to see your code to determine what's wrong.

    Try making a small simple compilable program that creates a window + menubutton
    and then call deactivate() the way you are doing it now, and if it doesn't work, show us the code.

   

Reply all
Reply to author
Forward
0 new messages