forked from sshivaji/kivy-chess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kivy_util.py
29 lines (23 loc) · 1.08 KB
/
kivy_util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from kivy.resources import resource_find
from kivy.uix.label import Label
from kivy.uix.scrollview import ScrollView
from kivy.graphics import Rectangle
class ScrollableLabel(ScrollView):
def __init__(self, text, ref_callback=None, *args, **kwargs):
super(ScrollableLabel, self).__init__(*args, **kwargs)
with self.canvas:
self.background = Rectangle(source=resource_find("img/panel.png"), size_hint=(1,1))
self.label=Label(text="", size_hint_y=None, pos_hint={'x':0.1, 'y':0.1})
self.label.bind(texture_size=self._set_summary_height, on_ref_press=ref_callback)
self.label.text=text
self.label.markup=True
self.add_widget(self.label)
self.bind(pos=self.change_position)
self.bind(size=self.change_size)
def _set_summary_height(self, instance, size):
instance.height = size[1]
def change_position(self, instance, position):
self.background.pos = position
def change_size(self, instance, size):
self.background.size = size
self.label.text_size = (size[0]-50, None)