Forward Slash Fl_Choice::add("DD/MM/YYYY") ?

35 views
Skip to first unread message

Svets

unread,
Sep 23, 2016, 2:56:52 AM9/23/16
to fltk.general
Is there any way to add a forward slash to an Fl_Choice combobox menu?

Fl_Choice::add("DD/MM/YYYY");

results in the combobox only displaying the "DD" with an option to choose the "MM".

Obviously it sees the / slash as being part of a directory path.

Thanks

Svets

unread,
Sep 23, 2016, 3:07:47 AM9/23/16
to fltk.general

Please disregard this question, I found it.
Add a double backslash.

This works
Fl_Choice::add("DD\\/MM\\/YYYY");


Manolo Gouy

unread,
Sep 23, 2016, 4:06:02 AM9/23/16
to fltkg...@googlegroups.com
You can construct the menu item without /
Fl_Choice *myflchoice = ……...;
int index = myflchoice ->add("DD-MM-YYYY");
and then rename it
const Fl_Menu_Item *item = myflchoice->menu() + index;
((Fl_Menu_Item*) item)->label("DD/MM/YYYY");


Svets

unread,
Sep 25, 2016, 11:33:05 AM9/25/16
to fltk.general, manol...@univ-lyon1.fr
Thanks for that.. I'll keep that in mind as well ;)

Greg Ercolano

unread,
Sep 25, 2016, 12:13:30 PM9/25/16
to fltkg...@googlegroups.com
> On Friday, September 23, 2016 at 6:06:02 PM UTC+10, Manolo Gouy wrote:
> > Le 23 sept. 2016 ą 08:56, Svets a écrit :
> > Is there any way to add a forward slash to an Fl_Choice combobox menu?
> > Fl_Choice::add("DD/MM/YYYY");
> > results in the combobox only displaying the "DD" with an option to choose the "MM".
> > Obviously it sees the / slash as being part of a directory path.
>
> You can construct the menu item without /
> Fl_Choice *myflchoice = ...;
> int index = myflchoice ->add("DD-MM-YYYY");
> and then rename it
> const Fl_Menu_Item *item = myflchoice->menu() + index;
> ((Fl_Menu_Item*) item)->label("DD/MM/YYYY");

> On 09/25/16 08:33, Svets wrote:
> Thanks for that.. I'll keep that in mind as well ;)

Yes, that technique can be useful if you're taking human supplied
content, such as from a config file that defines menu items and
their labels.

With Manolo's suggestion, you won't have to first convert the
string by escaping the slashes.. you can just pass the content
straight in.

The other thing to watch out for is "@" in your strings; those
are parsed as "symbols", and have to be escaped with another @ sign,
or you'd have to disable symbols globally in your app:
http://seriss.com/people/erco/fltk/#DisableSymbols

Reply all
Reply to author
Forward
0 new messages