mirror of https://github.com/kivy/kivy.git
core:text make shorten work with a single word. closes #1334
This commit is contained in:
parent
3b2d493e50
commit
cf5fc48229
|
@ -203,15 +203,15 @@ class LabelBase(object):
|
|||
|
||||
def shorten(self, text, margin=2):
|
||||
# Just a tiny shortcut
|
||||
textwidth = lambda txt: self.get_extents(txt)[0]
|
||||
textwidth = self.get_extents
|
||||
if self.text_size[0] is None:
|
||||
width = 0
|
||||
else:
|
||||
width = int(self.text_size[0])
|
||||
|
||||
letters = ' ... ' + text
|
||||
while textwidth(letters) > width:
|
||||
letters = letters[: letters.rfind(' ')]
|
||||
letters = '_..._' + text
|
||||
while textwidth(letters)[0] > width:
|
||||
letters = letters[:letters.rfind(' ')]
|
||||
|
||||
max_letters = len(letters) - 2
|
||||
segment = (max_letters // 2)
|
||||
|
|
Loading…
Reference in New Issue