ladybird/Userland/Libraries/LibWeb/CSS/Position.h
Sam Atkins d64ddeaec4 LibWeb: Move PositionValue into its own files
It's in Position.{h,cpp} because it represents a <position> in CSS, even
though it's currently named PositionValue to avoid collisions.
2023-03-30 21:29:50 +02:00

53 lines
1.2 KiB
C++

/*
* Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/CSS/Percentage.h>
#include <LibWeb/PixelUnits.h>
namespace Web::CSS {
// FIXME: Named PositionValue to avoid conflicts with enums, but this represents a <position>
struct PositionValue {
enum class HorizontalPreset {
Left,
Center,
Right
};
enum class VerticalPreset {
Top,
Center,
Bottom
};
enum class HorizontalEdge {
Left,
Right
};
enum class VerticalEdge {
Top,
Bottom
};
static PositionValue center()
{
return PositionValue { HorizontalPreset::Center, VerticalPreset::Center };
}
Variant<HorizontalPreset, LengthPercentage> horizontal_position { HorizontalPreset::Left };
Variant<VerticalPreset, LengthPercentage> vertical_position { VerticalPreset::Top };
HorizontalEdge x_relative_to { HorizontalEdge::Left };
VerticalEdge y_relative_to { VerticalEdge::Top };
CSSPixelPoint resolved(Layout::Node const& node, CSSPixelRect const& rect) const;
ErrorOr<void> serialize(StringBuilder&) const;
bool operator==(PositionValue const&) const = default;
};
}