~aleteoryx/muditaos

ref: 0823d82e5141f44812c54debf07245d0ca746124 muditaos/module-gui/gui/widgets/Alignment.cpp -rw-r--r-- 1.5 KiB
0823d82e — Radoslaw Wicik [EGD-3743] Update copyrights in fies - add empty line after license 5 years 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
#include "Alignment.hpp"

namespace gui
{

    Alignment::Alignment(Alignment::Horizontal valH, Alignment::Vertical valV) : horizontal(valH), vertical(valV)
    {}

    Alignment::Alignment(Alignment::Horizontal valH) : horizontal(valH)
    {}

    Alignment::Alignment(Alignment::Vertical valV) : vertical(valV)
    {}

    bool Alignment::operator==(const Alignment &alignment) const
    {
        return !(horizontal != alignment.horizontal || vertical != alignment.vertical);
    }

    bool Alignment::operator!=(const Alignment &alignment) const
    {
        return (horizontal != alignment.horizontal || vertical != alignment.vertical);
    }

    Position Alignment::calculateHAlignment(Length parentSize, Length childSize) const
    {
        switch (horizontal) {
        case Alignment::Horizontal::Left:
            return 0;
        case (Alignment::Horizontal::Center):
            return (parentSize - childSize) / 2;
        case Alignment::Horizontal::Right:
            return parentSize - childSize;
        default:
            return 0;
        }
    }

    Position Alignment::calculateVAlignment(Length parentSize, Length childSize) const
    {
        switch (vertical) {
        case Alignment::Vertical::Top:
            return 0;
        case (Alignment::Vertical::Center):
            return (parentSize - childSize) / 2;
        case Alignment::Vertical::Bottom:
            return parentSize - childSize;
        default:
            return 0;
        }
    }

} /* namespace gui */