2 #include <simgear/props/props.hxx>
6 // This file contains the code implementing the LayoutWidget class in
7 // terms of a PropertyNode (plus a tiny bit of PUI glue). See
8 // layout.cxx for the actual layout engine.
10 puFont LayoutWidget::FONT;
12 void LayoutWidget::setDefaultFont(puFont* font, int pixels)
14 UNIT = (int)(pixels * (1/3.) + 0.999);
18 int LayoutWidget::stringLength(const char* s)
20 return (int)(FONT.getFloatStringWidth(s) + 0.999);
23 const char* LayoutWidget::type()
25 const char* t = _prop->getName();
26 return (*t == 0) ? "dialog" : t;
29 bool LayoutWidget::hasParent()
31 return _prop->getParent() ? true : false;
34 LayoutWidget LayoutWidget::parent()
36 return LayoutWidget(_prop->getParent());
39 int LayoutWidget::nChildren()
41 // Hack: assume that any non-leaf nodes are widgets...
43 for(int i=0; i<_prop->nChildren(); i++)
44 if(_prop->getChild(i)->nChildren() != 0)
49 LayoutWidget LayoutWidget::getChild(int idx)
51 // Same hack. Note that access is linear time in the number of
54 for(int i=0; i<_prop->nChildren(); i++) {
55 SGPropertyNode* p = _prop->getChild(i);
56 if(p->nChildren() != 0) {
57 if(idx == n) return LayoutWidget(p);
61 return LayoutWidget(0);
64 bool LayoutWidget::hasField(const char* f)
66 return _prop->hasChild(f);
69 int LayoutWidget::getNum(const char* f)
71 return _prop->getIntValue(f);
74 bool LayoutWidget::getBool(const char* f)
76 return _prop->getBoolValue(f);
79 const char* LayoutWidget::getStr(const char* f)
81 return _prop->getStringValue(f);
84 void LayoutWidget::setNum(const char* f, int num)
86 _prop->setIntValue(f, num);