aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls/linear_layout.hpp
blob: b7ca42ec1bc62a81ead20bac39c511f31691c19c (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
#pragma once

#include "ui/control.hpp"

namespace cru::ui::controls
{
    // Min length of main side in layout params is of no meaning.
    // All children will layout from start and redundant length is blank.
    class LinearLayout : public Control
    {
    public:
        static constexpr auto control_type = L"LinearLayout";

        enum class Orientation
        {
            Horizontal,
            Vertical
        };

        static LinearLayout* Create(const Orientation orientation = Orientation::Vertical, const std::initializer_list<Control*>& children = std::initializer_list<Control*>())
        {
            const auto linear_layout = new LinearLayout(orientation);
                        for (const auto control : children)
                linear_layout->AddChild(control);
            return linear_layout;
        }

    protected:
        explicit LinearLayout(Orientation orientation = Orientation::Vertical);

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

        StringView GetControlType() const override final;

    protected:
        Size OnMeasureContent(const Size& available_size) override;
        void OnLayoutContent(const Rect& rect) override;

    private:
        Orientation orientation_;
    };
}