mirror of https://github.com/kivy/kivy.git
Merge pull request #843 from kivy/fix_832
Core:text fix `shorten` routine (was assuming constant letter width)
This commit is contained in:
commit
7c4e941fa4
|
@ -204,9 +204,11 @@ class LabelBase(object):
|
||||||
else:
|
else:
|
||||||
width = int(self.text_size[0])
|
width = int(self.text_size[0])
|
||||||
|
|
||||||
letters = text + '...'
|
letters = ' ... ' + text
|
||||||
letter_width = textwidth(letters) // len(letters)
|
while textwidth(letters) > width:
|
||||||
max_letters = width // letter_width
|
letters = letters[: letters.rfind(' ')]
|
||||||
|
|
||||||
|
max_letters = len(letters) - 2
|
||||||
segment = (max_letters // 2)
|
segment = (max_letters // 2)
|
||||||
|
|
||||||
if segment - margin > 5:
|
if segment - margin > 5:
|
||||||
|
@ -279,7 +281,9 @@ class LabelBase(object):
|
||||||
|
|
||||||
# Shorten the text that we actually display
|
# Shorten the text that we actually display
|
||||||
text = self.text
|
text = self.text
|
||||||
if options['shorten'] and get_extents(text)[0] > uw:
|
last_word_width = get_extents(text[text.rstrip().rfind(' '):])[0]
|
||||||
|
if (options['shorten'] and get_extents(text)[0] >
|
||||||
|
uw - last_word_width):
|
||||||
text = self.shorten(text)
|
text = self.shorten(text)
|
||||||
|
|
||||||
# first, split lines
|
# first, split lines
|
||||||
|
|
Loading…
Reference in New Issue