Length.h 747 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. };