aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls/list_item.hpp
blob: a50b24968ca3117916dfe8e4a32b78cc6caee23e (plain)
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
#pragma once

// ReSharper disable once CppUnusedIncludeDirective
#include "pre.hpp"

#include <map>
#include <initializer_list>

#include "ui/control.hpp"

namespace cru::ui::controls
{
    class ListItem : public SingleChildControl
    {
    public:
        static constexpr auto control_type = L"ListItem";

        enum class State
        {
            Normal,
            Hover,
            Select
        };

    private:
        struct StateBrush
        {
            Microsoft::WRL::ComPtr<ID2D1Brush> border_brush;
            Microsoft::WRL::ComPtr<ID2D1Brush> fill_brush;
        };

    public:
        static ListItem* Create(Control* child = nullptr)
        {
            const auto list_item = new ListItem();
            list_item->SetChild(child);
            return list_item;
        }

    private:
        ListItem();
    public:
        ListItem(const ListItem& other) = delete;
        ListItem(ListItem&& other) = delete;
        ListItem& operator=(const ListItem& other) = delete;
        ListItem& operator=(ListItem&& other) = delete;
        ~ListItem() override = default;

        StringView GetControlType() const override;

        State GetState() const
        {
            return state_;
        }

        void SetState(State state);

    private:
        State state_ = State::Normal;
        std::map<State, StateBrush> brushes_{};
    };
}