Guest User

Untitled

a guest
Mar 24th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. from kivy.lang import Builder
  2. from kivy.base import runTouchApp
  3.  
  4. KV = '''
  5.  
  6. <-ScaleButton@Button>:
  7. x_ratio: min(1, self.width / (self.texture_size[0] or 1))
  8. y_ratio: min(1, self.height / (self.texture_size[1] or 1))
  9. min_ratio: min(self.x_ratio or 1, self.y_ratio or 1)
  10. keep_ratio: False
  11. scale_x: (self.min_ratio or 1) if self.keep_ratio else self.x_ratio or 1
  12. scale_y: (self.min_ratio or 1) if self.keep_ratio else self.y_ratio or 1
  13.  
  14. state_image: self.background_normal if self.state == 'normal' else self.background_down
  15. disabled_image: self.background_disabled_normal if self.state == 'normal' else self.background_disabled_down
  16.  
  17. canvas:
  18. Color:
  19. rgba: self.background_color
  20. BorderImage:
  21. border: self.border
  22. pos: self.pos
  23. size: self.size
  24. source: self.disabled_image if self.disabled else self.state_image
  25. Color:
  26. rgba: 1, 1, 1, 1
  27.  
  28. PushMatrix
  29. Scale:
  30. x: self.scale_x or 1
  31. y: self.scale_y or 1
  32.  
  33. Rectangle:
  34. texture: self.texture
  35. size: self.texture_size
  36. pos:
  37. (
  38. int((self.center_x / (self.scale_x or 1)) - self.texture_size[0] / 2.),
  39. int((self.center_y / (self.scale_y or 1)) - self.texture_size[1] / 2.)
  40. )
  41.  
  42. PopMatrix
  43.  
  44.  
  45. FloatLayout:
  46. ScaleButton:
  47. text: 'test ' * 5
  48. font_size: font_size.value
  49. size_hint: size_hint_x.value, size_hint_y.value
  50. pos_hint: {'center': (.5, .5)}
  51. keep_ratio: lock_ratio.active
  52.  
  53. Slider:
  54. id: size_hint_y
  55. orientation: 'vertical'
  56. size_hint_x: None
  57. value: .5
  58. min: 0
  59. max: 1
  60.  
  61. Slider:
  62. id: size_hint_x
  63. size_hint_y: None
  64. value: .5
  65. min: 0
  66. max: 1
  67.  
  68. Slider:
  69. id: font_size
  70. orientation: 'vertical'
  71. size_hint_x: None
  72. value: 20
  73. min: 10
  74. max: 1000
  75. pos_hint: {'right': 1}
  76.  
  77. BoxLayout:
  78. size: self.minimum_size
  79. size_hint: None, None
  80. pos_hint: {'center': (.5, .8)}
  81.  
  82. CheckBox:
  83. id: lock_ratio
  84. size_hint: None, None
  85. size: 20, 20
  86. Label:
  87. text: 'lock ratio'
  88. size_hint: None, None
  89. size: self.texture_size
  90. ''' # noqa
  91.  
  92.  
  93. runTouchApp(Builder.load_string(KV))
Add Comment
Please, Sign In to add comment