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 but "hrule" and "vrule"
48 for(int i=0; i<_prop->nChildren(); i++) {
49 SGPropertyNode* p = _prop->getChild(i);
50 const char* name = p->getName();
51 if(p->nChildren() != 0 || !strcmp(name, "hrule")
52 || !strcmp(name, "vrule"))
58 LayoutWidget LayoutWidget::getChild(int idx)
60 // Same hack. Note that access is linear time in the number of
63 for(int i=0; i<_prop->nChildren(); i++) {
64 SGPropertyNode* p = _prop->getChild(i);
65 const char* name = p->getName();
66 if(p->nChildren() != 0 || !strcmp(name, "hrule")
67 || !strcmp(name, "vrule")) {
68 if(idx == n) return LayoutWidget(p);
72 return LayoutWidget(0);
75 bool LayoutWidget::hasField(const char* f)
77 return _prop->hasChild(f);
80 int LayoutWidget::getNum(const char* f)
82 return _prop->getIntValue(f);
85 bool LayoutWidget::getBool(const char* f)
87 return _prop->getBoolValue(f);
90 const char* LayoutWidget::getStr(const char* f)
92 return _prop->getStringValue(f);
95 void LayoutWidget::setNum(const char* f, int num)
97 _prop->setIntValue(f, num);