mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:48:12 +00:00
LibCore: Make Core::Object properties more dynamic
Instead of everyone overriding save_to() and set_property() and doing a pretty asymmetric job of implementing the various properties, let's add a bit of structure here. Object properties are now represented by a Core::Property. Properties are registered with a getter and setter (optional) in constructors. I've added some convenience macros for creating and registering properties, but this does still feel a bit bulky. We'll have to iterate on this and see where it goes.
This commit is contained in:
parent
1e96e46a81
commit
e2f32b8f9d
23 changed files with 373 additions and 250 deletions
|
@ -31,13 +31,18 @@
|
|||
|
||||
namespace Gfx {
|
||||
|
||||
#define GFX_ENUMERATE_TEXT_ALIGNMENTS(M) \
|
||||
M(TopLeft) \
|
||||
M(CenterLeft) \
|
||||
M(Center) \
|
||||
M(CenterRight) \
|
||||
M(TopRight) \
|
||||
M(BottomRight)
|
||||
|
||||
enum class TextAlignment {
|
||||
TopLeft,
|
||||
CenterLeft,
|
||||
Center,
|
||||
CenterRight,
|
||||
TopRight,
|
||||
BottomRight,
|
||||
#define __ENUMERATE(x) x,
|
||||
GFX_ENUMERATE_TEXT_ALIGNMENTS(__ENUMERATE)
|
||||
#undef __ENUMERATE
|
||||
};
|
||||
|
||||
inline bool is_right_text_alignment(TextAlignment alignment)
|
||||
|
@ -54,18 +59,21 @@ inline bool is_right_text_alignment(TextAlignment alignment)
|
|||
|
||||
inline Optional<TextAlignment> text_alignment_from_string(const StringView& string)
|
||||
{
|
||||
if (string == "TopLeft")
|
||||
return TextAlignment::TopLeft;
|
||||
if (string == "CenterLeft")
|
||||
return TextAlignment::CenterLeft;
|
||||
if (string == "Center")
|
||||
return TextAlignment::Center;
|
||||
if (string == "CenterRight")
|
||||
return TextAlignment::CenterRight;
|
||||
if (string == "TopRight")
|
||||
return TextAlignment::TopRight;
|
||||
if (string == "BottomRight")
|
||||
return TextAlignment::BottomRight;
|
||||
#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 {};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue