label: add text_size as a 'size_hint' but for label creation.

(it's an alias to the Label(size=) in core provider (or usersize.))
Before, it was impossible to constraint the text creation to a box, now it's possible.
This commit is contained in:
Mathieu Virbel 2011-02-25 01:35:07 +01:00
parent 17b9c42807
commit 48abacbaf2
1 changed files with 23 additions and 1 deletions

View File

@ -38,7 +38,7 @@ class Label(Widget):
# bind all the property for recreating the texture
d = ('text', 'font_size', 'font_name', 'bold', 'italic', 'halign',
'valign', 'padding_x', 'padding_y')
'valign', 'padding_x', 'padding_y', 'text_size')
dkw = {}
for x in d:
dkw[x] = curry(self._trigger_texture_update, x)
@ -54,6 +54,8 @@ class Label(Widget):
if source:
if name == 'text':
self._label.text = value
elif name == 'text_size':
self._label.usersize = value
else:
self._label.options[name] = value
Clock.unschedule(self.texture_update)
@ -87,6 +89,26 @@ class Label(Widget):
:data:`text` a :class:`~kivy.properties.StringProperty`.
'''
text_size = ListProperty([None, None])
'''By default, the label is not contraint to any bounding box.
You can set the size constraint of the label creation with this property.
For example, whatever is your current widget size, if you want your label to
be created in a box with width=200 and unlimited height::
Label(text='Very big big line', text_size=(200, None))
.. note::
This text_size property is the same as
:data:`~kivy.core.text.Label.usersize` property in
:class:`~kivy.core.text.Label` class. (Even if it's named size= in
constructor.)
:data:`text_size` is a :class:`~kivy.properties.ListProperty` instance,
default to (None, None). Mean they are no size restriction by default.
'''
font_name = StringProperty('fonts/DroidSans.ttf')
'''File of the font to use. The path used for the font can be a absolute
path, or a relative path that will be search with the