~aleteoryx/muditaos

d16daf775357cffea1d4448dbce8d0160e7340f3 — Wojtek Rzepecki 4 years ago 3b41f4a
[BH-977] Fix inversed list navigation

Invert of list navigation keys in relation to knob
movements
M module-gui/gui/widgets/ListView.cpp => module-gui/gui/widgets/ListView.cpp +2 -4
@@ 148,6 148,8 @@ namespace gui
            }
        };

        inputCallback = [&](Item &item, const InputEvent &event) { return body->onInput(event); };

        focusChangedCallback = [this]([[maybe_unused]] Item &item) -> bool {
            if (focus) {
                setFocus();


@@ 261,8 263,4 @@ namespace gui
        return Size(request_w, request_h);
    }

    bool ListView::onInput(const InputEvent &inputEvent)
    {
        return body->onInput(inputEvent);
    }
} /* namespace gui */

M module-gui/gui/widgets/ListView.hpp => module-gui/gui/widgets/ListView.hpp +0 -1
@@ 55,7 55,6 @@ namespace gui
        void setAlignment(const Alignment &value) override;

        // virtual methods from Item
        bool onInput(const InputEvent &inputEvent) override;
        bool onDimensionChanged(const BoundingBox &oldDim, const BoundingBox &newDim) override;
        auto handleRequestResize(const Item *, Length request_w, Length request_h) -> Size override;
    };

M module-gui/gui/widgets/ListViewWithArrows.cpp => module-gui/gui/widgets/ListViewWithArrows.cpp +2 -5
@@ 33,6 33,8 @@ namespace gui
            }
        };

        inputCallback = [&](Item &item, const InputEvent &event) { return body->onInput(event); };

        focusChangedCallback = [this]([[maybe_unused]] Item &item) -> bool {
            if (focus) {
                setFocus();


@@ 213,9 215,4 @@ namespace gui
        return true;
    }

    bool ListViewWithArrows::onInput(const InputEvent &inputEvent)
    {
        return body->onInput(inputEvent);
    }

} /* namespace gui */

M module-gui/gui/widgets/ListViewWithArrows.hpp => module-gui/gui/widgets/ListViewWithArrows.hpp +0 -1
@@ 36,7 36,6 @@ namespace gui
        void applySizeRestrictions(unsigned int w, unsigned int h, unsigned int outerLayoutsH, int outerLayoutsMargin);

        void setAlignment(const Alignment &value) override;
        bool onInput(const InputEvent &inputEvent) override;
        bool onDimensionChanged(const BoundingBox &oldDim, const BoundingBox &newDim) override;
    };


M products/BellHybrid/apps/common/CMakeLists.txt => products/BellHybrid/apps/common/CMakeLists.txt +1 -0
@@ 38,6 38,7 @@ target_sources(application-bell-common
        src/options/BellOptionWindow.cpp
        src/options/BellShortOptionWindow.cpp
        src/options/OptionBellMenu.cpp
        src/options/BellOptionsNavigation.cpp
    PUBLIC
        include/common/BellListItemProvider.hpp
        include/common/SoundsRepository.hpp

A products/BellHybrid/apps/common/include/common/options/BellOptionsNavigation.hpp => products/BellHybrid/apps/common/include/common/options/BellOptionsNavigation.hpp +11 -0
@@ 0,0 1,11 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <InputEvent.hpp>

namespace gui
{
    InputEvent invertNavigationDirection(const InputEvent &inputEvent);
}; // namespace gui

M products/BellHybrid/apps/common/src/options/BellOptionWindow.cpp => products/BellHybrid/apps/common/src/options/BellOptionWindow.cpp +6 -0
@@ 3,6 3,7 @@

#include "common/options/BellOptionWindow.hpp"
#include "common/options/OptionBellMenu.hpp"
#include "common/options/BellOptionsNavigation.hpp"

#include <messages/OptionsWindow.hpp>
#include <TextFixedSize.hpp>


@@ 38,6 39,11 @@ namespace gui
        optionsList->prepareRebuildCallback = [this]() { recreateOptions(); };
        optionsModel->createData(options);

        auto storedCallback        = optionsList->inputCallback;
        optionsList->inputCallback = [&, storedCallback](Item &item, const InputEvent &event) {
            return storedCallback(item, invertNavigationDirection(event));
        };

        setFocusItem(optionsList);
    }


A products/BellHybrid/apps/common/src/options/BellOptionsNavigation.cpp => products/BellHybrid/apps/common/src/options/BellOptionsNavigation.cpp +19 -0
@@ 0,0 1,19 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "common/options/BellOptionsNavigation.hpp"

namespace gui
{
    InputEvent invertNavigationDirection(const InputEvent &inputEvent)
    {
        InputEvent input = inputEvent;
        if (input.is(KeyCode::KEY_UP)) {
            input.setKeyCode(KeyCode::KEY_DOWN);
        }
        else if (input.is(KeyCode::KEY_DOWN)) {
            input.setKeyCode(KeyCode::KEY_UP);
        }
        return input;
    }
}; // namespace gui

M products/BellHybrid/apps/common/src/options/BellShortOptionWindow.cpp => products/BellHybrid/apps/common/src/options/BellShortOptionWindow.cpp +7 -0
@@ 3,6 3,7 @@

#include "common/options/BellShortOptionWindow.hpp"
#include "common/options/OptionBellMenu.hpp"
#include "common/options/BellOptionsNavigation.hpp"

#include <messages/OptionsWindow.hpp>
#include <TextFixedSize.hpp>


@@ 14,6 15,11 @@ namespace gui
                                    app, style::bell_options::h + 2 * style::bell_options::option_margin))
    {
        buildInterface();

        auto storedCallback        = optionsList->inputCallback;
        optionsList->inputCallback = [&, storedCallback](Item &item, const InputEvent &event) {
            return storedCallback(item, invertNavigationDirection(event));
        };
    }

    void BellShortOptionWindow::rebuild()


@@ 72,4 78,5 @@ namespace gui

        optionsList->rebuildList(listview::RebuildType::InPlace);
    }

} /* namespace gui */