Skip to content

Commit

Permalink
UI|libappfw: Focus indicator appearance and navigation improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Aug 4, 2016
1 parent 2982511 commit 3a14ce8
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 8 deletions.
25 changes: 23 additions & 2 deletions doomsday/apps/client/src/ui/widgets/homeitemwidget.cpp
Expand Up @@ -18,6 +18,7 @@

#include "ui/widgets/homeitemwidget.h"
#include "ui/widgets/homemenuwidget.h"
#include "ui/home/columnwidget.h"
#include "resource/idtech1image.h"

#include <doomsday/LumpCatalog>
Expand Down Expand Up @@ -194,6 +195,19 @@ DENG_GUI_PIMPL(HomeItemWidget)
background->set(bg);
label->setTextColor(selected? selectedTextColor : textColor);
}

/**
* Determines if this item is inside a Home column. This is not true if the item
* is used in a standalone dialog, for example.
*/
bool hasColumnAncestor() const
{
for (Widget *i = self.parentWidget(); i; i = i->parent())
{
if (i->is<ColumnWidget>()) return true;
}
return false;
}
};

HomeItemWidget::HomeItemWidget(Flags flags, String const &name)
Expand Down Expand Up @@ -340,11 +354,18 @@ bool HomeItemWidget::handleEvent(Event const &event)
if (hasFocus() && event.isKey())
{
auto const &key = event.as<KeyEvent>();

if (key.ddKey() == DDKEY_LEFTARROW || key.ddKey() == DDKEY_RIGHTARROW ||
key.ddKey() == DDKEY_UPARROW || key.ddKey() == DDKEY_DOWNARROW)
{
// Fall back to menu and HomeWidget for navigation.
return false;
if ( not ((key.ddKey() == DDKEY_UPARROW && isFirstChild()) ||
(key.ddKey() == DDKEY_DOWNARROW && isLastChild()) ||
(key.ddKey() == DDKEY_LEFTARROW && !d->hasColumnAncestor()) ||
(key.ddKey() == DDKEY_RIGHTARROW && !d->hasColumnAncestor())) )
{
// Fall back to menu and HomeWidget for navigation.
return false;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions doomsday/sdk/libappfw/include/de/framework/guiwidget.h
Expand Up @@ -102,6 +102,7 @@ class LIBAPPFW_PUBLIC GuiWidget : public QObject, public Widget
None, ///< No background, no solid fill.
GradientFrame, ///< Bold round corners, square background.
GradientFrameWithRoundedFill, ///< Bold round corners with solid rounded background.
GradientFrameWithThinBorder, ///< Bold round corners, black thin secondary border.
BorderGlow, ///< Border glow with specified color/thickness.
Blurred, ///< Blurs whatever is showing behind the widget.
BlurredWithBorderGlow,
Expand Down
8 changes: 4 additions & 4 deletions doomsday/sdk/libappfw/include/de/widgets/buttonwidget.h
Expand Up @@ -113,8 +113,8 @@ class LIBAPPFW_PUBLIC ButtonWidget : public LabelWidget
State state() const;

// Events.
void update();
bool handleEvent(Event const &event);
void update() override;
bool handleEvent(Event const &event) override;

public slots:
/**
Expand All @@ -126,8 +126,8 @@ public slots:
void pressed();

protected:
void updateModelViewProjection(GLUniform &uMvp);
void updateStyle();
void updateModelViewProjection(GLUniform &uMvp) override;
void updateStyle() override;

private:
DENG2_PRIVATE(d)
Expand Down
13 changes: 12 additions & 1 deletion doomsday/sdk/libappfw/src/guiwidget.cpp
Expand Up @@ -401,7 +401,10 @@ DENG2_PIMPL(GuiWidget)
return -1;
}

Vector2f const middle = selfRect.middle();
Vector2f const middle = (dir == ui::Up? selfRect.midTop() :
dir == ui::Down? selfRect.midBottom() :
dir == ui::Left? selfRect.midLeft() :
selfRect.midRight() );
Vector2f const delta = otherMiddle - middle;
Vector2f const dirVector = directionVector(dir);
auto dotProd = delta.normalize().dot(dirVector);
Expand Down Expand Up @@ -1117,6 +1120,14 @@ void GuiWidget::glMakeGeometry(DefaultVertexBuf::Builder &verts)
{
case Background::GradientFrame:
case Background::GradientFrameWithRoundedFill:
case Background::GradientFrameWithThinBorder:
if (d->background.type == Background::GradientFrameWithThinBorder)
{
verts.makeFlexibleFrame(rule().recti().shrunk(d->toDevicePixels(2)),
thick,
Vector4f(0, 0, 0, 1),
rootWgt.atlas().imageRectf(rootWgt.boldRoundCorners()));
}
verts.makeFlexibleFrame(rule().recti().shrunk(d->toDevicePixels(1)),
thick,
d->background.color,
Expand Down
4 changes: 3 additions & 1 deletion doomsday/sdk/libappfw/src/widgets/focuswidget.cpp
Expand Up @@ -44,10 +44,12 @@ DENG2_PIMPL(FocusWidget)
{
if (color.target() > .5f)
{
color.setStyle(Animation::EaseIn);
color.setValue(0, FLASH_SPAN);
}
else
{
color.setStyle(Animation::EaseOut);
color.setValue(1, FLASH_SPAN);
}
}
Expand Down Expand Up @@ -86,7 +88,7 @@ void FocusWidget::stopFlashing()
void FocusWidget::update()
{
setOpacity(d->reference? d->reference->visibleOpacity() : 0.f);
set(Background(Background::GradientFrame, d->currentColor(), 6));
set(Background(Background::GradientFrameWithThinBorder, d->currentColor(), 6));

LabelWidget::update();
}
Expand Down

0 comments on commit 3a14ce8

Please sign in to comment.