ladybird/Userland/Libraries/LibGfx/TextAlignment.h
Brian Gianforcaro 1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00

73 lines
1.6 KiB
C++

/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Optional.h>
#include <AK/StringView.h>
namespace Gfx {
#define GFX_ENUMERATE_TEXT_ALIGNMENTS(M) \
M(TopLeft) \
M(CenterLeft) \
M(Center) \
M(CenterRight) \
M(TopRight) \
M(BottomRight)
enum class TextAlignment {
#define __ENUMERATE(x) x,
GFX_ENUMERATE_TEXT_ALIGNMENTS(__ENUMERATE)
#undef __ENUMERATE
};
inline bool is_right_text_alignment(TextAlignment alignment)
{
switch (alignment) {
case TextAlignment::CenterRight:
case TextAlignment::TopRight:
case TextAlignment::BottomRight:
return true;
default:
return false;
}
}
inline bool is_vertically_centered_text_alignment(TextAlignment alignment)
{
switch (alignment) {
case TextAlignment::CenterLeft:
case TextAlignment::CenterRight:
case TextAlignment::Center:
return true;
default:
return false;
}
}
inline Optional<TextAlignment> text_alignment_from_string(const StringView& string)
{
#define __ENUMERATE(x) \
if (string == #x) \
return TextAlignment::x;
GFX_ENUMERATE_TEXT_ALIGNMENTS(__ENUMERATE)
#undef __ENUMERATE
return {};
}
inline const char* to_string(TextAlignment text_alignment)
{
#define __ENUMERATE(x) \
if (text_alignment == TextAlignment::x) \
return #x;
GFX_ENUMERATE_TEXT_ALIGNMENTS(__ENUMERATE)
#undef __ENUMERATE
return {};
}
}