Length.h 873 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #pragma once
  2. #include <AK/AKString.h>
  3. class Length {
  4. public:
  5. enum class Type {
  6. Auto,
  7. Absolute,
  8. };
  9. Length() {}
  10. Length(int value, Type type)
  11. : m_type(type)
  12. , m_value(value)
  13. {
  14. }
  15. ~Length() {}
  16. bool is_auto() const { return m_type == Type::Auto; }
  17. bool is_absolute() const { return m_type == Type::Absolute; }
  18. int value() const { return m_value; }
  19. String to_string() const
  20. {
  21. if (is_auto())
  22. return "auto";
  23. return String::format("%d [Length/Absolute]", m_value);
  24. }
  25. int to_px() const
  26. {
  27. if (is_auto())
  28. return 0;
  29. return m_value;
  30. }
  31. private:
  32. Type m_type { Type::Auto };
  33. int m_value { 0 };
  34. };
  35. inline const LogStream& operator<<(const LogStream& stream, const Length& value)
  36. {
  37. return stream << value.to_string();
  38. }