Changed the way how tab label is displayed so it cannot overlap with tab close button

This commit is contained in:
HomeWorld
2011-02-26 16:47:30 +02:00
parent 894fb034f7
commit a2f7e37131
2 changed files with 16 additions and 21 deletions

View File

@@ -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:

View File

@@ -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