6 #include <simgear/props/props.hxx>
10 // This file contains the code implementing the LayoutWidget class in
11 // terms of a PropertyNode (plus a tiny bit of PUI glue). See
12 // layout.cxx for the actual layout engine.
14 puFont LayoutWidget::FONT;
16 void LayoutWidget::setDefaultFont(puFont* font, int pixels)
18 UNIT = (int)(pixels * (1/3.) + 0.999);
22 int LayoutWidget::stringLength(const char* s)
24 return (int)(FONT.getFloatStringWidth(s) + 0.999);
27 const char* LayoutWidget::type()
29 const char* t = _prop->getName();
30 return (*t == 0) ? "dialog" : t;
33 bool LayoutWidget::hasParent()
35 return _prop->getParent() ? true : false;
38 LayoutWidget LayoutWidget::parent()
40 return LayoutWidget(_prop->getParent());
43 int LayoutWidget::nChildren()
45 // Hack: assume that any non-leaf nodes are widgets...
47 for(int i=0; i<_prop->nChildren(); i++)
48 if(_prop->getChild(i)->nChildren() != 0)
53 LayoutWidget LayoutWidget::getChild(int idx)
55 // Same hack. Note that access is linear time in the number of
58 for(int i=0; i<_prop->nChildren(); i++) {
59 SGPropertyNode* p = _prop->getChild(i);
60 if(p->nChildren() != 0) {
61 if(idx == n) return LayoutWidget(p);
65 return LayoutWidget(0);
68 bool LayoutWidget::hasField(const char* f)
70 return _prop->hasChild(f);
73 int LayoutWidget::getNum(const char* f)
75 return _prop->getIntValue(f);
78 bool LayoutWidget::getBool(const char* f)
80 return _prop->getBoolValue(f);
83 const char* LayoutWidget::getStr(const char* f)
85 return _prop->getStringValue(f);
88 void LayoutWidget::setNum(const char* f, int num)
90 _prop->setIntValue(f, num);