Пример #1
0
void UIWidget::focusPreviousChild(Fw::FocusReason reason)
{
    if(m_destroyed)
        return;

    UIWidgetPtr toFocus;
    UIWidgetList rotatedChildren(m_children);
    std::reverse(rotatedChildren.begin(), rotatedChildren.end());

    if(m_focusedChild) {
        auto focusedIt = std::find(rotatedChildren.begin(), rotatedChildren.end(), m_focusedChild);
        if(focusedIt != rotatedChildren.end()) {
            std::rotate(rotatedChildren.begin(), focusedIt, rotatedChildren.end());
            rotatedChildren.pop_front();
        }
    }

    // finds next child to focus
    for(const UIWidgetPtr& child : rotatedChildren) {
        if(child->isFocusable() && child->isExplicitlyEnabled() && child->isVisible()) {
            toFocus = child;
            break;
        }
    }

    if(toFocus)
        focusChild(toFocus, reason);
}
Пример #2
0
void UIWidget::focusNextChild(Fw::FocusReason reason, bool rotate)
{
    if(m_destroyed)
        return;

    UIWidgetPtr toFocus;

    if(rotate) {
        UIWidgetList rotatedChildren(m_children);

        if(m_focusedChild) {
            auto focusedIt = std::find(rotatedChildren.begin(), rotatedChildren.end(), m_focusedChild);
            if(focusedIt != rotatedChildren.end()) {
                std::rotate(rotatedChildren.begin(), focusedIt, rotatedChildren.end());
                rotatedChildren.pop_front();
            }
        }

        // finds next child to focus
        for(const UIWidgetPtr& child : rotatedChildren) {
            if(child->isFocusable() && child->isExplicitlyEnabled() && child->isVisible()) {
                toFocus = child;
                break;
            }
        }
    } else {
        auto it = m_children.begin();
        if(m_focusedChild)
            it = std::find(m_children.begin(), m_children.end(), m_focusedChild);

        for(; it != m_children.end(); ++it) {
            const UIWidgetPtr& child = *it;
            if(child != m_focusedChild && child->isFocusable() && child->isExplicitlyEnabled() && child->isVisible()) {
                toFocus = child;
                break;
            }
        }
    }

    if(toFocus && toFocus != m_focusedChild)
        focusChild(toFocus, reason);
}