mirror of https://github.com/kivy/kivy.git
add line_height property to label
This commit is contained in:
parent
dfb9930da9
commit
44492e2ea4
|
@ -84,12 +84,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 +245,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 +293,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 +303,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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
'''
|
||||
|
||||
|
||||
|
||||
bold = BooleanProperty(False)
|
||||
'''Indicates use of the bold version of your font.
|
||||
|
||||
|
|
Loading…
Reference in New Issue