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