Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2013-03-12 16:11:28 (GMT)
committer Walter Bender <walter.bender@gmail.com>2013-03-12 16:11:28 (GMT)
commitdf07f5d3cbc595a8150de2a1a2ba3a8c3347af6d (patch)
tree96aa3d3c9f39aa133727362c763c7123a70f0864
parentebfc547ab50b5084a25d7a14445f886fbacf8a64 (diff)
add word wrap and ellipsize to label
-rw-r--r--sprites.py15
1 files changed, 7 insertions, 8 deletions
diff --git a/sprites.py b/sprites.py
index baae94f..04e696a 100644
--- a/sprites.py
+++ b/sprites.py
@@ -364,6 +364,8 @@ class Sprite:
my_height = self.rect.height - self._margins[1] - self._margins[3]
for i in range(len(self.labels)):
pl = cr.create_layout()
+ pl.set_wrap(pango.WRAP_WORD)
+ pl.set_width(my_width * pango.SCALE)
pl.set_text(str(self.labels[i]))
self._fd.set_size(int(self._scale[i] * pango.SCALE))
pl.set_font_description(self._fd)
@@ -375,14 +377,11 @@ class Sprite:
pl.set_font_description(self._fd)
w = pl.get_size()[0] / pango.SCALE
else:
- j = len(self.labels[i]) - 1
- while(w > my_width and j > 0):
- pl.set_text(
- "…" + self.labels[i][len(self.labels[i]) - j:])
- self._fd.set_size(int(self._scale[i] * pango.SCALE))
- pl.set_font_description(self._fd)
- w = pl.get_size()[0] / pango.SCALE
- j -= 1
+ self._fd.set_size(
+ int(self._scale[i] * pango.SCALE * my_width / w))
+ pl.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
+ pl.set_font_description(self._fd)
+ w = pl.get_size()[0] / pango.SCALE
if self._horiz_align[i] == "center":
x = int(self.rect.x + self._margins[0] + (my_width - w) / 2)
elif self._horiz_align[i] == 'left':