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