aboutsummaryrefslogtreecommitdiff
path: root/CruUI/ui/layout_base.h
blob: bae01949797737bc78fd8a6e8d2d1a271207ef32 (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
63
64
65
66
67
68
69
70
#pragma once

namespace cru
{
    namespace ui
    {
        enum class MeasureMode
        {
            Exactly,
            Content,
            Stretch
        };

        struct MeasureLength final
        {
            explicit MeasureLength(const float length = 0.0, const MeasureMode mode = MeasureMode::Content)
                : length(length), mode(mode)
            {

            }

            bool Validate() const
            {
                if (mode == MeasureMode::Exactly && length < 0.0)
                {
#ifdef CRU_DEBUG
                    ::OutputDebugStringW(L"MeasureLength validation error: mode is Exactly but length is less than 0.\n");
#endif
                    return false;
                }
                return true;
            }

            float length;
            MeasureMode mode;
        };

        struct BasicLayoutParams
        {
            BasicLayoutParams() = default;
            BasicLayoutParams(const BasicLayoutParams&) = default;
            BasicLayoutParams(BasicLayoutParams&&) = default;
            BasicLayoutParams& operator = (const BasicLayoutParams&) = default;
            BasicLayoutParams& operator = (BasicLayoutParams&&) = default;
            virtual ~BasicLayoutParams() = default;

            bool Validate() const
            {
                if (!width.Validate())
                {
#ifdef CRU_DEBUG
                    ::OutputDebugStringW(L"Width(MeasureLength) is not valid.");
#endif
                    return false;
                }
                if (!height.Validate())
                {
#ifdef CRU_DEBUG
                    ::OutputDebugStringW(L"Height(MeasureLength) is not valid.");
#endif
                    return false;
                }
                return true;
            }

            MeasureLength width;
            MeasureLength height;
        };
    }
}