Fl_Multi_Label.H 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //
  2. // "$Id: Fl_Multi_Label.H 12452 2017-09-12 20:12:21Z greg.ercolano $"
  3. //
  4. // Multi-label header file for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-2015 by Bill Spitzak and others.
  7. //
  8. // This library is free software. Distribution and use rights are outlined in
  9. // the file "COPYING" which should have been included with this file. If this
  10. // file is missing or damaged, see the license at:
  11. //
  12. // http://www.fltk.org/COPYING.php
  13. //
  14. // Please report all bugs and problems on the following page:
  15. //
  16. // http://www.fltk.org/str.php
  17. //
  18. #ifndef Fl_Multi_Label_H
  19. #define Fl_Multi_Label_H
  20. class Fl_Widget;
  21. struct Fl_Menu_Item;
  22. /** This struct allows multiple labels to be added to objects that might normally have only one label.
  23. This struct allows a mixed text and/or graphics label to be applied to an object that
  24. would normally only have a single (usually text only) label.
  25. Most regular FLTK widgets now support the ability to associate both images and text
  26. with a label but some special cases, notably the non-widget Fl_Menu_Item objects, do not.
  27. Fl_Multi_Label may be used to create menu items that have an icon and text, which would
  28. not normally be possible for an Fl_Menu_Item.
  29. For example, Fl_Multi_Label is used in the New->Code submenu in fluid, and others.
  30. \image html Fl_Multi_Label-menu-item.png "Menu items with icons using Fl_Multi_Label"
  31. \image latex Fl_Multi_Label-menu-item.png "Menu items with icons using Fl_Multi_Label" width=4cm
  32. Each Fl_Multi_Label holds two elements, labela and labelb; each may hold either a
  33. text label (const char*) or an image (Fl_Image*). When displayed, labela is drawn first
  34. and labelb is drawn immediately to its right.
  35. More complex labels might be constructed by setting labelb as another Fl_Multi_Label and
  36. thus chaining up a series of label elements.
  37. When assigning a label element to one of labela or labelb, they should be explicitly cast
  38. to (const char*) if they are not of that type already.
  39. Example Use: Fl_Menu_Bar
  40. \code
  41. Fl_Pixmap *image = new Fl_Pixmap(..); // image for menu item; any Fl_Image based widget
  42. Fl_Menu_Bar *menu = new Fl_Menu_Bar(..); // can be any Fl_Menu_ oriented widget (Fl_Choice, Fl_Menu_Button..)
  43. // Create a menu item
  44. int i = menu->add("File/New", ..);
  45. Fl_Menu_Item *item = (Fl_Menu_Item*)&(menu->menu()[i]);
  46. // Create a multi label, assign it an image + text
  47. Fl_Multi_Label *ml = new Fl_Multi_Label;
  48. // Left side of label is an image
  49. ml->typea = FL_IMAGE_LABEL;
  50. ml->labela = (const char*)image; // any Fl_Image widget: Fl_Pixmap, Fl_PNG_Image, etc..
  51. // Right side of label is label text
  52. ml->typeb = FL_NORMAL_LABEL;
  53. ml->labelb = item->label();
  54. // Assign the multilabel to the menu item
  55. ml->label(item);
  56. \endcode
  57. \see Fl_Label and Fl_Labeltype and examples/howto-menu-with-images.cxx
  58. */
  59. struct FL_EXPORT Fl_Multi_Label {
  60. /** Holds the "leftmost" of the two elements in the composite label.
  61. Typically this would be assigned either a text string (const char*),
  62. a (Fl_Image*) or a (Fl_Multi_Label*). */
  63. const char* labela;
  64. /** Holds the "rightmost" of the two elements in the composite label.
  65. Typically this would be assigned either a text string (const char*),
  66. a (Fl_Image*) or a (Fl_Multi_Label*). */
  67. const char* labelb;
  68. /** Holds the "type" of labela.
  69. Typically this is set to FL_NORMAL_LABEL for a text label,
  70. FL_IMAGE_LABEL for an image (based on Fl_image) or FL_MULTI_LABEL
  71. if "chaining" multiple Fl_Multi_Label elements together. */
  72. uchar typea;
  73. /** Holds the "type" of labelb.
  74. Typically this is set to FL_NORMAL_LABEL for a text label,
  75. FL_IMAGE_LABEL for an image (based on Fl_image) or FL_MULTI_LABEL
  76. if "chaining" multiple Fl_Multi_Label elements together. */
  77. uchar typeb;
  78. /** This method is used to associate a Fl_Multi_Label with a Fl_Widget. */
  79. void label(Fl_Widget*);
  80. /** This method is used to associate a Fl_Multi_Label with a Fl_Menu_Item. */
  81. void label(Fl_Menu_Item*);
  82. };
  83. #endif
  84. //
  85. // End of "$Id: Fl_Multi_Label.H 12452 2017-09-12 20:12:21Z greg.ercolano $".
  86. //