mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:47:34 +00:00
LibWeb: Refactor GridTrackPlacement
Refactor this class for quality-of-life reasons as well as to better prepare for the addition of line names.
This commit is contained in:
parent
b2b677e984
commit
1a4f2dca38
2 changed files with 18 additions and 9 deletions
|
@ -9,9 +9,9 @@
|
||||||
|
|
||||||
namespace Web::CSS {
|
namespace Web::CSS {
|
||||||
|
|
||||||
GridTrackPlacement::GridTrackPlacement(int span_or_position, bool has_span)
|
GridTrackPlacement::GridTrackPlacement(int span_count_or_position, bool has_span)
|
||||||
: m_type(has_span ? Type::Span : Type::Position)
|
: m_type(has_span ? Type::Span : Type::Position)
|
||||||
, m_value(span_or_position)
|
, m_span_count_or_position(span_count_or_position)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,9 +23,18 @@ GridTrackPlacement::GridTrackPlacement()
|
||||||
String GridTrackPlacement::to_string() const
|
String GridTrackPlacement::to_string() const
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
if (is_span())
|
if (is_auto()) {
|
||||||
builder.append("span "sv);
|
builder.append("auto"sv);
|
||||||
builder.append(String::number(m_value));
|
return builder.to_string();
|
||||||
|
}
|
||||||
|
if (is_span()) {
|
||||||
|
builder.append("span"sv);
|
||||||
|
builder.append(" "sv);
|
||||||
|
}
|
||||||
|
if (m_span_count_or_position != 0) {
|
||||||
|
builder.append(String::number(m_span_count_or_position));
|
||||||
|
builder.append(" "sv);
|
||||||
|
}
|
||||||
return builder.to_string();
|
return builder.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ public:
|
||||||
Auto
|
Auto
|
||||||
};
|
};
|
||||||
|
|
||||||
GridTrackPlacement(int, bool = false);
|
GridTrackPlacement(int span_count_or_position, bool has_span = false);
|
||||||
GridTrackPlacement();
|
GridTrackPlacement();
|
||||||
|
|
||||||
static GridTrackPlacement make_auto() { return GridTrackPlacement(); };
|
static GridTrackPlacement make_auto() { return GridTrackPlacement(); };
|
||||||
|
@ -28,18 +28,18 @@ public:
|
||||||
bool is_auto() const { return m_type == Type::Auto; }
|
bool is_auto() const { return m_type == Type::Auto; }
|
||||||
bool is_auto_positioned() const { return m_type == Type::Auto || m_type == Type::Span; }
|
bool is_auto_positioned() const { return m_type == Type::Auto || m_type == Type::Span; }
|
||||||
|
|
||||||
int raw_value() const { return m_value; }
|
int raw_value() const { return m_span_count_or_position; }
|
||||||
Type type() const { return m_type; }
|
Type type() const { return m_type; }
|
||||||
|
|
||||||
String to_string() const;
|
String to_string() const;
|
||||||
bool operator==(GridTrackPlacement const& other) const
|
bool operator==(GridTrackPlacement const& other) const
|
||||||
{
|
{
|
||||||
return m_type == other.type() && m_value == other.raw_value();
|
return m_type == other.type() && m_span_count_or_position == other.raw_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Type m_type;
|
Type m_type;
|
||||||
int m_value { 0 };
|
int m_span_count_or_position { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue