Skip to content

Commit

Permalink
Widgets: Setting input focus depending on the context
Browse files Browse the repository at this point in the history
Added a method for offering focus to widgets. This is used for setting
the appropriate focus when a popup is opened (e.g., menu, dialog).

IssueID #2131
  • Loading branch information
skyjake committed Jul 27, 2016
1 parent 5beae8b commit b024b9d
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 37 deletions.
7 changes: 4 additions & 3 deletions doomsday/sdk/libappfw/include/de/widgets/dialogwidget.h
Expand Up @@ -230,8 +230,9 @@ class LIBAPPFW_PUBLIC DialogWidget : public PopupWidget
ui::ActionItem *defaultActionItem();

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

public slots:
void accept(int result = 1);
Expand All @@ -242,7 +243,7 @@ public slots:
void rejected(int result);

protected:
void preparePanelForOpening();
void preparePanelForOpening() override;

/**
* Derived classes can override this to do additional tasks before
Expand Down
5 changes: 3 additions & 2 deletions doomsday/sdk/libappfw/include/de/widgets/menuwidget.h
Expand Up @@ -173,8 +173,9 @@ class LIBAPPFW_PUBLIC MenuWidget : public ScrollAreaWidget, public IAssetGroup
Rule const &contentHeight() const;

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

public slots:
void dismissPopups();
Expand Down
9 changes: 5 additions & 4 deletions doomsday/sdk/libappfw/include/de/widgets/popupmenuwidget.h
Expand Up @@ -44,12 +44,13 @@ class LIBAPPFW_PUBLIC PopupMenuWidget : public PopupWidget
void setColorTheme(ColorTheme theme);

// Events.
void update();
void offerFocus() override;
void update() override;

protected:
void glMakeGeometry(DefaultVertexBuf::Builder &verts);
void preparePanelForOpening();
void panelClosing();
void glMakeGeometry(DefaultVertexBuf::Builder &verts) override;
void preparePanelForOpening() override;
void panelClosing() override;

private:
DENG2_PRIVATE(d)
Expand Down
11 changes: 6 additions & 5 deletions doomsday/sdk/libappfw/include/de/widgets/popupwidget.h
Expand Up @@ -112,14 +112,15 @@ class LIBAPPFW_PUBLIC PopupWidget : public PanelWidget
ButtonWidget &closeButton();

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

protected:
void glMakeGeometry(DefaultVertexBuf::Builder &verts);
void updateStyle();
void glMakeGeometry(DefaultVertexBuf::Builder &verts) override;
void updateStyle() override;

virtual void preparePanelForOpening();
virtual void panelDismissed();
virtual void preparePanelForOpening() override;
virtual void panelDismissed() override;

private:
DENG2_PRIVATE(d)
Expand Down
7 changes: 5 additions & 2 deletions doomsday/sdk/libappfw/src/widgets/dialogwidget.cpp
Expand Up @@ -579,6 +579,11 @@ ui::ActionItem *DialogWidget::defaultActionItem()
return const_cast<ui::ActionItem *>(d->findDefaultAction());
}

void DialogWidget::offerFocus()
{
root().setFocus(d->findDefaultButton());
}

void DialogWidget::update()
{
PopupWidget::update();
Expand Down Expand Up @@ -682,8 +687,6 @@ void DialogWidget::prepare()
// Mouse needs to be untrapped for the user to be access the dialog.
d->untrapper.reset(new Untrapper(root().window()));

root().setFocus(d->findDefaultButton());

if (openingDirection() == ui::NoDirection)
{
// Center the dialog.
Expand Down
18 changes: 1 addition & 17 deletions doomsday/sdk/libappfw/src/widgets/focuswidget.cpp
Expand Up @@ -42,18 +42,6 @@ DENG2_PIMPL(FocusWidget)

void flash()
{
// Flashing depends on the reference widget's visibility.
//float const maxOpacity = (reference? reference->visibleOpacity() : 1.f);
if (reference)
{
self.show(reference->isVisible());
}

/*if (color.target() == 0)
{
color.setValue(.8f * maxOpacity, FLASH_SPAN + .1, .1);
}
else*/
if (color.target() > .5f)
{
color.setValue(0, FLASH_SPAN);
Expand Down Expand Up @@ -98,11 +86,7 @@ void FocusWidget::stopFlashing()
void FocusWidget::update()
{
setOpacity(d->reference? d->reference->visibleOpacity() : 0.f);

if (isVisible())
{
set(Background(Background::GradientFrame, d->currentColor(), 6));
}
set(Background(Background::GradientFrame, d->currentColor(), 6));

LabelWidget::update();
}
Expand Down
16 changes: 16 additions & 0 deletions doomsday/sdk/libappfw/src/widgets/menuwidget.cpp
Expand Up @@ -593,6 +593,22 @@ Rule const &MenuWidget::contentHeight() const
return *d->outContentHeight;
}

void MenuWidget::offerFocus()
{
foreach (Widget *w, childWidgets())
{
if (GuiWidget const *widget = w->maybeAs<GuiWidget>())
{
if (!widget->behavior().testFlag(Hidden) &&
widget->behavior().testFlag(Focusable))
{
root().setFocus(w);
return;
}
}
}
}

ChildWidgetOrganizer &MenuWidget::organizer()
{
return d->organizer;
Expand Down
5 changes: 5 additions & 0 deletions doomsday/sdk/libappfw/src/widgets/popupmenuwidget.cpp
Expand Up @@ -439,6 +439,11 @@ void PopupMenuWidget::setColorTheme(ColorTheme theme)
d->updateButtonColors();
}

void PopupMenuWidget::offerFocus()
{
menu().offerFocus();
}

void PopupMenuWidget::update()
{
PopupWidget::update();
Expand Down
13 changes: 9 additions & 4 deletions doomsday/sdk/libappfw/src/widgets/popupwidget.cpp
Expand Up @@ -350,6 +350,14 @@ ButtonWidget &PopupWidget::closeButton()
return *d->close;
}

void PopupWidget::offerFocus()
{
if (d->close)
{
root().setFocus(d->close);
}
}

GuiWidget::Background PopupWidget::infoStyleBackground() const
{
return Background(style().colors().colorf("popup.info.background"),
Expand Down Expand Up @@ -479,10 +487,7 @@ void PopupWidget::preparePanelForOpening()

d->updateLayout();

if (d->close)
{
root().setFocus(d->close);
}
offerFocus();
}

void PopupWidget::panelDismissed()
Expand Down
1 change: 1 addition & 0 deletions doomsday/sdk/libcore/include/de/widgets/widget.h
Expand Up @@ -300,6 +300,7 @@ class DENG2_PUBLIC Widget
virtual void viewResized();
virtual void focusGained();
virtual void focusLost();
virtual void offerFocus();
virtual void update();
virtual void draw();
virtual void preDrawChildren();
Expand Down
3 changes: 3 additions & 0 deletions doomsday/sdk/libcore/src/widgets/widget.cpp
Expand Up @@ -764,6 +764,9 @@ void Widget::focusGained()
void Widget::focusLost()
{}

void Widget::offerFocus()
{}

void Widget::update()
{}

Expand Down

0 comments on commit b024b9d

Please sign in to comment.