mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 20:28:11 +00:00
LibWeb: Add GridTrackSize class for grid-template-*
Add GridTrackSize to be used with grid-template-column and grid-template-row.
This commit is contained in:
parent
e4c5799026
commit
fc36970973
4 changed files with 103 additions and 0 deletions
46
Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp
Normal file
46
Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Martin Falisse <mfalisse@outlook.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "GridTrackSize.h"
|
||||
#include <AK/String.h>
|
||||
#include <LibWeb/CSS/Length.h>
|
||||
#include <LibWeb/CSS/Percentage.h>
|
||||
#include <LibWeb/CSS/StyleValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
GridTrackSize::GridTrackSize(Length length)
|
||||
: m_type(Type::Length)
|
||||
, m_length(length)
|
||||
{
|
||||
}
|
||||
|
||||
GridTrackSize::GridTrackSize(Percentage percentage)
|
||||
: m_type(Type::Percentage)
|
||||
, m_percentage(percentage)
|
||||
{
|
||||
}
|
||||
|
||||
GridTrackSize::GridTrackSize(int flexible_length)
|
||||
: m_type(Type::FlexibleLength)
|
||||
, m_flexible_length(flexible_length)
|
||||
{
|
||||
}
|
||||
|
||||
String GridTrackSize::to_string() const
|
||||
{
|
||||
switch (m_type) {
|
||||
case Type::Length:
|
||||
return m_length.to_string();
|
||||
case Type::Percentage:
|
||||
return m_percentage.to_string();
|
||||
case Type::FlexibleLength:
|
||||
return String::formatted("{}fr", m_flexible_length);
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue