Merge branch 'master' of github.com:kivy/kivy

This commit is contained in:
tshirtman 2012-11-27 01:42:51 +01:00
commit fc62285c9e
5 changed files with 58 additions and 7 deletions

View File

@ -0,0 +1,34 @@
'''
Label textsize
============
This example shows how the textsize and line_height property are used
to format label widget
'''
import kivy
kivy.require('1.0.7')
from kivy.app import App
from kivy.uix.label import Label
_long_text = """
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus odio nisi, pellentesque molestie adipiscing vitae, aliquam at tellus. Fusce quis est ornare erat pulvinar elementum ut sed felis. Donec vel neque mauris. In sit amet nunc sit amet diam dapibus lacinia. In sodales placerat mauris, ut euismod augue laoreet at. Integer in neque non odio fermentum volutpat nec nec nulla. Donec et risus non mi viverra posuere. Phasellus cursus augue purus, eget volutpat leo. Phasellus sed dui vitae ipsum mattis facilisis vehicula eu justo.
Quisque neque dolor, egestas sed venenatis eget, porta id ipsum. Ut faucibus, massa vitae imperdiet rutrum, sem dolor rhoncus magna, non lacinia nulla risus non dui. Nulla sit amet risus orci. Nunc libero justo, interdum eu pulvinar vel, pulvinar et lectus. Phasellus sed luctus diam. Pellentesque non feugiat dolor. Cras at dolor velit, gravida congue velit. Aliquam erat volutpat. Nullam eu nunc dui, quis sagittis dolor. Ut nec dui eget odio pulvinar placerat. Pellentesque mi metus, tristique et placerat ac, pulvinar vel quam. Nam blandit magna a urna imperdiet molestie. Nullam ut nisi eget enim laoreet sodales sit amet a felis.
"""
class LabelTextSizeTest(App):
def build(self):
l = Label(
text=_long_text,
text_size = (600,None),
line_height=1.5
)
return l
if __name__ == '__main__':
LabelTextSizeTest().run()

View File

@ -286,7 +286,7 @@ class App(EventDispatcher):
self._app_name = None
self._app_settings = None
self._app_window = None
super(App, self).__init__()
super(App, self).__init__(**kwargs)
self.register_event_type('on_start')
self.register_event_type('on_stop')
self.register_event_type('on_pause')

View File

@ -5,6 +5,9 @@ Text
Abstraction of text creation. Depending of the selected backend, the text
rendering can be more or less accurate.
.. versionchanged:: 1.5.0
:data:`LabelBase.line_height` added.
.. versionchanged:: 1.0.7
The :class:`LabelBase` don't generate any texture is the text have a width
<= 1.
@ -84,12 +87,12 @@ class LabelBase(object):
def __init__(self, text='', font_size=12, font_name=DEFAULT_FONT,
bold=False, italic=False, halign='left', valign='bottom',
shorten=False, text_size=None, mipmap=False, color=None,
**kwargs):
line_height=1.0, **kwargs):
options = {'text': text, 'font_size': font_size,
'font_name': font_name, 'bold': bold, 'italic': italic,
'halign': halign, 'valign': valign, 'shorten': shorten,
'mipmap': mipmap}
'mipmap': mipmap, 'line_height': line_height}
options['color'] = color or (1, 1, 1, 1)
options['padding'] = kwargs.get('padding', 0)
@ -245,6 +248,7 @@ class LabelBase(object):
if uw is None:
for line in self.text.split('\n'):
lw, lh = get_extents(line)
lh = lh * options['line_height']
if real:
x = 0
if halign == 'center':
@ -292,6 +296,7 @@ class LabelBase(object):
gw, gh = cache[glyph]
ww += gw
wh = max(gh, wh)
wh = wh * options['line_height']
# is the word fit on the uw ?
if ww > uw:
@ -301,7 +306,6 @@ class LabelBase(object):
# get the maximum height for this line
lh = max(wh, lh)
# is the word fit on the line ?
if (word == '\n' or x + ww > uw) and lw != 0:
# no, push actuals glyph
@ -327,6 +331,9 @@ class LabelBase(object):
if not real:
self._internal_height = sum([size[1] for size, glyphs in lines])
ll_h = lines[-1][0][1]
lh_offset = ll_h - (ll_h / self.options['line_height'])
self._internal_height = self._internal_height - lh_offset
h = self._internal_height if uh is None else uh
w = uw
else:

View File

@ -222,7 +222,7 @@ class MarkupLabel(MarkupLabelBase):
uw, uh = self.text_size
# split the word
default_line_height = get_extents(' ')[1]
default_line_height = get_extents(' ')[1] * self.options['line_height']
for part in re.split(r'( |\n)', word):
if part == '':
@ -244,7 +244,7 @@ class MarkupLabel(MarkupLabelBase):
pg = [cache[g] for g in part]
pw = get_extents(part)[0]
ph = max([g[1] for g in pg])
ph = ph * self.options['line_height']
options = copy(options)
# check if the part can be put in the line

View File

@ -117,7 +117,7 @@ class Label(Widget):
_font_properties = ('text', 'font_size', 'font_name', 'bold', 'italic',
'halign', 'valign', 'padding_x', 'padding_y', 'text_size', 'shorten',
'mipmap', 'markup')
'mipmap', 'markup', 'line_height')
def __init__(self, **kwargs):
self._trigger_texture = Clock.create_trigger(self.texture_update, -1)
@ -284,6 +284,16 @@ class Label(Widget):
12dp.
'''
line_height = NumericProperty(1.0)
'''Line Height for the text. e.g. line_height = 2 will cause the spacing
between lines to be twice the size.
:data:`line_height` is a :class:`~kivy.properties.NumericProperty`, default to
1.0.
.. versionadded:: 1.5.0
'''
bold = BooleanProperty(False)
'''Indicates use of the bold version of your font.