Skip to content

Commit

Permalink
Widgets|libcore: Checking for layout rectangle validity
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Nov 14, 2018
1 parent 4e2778e commit f3bdfcc
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
2 changes: 2 additions & 0 deletions doomsday/sdk/libcore/include/de/widgets/indirectrule.h
Expand Up @@ -49,6 +49,8 @@ class DENG2_PUBLIC IndirectRule : public Rule

void unsetSource();

bool hasSource() const;

void update();

Rule const &source() const;
Expand Down
2 changes: 2 additions & 0 deletions doomsday/sdk/libcore/include/de/widgets/rulerectangle.h
Expand Up @@ -150,6 +150,8 @@ class DENG2_PUBLIC RuleRectangle : public ISizeRule

void setDebugName(String const &name);

bool isFullyDefined() const;

String description() const;

private:
Expand Down
11 changes: 8 additions & 3 deletions doomsday/sdk/libcore/src/widgets/indirectrule.cpp
Expand Up @@ -20,7 +20,7 @@

namespace de {

IndirectRule::IndirectRule() : _source(0)
IndirectRule::IndirectRule() : _source(nullptr)
{}

IndirectRule::~IndirectRule()
Expand All @@ -42,9 +42,14 @@ void IndirectRule::unsetSource()
invalidate();
}

bool IndirectRule::hasSource() const
{
return _source != nullptr;
}

void IndirectRule::update()
{
setValue(_source? _source->value() : 0);
setValue(_source ? _source->value() : 0.f);
}

Rule const &IndirectRule::source() const
Expand All @@ -61,7 +66,7 @@ String IndirectRule::description() const
}
else
{
return String("(null)");
return String("[0]");
}
}

Expand Down
27 changes: 25 additions & 2 deletions doomsday/sdk/libcore/src/widgets/rulerectangle.cpp
Expand Up @@ -409,13 +409,25 @@ void RuleRectangle::setDebugName(String const &name)
d->debugName = name;
}

bool RuleRectangle::isFullyDefined() const
{
for (const auto *out : d->outputRules)
{
if (!out->hasSource())
{
return false;
}
}
return true;
}

String RuleRectangle::description() const
{
String desc = QString("RuleRectangle '%1'").arg(d->debugName);

for (int i = 0; i < int(Rule::MAX_SEMANTICS); ++i)
{
desc += String("\n - ") +
desc += String("\n INPUT ") +
(i == Rule::Left? "Left" :
i == Rule::Top? "Top" :
i == Rule::Right? "Right" :
Expand All @@ -430,9 +442,20 @@ String RuleRectangle::description() const
}
else
{
desc += "(null)";
desc += "(not set)";
}
}
for (int i = 0; i < Impl::MAX_OUTPUT_RULES; ++i)
{
desc += String::format("\n OUTPUT %s: ",
i == Impl::OutLeft ? "Left"
: i == Impl::OutTop ? "Top"
: i == Impl::OutRight ? "Right"
: i == Impl::OutBottom ? "Bottom"
: i == Impl::OutWidth ? "Width"
: "Height");
desc += d->outputRules[i]->description();
}
return desc;
}

Expand Down

0 comments on commit f3bdfcc

Please sign in to comment.