summaryrefslogtreecommitdiff
path: root/FL/Fl_Menu_Item.H
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2023-12-23 18:51:43 +0100
committerAlbrecht Schlosser <albrechts.fltk@online.de>2023-12-23 20:08:18 +0100
commit1d73c0195c8bf256f23b58d0288d1bb9eb87448d (patch)
treeb0d9179cb990fb1cf6d9e325dab65d3a17f5db6a /FL/Fl_Menu_Item.H
parent016c36c917de79383fb2d81c267faa0829147bdf (diff)
Improve docs and add two new Fl_Menu_Item methods (#875)
This addresses some issues pointed out by GitHub Issue #875. Documentation lacked details about Fl_Multi_Label assignment and correct memory handling. The new methods - Fl_Menu_Item::image_label(const Fl_Image *) and - Fl_Menu_Item::multi_label(const Fl_Multi_Label *) provide a cleaner interface to assign images and Fl_Multi_Label's to menu items. examples/howto-menu-with-images.cxx: carify some issues, fix leak, and use new Fl_Menu_Item::multi_label(const Fl_Multi_Label *).
Diffstat (limited to 'FL/Fl_Menu_Item.H')
-rw-r--r--FL/Fl_Menu_Item.H104
1 files changed, 93 insertions, 11 deletions
diff --git a/FL/Fl_Menu_Item.H b/FL/Fl_Menu_Item.H
index 4bca0e1ce..94035d097 100644
--- a/FL/Fl_Menu_Item.H
+++ b/FL/Fl_Menu_Item.H
@@ -17,9 +17,10 @@
#ifndef Fl_Menu_Item_H
#define Fl_Menu_Item_H
-# include "Fl_Widget.H"
-# include "Fl_Image.H"
-# include <FL/platform_types.h> // for FL_COMMAND and FL_CONTROL
+#include <FL/Fl_Widget.H>
+#include <FL/Fl_Image.H>
+#include <FL/Fl_Multi_Label.H>
+#include <FL/platform_types.h> // for FL_COMMAND and FL_CONTROL
// doxygen needs the following line to enable e.g. ::FL_MENU_TOGGLE to link to the enums
/// @file
@@ -141,19 +142,100 @@ struct FL_EXPORT Fl_Menu_Item {
// methods on menu items:
/**
- Returns the title of the item.
+ Returns the title (label) of the menu item.
+
A NULL here indicates the end of the menu (or of a submenu).
A '&' in the item will print an underscore under the next letter,
- and if the menu is popped up that letter will be a "shortcut" to pick
- that item. To get a real '&' put two in a row.
+ and if the menu is popped up that letter will be a "shortcut" to
+ pick that item. To get a real '&' put two in a row.
+
+ The returned value depends on the labeltype() that has been used
+ to store the label.
+
+ \returns A pointer to the label cast to (const char *)
+
+ \retval (a) A pointer to text (const char *)
+ \retval (b) A pointer to an image (Fl_Image *)
+ \retval (c) A pointer to a "multi label" (Fl_Multi_Label *)
+ \retval NULL End of menu or submenu
+
+ \see Fl_Menu_Item::label(const char *)
+ \see Fl_Menu_Item::label(Fl_Labeltype, const char *)
+ \see Fl_Menu_Item::image_label(const Fl_Image *)
+ \see Fl_Menu_Item::multi_label(const Fl_Multi_Label *)
+ \see Fl_Multi_Label::label(Fl_Menu_Item *)
+ */
+ const char* label() const { return text; }
+
+ /**
+ Sets the title (label) of the menu item.
+
+ \note This does \b not change the labeltype() for backwards compatibility.
+ Take care to assign the correct labeltype() if you assign different
+ label types to the same menu item sequentially.
+
+ The default labeltype() is FL_NORMAL_LABEL.
+
+ \see label(Fl_Labeltype, const char*)
+ \see const char* Fl_Menu_Item::label() const
+ */
+ void label(const char* a) { text = a; }
+
+ /**
+ Sets the title (label) and the label type of the menu item.
+
+ The default Fl_Labeltype when using Fl_Menu_Item::label(const char* a)
+ is FL_NORMAL_LABEL but you can set any other label type, for instance
+ FL_EMBOSSED_LABEL.
+
+ Special labeltypes are:
+
+ - FL_ICON_LABEL: draws the icon (Fl_Image) associated with the text
+ - FL_IMAGE_LABEL: draws the image (Fl_Image) associated with the text
+ - FL_MULTI_LABEL: draws multiple parts side by side, see Fl_Multi_Label
+
+ \see const char* Fl_Menu_Item::label() const
*/
- const char* label() const {return text;}
+ void label(Fl_Labeltype a, const char* b) {
+ labeltype_ = a;
+ text = b;
+ }
+
+ /**
+ Sets the title (label()) and labeltype() to an Fl_Multi_Label.
+
+ This sets the labeltype() to \_FL_MULTI_LABEL (note the leading
+ underscore).
- /** See const char* Fl_Menu_Item::label() const */
- void label(const char* a) {text=a;}
+ \see const char* Fl_Menu_Item::label() const
- /** See const char* Fl_Menu_Item::label() const */
- void label(Fl_Labeltype a,const char* b) {labeltype_ = a; text = b;}
+ \since 1.4.0
+
+ \internal Overloading Fl_Menu_Item::image() would lead to ambiguities
+ when used like `item->label(0)`, hence we need our own method name.
+ Otherwise existing programs might not compile w/o error (e.g. fluid).
+ */
+ void multi_label(const Fl_Multi_Label *ml) {
+ label(FL_MULTI_LABEL, (const char *)ml);
+ }
+
+ /**
+ Sets the title (label()) to an icon or image.
+
+ This sets the labeltype() to \_FL_IMAGE_LABEL (note the leading
+ underscore).
+
+ \see const char* Fl_Menu_Item::label() const
+
+ \since 1.4.0
+
+ \internal Overloading Fl_Menu_Item::image() would lead to ambiguities
+ when used like `item->label(0)`, hence we need our own method name.
+ Otherwise existing programs might not compile w/o error (e.g. fluid).
+ */
+ void image_label(const Fl_Image *image) {
+ label(FL_IMAGE_LABEL, (const char *)image);
+ }
/**
Returns the menu item's labeltype.