]> git.mxchange.org Git - flightgear.git/blob - src/GUI/layout.hxx
GUI layout management and a few visual/eye-candy modifications. See
[flightgear.git] / src / GUI / layout.hxx
1 #ifndef __LAYOUT_HXX
2 #define __LAYOUT_HXX
3
4 class SGPropertyNode;
5 class puFont;
6
7 // For the purposes of doing layout management, widgets have a type,
8 // zero or more children, and string-indexed "fields" which can be
9 // constraints, parameters or x/y/width/height geometry values.  It
10 // can provide a "preferred" width and height to its parent, and is
11 // capable of laying itself out into a specified x/y/w/h box.  The
12 // widget "type" is not a field for historical reasons having to do
13 // with the way the dialog property format works.
14 //
15 // Note that this is a simple wrapper around an SGPropertyNode
16 // pointer.  The intent is that these objects will be created on the
17 // stack as needed and passed by value.  All persistent data is stored
18 // in the wrapped properties.
19 class LayoutWidget {
20 public:
21     static void setDefaultFont(puFont* font, int pixels);
22
23     LayoutWidget() { _prop = 0; }
24     LayoutWidget(SGPropertyNode* p) { _prop = p; }
25
26     const char*  type();
27     bool         hasParent();
28     LayoutWidget parent();
29     int          nChildren();
30     LayoutWidget getChild(int i);
31     bool         hasField(const char* f);
32     int          getNum(const char* f);
33     bool         getBool(const char* f);
34     const char*  getStr(const char* f);
35     void         setNum(const char* f, int num);
36
37     void calcPrefSize(int* w, int* h);
38     void layout(int x, int y, int w, int h);
39
40 private:
41     static int UNIT;
42     static puFont FONT;
43
44     static bool eq(const char* a, const char* b);
45     bool isType(const char* t) { return eq(t, type()); }
46
47     int padding();
48     int stringLength(const char* s); // must handle null argument
49
50     void doHVBox(bool doLayout, bool vertical, int* w=0, int* h=0);
51     void doTable(bool doLayout, int* w=0, int* h=0);
52
53     SGPropertyNode* _prop;
54 };
55
56 #endif // __LAYOUT_HXX