Skip to content

Commit

Permalink
Refactor|UI|Client|ScrollAreaWidget: Use ui::Margins
Browse files Browse the repository at this point in the history
The scroll area widget was using a couple of custom margin methods
that are now obsolete. Also internally the widget now uses the full
four-sided ui::Margins.
  • Loading branch information
skyjake committed Aug 28, 2013
1 parent 1c3f268 commit 1b164a0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 45 deletions.
8 changes: 0 additions & 8 deletions doomsday/client/include/ui/widgets/scrollareawidget.h
Expand Up @@ -68,14 +68,6 @@ class ScrollAreaWidget : public GuiWidget
de::Rectanglei viewport() const;
de::Vector2i viewportSize() const;

/**
* Returns the amount of space between the top edge of the widget and the
* top edge of the content.
*/
int topMargin() const;

int rightMargin() const;

/**
* Returns the current scroll XY position, with 0 being the top/left corner
* and maximumScroll() being the bottom right position.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/ui/widgets/consolewidget.cpp
Expand Up @@ -93,7 +93,7 @@ DENG_GUI_PIMPL(ConsoleWidget)
if(height->animation().target() == 0)
{
// On the first expansion make sure the margins are taken into account.
delta += 2 * log->topMargin();
delta += log->margins().height().valuei();
}

height->set(height->animation().target() + delta, .25f);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/ui/widgets/logwidget.cpp
Expand Up @@ -742,7 +742,7 @@ public Font::RichFormat::IStyle
{
GLState &st = GLState::push();
// Leave room for the indicator in the scissor.
st.setScissor(vp.adjusted(Vector2i(), Vector2i(self.rightMargin(), 0)));
st.setScissor(vp.adjusted(Vector2i(), Vector2i(self.margins().right().valuei(), 0)));

// First draw the shadow of the text.
uMvpMatrix = projMatrix * Matrix4f::translate(
Expand Down
52 changes: 17 additions & 35 deletions doomsday/client/src/ui/widgets/scrollareawidget.cpp
Expand Up @@ -49,18 +49,13 @@ DENG_GUI_PIMPL(ScrollAreaWidget), public Lockable
bool indicatorAnimating;
ColorBank::Colorf accent;

Rule const *margin;
Rule const *vertMargin;

Instance(Public *i)
: Base(i),
origin(Top),
pageKeysEnabled(true),
scrollOpacity(0),
scrollBarWidth(0),
indicatorAnimating(false),
margin(0),
vertMargin(0)
indicatorAnimating(false)
{
contentRule.setDebugName("ScrollArea-contentRule");

Expand All @@ -70,10 +65,10 @@ DENG_GUI_PIMPL(ScrollAreaWidget), public Lockable
y = new ScalarRule(0);

maxX = new OperatorRule(OperatorRule::Maximum, Const(0),
contentRule.width() - self.rule().width() + *margin * 2);
contentRule.width() - self.rule().width() + self.margins().width());

maxY = new OperatorRule(OperatorRule::Maximum, Const(0),
contentRule.height() - self.rule().height() + *vertMargin * 2);
contentRule.height() - self.rule().height() + self.margins().height());
}

~Instance()
Expand All @@ -88,8 +83,6 @@ DENG_GUI_PIMPL(ScrollAreaWidget), public Lockable
{
Style const &st = style();

margin = &st.rules().rule("gap");
vertMargin = &st.rules().rule("gap");
scrollBarWidth = st.rules().rule("scrollarea.bar").valuei();
accent = st.colors().colorf("accent");
}
Expand All @@ -114,7 +107,7 @@ ScrollAreaWidget::ScrollAreaWidget(String const &name)
setBehavior(ChildHitClipping);

// Link the content rule into the widget's rectangle.
d->contentRule.setInput(Rule::Left, rule().left() + *d->margin -
d->contentRule.setInput(Rule::Left, rule().left() + margins().left() -
OperatorRule::minimum(*d->x, *d->maxX));

setOrigin(Top);
Expand All @@ -131,15 +124,15 @@ void ScrollAreaWidget::setOrigin(Origin origin)
if(origin == Top)
{
// Anchor content to the top of the widget.
d->contentRule.setInput(Rule::Top, rule().top() + *d->vertMargin -
d->contentRule.setInput(Rule::Top, rule().top() + margins().top() -
OperatorRule::minimum(*d->y, *d->maxY));

d->contentRule.clearInput(Rule::Bottom);
}
else
{
// Anchor content to the bottom of the widget.
d->contentRule.setInput(Rule::Bottom, rule().bottom() - *d->vertMargin +
d->contentRule.setInput(Rule::Bottom, rule().bottom() - margins().bottom() +
OperatorRule::minimum(*d->y, *d->maxY));

d->contentRule.clearInput(Rule::Top);
Expand Down Expand Up @@ -255,46 +248,35 @@ bool ScrollAreaWidget::isScrolling() const

Rectanglei ScrollAreaWidget::viewport() const
{
duint const margin = d->margin->valuei();
duint const vertMargin = d->vertMargin->valuei();
Vector4i const margin = margins().toVector();

Rectanglei vp = rule().recti().moved(Vector2i(margin, vertMargin));
if(vp.width() <= 2 * margin)
Rectanglei vp = rule().recti().moved(margin.xy());
if(int(vp.width()) <= margin.x + margin.z)
{
vp.setWidth(0);
}
else
{
vp.bottomRight.x -= 2 * margin;
vp.bottomRight.x -= margin.x + margin.z;
}
if(vp.height() <= 2 * vertMargin)
if(int(vp.height()) <= margin.y + margin.w)
{
vp.setHeight(0);
}
else
{
vp.bottomRight.y -= 2 * vertMargin;
vp.bottomRight.y -= margin.y + margin.w;
}
return vp;
}

Vector2i ScrollAreaWidget::viewportSize() const
{
return Vector2i(rule().width().valuei() - 2 * d->margin->valuei(),
rule().height().valuei() - 2 * d->vertMargin->valuei())
return Vector2i(rule().width().valuei() - margins().width().valuei(),
rule().height().valuei() - margins().height().valuei())
.max(Vector2i(0, 0));
}

int ScrollAreaWidget::topMargin() const
{
return d->vertMargin->valuei();
}

int ScrollAreaWidget::rightMargin() const
{
return d->margin->valuei();
}

Vector2i ScrollAreaWidget::scrollPosition() const
{
DENG2_GUARD(d);
Expand Down Expand Up @@ -441,7 +423,7 @@ void ScrollAreaWidget::glMakeScrollIndicatorGeometry(DefaultVertexBuf::Builder &
if(viewSize == Vector2i(0, 0)) return;

int const indHeight = de::clamp(
d->vertMargin->valuei() * 2,
margins().height().valuei(),
int(float(viewSize.y * viewSize.y) / float(d->contentRule.height().value())),
viewSize.y / 2);

Expand All @@ -450,9 +432,9 @@ void ScrollAreaWidget::glMakeScrollIndicatorGeometry(DefaultVertexBuf::Builder &

float const avail = viewSize.y - indHeight;

verts.makeQuad(Rectanglef(origin + Vector2f(viewSize.x + d->margin->value() - 2 * d->scrollBarWidth,
verts.makeQuad(Rectanglef(origin + Vector2f(viewSize.x + margins().left().value() - 2 * d->scrollBarWidth,
avail - indPos * avail + indHeight),
origin + Vector2f(viewSize.x + d->margin->value() - d->scrollBarWidth,
origin + Vector2f(viewSize.x + margins().left().value() - d->scrollBarWidth,
avail - indPos * avail)),
Vector4f(1, 1, 1, d->scrollOpacity) * d->accent,
d->indicatorUv);
Expand Down

0 comments on commit 1b164a0

Please sign in to comment.