From a2f7e371311970bfe044ae00f0ca5226869196ba Mon Sep 17 00:00:00 2001 From: HomeWorld Date: Sat, 26 Feb 2011 16:47:30 +0200 Subject: [PATCH] Changed the way how tab label is displayed so it cannot overlap with tab close button --- gui/chromeTabs.py | 31 +++++++++++++------------------ gui/utils/drawUtils.py | 6 +++--- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/gui/chromeTabs.py b/gui/chromeTabs.py index 1dc413822..621011954 100644 --- a/gui/chromeTabs.py +++ b/gui/chromeTabs.py @@ -13,6 +13,7 @@ import wx.lib.newevent import copy import time import gui.utils.colorUtils as colorUtils +import gui.utils.drawUtils as drawUtils from gui import bitmapLoader _PageChanging, EVT_NOTEBOOK_PAGE_CHANGING = wx.lib.newevent.NewEvent() @@ -479,27 +480,21 @@ class PFTabRenderer: textStart = self.leftWidth mdc.SetFont(self.font) - text = self.text - fnwidths = mdc.GetPartialTextExtents(text) - count = 0 - maxsize = self.tabWidth - textStart - self.rightWidth - self.padding*2 - for i in fnwidths: - if i <= maxsize: - count +=1 - else: - break - if count > 0: - text = "%s" % text[:count] - tx,ty = mdc.GetTextExtent(text) - if self.selected: - color = self.selectedColor - else: - color = self.inactiveColor + maxsize = self.tabWidth - textStart - self.rightWidth - self.padding*4 - mdc.SetTextForeground(colorUtils.GetSuitableColor(color, 1)) + if self.selected: + color = self.selectedColor + else: + color = self.inactiveColor - mdc.DrawText(text, textStart + self.padding , height / 2 - ty / 2) + mdc.SetTextForeground(colorUtils.GetSuitableColor(color, 1)) + + text = drawUtils.GetPartialText(mdc, self.text, maxsize, "") + + tx,ty = mdc.GetTextExtent(text) + + mdc.DrawText(text, textStart + self.padding , height / 2 - ty / 2) if self.closeButton: if self.closeBtnHovering: diff --git a/gui/utils/drawUtils.py b/gui/utils/drawUtils.py index 752bd4c62..07bb3317f 100644 --- a/gui/utils/drawUtils.py +++ b/gui/utils/drawUtils.py @@ -56,15 +56,15 @@ def DrawGradientBar(width, height, gStart, gEnd, gMid = None): return canvas -def GetPartialText(dc, text , maxWidth): - ellipsis = "..." +def GetPartialText(dc, text , maxWidth, defEllipsis = "..."): + ellipsis = defEllipsis base_w, h = dc.GetTextExtent(ellipsis) lenText = len(text) drawntext = text w, dummy = dc.GetTextExtent(text) - while lenText > 1: + while lenText > 0: if w + base_w <= maxWidth: break