Program Listing for File vertical_scroll_logic_handler.hpp

Return to documentation for file (src/tap/display/vertical_scroll_logic_handler.hpp)

/*
 * Copyright (c) 2020-2021 Advanced Robotics at the University of Washington <robomstr@uw.edu>
 *
 * This file is part of Taproot.
 *
 * Taproot is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Taproot is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Taproot.  If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef TAPROOT_VERTICAL_SCROLL_LOGIC_HANDLER_HPP_
#define TAPROOT_VERTICAL_SCROLL_LOGIC_HANDLER_HPP_

#include <inttypes.h>

#include "modm/ui/menu/menu_buttons.hpp"

namespace tap
{
class Drivers;
namespace display
{
class VerticalScrollLogicHandler
{
public:
    VerticalScrollLogicHandler(Drivers *drivers, int8_t size, int8_t maxEntries);

    void setSize(int8_t size);

    void onShortButtonPress(modm::MenuButtons::Button button);

    bool acknowledgeCursorChanged();

    inline int8_t getCursorIndex() const { return cursorIndex; }

    inline int8_t getSmallestIndexDisplayed() const { return smallestIndexDisplayed; }

    inline int8_t getLargestIndexDisplayed() const
    {
        return (smallestIndexDisplayed + maxEntries < size ? smallestIndexDisplayed + maxEntries
                                                           : size) -
               1;
    }

    inline int8_t getSize() const { return size; }

private:
    Drivers *drivers;

    const int8_t maxEntries;

    int8_t size;

    int8_t cursorIndex;

    int8_t smallestIndexDisplayed;

    bool cursorChanged;

    inline void setCursor(int8_t newCursor)
    {
        cursorIndex = newCursor;
        cursorChanged = true;
    }
};  // class VerticalScrollLogicHandler
}  // namespace display
}  // namespace tap

#endif  // TAPROOT_VERTICAL_SCROLL_LOGIC_HANDLER_HPP_