Right clicking on a check button label

40 views
Skip to first unread message

supsm17

unread,
May 2, 2022, 5:11:50 PM5/2/22
to fltk.general
I have a Fl_Check_Button which has a label, I want some menu to pop up when I right click the label. I'm not sure if this could be accomplished with Fl_Menu, but for the right click I think I can use a boxless Fl_Button. Will I have to have a hidden Fl_Box?

Ian MacArthur

unread,
May 2, 2022, 5:34:18 PM5/2/22
to Fltk General
On 2 May 2022, at 19:17, supsm17 wrote:
>
> I have a Fl_Check_Button which has a label, I want some menu to pop up when I right click the label. I'm not sure if this could be accomplished with Fl_Menu, but for the right click I think I can use a boxless Fl_Button. Will I have to have a hidden Fl_Box?


Would you not just use an Fl_Menu_Button, with the box type and text set appropriately, as the label?

Just set the type to POPUP3 (well, I think it is POPUP3 for the right click... might be POPUP2...) and that’s basically the job done.

https://www.fltk.org/doc-1.4/classFl__Menu__Button.html#a2c0d1cab5522c531309169acf0e1517e


supsm17

unread,
May 3, 2022, 3:48:58 PM5/3/22
to fltk.general
That should probably work, but for some reason the label (or box) doesn't show up when the type is changed. It still appears, but is just invisible. Am I missing something?

Ian MacArthur

unread,
May 3, 2022, 5:53:07 PM5/3/22
to Fltk General
On 3 May 2022, at 20:16, supsm17 wrote:
>
> That should probably work, but for some reason the label (or box) doesn't show up when the type is changed. It still appears, but is just invisible. Am I missing something?


It certainly should work.
I have no idea why it would not - you will have to show us an example of what you are doing.
Can you post a minimal, compileable, example that shows the effect, so we can see what has gone awry, please?

supsm17

unread,
May 4, 2022, 2:47:44 AM5/4/22
to fltk.general
this should work as an example

// generated by Fast Light User Interface Designer (fluid) version 1.0306

#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Menu_Button.H>

Fl_Menu_Item menu_menu[] = {
 {"item", 0,  0, 0, 0, (uchar)FL_NORMAL_LABEL, 0, 14, 0},
 {0,0,0,0,0,0,0,0,0}
};

int main(int argc, char **argv) {
  Fl_Double_Window* w;
  { Fl_Double_Window* o = new Fl_Double_Window(120, 100);
    w = o; if (w) {/* empty */}
    { Fl_Menu_Button* o = new Fl_Menu_Button(25, 25, 69, 20, "menu");
      o->type(2);
      o->menu(menu_menu);
    } // Fl_Menu_Button* o
    o->end();
  } // Fl_Double_Window* o
  w->show(argc, argv);
  return Fl::run();
}

Ian MacArthur

unread,
May 4, 2022, 4:54:28 AM5/4/22
to fltk.general
On Tuesday, 3 May 2022 at 20:48:58 UTC+1 sups... wrote:
That should probably work, but for some reason the label (or box) doesn't show up when the type is changed. It still appears, but is just invisible. Am I missing something?

Ah, yes: Right, so the bit of missing knowledge is that if you set the button to a "popup" type, the button becomes an invisible overlay so that you can position it over some other artefact.

So the idea there is that you set up whatever widgets, boxes, etc., that you need, then you can overlay an invisible "popup" over some of them to trigger additional behaviours.

Which... is what I thought you wanted?

lifeatt...@gmail.com

unread,
May 4, 2022, 11:02:50 AM5/4/22
to fltk.general
Right-click is POPUP3 or 3.

> I have a Fl_Check_Button which has a label, I want some menu to pop up when I right click the label

But I see the problem. Your sample works fine if you create a Fl_Box with a label to be right-clicked over. A Fl_Check_Button, on the other hand,
is grabbing all mouse events, and the Fl_Menu_Button is never activated.

The modified version below works by making the check button really narrow and faking up a label via Fl_Box. The Fl_Menu_Button works
now because Fl_Box isn't grabbing mouse events.

#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Menu_Button.H>
#include <FL/Fl_Check_Button.H>
#include <FL/Fl_Box.H>


Fl_Menu_Item menu_menu[] = {
 {"item", 0,  0, 0, 0, (uchar)FL_NORMAL_LABEL, 0, 14, 0},
 {0,0,0,0,0,0,0,0,0}
};

int main(int argc, char **argv) {
  Fl_Double_Window* w;
  { Fl_Double_Window* o = new Fl_Double_Window(120, 100);
    w = o; if (w) {/* empty */}
    { Fl_Menu_Button* o = new Fl_Menu_Button(25, 25, 69, 20, "menu");
      o->type(Fl_Menu_Button::POPUP3);

      o->menu(menu_menu);
    } // Fl_Menu_Button* o
    auto cb = new Fl_Check_Button(20,25,20,20);
    auto bx = new Fl_Box(25,25,100,20,"CB Label");

    o->end();
  } // Fl_Double_Window* o
  w->show(argc, argv);
  return Fl::run();
}

Someone smarter than me might know how to create a Fl_Check_Button which doesn't grab the right mouse button.

supsm17

unread,
May 7, 2022, 12:55:07 AM5/7/22
to fltk.general
Thanks a lot, I have a bit of an issue though...
Here is my code (roughly, my memory isn't perfect):

Fl_Menu_Item menu_item[] = { {"name", 0, nullptr, int_ptr } }; // here int_ptr is a int* which exists for the entire duration of the program
Fl_Menu_Button* o = new Fl_Menu_Button(400, 30, 40, 15);
o->copy(menu_item); // < here, it crashes and complains about menu_item.size()

Do you know what this might be caused by, and how it could be fixed?

imm

unread,
May 7, 2022, 3:54:45 AM5/7/22
to General FLTK
On Sat, 7 May 2022, 05:55 supsm17 wrote:
Thanks a lot, I have a bit of an issue though...
Here is my code (roughly, my memory isn't perfect):

Fl_Menu_Item menu_item[] = { {"name", 0, nullptr, int_ptr } }; // here int_ptr is a int* which exists for the entire duration of the program
Fl_Menu_Button* o = new Fl_Menu_Button(400, 30, 40, 15);
o->copy(menu_item); // < here, it crashes and complains about menu_item.size()

Do you know what this might be caused by, and how it could be fixed?


It doesn't look like you have terminated the menu item array properly, nor even populated it correctly.

Check the docs, and the menubar test example.
--
Ian
From my Fairphone FP3
   

lifeatt...@gmail.com

unread,
May 7, 2022, 11:21:32 AM5/7/22
to fltk.general
This is the simpliest menu declaration I would use:

Fl_Menu_Item menu_item[] = {
 {"name", 0, nullptr, (void*)(int_ptr)},
 {0}
};

The o->copy code is looking for the zero-filled item as a terminator.

supsm17

unread,
May 7, 2022, 1:20:04 PM5/7/22
to fltk.general
Ah, sorry about that. As for populating the array, I sort of copied an example from the docs:

{"&alpha", FL_ALT+'a', the_cb, (void*)1},
{"&beta", FL_ALT+'b', the_cb, (void*)2},
{"gamma", FL_ALT+'c', the_cb, (void*)3, FL_MENU_DIVIDER},
{"&strange", 0, strange_cb},
{"&charm", 0, charm_cb},
{"&truth", 0, truth_cb},
{"b&eauty", 0, beauty_cb},
{"sub&menu", 0, 0, 0, FL_SUBMENU},
{"one"},
{"two"},
{"three"},
{0},
{"inactive", FL_ALT+'i', 0, 0, FL_MENU_INACTIVE|FL_MENU_DIVIDER},
{"invisible",FL_ALT+'i', 0, 0, FL_MENU_INVISIBLE},
{"check", FL_ALT+'i', 0, 0, FL_MENU_TOGGLE|FL_MENU_VALUE},
{"box", FL_ALT+'i', 0, 0, FL_MENU_TOGGLE},
{0}};

it's essentially a combination of the 1st (&alpha) and 8th (sub&menu) one. It seems to be working after adding the last blank item
Reply all
Reply to author
Forward
0 new messages