Coverage Report

Created: 2025-03-04 07:22

/src/serenity/Userland/Libraries/LibGfx/TextAlignment.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#pragma once
8
9
#include <AK/Optional.h>
10
#include <AK/StringView.h>
11
12
namespace Gfx {
13
14
#define GFX_ENUMERATE_TEXT_ALIGNMENTS(M) \
15
    M(Center)                            \
16
    M(CenterLeft)                        \
17
    M(CenterRight)                       \
18
    M(TopCenter)                         \
19
    M(TopLeft)                           \
20
    M(TopRight)                          \
21
    M(BottomCenter)                      \
22
    M(BottomLeft)                        \
23
    M(BottomRight)
24
25
enum class TextAlignment {
26
#define __ENUMERATE(x) x,
27
    GFX_ENUMERATE_TEXT_ALIGNMENTS(__ENUMERATE)
28
#undef __ENUMERATE
29
};
30
31
inline bool is_right_text_alignment(TextAlignment alignment)
32
0
{
33
0
    switch (alignment) {
34
0
    case TextAlignment::CenterRight:
35
0
    case TextAlignment::TopRight:
36
0
    case TextAlignment::BottomRight:
37
0
        return true;
38
0
    default:
39
0
        return false;
40
0
    }
41
0
}
42
43
inline bool is_vertically_centered_text_alignment(TextAlignment alignment)
44
0
{
45
0
    switch (alignment) {
46
0
    case TextAlignment::CenterLeft:
47
0
    case TextAlignment::CenterRight:
48
0
    case TextAlignment::Center:
49
0
        return true;
50
0
    default:
51
0
        return false;
52
0
    }
53
0
}
54
55
inline Optional<TextAlignment> text_alignment_from_string(StringView string)
56
0
{
57
0
#define __ENUMERATE(x) \
58
0
    if (string == #x)  \
59
0
        return TextAlignment::x;
60
0
    GFX_ENUMERATE_TEXT_ALIGNMENTS(__ENUMERATE)
61
0
#undef __ENUMERATE
62
0
    return {};
63
0
}
64
65
inline char const* to_string(TextAlignment text_alignment)
66
0
{
67
0
#define __ENUMERATE(x)                      \
68
0
    if (text_alignment == TextAlignment::x) \
69
0
        return #x;
70
0
    GFX_ENUMERATE_TEXT_ALIGNMENTS(__ENUMERATE)
71
0
#undef __ENUMERATE
72
0
    return {};
73
0
}
74
75
}