1
0
Fork 0
flightgear/src/GUI/layout-props.cxx
mfranz f27d7b2340 layout-props.cxx: hrule/vrule shall be accepted as widgets even if they
have no children (in which case they default to 1px thickness & stretch).
    This allows to just write <hrule/> instead of <hrule><dummy/></hrule>.
    One can still use <hrule><pref-height>3</pref-height></hrule>, of course.
layout.cxx: drop silly do??Box calls for hrule/vrule (yes, I wrote that :-)
2007-03-26 15:17:38 +00:00

99 lines
2.1 KiB
C++

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <plib/pu.h>
#include <simgear/props/props.hxx>
#include "layout.hxx"
// This file contains the code implementing the LayoutWidget class in
// terms of a PropertyNode (plus a tiny bit of PUI glue). See
// layout.cxx for the actual layout engine.
puFont LayoutWidget::FONT;
void LayoutWidget::setDefaultFont(puFont* font, int pixels)
{
UNIT = (int)(pixels * (1/3.) + 0.999);
FONT = *font;
}
int LayoutWidget::stringLength(const char* s)
{
return (int)(FONT.getFloatStringWidth(s) + 0.999);
}
const char* LayoutWidget::type()
{
const char* t = _prop->getName();
return (*t == 0) ? "dialog" : t;
}
bool LayoutWidget::hasParent()
{
return _prop->getParent() ? true : false;
}
LayoutWidget LayoutWidget::parent()
{
return LayoutWidget(_prop->getParent());
}
int LayoutWidget::nChildren()
{
// Hack: assume that any non-leaf nodes but "hrule" and "vrule"
// are widgets...
int n = 0;
for(int i=0; i<_prop->nChildren(); i++) {
SGPropertyNode* p = _prop->getChild(i);
const char* name = p->getName();
if(p->nChildren() != 0 || !strcmp(name, "hrule")
|| !strcmp(name, "vrule"))
n++;
}
return n;
}
LayoutWidget LayoutWidget::getChild(int idx)
{
// Same hack. Note that access is linear time in the number of
// children...
int n = 0;
for(int i=0; i<_prop->nChildren(); i++) {
SGPropertyNode* p = _prop->getChild(i);
const char* name = p->getName();
if(p->nChildren() != 0 || !strcmp(name, "hrule")
|| !strcmp(name, "vrule")) {
if(idx == n) return LayoutWidget(p);
n++;
}
}
return LayoutWidget(0);
}
bool LayoutWidget::hasField(const char* f)
{
return _prop->hasChild(f);
}
int LayoutWidget::getNum(const char* f)
{
return _prop->getIntValue(f);
}
bool LayoutWidget::getBool(const char* f)
{
return _prop->getBoolValue(f);
}
const char* LayoutWidget::getStr(const char* f)
{
return _prop->getStringValue(f);
}
void LayoutWidget::setNum(const char* f, int num)
{
_prop->setIntValue(f, num);
}