Skip to content

Commit

Permalink
libappfw: Improved animations
Browse files Browse the repository at this point in the history
TabWidget selection highlight moves with an animation.
The FoldPanelWidget animation is slightly faster.
  • Loading branch information
skyjake committed Jan 9, 2016
1 parent 836440a commit 12b6bf0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion doomsday/sdk/libappfw/src/widgets/foldpanelwidget.cpp
Expand Up @@ -25,7 +25,7 @@ namespace de {

using namespace ui;

static TimeDelta const INDICATOR_ANIM_SPAN = 0.7;
static TimeDelta const INDICATOR_ANIM_SPAN = 0.6;

DENG2_PIMPL_NOREF(FoldPanelWidget)
{
Expand Down
35 changes: 30 additions & 5 deletions doomsday/sdk/libappfw/src/widgets/tabwidget.cpp
Expand Up @@ -20,6 +20,8 @@
#include "de/ui/ListData"
#include "de/MenuWidget"

#include <de/ScalarRule>

Q_DECLARE_METATYPE(de::ui::Item const *)

namespace de {
Expand All @@ -35,6 +37,8 @@ DENG_GUI_PIMPL(TabWidget)
bool needUpdate = false;
bool invertedStyle = false;
LabelWidget *selected = nullptr;
ScalarRule *selLeft = nullptr;
ScalarRule *selWidth = nullptr;

Instance(Public *i) : Base(i)
{
Expand All @@ -52,10 +56,17 @@ DENG_GUI_PIMPL(TabWidget)
.setInput(Rule::AnchorX, self.rule().left() + self.rule().width() / 2)
.setInput(Rule::Top, self.rule().top())
.setAnchorPoint(Vector2f(.5f, 0));


// Selection highlight.
self.add(selected = new LabelWidget);
}

~Instance()
{
releaseRef(selLeft);
releaseRef(selWidth);
}

void widgetCreatedForItem(GuiWidget &widget, ui::Item const &)
{
// Set the font and style.
Expand All @@ -69,7 +80,7 @@ DENG_GUI_PIMPL(TabWidget)
}

void buttonPressed(ButtonWidget &button)
{
{
self.setCurrent(buttons->items().find(*buttons->organizer().findItemForWidget(button)));
}

Expand All @@ -96,7 +107,7 @@ DENG_GUI_PIMPL(TabWidget)
void updateSelected()
{
selected->set(Background(style().colors().colorf(invertedStyle? "tab.inverted.selected" : "tab.selected")));

for(ui::Data::Pos i = 0; i < buttons->items().size(); ++i)
{
bool const sel = (i == current);
Expand All @@ -115,10 +126,24 @@ DENG_GUI_PIMPL(TabWidget)
}
if(sel)
{
TimeDelta span = .2;
if(!selLeft)
{
// Initialize the animated rules for positioning the
// selection highlight.
selLeft = new ScalarRule(0);
selWidth = new ScalarRule(0);
selected->rule()
.setInput(Rule::Width, *selWidth)
.setInput(Rule::Left, *selLeft);
span = 0;
}
// Animate to new position.
selLeft ->set(w.rule().left(), span);
selWidth->set(w.rule().width(), span);

selected->rule()
.setInput(Rule::Width, w.rule().width())
.setInput(Rule::Height, style().rules().rule("halfunit"))
.setInput(Rule::Left, w.rule().left())
.setInput(Rule::Top, w.rule().bottom());
}
}
Expand Down

0 comments on commit 12b6bf0

Please sign in to comment.