Skip to content

Commit

Permalink
Widgets|Home|libappfw: Focus highlight and scrolling improvements
Browse files Browse the repository at this point in the history
Mouse wheel now disengages the keyboard highlight, which stops the
menus from scrolling to the focused item and potentially confusing
the user with unintended scrolls.

Improved selected item handling in Home menus.
  • Loading branch information
skyjake committed Jun 25, 2017
1 parent ec4e362 commit b0df659
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 41 deletions.
30 changes: 0 additions & 30 deletions doomsday/apps/client/src/ui/home/columnwidget.cpp
Expand Up @@ -96,16 +96,11 @@ DENG_GUI_PIMPL(ColumnWidget)
HeaderWidget *header;
Rule const *maxContentWidth = nullptr;
Vector4f backTintColor;

//GLProgram bgProgram;
//GLUniform uSaturation { "uSaturation", GLUniform::Float }; // background saturation
//GLUniform uBgColor { "uColor", GLUniform::Vec4 };
Animation backSaturation { 0.f, Animation::Linear };

Impl(Public *i) : Base(i)
{
back = new LabelWidget;
//back->setCustomShader(&bgProgram);
back->margins().setZero();

scrollArea = new ScrollAreaWidget;
Expand All @@ -125,19 +120,6 @@ DENG_GUI_PIMPL(ColumnWidget)
{
releaseRef(maxContentWidth);
}

/*void glInit()
{
root().shaders().build(bgProgram, "generic.textured.hsv.color_ucolor")
<< uSaturation
<< uBgColor
<< root().uAtlas();
}
void glDeinit()
{
bgProgram.clear();
}*/
};

ColumnWidget::ColumnWidget(String const &name)
Expand Down Expand Up @@ -225,20 +207,8 @@ void ColumnWidget::update()
GuiWidget::update();

d->back->setSaturation(d->backSaturation);
/*d->uSaturation = d->backSaturation;
d->uBgColor = Vector4f(1, 1, 1, visibleOpacity());*/
}

/*void ColumnWidget::glInit()
{
d->glInit();
}
void ColumnWidget::glDeinit()
{
d->bgProgram.clear();
}*/

void ColumnWidget::updateStyle()
{
GuiWidget::updateStyle();
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/ui/home/gamecolumnwidget.cpp
Expand Up @@ -624,7 +624,7 @@ void GameColumnWidget::setHighlighted(bool highlighted)
}
else
{
//root().setFocus(nullptr);
root().setFocus(nullptr);
d->menu->unselectAll();
}
d->showActions(highlighted);
Expand Down
27 changes: 19 additions & 8 deletions doomsday/apps/client/src/ui/widgets/homemenuwidget.cpp
Expand Up @@ -20,6 +20,8 @@
#include "ui/widgets/homeitemwidget.h"
#include "ui/home/columnwidget.h"

#include <de/FocusWidget>

using namespace de;

DENG_GUI_PIMPL(HomeMenuWidget)
Expand Down Expand Up @@ -113,19 +115,28 @@ ui::DataPos HomeMenuWidget::selectedIndex() const

void HomeMenuWidget::setSelectedIndex(ui::DataPos index)
{
DENG2_ASSERT(hasRoot());

root().setFocus(nullptr);
unselectAll();

if (auto *widget = itemWidget<HomeItemWidget>(index))
{
widget->acquireFocus();

// Check if we can scroll to the selected widget right away.
// If not, we are observing the asset and will scroll when it is ready.
if (assets().isReady())
{
d->scrollToSelected();
}
else
// Focus-based scrolling is only enabled when keyboard focus is in use.
if (root().focusIndicator().isKeyboardFocusActive())
{
assets().audienceForStateChange() += d;
// Check if we can scroll to the selected widget right away.
// If not, we are observing the asset and will scroll when it is ready.
if (assets().isReady())
{
d->scrollToSelected();
}
else
{
assets().audienceForStateChange() += d;
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions doomsday/sdk/libappfw/include/de/widgets/focuswidget.h
Expand Up @@ -42,6 +42,11 @@ class LIBAPPFW_PUBLIC FocusWidget : public LabelWidget
void fadeIn();
void fadeOut();

/**
* Determines whether the focus widget is active and flashing.
*/
bool isKeyboardFocusActive() const;

// Events.
void update() override;

Expand Down
5 changes: 3 additions & 2 deletions doomsday/sdk/libappfw/src/guirootwidget.cpp
Expand Up @@ -343,8 +343,9 @@ bool GuiRootWidget::processEvent(Event const &event)
{
window().glActivate();

if (event.type() == Event::MouseButton &&
event.as<MouseEvent>().state() != MouseEvent::Released)
if ((event.type() == Event::MouseButton &&
event.as<MouseEvent>().state() != MouseEvent::Released) ||
event.type() == Event::MouseWheel)
{
d->focusIndicator->fadeOut();
}
Expand Down
5 changes: 5 additions & 0 deletions doomsday/sdk/libappfw/src/widgets/focuswidget.cpp
Expand Up @@ -96,6 +96,11 @@ void FocusWidget::fadeOut()
d->fadeOpacity = 0.f;
}

bool FocusWidget::isKeyboardFocusActive() const
{
return d->fadeOpacity > 0 && d->reference;
}

void FocusWidget::update()
{
setOpacity(d->fadeOpacity * (d->reference? d->reference->visibleOpacity() : 0.f));
Expand Down

0 comments on commit b0df659

Please sign in to comment.