mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-21 02:08:12 +03:00
LibWeb: Add CSS::Size::to_string() and an AK::Formatter for it
This commit is contained in:
parent
fdc9dc5729
commit
fce1c673c7
Notes:
sideshowbarker
2024-07-17 20:22:04 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/fce1c673c7
@ -74,4 +74,24 @@ bool Size::contains_percentage() const
|
||||
}
|
||||
}
|
||||
|
||||
String Size::to_string() const
|
||||
{
|
||||
switch (m_type) {
|
||||
case Type::Auto:
|
||||
return "auto";
|
||||
case Type::Length:
|
||||
case Type::Percentage:
|
||||
return m_length_percentage.to_string();
|
||||
case Type::MinContent:
|
||||
return "min-content";
|
||||
case Type::MaxContent:
|
||||
return "max-content";
|
||||
case Type::FitContent:
|
||||
return String::formatted("fit-content({})", m_length_percentage.to_string());
|
||||
case Type::None:
|
||||
return "none";
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -63,6 +63,8 @@ public:
|
||||
return m_length_percentage.length();
|
||||
}
|
||||
|
||||
String to_string() const;
|
||||
|
||||
private:
|
||||
Size(Type type, LengthPercentage);
|
||||
|
||||
@ -71,3 +73,11 @@ private:
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
template<>
|
||||
struct AK::Formatter<Web::CSS::Size> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::Size const& size)
|
||||
{
|
||||
return Formatter<StringView>::format(builder, size.to_string());
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user