ComputedValues.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "../../Include/RmlUi/Core/ComputedValues.h"
  2. #include "../../Include/RmlUi/Core/Element.h"
  3. #include "ComputeProperty.h"
  4. namespace Rml {
  5. const AnimationList* Style::ComputedValues::animation() const
  6. {
  7. if (auto p = element->GetLocalProperty(PropertyId::Animation))
  8. {
  9. if (p->unit == Unit::ANIMATION)
  10. return &(p->value.GetReference<AnimationList>());
  11. }
  12. return nullptr;
  13. }
  14. const TransitionList* Style::ComputedValues::transition() const
  15. {
  16. if (auto p = element->GetLocalProperty(PropertyId::Transition))
  17. {
  18. if (p->unit == Unit::TRANSITION)
  19. return &(p->value.GetReference<TransitionList>());
  20. }
  21. return nullptr;
  22. }
  23. String Style::ComputedValues::font_family() const
  24. {
  25. if (auto p = element->GetProperty(PropertyId::FontFamily))
  26. return ComputeFontFamily(p->Get<String>());
  27. return String();
  28. }
  29. String Style::ComputedValues::cursor() const
  30. {
  31. if (auto p = element->GetProperty(PropertyId::Cursor))
  32. return p->Get<String>();
  33. return String();
  34. }
  35. float Style::ComputedValues::letter_spacing() const
  36. {
  37. if (inherited.has_letter_spacing)
  38. {
  39. if (auto p = element->GetProperty(PropertyId::LetterSpacing))
  40. return element->ResolveLength(p->GetNumericValue());
  41. }
  42. return 0.f;
  43. }
  44. float ResolveValueOr(Style::LengthPercentageAuto length, float base_value, float default_value)
  45. {
  46. if (length.type == Style::LengthPercentageAuto::Length)
  47. return length.value;
  48. else if (length.type == Style::LengthPercentageAuto::Percentage && base_value >= 0.f)
  49. return length.value * 0.01f * base_value;
  50. return default_value;
  51. }
  52. float ResolveValueOr(Style::LengthPercentage length, float base_value, float default_value)
  53. {
  54. if (length.type == Style::LengthPercentage::Length)
  55. return length.value;
  56. else if (length.type == Style::LengthPercentage::Percentage && base_value >= 0.f)
  57. return length.value * 0.01f * base_value;
  58. return default_value;
  59. }
  60. } // namespace Rml