void forceRender();
void eraseFrame();
- void moveToNextPosition(bool invertDirection = false);
- int getFirstElementIndex(const std::shared_ptr<NavigationElement> &parent);
- int getIncrementForCalculatingNextElement(const std::shared_ptr<NavigationElement> &parent, bool reverse);
+ void moveToNextPosition(bool invertDirection = false, bool movedByAutoScan = false);
+ int getFirstElementIndex(const std::shared_ptr<NavigationElement> &parent, bool invertDirection = false);
+ int getIncrementForCalculatingNextElement(const std::shared_ptr<NavigationElement> &parent, bool invertDirection = false);
ecore::Timer timer;
evas::Shape frame;
void RowScannerImpl::startAutoTraversingUI(bool firstTime)
{
- if (state == State::NO_ELEMENTS) return;
-
- state = State::ACTIVE;
+ if (state == State::NO_ELEMENTS)
+ return;
if (!properties.isAutoScanEnabled()) {
timer.reset();
return;
}
+ state = State::ACTIVE;
+ inactiveLoopCounter = 0;
+
auto firstElementTime = properties.getAutoScanInterval();
firstElementTime += firstTime ? properties.getPauseOnFirstElementTime() : 0;
timer.reset({firstElementTime, properties.getAutoScanInterval()}, [this]() {
- moveToNextPosition();
+ moveToNextPosition(false, true);
return timer.isSet() ? ecore::TimerRepetitionPolicy::renew : ecore::TimerRepetitionPolicy::cancel;
});
- inactiveLoopCounter = 0;
}
void RowScannerImpl::drawFrame(Rectangle dimensions, NavigationInterface::BoxPositionMode mode, Color color)
elm_win_render(Singleton<UniversalSwitch>::instance().getMainWindow()->getHandler());
}
-int RowScannerImpl::getFirstElementIndex(const std::shared_ptr<NavigationElement> &parent)
+int RowScannerImpl::getFirstElementIndex(const std::shared_ptr<NavigationElement> &parent, bool invertDirection)
{
auto count = static_cast<int>(parent->getChildren().size());
- if (count <= 1) return 0;
- int pos = 0;
+ if (count <= 1)
+ return 0;
- auto dir = parent->getScanningDirection();
- if (dir == NavigationElement::Direction::VERTICAL) {
+ if (parent->getScanningDirection() == NavigationElement::Direction::VERTICAL) {
auto direction = properties.getDirectionVertical();
- pos = direction == VerticalScanningDirection::TO_BOTTOM ? 0 : count - 1;
- } else {
- ASSERT(dir == NavigationElement::Direction::HORIZONTAL);
-
- auto direction = properties.getDirectionHorizontal();
- pos = direction == HorizontalScanningDirection::TO_RIGHT ? 0 : count - 1;
+ return (direction == VerticalScanningDirection::TO_BOTTOM) ^ invertDirection ? 0 : count - 1;
}
- return pos;
+
+ auto direction = properties.getDirectionHorizontal();
+ return (direction == HorizontalScanningDirection::TO_RIGHT) ^ invertDirection ? 0 : count - 1;
}
int RowScannerImpl::getIncrementForCalculatingNextElement(const std::shared_ptr<NavigationElement> &parent, bool invertDirection)
return direction == HorizontalScanningDirection::TO_RIGHT ? 1 : -1;
}
-void RowScannerImpl::moveToNextPosition(bool invertDirection)
+void RowScannerImpl::moveToNextPosition(bool invertDirection, bool movedByAutoScan)
{
- if (state == State::NO_ELEMENTS) return;
+ if (state == State::NO_ELEMENTS)
+ return;
auto count = static_cast<int>(currentNavState.parent->getChildren().size());
- Optional<int> newPos;
+ if (count == 0) {
+ ERROR("State should be equal to NO_ELEMENTS");
+ state = State::NO_ELEMENTS;
+ return;
+ }
+
if (currentNavState.childIndex) {
auto increment = getIncrementForCalculatingNextElement(currentNavState.parent, invertDirection);
- auto p = *currentNavState.childIndex + increment;
- if (p >= 0 && p < count)
- newPos = p;
- } else if (count > 0) {
- newPos = getFirstElementIndex(currentNavState.parent);
- }
- if (!newPos) {
- ++inactiveLoopCounter;
- if (inactiveLoopCounter >= properties.getLoopLimitToInaction()) {
- timer.reset();
- eraseFrame();
- state = State::INACTIVE;
+ auto index = *currentNavState.childIndex + increment;
+ if (index >= 0 && index < count) {
+ selectNewElement({currentNavState.parent, index});
+ return;
+ }
+
+ if (currentNavState.parent != rootNavigationElement || properties.isEscapeFrameEnabled()) {
+ selectNewElement({currentNavState.parent, {}});
return;
}
}
- if (!newPos && !properties.isEscapeFrameEnabled() && currentNavState.parent == rootNavigationElement && count > 0) {
- newPos = getFirstElementIndex(currentNavState.parent);
+
+ if (movedByAutoScan && ++inactiveLoopCounter >= properties.getLoopLimitToInaction()) {
+ timer.reset();
+ eraseFrame();
+ currentNavState.childIndex = {};
+ state = State::INACTIVE;
+ return;
}
- selectNewElement({ currentNavState.parent, newPos });
+ selectNewElement({currentNavState.parent, getFirstElementIndex(currentNavState.parent, invertDirection)});
}