Advertisement
bulbigood

Untitled

Jan 25th, 2020
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.77 KB | None | 0 0
  1. interface Rect {
  2.     var x: Float
  3.     var y: Float
  4.     var width: Float
  5.     var height: Float
  6. }
  7.  
  8. class UIRect: Rect {
  9.     override var x: Float = 0f
  10.     override var y: Float = 0f
  11.     override var width: Float = 1f
  12.     override var height: Float = 1f
  13.  
  14.     operator fun getValue(rect: Rect, property: KProperty<*>): Rect {
  15.         x = rect.x
  16.         y = rect.y
  17.         width = rect.width
  18.         height = rect.height
  19.         return this
  20.     }
  21. }
  22.  
  23. class ScalableUIRect(
  24.     private val scaleBehavior: ScalableRectBehavior
  25. ): Rect by UIRect() {
  26.  
  27.     private val cachedRect: Rect by UIRect()
  28.  
  29.     fun getScaledRect(viewWidth: Float, viewHeight: Float, scale: Float): Rect {
  30.         return scaleBehavior.scale(cachedRect, viewWidth, viewHeight, scale)
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement