Non reinvents the DAW. Powerful enough to form a complete studio, fast and light enough to run on low-end hardware like the eeePC or Raspberry Pi, and so reliable that it can be used live https://non.tuxfamily.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Fl_Labelpad_Group.H 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*******************************************************************************/
  2. /* Copyright (C) 2009 Jonathan Moore Liles */
  3. /* */
  4. /* This program is free software; you can redistribute it and/or modify it */
  5. /* under the terms of the GNU General Public License as published by the */
  6. /* Free Software Foundation; either version 2 of the License, or (at your */
  7. /* option) any later version. */
  8. /* */
  9. /* This program is distributed in the hope that it will be useful, but WITHOUT */
  10. /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
  11. /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
  12. /* more details. */
  13. /* */
  14. /* You should have received a copy of the GNU General Public License along */
  15. /* with This program; see the file COPYING. If not,write to the Free Software */
  16. /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  17. /*******************************************************************************/
  18. /* wrap a widget in a group as wide as the widget's label. This is
  19. * useful when you want to put labeled widgets into a pack */
  20. #include <FL/Fl_Widget.H>
  21. #include <FL/Fl_Group.H>
  22. #include <FL/fl_draw.H>
  23. class Fl_Labelpad_Group : public Fl_Group
  24. {
  25. public:
  26. static void measure_label ( Fl_Widget *o, int &W, int &H )
  27. {
  28. W = fl_width( o->label() );
  29. H = fl_height();
  30. }
  31. Fl_Labelpad_Group ( Fl_Widget *o ) : Fl_Group( 0, 0, 50, 50, 0 )
  32. {
  33. resizable( 0 );
  34. end();
  35. add( o );
  36. fl_font( o->labelfont(), o->labelsize() );
  37. int W, H;
  38. measure_label( o, W, H );
  39. // set size to contain widget
  40. if ( o->align() & ( FL_ALIGN_TOP | FL_ALIGN_BOTTOM ) )
  41. size( W > o->w() ? W : o->w(), o->h() + H );
  42. if ( o->align() & ( FL_ALIGN_LEFT | FL_ALIGN_RIGHT ) )
  43. size( o->w() + W, H > o->h() ? H : o->h() );
  44. // center widget in group
  45. if ( o->align() & FL_ALIGN_TOP )
  46. o->position( x() + w() / 2 - (o->w() / 2 ), y() + H );
  47. else if ( o->align() & FL_ALIGN_BOTTOM )
  48. o->position( x() + w() / 2 - (o->w() / 2 ), y() );
  49. else if ( o->align() & FL_ALIGN_RIGHT )
  50. o->position( x(), y() );
  51. else if ( o->align() & FL_ALIGN_LEFT )
  52. o->position( x() + W, y() );
  53. else
  54. {
  55. /* TODO: other alignments */
  56. }
  57. resizable(o);
  58. init_sizes();
  59. }
  60. virtual ~Fl_Labelpad_Group ( )
  61. {
  62. }
  63. };