GridTrackSize.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (c) 2022, Martin Falisse <mfalisse@outlook.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/CSS/Length.h>
  8. #include <LibWeb/CSS/Percentage.h>
  9. namespace Web::CSS {
  10. class GridTrackSize {
  11. public:
  12. enum class Type {
  13. Length,
  14. Percentage,
  15. FlexibleLength,
  16. // TODO: MinMax
  17. // TODO: Repeat
  18. // TODO: Max-Content
  19. };
  20. GridTrackSize(Length);
  21. GridTrackSize(Percentage);
  22. GridTrackSize(float);
  23. Type type() const { return m_type; }
  24. bool is_length() const { return m_type == Type::Length; }
  25. bool is_percentage() const { return m_type == Type::Percentage; }
  26. bool is_flexible_length() const { return m_type == Type::FlexibleLength; }
  27. Length length() const { return m_length; }
  28. Percentage percentage() const { return m_percentage; }
  29. float flexible_length() const { return m_flexible_length; }
  30. String to_string() const;
  31. bool operator==(GridTrackSize const& other) const
  32. {
  33. return m_type == other.type()
  34. && m_length == other.length()
  35. && m_percentage == other.percentage()
  36. && m_flexible_length == other.flexible_length();
  37. }
  38. private:
  39. Type m_type;
  40. Length m_length { Length::make_px(0) };
  41. Percentage m_percentage { Percentage(0) };
  42. float m_flexible_length { 0 };
  43. };
  44. }