summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/CSS/GridTrackSize.cpp
blob: 5c4e0f478c2beb0dedffdaecf523a49bd1f5c682 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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();
}

}