layout.h
Go to the documentation of this file.
1 /*
2  * Roboception GmbH
3  * Munich, Germany
4  * www.roboception.com
5  *
6  * Copyright (c) 2024 Roboception GmbH
7  * All rights reserved
8  *
9  * Author: Heiko Hirschmueller
10  */
11 
12 #ifndef RC_LAYOUT_H
13 #define RC_LAYOUT_H
14 
15 #include <FL/Fl.H>
16 #include <FL/Fl_Group.H>
17 #include <FL/Fl_Widget.H>
18 
19 #include <algorithm>
20 
21 #define GAP_SIZE 10
22 
27 inline int addRightX(int gap=GAP_SIZE)
28 {
29  int n=Fl_Group::current()->children();
30  if (n > 0)
31  {
32  Fl_Widget *c=Fl_Group::current()->child(n-1);
33  return c->x()+c->w()+gap;
34  }
35 
36  return gap;
37 }
38 
43 inline int addRightY(int gap=GAP_SIZE)
44 {
45  int n=Fl_Group::current()->children();
46  if (n > 0)
47  {
48  Fl_Widget *c=Fl_Group::current()->child(n-1);
49  return c->y();
50  }
51 
52  return gap;
53 }
54 
59 inline int addBelowX(int gap=GAP_SIZE)
60 {
61  return gap;
62 }
63 
68 inline int addBelowY(int gap=GAP_SIZE)
69 {
70  int ret=gap;
71  int n=Fl_Group::current()->children();
72  for (int i=0; i<n; i++)
73  {
74  Fl_Widget *c=Fl_Group::current()->child(i);
75  ret=std::max(ret, c->y()+c->h()+gap);
76  }
77 
78  return ret;
79 }
80 
88 inline void checkGroupSize(const char *group_name)
89 {
90  int n=Fl_Group::current()->children();
91  if (n > 0)
92  {
93  Fl_Group *g=Fl_Group::current();
94  Fl_Widget *c=g->child(0);
95 
96  int xmin=c->x(), xmax=c->x()+c->w();
97  int ymin=c->y(), ymax=c->y()+c->h();
98 
99  for (int i=1; i<n; i++)
100  {
101  c=g->child(i);
102  xmin=std::min(xmin, c->x());
103  xmax=std::max(xmax, c->x()+c->w());
104  ymin=std::min(ymin, c->y());
105  ymax=std::max(ymax, c->y()+c->h());
106  }
107 
108  if ((g->w() != xmax+xmin && g->w() != xmax+xmin+GAP_SIZE) ||
109  (g->h() != ymax+ymin && g->h() != ymax+ymin+GAP_SIZE))
110  {
111  Fl::warning("Size of group '%s' is %dx%d, but should be %dx%d!",
112  group_name, g->w(), g->h(), xmax+xmin, ymax+ymin);
113  }
114  }
115 }
116 
117 // Can be used to replace the first two arguments in the constructor of a new
118 // widget
119 
120 #define ADD_RIGHT_XY addRightX(), addRightY()
121 #define ADD_BELOW_XY addBelowX(), addBelowY()
122 
123 #endif
GAP_SIZE
#define GAP_SIZE
Definition: layout.h:21
addRightY
int addRightY(int gap=GAP_SIZE)
Computes the y coordinate of a widget to the right of the last added widget.
Definition: layout.h:43
addRightX
int addRightX(int gap=GAP_SIZE)
Computes the x coordinate of a widget to the right of the last added widget.
Definition: layout.h:27
checkGroupSize
void checkGroupSize(const char *group_name)
The size of the current group must be set before adding all children, especially resizable ones.
Definition: layout.h:88
addBelowX
int addBelowX(int gap=GAP_SIZE)
Computes the x coordinate of a widget in the next line.
Definition: layout.h:59
addBelowY
int addBelowY(int gap=GAP_SIZE)
Computes the y coordinate of a widget to the next line.
Definition: layout.h:68


rcdiscover
Author(s): Heiko Hirschmueller , Raphael Schaller
autogenerated on Thu Aug 1 2024 02:55:56