Skip to content

Commit

Permalink
UI|Widgets|libappfw: Use a smooth opening animation for sidebars
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Apr 10, 2017
1 parent c5752d7 commit d4e23b7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
1 change: 1 addition & 0 deletions doomsday/apps/client/src/ui/widgets/sidebarwidget.cpp
Expand Up @@ -81,6 +81,7 @@ SidebarWidget::SidebarWidget(String const &titleText, String const &name)
setSizePolicy(Fixed);
setWaitForContentReady(false);
setOpeningDirection(Left);
setAnimationStyle(Smooth);
set(Background(style().colors().colorf("background")).withSolidFillOpacity(1));

// Set up the editor UI.
Expand Down
4 changes: 4 additions & 0 deletions doomsday/sdk/libappfw/include/de/widgets/panelwidget.h
Expand Up @@ -49,11 +49,15 @@ class LIBAPPFW_PUBLIC PanelWidget : public GuiWidget
*/
DENG2_DEFINE_AUDIENCE2(Close, void panelBeingClosed(PanelWidget &))

enum AnimationStyle { Bouncy, Smooth };

public:
PanelWidget(String const &name = String());

void setWaitForContentReady(bool yes);

void setAnimationStyle(AnimationStyle style);

/**
* Enables or disables mouse event eating. The default is that a panel eats
* events that hit it.
Expand Down
44 changes: 26 additions & 18 deletions doomsday/sdk/libappfw/src/widgets/panelwidget.cpp
Expand Up @@ -36,22 +36,19 @@ static TimeDelta const CLOSING_ANIM_SPAN = 0.3;
DENG_GUI_PIMPL(PanelWidget)
, DENG2_OBSERVES(Asset, StateChange)
{
//typedef DefaultVertexBuf VertexBuf;

bool waitForContentReady = true;
bool eatMouseEvents = true;
bool opened = false;
ui::Direction dir = ui::Down;
ui::SizePolicy secondaryPolicy = ui::Expand;
GuiWidget *content = nullptr;
AnimationRule *openingRule;
AnimationStyle openingStyle = Bouncy;
QTimer dismissTimer;
std::unique_ptr<AssetGroup> pendingShow;

// GL objects.
GuiVertexBuilder verts;
//Drawable drawable;
//GLUniform uMvpMatrix { "uMvpMatrix", GLUniform::Mat4 };

Impl(Public *i) : Base(i)
{
Expand All @@ -69,14 +66,10 @@ DENG_GUI_PIMPL(PanelWidget)

void glInit()
{
/*drawable.addBuffer(new VertexBuf);
shaders().build(drawable.program(), "generic.textured.color")
<< uMvpMatrix << uAtlas();*/
}

void glDeinit()
{
//drawable.clear();
verts.clear();
}

Expand Down Expand Up @@ -114,11 +107,8 @@ DENG_GUI_PIMPL(PanelWidget)
if (self().hasChangedPlace(pos) || self().geometryRequested())
{
self().requestGeometry(false);

//VertexBuf::Builder verts;
verts.clear();
self().glMakeGeometry(verts);
//drawable.buffer<VertexBuf>().setVertices(gl::TriangleStrip, verts, gl::Static);
}
}

Expand All @@ -132,7 +122,16 @@ DENG_GUI_PIMPL(PanelWidget)
{
openingRule->set(content->rule().width(), span);
}
openingRule->setStyle(Animation::Bounce, 12);

switch (openingStyle)
{
case Bouncy:
openingRule->setStyle(Animation::Bounce, 12);
break;
case Smooth:
openingRule->setStyle(Animation::EaseBoth);
break;
}
}

void close(TimeDelta delay)
Expand All @@ -145,7 +144,15 @@ DENG_GUI_PIMPL(PanelWidget)

// Begin the closing animation.
openingRule->set(0, CLOSING_ANIM_SPAN + delay, delay);
openingRule->setStyle(Animation::EaseIn);
switch (openingStyle)
{
case Bouncy:
openingRule->setStyle(Animation::EaseIn);
break;
case Smooth:
openingRule->setStyle(Animation::EaseBoth);
break;
}

self().panelClosing();

Expand Down Expand Up @@ -222,7 +229,12 @@ void PanelWidget::setWaitForContentReady(bool yes)
d->waitForContentReady = yes;
}

void de::PanelWidget::setEatMouseEvents(bool yes)
void PanelWidget::setAnimationStyle(AnimationStyle style)
{
d->openingStyle = style;
}

void PanelWidget::setEatMouseEvents(bool yes)
{
d->eatMouseEvents = yes;
}
Expand Down Expand Up @@ -302,9 +314,6 @@ void PanelWidget::close(TimeDelta delayBeforeClosing)
void PanelWidget::viewResized()
{
GuiWidget::viewResized();

//d->uMvpMatrix = root().projMatrix2D();

requestGeometry();
}

Expand All @@ -322,7 +331,6 @@ bool PanelWidget::handleEvent(Event const &event)
// Eat buttons that land on the panel.
if (hitTest(mouse.pos()))
{
//root().setFocus(0);
return true;
}
}
Expand Down

0 comments on commit d4e23b7

Please sign in to comment.