2020-01-18 08:38:21 +00:00
|
|
|
/*
|
2024-10-04 11:19:50 +00:00
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
2020-01-18 08:38:21 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 08:38:21 +00:00
|
|
|
*/
|
|
|
|
|
2019-02-28 10:27:04 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-09-14 16:28:22 +00:00
|
|
|
#include <AK/Optional.h>
|
|
|
|
#include <AK/StringView.h>
|
|
|
|
|
2020-02-06 10:56:38 +00:00
|
|
|
namespace Gfx {
|
|
|
|
|
2020-09-15 19:33:37 +00:00
|
|
|
#define GFX_ENUMERATE_TEXT_ALIGNMENTS(M) \
|
|
|
|
M(Center) \
|
2021-05-21 00:03:02 +00:00
|
|
|
M(CenterLeft) \
|
2020-09-15 19:33:37 +00:00
|
|
|
M(CenterRight) \
|
2022-02-27 00:33:48 +00:00
|
|
|
M(TopCenter) \
|
2021-05-21 00:03:02 +00:00
|
|
|
M(TopLeft) \
|
2020-09-15 19:33:37 +00:00
|
|
|
M(TopRight) \
|
2022-02-27 00:33:48 +00:00
|
|
|
M(BottomCenter) \
|
2021-05-21 00:03:02 +00:00
|
|
|
M(BottomLeft) \
|
2020-09-15 19:33:37 +00:00
|
|
|
M(BottomRight)
|
|
|
|
|
2019-06-07 15:13:23 +00:00
|
|
|
enum class TextAlignment {
|
2020-09-15 19:33:37 +00:00
|
|
|
#define __ENUMERATE(x) x,
|
|
|
|
GFX_ENUMERATE_TEXT_ALIGNMENTS(__ENUMERATE)
|
|
|
|
#undef __ENUMERATE
|
2019-06-07 09:46:55 +00:00
|
|
|
};
|
2019-04-24 21:46:19 +00:00
|
|
|
|
|
|
|
inline bool is_right_text_alignment(TextAlignment alignment)
|
|
|
|
{
|
|
|
|
switch (alignment) {
|
|
|
|
case TextAlignment::CenterRight:
|
2019-09-06 17:23:36 +00:00
|
|
|
case TextAlignment::TopRight:
|
2020-08-21 14:52:39 +00:00
|
|
|
case TextAlignment::BottomRight:
|
2019-04-24 21:46:19 +00:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2020-02-06 10:56:38 +00:00
|
|
|
|
2020-09-19 16:21:24 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-10 23:55:02 +00:00
|
|
|
inline Optional<TextAlignment> text_alignment_from_string(StringView string)
|
2020-09-14 16:28:22 +00:00
|
|
|
{
|
2020-09-15 19:33:37 +00:00
|
|
|
#define __ENUMERATE(x) \
|
|
|
|
if (string == #x) \
|
|
|
|
return TextAlignment::x;
|
|
|
|
GFX_ENUMERATE_TEXT_ALIGNMENTS(__ENUMERATE)
|
|
|
|
#undef __ENUMERATE
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2022-04-01 17:58:27 +00:00
|
|
|
inline char const* to_string(TextAlignment text_alignment)
|
2020-09-15 19:33:37 +00:00
|
|
|
{
|
|
|
|
#define __ENUMERATE(x) \
|
|
|
|
if (text_alignment == TextAlignment::x) \
|
|
|
|
return #x;
|
|
|
|
GFX_ENUMERATE_TEXT_ALIGNMENTS(__ENUMERATE)
|
|
|
|
#undef __ENUMERATE
|
2020-09-14 16:28:22 +00:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2020-02-06 10:56:38 +00:00
|
|
|
}
|