Pierre Ossman | d463b57 | 2011-05-16 12:04:43 +0000 | [diff] [blame] | 1 | /* Copyright 2011 Pierre Ossman <ossman@cendio.se> for Cendio AB |
| 2 | * |
| 3 | * This is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This software is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this software; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 16 | * USA. |
| 17 | */ |
| 18 | |
| 19 | #ifndef __FLTK_LAYOUT_H__ |
| 20 | #define __FLTK_LAYOUT_H__ |
| 21 | |
| 22 | #include <FL/fl_draw.H> |
| 23 | |
| 24 | /* Calculates the width of a string as printed by FLTK (pixels) */ |
| 25 | static inline int gui_str_len(const char *str) |
| 26 | { |
| 27 | float len; |
| 28 | |
| 29 | fl_font(FL_HELVETICA, FL_NORMAL_SIZE); |
| 30 | |
| 31 | len = fl_width(str); |
| 32 | |
| 33 | return (int)(len + 0.5f); |
| 34 | } |
| 35 | |
Pierre Ossman | c628ba4 | 2011-05-23 12:21:21 +0000 | [diff] [blame^] | 36 | /* Escapes all @ in text as those have special meaning in labels */ |
| 37 | static inline int fltk_escape(const char *in, char *out, size_t maxlen) |
| 38 | { |
| 39 | int len; |
| 40 | |
| 41 | len = 0; |
| 42 | |
| 43 | while (*in != '\0') { |
| 44 | if (*in == '@') { |
| 45 | if (maxlen >= 3) { |
| 46 | *out++ = '@'; |
| 47 | *out++ = '@'; |
| 48 | maxlen -= 2; |
| 49 | } |
| 50 | |
| 51 | len += 2; |
| 52 | } else { |
| 53 | if (maxlen >= 2) { |
| 54 | *out++ = *in; |
| 55 | maxlen--; |
| 56 | } |
| 57 | |
| 58 | len += 1; |
| 59 | } |
| 60 | |
| 61 | in++; |
| 62 | } |
| 63 | |
| 64 | if (maxlen) |
| 65 | *out = '\0'; |
| 66 | |
| 67 | return len; |
| 68 | } |
| 69 | |
Pierre Ossman | d463b57 | 2011-05-16 12:04:43 +0000 | [diff] [blame] | 70 | /**** MARGINS ****/ |
| 71 | |
| 72 | #define OUTER_MARGIN 10 |
| 73 | #define INNER_MARGIN 10 |
| 74 | |
| 75 | /* Tighter grouping of related fields */ |
| 76 | #define TIGHT_MARGIN 5 |
| 77 | |
| 78 | /**** ADJUSTMENTS ****/ |
| 79 | #define INDENT 20 |
| 80 | |
| 81 | /**** FLTK WIDGETS ****/ |
| 82 | |
| 83 | /* Fl_Tabs */ |
| 84 | #define TABS_HEIGHT 30 |
| 85 | |
| 86 | /* Fl_Input */ |
| 87 | #define INPUT_LABEL_OFFSET FL_NORMAL_SIZE |
| 88 | #define INPUT_HEIGHT 25 |
| 89 | |
| 90 | /* Fl_Button */ |
| 91 | #define BUTTON_WIDTH 115 |
| 92 | #define BUTTON_HEIGHT 27 |
| 93 | |
| 94 | /* Fl_Round_Button */ |
| 95 | #define RADIO_MIN_WIDTH (FL_NORMAL_SIZE + 5) |
| 96 | #define RADIO_HEIGHT (FL_NORMAL_SIZE + 7) |
| 97 | |
| 98 | /* Fl_Check_Button */ |
| 99 | #define CHECK_MIN_WIDTH RADIO_MIN_WIDTH |
| 100 | #define CHECK_HEIGHT RADIO_HEIGHT |
| 101 | |
| 102 | /* Fl_Group */ |
| 103 | #define GROUP_LABEL_OFFSET FL_NORMAL_SIZE |
| 104 | #define GROUP_MARGIN 12 |
| 105 | |
| 106 | /**** HELPERS FOR DYNAMIC TEXT ****/ |
| 107 | |
| 108 | /* Extra space to add after any text line */ |
| 109 | #define TEXT_PADDING 2 |
| 110 | |
| 111 | /* Use this when the text extends to the right (e.g. checkboxes) */ |
| 112 | #define LBLRIGHT(x, y, w, h, str) \ |
| 113 | (x), (y), (w) + gui_str_len(str) + TEXT_PADDING, (h), (str) |
| 114 | |
| 115 | /* Use this when the space for the label is taken from the left (e.g. input) */ |
| 116 | #define LBLLEFT(x, y, w, h, str) \ |
| 117 | (x) + (gui_str_len(str) + TEXT_PADDING), (y), \ |
| 118 | (w) - (gui_str_len(str) + TEXT_PADDING), (h), (str) |
| 119 | |
| 120 | #endif |