6 #include <simgear/props/props.hxx>
7 #include <simgear/math/SGMath.hxx>
11 // This file contains the code implementing the LayoutWidget class in
12 // terms of a PropertyNode (plus a tiny bit of PUI glue). See
13 // layout.cxx for the actual layout engine.
15 puFont LayoutWidget::FONT;
17 void LayoutWidget::setDefaultFont(puFont* font, int pixels)
19 UNIT = (int)(pixels * (1/3.) + 0.999);
23 int LayoutWidget::stringLength(const char* s)
25 return (int)(FONT.getFloatStringWidth(s) + 0.999);
28 const char* LayoutWidget::type()
30 const char* t = _prop->getName();
31 return (*t == 0) ? "dialog" : t;
34 bool LayoutWidget::hasParent()
36 return _prop->getParent() ? true : false;
39 LayoutWidget LayoutWidget::parent()
41 return LayoutWidget(_prop->getParent());
44 int LayoutWidget::nChildren()
46 // Hack: assume that any non-leaf nodes but "hrule" and "vrule"
49 for(int i=0; i<_prop->nChildren(); i++) {
50 SGPropertyNode* p = _prop->getChild(i);
51 const char* name = p->getName();
52 if(p->nChildren() != 0 || !strcmp(name, "hrule")
53 || !strcmp(name, "vrule"))
59 LayoutWidget LayoutWidget::getChild(int idx)
61 // Same hack. Note that access is linear time in the number of
64 for(int i=0; i<_prop->nChildren(); i++) {
65 SGPropertyNode* p = _prop->getChild(i);
66 const char* name = p->getName();
67 if(p->nChildren() != 0 || !strcmp(name, "hrule")
68 || !strcmp(name, "vrule")) {
69 if(idx == n) return LayoutWidget(p);
73 return LayoutWidget(0);
76 bool LayoutWidget::hasField(const char* f)
78 return _prop->hasChild(f);
81 int LayoutWidget::getNum(const char* f)
83 return _prop->getIntValue(f);
86 bool LayoutWidget::getBool(const char* f, bool dflt)
88 return _prop->getBoolValue(f, dflt);
91 const char* LayoutWidget::getStr(const char* f)
93 return _prop->getStringValue(f);
96 void LayoutWidget::setNum(const char* f, int num)
98 _prop->setIntValue(f, num);