~aleteoryx/muditaos

muditaos/module-gui/gui/widgets/Alignment.cpp -rw-r--r-- 1.3 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
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#include "Alignment.hpp"

namespace gui
{
    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 */