~aleteoryx/muditaos

muditaos/module-gui/gui/widgets/ListView.hpp -rw-r--r-- 2.2 KiB
a405cad6Aleteoryx trim readme 6 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#pragma once

#include "ListViewEngine.hpp"
#include "ListItemProvider.hpp"
#include "BoxLayout.hpp"

namespace gui
{

    class ListViewScroll : public Rect
    {
      private:
        unsigned int storedStartIndex = 0;
        unsigned int currentPage      = listview::nPos;
        unsigned int pagesCount       = 0;
        int topMargin                 = style::margins::big;

        void updateProportional(const ListViewScrollUpdateData &data);
        void updateFixed(const ListViewScrollUpdateData &data);
        void updatePreRendered(const ListViewScrollUpdateData &data);

      public:
        listview::ScrollBarType type = listview::ScrollBarType::None;

        ListViewScroll(
            Item *parent, unsigned int x, unsigned int y, unsigned int w, unsigned int h, listview::ScrollBarType type);

        bool shouldShowScroll(unsigned int listPageSize, unsigned int elementsCount);
        void updateStartConditions(const ListViewScrollSetupData &data);
        void update(const ListViewScrollUpdateData &data);
        void setTopMargin(int _topMargin);
    };

    class ListView : public Rect, public ListViewEngine
    {
      protected:
        ListViewScroll *scroll = nullptr;
        void applyScrollCallbacks();
        void determineFetchType(listview::ScrollBarType scrollType);
        void setFocus() override;

      public:
        ListView(Item *parent,
                 unsigned int x,
                 unsigned int y,
                 unsigned int w,
                 unsigned int h,
                 std::shared_ptr<ListItemProvider> prov,
                 listview::ScrollBarType scrollType = listview::ScrollBarType::Proportional);

        void setScrollTopMargin(int value);
        void clear() override;
        void setAlignment(const Alignment &value) override;

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

} /* namespace gui */