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.

layout.h 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* Copyright 2011 Pierre Ossman <ossman@cendio.se> for Cendio AB
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining
  4. * a copy of this software and associated documentation files (the
  5. * "Software"), to deal in the Software without restriction, including
  6. * without limitation the rights to use, copy, modify, merge, publish,
  7. * distribute, sublicense, and/or sell copies of the Software, and to
  8. * permit persons to whom the Software is furnished to do so, subject to
  9. * the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be
  12. * included in all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  18. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  19. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  20. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. */
  23. #ifndef __FLTK_LAYOUT_H__
  24. #define __FLTK_LAYOUT_H__
  25. #include <FL/fl_draw.H>
  26. /* Calculates the width of a string as printed by FLTK (pixels) */
  27. static inline int gui_str_len(const char *str)
  28. {
  29. float len;
  30. fl_font(FL_HELVETICA, FL_NORMAL_SIZE);
  31. len = fl_width(str);
  32. return (int)(len + 0.5f);
  33. }
  34. /**** MARGINS ****/
  35. #define OUTER_MARGIN 15
  36. #define INNER_MARGIN 10
  37. /* Tighter grouping of related fields */
  38. #define TIGHT_MARGIN 5
  39. /**** ADJUSTMENTS ****/
  40. #define INDENT 10
  41. /**** FLTK WIDGETS ****/
  42. /* Fl_Input */
  43. #define INPUT_LABEL_OFFSET FL_NORMAL_SIZE
  44. #define INPUT_HEIGHT 25
  45. /* Fl_Button */
  46. #define BUTTON_WIDTH 115
  47. #define BUTTON_HEIGHT 27
  48. /* Fl_Round_Button (padding + focus draw bug) */
  49. #define RADIO_MIN_WIDTH (FL_NORMAL_SIZE + 4 + 1)
  50. #define RADIO_HEIGHT (FL_NORMAL_SIZE + 4 + 1)
  51. /* Fl_Check_Button */
  52. #define CHECK_MIN_WIDTH RADIO_MIN_WIDTH
  53. #define CHECK_HEIGHT RADIO_HEIGHT
  54. /* Fl_Choice */
  55. #define CHOICE_HEIGHT INPUT_HEIGHT
  56. /* Fl_Group */
  57. #define GROUP_LABEL_OFFSET FL_NORMAL_SIZE
  58. /**** HELPERS FOR DYNAMIC TEXT ****/
  59. /* Extra space to add after any text line */
  60. #define TEXT_PADDING 2
  61. /* Use this when the text extends to the right (e.g. checkboxes) */
  62. #define LBLRIGHT(x, y, w, h, str) \
  63. (x), (y), (w) + gui_str_len(str) + TEXT_PADDING, (h), (str)
  64. /* Use this when the space for the label is taken from the left (e.g. input) */
  65. #define LBLLEFT(x, y, w, h, str) \
  66. (x) + (gui_str_len(str) + TEXT_PADDING), (y), \
  67. (w) - (gui_str_len(str) + TEXT_PADDING), (h), (str)
  68. #endif