summaryrefslogtreecommitdiffstats
path: root/vncviewer/fltk_layout.h
blob: c16a359fe8a0ccafb67f33d67e55808d0055ef78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* Copyright 2011 Pierre Ossman <ossman@cendio.se> for Cendio AB
 * 
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this software; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
 * USA.
 */

#ifndef __FLTK_LAYOUT_H__
#define __FLTK_LAYOUT_H__

#include <FL/fl_draw.H>

/* Calculates the width of a string as printed by FLTK (pixels) */
static inline int gui_str_len(const char *str)
{
    float len;

    fl_font(FL_HELVETICA, FL_NORMAL_SIZE);

    len = fl_width(str);

    return (int)(len + 0.5f);
}

/* Escapes all @ in text as those have special meaning in labels */
static inline int fltk_escape(const char *in, char *out, size_t maxlen)
{
    int len;

    len = 0;

    while (*in != '\0') {
        if (*in == '@') {
            if (maxlen >= 3) {
                *out++ = '@';
                *out++ = '@';
                maxlen -= 2;
            }

            len += 2;
        } else {
            if (maxlen >= 2) {
                *out++ = *in;
                maxlen--;
            }

            len += 1;
        }

        in++;
    }

    if (maxlen)
        *out = '\0';

    return len;
}

/**** MARGINS ****/

#define OUTER_MARGIN            10
#define INNER_MARGIN            10

/* Tighter grouping of related fields */
#define TIGHT_MARGIN            5

/**** ADJUSTMENTS ****/
#define INDENT                  20

/**** FLTK WIDGETS ****/

/* Fl_Tabs */
#define TABS_HEIGHT             30

/* Fl_Input */
#define INPUT_LABEL_OFFSET      FL_NORMAL_SIZE
#define INPUT_HEIGHT            25

/* Fl_Button */
#define BUTTON_WIDTH            115
#define BUTTON_HEIGHT           27

/* Fl_Round_Button */
#define RADIO_MIN_WIDTH         (FL_NORMAL_SIZE + 5)
#define RADIO_HEIGHT            (FL_NORMAL_SIZE + 7)

/* Fl_Check_Button */
#define CHECK_MIN_WIDTH         RADIO_MIN_WIDTH
#define CHECK_HEIGHT            RADIO_HEIGHT

/* Fl_Choice */

#define CHOICE_HEIGHT           INPUT_HEIGHT

/* Fl_Group */
#define GROUP_LABEL_OFFSET      FL_NORMAL_SIZE
#define GROUP_MARGIN            12

/**** HELPERS FOR DYNAMIC TEXT ****/

/* Extra space to add after any text line */
#define TEXT_PADDING            2

/* Use this when the text extends to the right (e.g. checkboxes) */
#define LBLRIGHT(x, y, w, h, str) \
    (x), (y), (w) + gui_str_len(str) + TEXT_PADDING, (h), (str)

/* Use this when the space for the label is taken from the left (e.g. input) */
#define LBLLEFT(x, y, w, h, str) \
    (x) + (gui_str_len(str) + TEXT_PADDING), (y), \
    (w) - (gui_str_len(str) + TEXT_PADDING), (h), (str)

#endif